Multihost Configuration

MultihostConfig has access to the whole configuration file that is used to run the tests. Its main purpose is to map domain identifier into a Python class that will be used to create the domain object.

Basic example of MultihostConfig
 1class MyProjectConfig(MultihostConfig):
 2    @property
 3    def id_to_domain_class(self) -> dict[str, Type[MultihostDomain]]:
 4        """
 5        Map domain id to domain class. Asterisk ``*`` can be used as fallback
 6        value.
 7
 8        :rtype: Class name.
 9        """
10        return {
11            "example": MyProjectExampleDomain,
12            "*": MyProjectGenericDomain
13        }

However, it can also be used to add a custom top-level configuration options or extend the functionality of pytest.mark.topology marker. The configuration file contents can be accessed as a dictionary through confdict, however it is recommended to place custom options under the config field which can be accessed directly through the config attribute. This way, it is possible to avoid name collisions if pytest-mh introduces new options in the future.

It is also possible to override or extend all public methods to further affect the behavior.

Custom configuration option and topology marker
 1class MyProjectConfig(MultihostConfig):
 2    @property
 3    def required_fields(self) -> list[str]:
 4        """
 5        Fields that must be set in the host configuration. An error is raised
 6        if any field is missing.
 7
 8        The field name may contain a ``.`` to check nested fields.
 9        """
10        return super().required_fields + ["config.my_config_required_option"]
11
12    @property
13    def my_config_option(self) -> bool:
14        return self.config.get("my_config_option", False)
15
16    @property
17    def my_config_required_option(self) -> bool:
18        # This option is required and pytest will error if
19        # it is not present in the configuration
20        return self.config.get("my_config_required_option")
21
22    @property
23    def TopologyMarkClass(self) -> Type[TopologyMark]:
24        # Set a custom topology marker type
25        return MyProjectTopologyMark
26
27    @property
28    def id_to_domain_class(self) -> dict[str, Type[MultihostDomain]]:
29        """
30        Map domain id to domain class. Asterisk ``*`` can be used as fallback
31        value.
32
33        :rtype: Class name.
34        """
35        return {"*": SSSDMultihostDomain}
1config:
2    my_config_option: True
3    my_config_required_option: True
4domains:
5- id: example
6  hosts:
7  - hostname: client.test
8    role: client