def __init__( self, inventory, dry_run, config=None, config_file=None, available_connections=None, logger=None, data=None, ): self.logger = logger or logging.getLogger("brigade") self.data = data or Data() self.inventory = inventory self.inventory.brigade = self self.data.dry_run = dry_run if config_file: self.config = Config(config_file=config_file) else: self.config = config or Config() self.configure_logging() if available_connections is not None: self.available_connections = available_connections else: self.available_connections = connections.available_connections
def test_get_user_defined_from_env(self): os.environ["USER_DEFINED"] = "zxczxc" config = Config(config_file=os.path.join(dir_path, "config.yaml")) assert (config.get("user_defined", env="USER_DEFINED", default="qweqwe") == "zxczxc") os.environ.pop("USER_DEFINED")
def test_configuration_normal_override_env(self): os.environ["BRIGADE_NUM_WORKERS"] = "30" os.environ["BRIGADE_RAISE_ON_ERROR"] = "1" config = Config(config_file=os.path.join(dir_path, "config.yaml")) assert config.num_workers == 30 assert config.raise_on_error os.environ.pop("BRIGADE_NUM_WORKERS") os.environ.pop("BRIGADE_RAISE_ON_ERROR")
def test_configuration_normal_override_argument(self): config = Config( config_file=os.path.join(dir_path, "config.yaml"), num_workers=20, raise_on_error=True, ) assert config.num_workers == 20 assert config.raise_on_error
def test_configuration_normal(self): config = Config( config_file=os.path.join(dir_path, "config.yaml"), arg1=1, arg2=False, arg3=None, arg4="asd", ) assert config.num_workers == 10 assert not config.raise_on_error assert config.arg1 == 1 assert config.arg2 is False assert config.arg3 is None assert config.arg4 == "asd"
def InitBrigade(config_file="", dry_run=False, **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:`brigade.core.configuration.Config` object Returns: :obj:`brigade.core.Brigade`: fully instantiated and configured """ conf = Config(config_file=config_file, **kwargs) inv_class = conf.inventory inv_args = getattr(conf, inv_class.__name__, {}) transform_function = conf.transform_function inv = inv_class(transform_function=transform_function, **inv_args) return Brigade(inventory=inv, dry_run=dry_run, config=conf)
def test_get_user_defined_nested(self): config = Config(config_file=os.path.join(dir_path, "config.yaml")) assert config.get("user_defined", root="my_root") == "i am nested"
def test_get_user_defined_from_env_bool(self): os.environ["USER_DEFINED"] = "0" config = Config() assert not config.get( "user_defined", env="USER_DEFINED", parameter_type="bool") os.environ.pop("USER_DEFINED")
def test_get_user_defined_from_default(self): config = Config() assert (config.get("user_defined", env="USER_DEFINED", default="qweqwe") == "qweqwe")
def test_get_user_defined_from_file(self): config = Config(config_file=os.path.join(dir_path, "config.yaml")) assert (config.get("user_defined", env="USER_DEFINED", default="qweqwe") == "asdasd")
def test_configuration_bool_env(self): os.environ["BRIGADE_RAISE_ON_ERROR"] = "0" config = Config() assert config.num_workers == 20 assert not config.raise_on_error