Exemplo n.º 1
0
 def test_missing_required_key_raises_node_configuration_error(
     self, key, minimal_definition_dict
 ):
     """OMissing required keys in the config dict raises an Exception."""
     minimal_definition_dict["nodes"].pop(key)
     with pytest.raises(Exception):
         NodesConfig(minimal_definition_dict)
Exemplo n.º 2
0
    def __init__(
        self,
        yaml_path: pathlib.Path,
        data_path: pathlib.Path,
        environment: EnvironmentConfig,
    ) -> None:
        self._scenario_dir = None
        self.path = yaml_path
        # Use the scenario file as jinja template and only parse the yaml, afterwards.
        with yaml_path.open() as f:
            yaml_template = jinja2.Template(f.read(),
                                            undefined=jinja2.StrictUndefined)
            rendered_yaml = yaml_template.render(**asdict(environment))
            self._loaded = yaml.safe_load(rendered_yaml)

        self.settings = SettingsConfig(self._loaded, environment)
        self.settings.sp_root_dir = data_path
        self.token = TokenConfig(self._loaded,
                                 self.scenario_dir.joinpath("token.info"))
        deploy_token = self.token.address is None
        self.nodes = NodesConfig(
            self._loaded, environment="development" if deploy_token else None)
        self.scenario = ScenarioConfig(self._loaded)

        # If the environment sets a list of matrix servers, the nodes must not
        # choose other servers, so let's set the first server from the list as
        # default.
        self.nodes.dict["default_options"][
            "matrix-server"] = environment.matrix_servers[0]
        self.nodes.dict["default_options"][
            "environment-type"] = environment.environment_type
Exemplo n.º 3
0
    def test_class_returns_required_keys(self, key, minimal_definition_dict):
        """Required keys are accessible via identically named class attributes."""
        config = NodesConfig(minimal_definition_dict)

        try:
            actual = getattr(config, key)
        except AttributeError as e:
            raise AssertionError(e)

        assert minimal_definition_dict["nodes"][key] == actual
Exemplo n.º 4
0
    def test_class_returns_expected_default_for_key(
        self, key, expected_defaults, minimal_definition_dict
    ):
        """If supported  keys are absent, sensible defaults are returned for them when accessing
        them as a class attribute."""
        config = NodesConfig(minimal_definition_dict)

        try:
            actual = getattr(config, key)
        except AttributeError as e:
            raise AssertionError(e)

        assert expected_defaults["nodes"][key] == actual
Exemplo n.º 5
0
 def test_instantiating_with_an_empty_dict_raises_node_configuration_error(self):
     """Passing the NodeConfig class an empty dict is not allowed."""
     with pytest.raises(Exception):
         NodesConfig({})
Exemplo n.º 6
0
 def test_is_subclass_of_config_mapping(self, minimal_definition_dict):
     """The class is a subclass of :class:`ConfigMapping`."""
     assert isinstance(NodesConfig(minimal_definition_dict), ConfigMapping)