Ejemplo n.º 1
0
    def test_deserialize_basic(self):
        c = ConfigDeserializer.deserialize(
            core={"num_workers": 30},
            user_defined={"my_opt": True},
            logging={
                "file": "",
                "level": "DEBUG"
            },
            ssh={"config_file": "~/.ssh/alt_config"},
            inventory={
                "plugin": "nornir.plugins.inventory.ansible.AnsibleInventory"
            },
        )
        assert isinstance(c, Config)

        assert c.core.num_workers == 30
        assert not c.core.raise_on_error
        assert c.user_defined == {"my_opt": True}

        assert c.logging.enabled is None
        assert c.logging.level == "DEBUG"
        assert c.logging.file == ""
        assert c.logging.format == DEFAULT_LOG_FORMAT
        assert not c.logging.to_console

        assert c.ssh.config_file == str(Path("~/.ssh/alt_config").expanduser())

        assert c.inventory.plugin == AnsibleInventory
        assert c.inventory.options == {}
        assert c.inventory.transform_function is None
        assert c.inventory.transform_function_options == {}
Ejemplo n.º 2
0
 def test_configuration_file_override_env(self):
     os.environ["NORNIR_CORE_NUM_WORKERS"] = "30"
     os.environ["NORNIR_CORE_RAISE_ON_ERROR"] = "1"
     os.environ["NORNIR_SSH_CONFIG_FILE"] = "/user/ssh_config"
     config = ConfigDeserializer.deserialize()
     assert config.core.num_workers == 30
     assert config.core.raise_on_error
     assert config.ssh.config_file == "/user/ssh_config"
     os.environ.pop("NORNIR_CORE_NUM_WORKERS")
     os.environ.pop("NORNIR_CORE_RAISE_ON_ERROR")
     os.environ.pop("NORNIR_SSH_CONFIG_FILE")
Ejemplo n.º 3
0
    def test_deserialize_defaults(self):
        c = ConfigDeserializer.deserialize()
        assert isinstance(c, Config)

        assert c.core.num_workers == 20
        assert not c.core.raise_on_error
        assert c.user_defined == {}

        assert c.logging.level == logging.DEBUG
        assert c.logging.file == "nornir.log"
        assert c.logging.format == DEFAULT_LOG_FORMAT
        assert not c.logging.to_console
        assert c.logging.loggers == ["nornir"]

        assert c.ssh.config_file == "~/.ssh/config"

        assert c.inventory.plugin == SimpleInventory
        assert c.inventory.options == {}
        assert c.inventory.transform_function is None
Ejemplo n.º 4
0
 def test_configuration_bool_env(self):
     os.environ["NORNIR_CORE_RAISE_ON_ERROR"] = "0"
     config = ConfigDeserializer.deserialize()
     assert config.core.num_workers == 20
     assert not config.core.raise_on_error
Ejemplo n.º 5
0
 def test_jinja_filters_error(self):
     with pytest.raises(ModuleNotFoundError):
         ConfigDeserializer.deserialize(jinja2={"filters": "asdasd.asdasd"})
Ejemplo n.º 6
0
 def test_jinja_filters(self):
     c = ConfigDeserializer.deserialize(jinja2={
         "filters":
         "tests.core.deserializer.my_jinja_filters.jinja_filters"
     })
     assert c.jinja2.filters == my_jinja_filters.jinja_filters()