def test_order_of_resolution_code_is_higher_than_env(self): os.environ["NORNIR_CORE_NUM_WORKERS"] = "20" config = ConfigDeserializer.load_from_file(os.path.join( dir_path, "config.yaml"), core={"num_workers": 30}) os.environ.pop("NORNIR_CORE_NUM_WORKERS") assert config.core.num_workers == 30
def test_configuration_file_empty(self): config = ConfigDeserializer.load_from_file(os.path.join( dir_path, "empty.yaml"), user_defined={"asd": "qwe"}) assert config.user_defined["asd"] == "qwe" assert config.core.num_workers == 20 assert not config.core.raise_on_error assert config.inventory.plugin == SimpleInventory
def InitNornir( config_file: str = "", dry_run: bool = False, configure_logging: Optional[bool] = None, **kwargs: Dict[str, 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 """ register_default_connection_plugins() if callable(kwargs.get("inventory", {}).get("plugin", "")): kwargs["inventory"]["plugin"] = cls_to_string(kwargs["inventory"]["plugin"]) if callable(kwargs.get("inventory", {}).get("transform_function", "")): kwargs["inventory"]["transform_function"] = cls_to_string( kwargs["inventory"]["transform_function"] ) conf = Config.load_from_file(config_file, **kwargs) data = GlobalState(dry_run=dry_run) if configure_logging is not None: msg = ( "'configure_logging' argument is deprecated, please use " "'logging.enabled' parameter in the configuration instead: " "https://nornir.readthedocs.io/en/stable/configuration/index.html" ) warnings.warn(msg, DeprecationWarning) if conf.logging.enabled is None: if configure_logging is not None: conf.logging.enabled = configure_logging else: conf.logging.enabled = True conf.logging.configure() inv = conf.inventory.plugin.deserialize( transform_function=conf.inventory.transform_function, transform_function_options=conf.inventory.transform_function_options, config=conf, **conf.inventory.options, ) return Nornir(inventory=inv, config=conf, data=data)
def test_configuration_file_override_argument(self): config = ConfigDeserializer.load_from_file( os.path.join(dir_path, "config.yaml"), core={ "num_workers": 20, "raise_on_error": True }, ) assert config.core.num_workers == 20 assert config.core.raise_on_error
def InitNornir(config_file="", dry_run=False, configure_logging=True, **kwargs): """ Arguments: config_file(str): Path to the configuration file (optional) dry_run(bool): Whether to simulate changes or not **kwargs: Extra information to pass to the :obj:`nornir.core.configuration.Config` object Returns: :obj:`nornir.core.Nornir`: fully instantiated and configured """ register_default_connection_plugins() if callable(kwargs.get("inventory", {}).get("plugin", "")): kwargs["inventory"]["plugin"] = cls_to_string( kwargs["inventory"]["plugin"]) if callable(kwargs.get("inventory", {}).get("transform_function", "")): kwargs["inventory"]["transform_function"] = cls_to_string( kwargs["inventory"]["transform_function"]) conf = Config.load_from_file(config_file, **kwargs) data = GlobalState(dry_run=dry_run) if configure_logging: conf.logging.configure() inv = conf.inventory.plugin.deserialize( transform_function=conf.inventory.transform_function, config=conf, **conf.inventory.options, ) return Nornir(inventory=inv, config=conf, data=data)
def test_order_of_resolution_config_is_lowest(self): config = ConfigDeserializer.load_from_file( os.path.join(dir_path, "config.yaml")) assert config.core.num_workers == 10
def test_get_user_defined_from_file(self): config = ConfigDeserializer.load_from_file( os.path.join(dir_path, "config.yaml")) assert config.user_defined["asd"] == "qwe"
def test_configuration_file_normal(self): config = ConfigDeserializer.load_from_file( os.path.join(dir_path, "config.yaml")) assert config.core.num_workers == 10 assert not config.core.raise_on_error assert config.inventory.plugin == AnsibleInventory