def test_config_from_dict_defaults(self): c = Config.from_dict() assert c.dict() == { "core": { "raise_on_error": False }, "runner": { "options": {}, "plugin": "threaded" }, "inventory": { "plugin": "SimpleInventory", "options": {}, "transform_function": "", "transform_function_options": {}, }, "ssh": { "config_file": str(Path("~/.ssh/config").expanduser()) }, "logging": { "enabled": True, "level": "INFO", "log_file": "nornir.log", "format": DEFAULT_LOG_FORMAT, "to_console": False, "loggers": ["nornir"], }, "user_defined": {}, }
def InitNornir( config_file: str = "", dry_run: bool = False, **kwargs: Any, ) -> Nornir: """ Arguments: config_file(str): Path to the configuration file (optional) dry_run(bool): Whether to simulate changes or not configure_logging: Whether to configure logging or not. This argument is being deprecated. Please use logging.enabled parameter in the configuration instead. **kwargs: Extra information to pass to the :obj:`nornir.core.configuration.Config` object Returns: :obj:`nornir.core.Nornir`: fully instantiated and configured """ ConnectionPluginRegister.auto_register() if config_file: config = Config.from_file(config_file, **kwargs) else: config = Config.from_dict(**kwargs) data = GlobalState(dry_run=dry_run) config.logging.configure() return Nornir( inventory=load_inventory(config), runner=load_runner(config), config=config, data=data, )
def test_configuration_file_override_env(self): os.environ["NORNIR_CORE_RAISE_ON_ERROR"] = "1" os.environ["NORNIR_SSH_CONFIG_FILE"] = "/user/ssh_config" config = Config.from_dict(inventory={"plugin": "an-inventory"}) assert config.core.raise_on_error assert config.ssh.config_file == "/user/ssh_config" os.environ.pop("NORNIR_CORE_RAISE_ON_ERROR") os.environ.pop("NORNIR_SSH_CONFIG_FILE")
def test_config_basic(self): c = Config.from_dict( inventory={"plugin": "an-inventory"}, runner={ "plugin": "serial", "options": { "a": 1, "b": 2 } }, logging={"log_file": ""}, user_defined={"my_opt": True}, ) assert c.dict() == { "inventory": { "plugin": "an-inventory", "options": {}, "transform_function": "", "transform_function_options": {}, }, "runner": { "options": { "a": 1, "b": 2 }, "plugin": "serial" }, "ssh": { "config_file": str(Path("~/.ssh/config").expanduser()) }, "logging": { "enabled": True, "level": "INFO", "log_file": "", "format": DEFAULT_LOG_FORMAT, "to_console": False, "loggers": ["nornir"], }, "core": { "raise_on_error": False }, "user_defined": { "my_opt": True }, }
def test_configuration_bool_env(self): os.environ["NORNIR_CORE_RAISE_ON_ERROR"] = "0" config = Config.from_dict(inventory={"plugin": "an-inventory"}) assert not config.core.raise_on_error