예제 #1
0
    def test_initialize_config_with_config_option_values(self):
        config_options_pupfile_path = "config_pupfile.yml"

        config_options = {"pupfile_path": config_options_pupfile_path}

        Config.initialize_config_singleton(config_options=config_options)
        config = Config.get_config_singleton()

        self.assertEqual(config.get("pupfile_path"),
                         config_options_pupfile_path)
예제 #2
0
def _initialize_config(config_file, config_options=None):
    # type: (str, Dict[str, str]) -> None
    config_options = config_options or {}

    with io.open(config_file, "r",
                 encoding="utf-8") as config_file_open_for_reading:
        config_file_contents = config_file_open_for_reading.read()

    Config.initialize_config_singleton(
        config_file_contents=config_file_contents,
        config_options=config_options)
예제 #3
0
    def test_initialize_config_with_config_file_values(self):
        config_file_pupfile_path = "config_pupfile.yml"
        config_file_contents = u"""
        [kennel]
        pupfile_path={}
        """.format(config_file_pupfile_path)

        Config.initialize_config_singleton(
            config_file_contents=config_file_contents)
        config = Config.get_config_singleton()

        self.assertEqual(config.get("pupfile_path"), config_file_pupfile_path)
예제 #4
0
    def test_initialize_config_with_config_file_and_non_default_options(self):
        config_file_vault_password_file = "/tmp/test.txt"

        config_file_contents = u"""
        [kennel]
        vault_password_file={}
        """.format(config_file_vault_password_file)

        Config.initialize_config_singleton(
            config_file_contents=config_file_contents)
        config = Config.get_config_singleton()

        self.assertEqual(config.get("vault_password_file"),
                         config_file_vault_password_file)
예제 #5
0
    def __init__(self, name, path, config=None):
        # type: (str, str, Config) -> None
        self._name = name
        self._path = path
        self._pup_dependencies = []  # type: List[PupDependencies]

        self._config = config or Config.get_config_singleton()
예제 #6
0
    def setUp(self, *args, **kwargs):
        super(BasePupTestCase, self).setUp(*args, **kwargs)

        dir_root, kennel_roles_dir, pupfile_dir = self._create_test_fs()

        self._dir_root = dir_root
        self._kennel_roles_dir = kennel_roles_dir
        self._pupfile_dir = pupfile_dir

        mock_config_options = {
            "kennel_roles_path": self._kennel_roles_dir,
            "pupfile_path": os.path.join(self._pupfile_dir, "pupfile.yml"),
        }

        Config.clear_config_singleton()
        Config.initialize_config_singleton(config_options=mock_config_options)
예제 #7
0
    def test_kennel_run_include_vault_password_file(self, mock_check_call):
        """Test that we do attempt to pass a vault password file to ansible
        when we have configured one.
        """
        Config.clear_config_singleton()
        Config.initialize_config_singleton(
            config_options={"vault_password_file": "/tmp/fake-password.txt"}
        )

        kennel = Kennel()
        kennel.run()

        self.assertEqual(mock_check_call.call_count, 1)

        check_call_args, check_call_kwargs = mock_check_call.call_args
        ansible_playbook_cmd = check_call_args[0]

        self.assertTrue("--vault-password-file" in ansible_playbook_cmd)
예제 #8
0
    def test_install(self, mock_check_call):
        ansible_dep_file_path = "/tmp/requirements.yml"

        deps = PupDependencies.create_from_dep_file_path(ansible_dep_file_path)
        deps.install()

        self.assertEqual(mock_check_call.call_count, 1)

        check_call_args, check_call_kwargs = mock_check_call.call_args
        ansible_galaxy_cmd = check_call_args[0]

        config = Config.get_config_singleton()

        expected_cmds = {
            "ansible-galaxy",
            "install",
            "-r {}".format(ansible_dep_file_path),
            "-p {}".format(config.get("abs_kennel_roles_dir")),
        }

        for cmd_line in expected_cmds:
            self.assertIn(cmd_line, ansible_galaxy_cmd)
예제 #9
0
 def __init__(self, additional_ansible_args="", config=None):
     # type: (str, Config) -> None
     self._additional_ansible_args = additional_ansible_args
     self._config = config or Config.get_config_singleton()
예제 #10
0
    def __init__(self, dep_file_path, config=None):
        # type: (str, Config) -> None
        self._dep_file_path = dep_file_path

        self._config = config or Config.get_config_singleton()
예제 #11
0
    def setUp(self, *args, **kwargs):
        super(AnsibleDependenciesTestCase, self).setUp(*args, **kwargs)

        Config.clear_config_singleton()
        Config.initialize_config_singleton()
예제 #12
0
    def test_initialize_config_with_defaults(self):
        Config.initialize_config_singleton()
        config = Config.get_config_singleton()

        for default_key, default_value in iteritems(DEFAULTS):
            self.assertEqual(config.get(default_key), default_value)
예제 #13
0
    def test_can_only_initialize_config_once(self):
        Config.initialize_config_singleton()

        with self.assertRaises(
                SheepdogeConfigurationAlreadyInitializedException):
            Config.initialize_config_singleton()
예제 #14
0
 def test_must_initialize_config_before_using(self):
     with self.assertRaises(SheepdogeConfigurationNotInitializedException):
         Config.get_config_singleton()
예제 #15
0
    def setUp(self, *args, **kwargs):
        super(ConfigTestCase, self).setUp(*args, **kwargs)

        Config.clear_config_singleton()
예제 #16
0
 def __init__(self, action, config=None):
     # type: (Action, Config) -> None
     self._action = action
     self._config = config or Config.get_config_singleton()
예제 #17
0
    def test_initialize_config_with_calculated_config(self):
        Config.initialize_config_singleton()
        config = Config.get_config_singleton()

        for key in {"abs_pupfile_dir", "abs_kennel_roles_dir"}:
            self.assertIn("/", config.get(key))
예제 #18
0
    def setUp(self, *args, **kwargs):
        super(KennelTestCase, self).setUp(*args, **kwargs)

        Config.clear_config_singleton()
        Config.initialize_config_singleton()
예제 #19
0
 def __init__(self, config=None):
     # type: (Config) -> None
     self._config = config or Config.get_config_singleton()
예제 #20
0
    def setUp(self, *args, **kwargs):
        super(InstallActionTestCase, self).setUp(*args, **kwargs)

        Config.clear_config_singleton()
        Config.initialize_config_singleton()