예제 #1
0
 def test_run_vault_password_file(self, mock_update, mock_validate,
                                  mock_run):
     parser = argparse.ArgumentParser()
     kolla_ansible.add_args(parser)
     vault.add_args(parser)
     args = [
         "--vault-password-file",
         "/path/to/vault/pw",
     ]
     parsed_args = parser.parse_args(args)
     kolla_ansible.run(parsed_args, "command", "overcloud")
     expected_cmd = [
         ".",
         "/path/to/cwd/venvs/kolla-ansible/bin/activate",
         "&&",
         "kolla-ansible",
         "command",
         "--key",
         "/path/to/vault/pw",
         "--inventory",
         "/etc/kolla/inventory/overcloud",
     ]
     expected_cmd = " ".join(expected_cmd)
     mock_run.assert_called_once_with(expected_cmd,
                                      shell=True,
                                      quiet=False,
                                      env={})
     mock_update.assert_called_once_with(mock.ANY, {})
예제 #2
0
 def test_run_func_args(self, mock_validate, mock_run):
     parser = argparse.ArgumentParser()
     ansible.add_args(parser)
     kolla_ansible.add_args(parser)
     vault.add_args(parser)
     args = [
         "--kolla-extra-vars", "ev_name1=ev_value1",
         "--kolla-tags", "tag1,tag2",
     ]
     parsed_args = parser.parse_args(args)
     kwargs = {
         "extra_vars": {"ev_name2": "ev_value2"},
         "tags": "tag3,tag4",
         "verbose_level": 1,
         "extra_args": ["--arg1", "--arg2"],
     }
     kolla_ansible.run(parsed_args, "command", "overcloud", **kwargs)
     expected_cmd = [
         ".", "/path/to/cwd/venvs/kolla-ansible/bin/activate", "&&",
         "kolla-ansible", "command",
         "-v",
         "--inventory", "/etc/kolla/inventory/overcloud",
         "-e", "ev_name1=ev_value1",
         "-e", "ev_name2='ev_value2'",
         "--tags", "tag1,tag2,tag3,tag4",
         "--arg1", "--arg2",
     ]
     expected_cmd = " ".join(expected_cmd)
     mock_run.assert_called_once_with(expected_cmd, shell=True, quiet=False,
                                      env={})
예제 #3
0
 def test_run_vault_password_helper(self, mock_update, mock_vars, mock_run):
     mock_vars.return_value = []
     parser = argparse.ArgumentParser()
     mock_run.return_value = "/path/to/kayobe-vault-password-helper"
     kolla_ansible.add_args(parser)
     vault.add_args(parser)
     mock_run.assert_called_once_with(
         ["which", "kayobe-vault-password-helper"], check_output=True)
     mock_run.reset_mock()
     parsed_args = parser.parse_args([])
     kolla_ansible.run(parsed_args, "command", "overcloud")
     expected_cmd = [
         ".",
         "/path/to/cwd/venvs/kolla-ansible/bin/activate",
         "&&",
         "kolla-ansible",
         "command",
         "--key",
         "/path/to/kayobe-vault-password-helper",
         "--inventory",
         "/etc/kolla/inventory/overcloud",
     ]
     expected_cmd = " ".join(expected_cmd)
     expected_env = {"KAYOBE_VAULT_PASSWORD": "******"}
     mock_run.assert_called_once_with(expected_cmd,
                                      shell=True,
                                      quiet=False,
                                      env=expected_env)
     mock_update.assert_called_once_with(mock.ANY, expected_env)
예제 #4
0
 def test_run_custom_ansible_cfg_2(self, mock_validate, mock_readable,
                                   mock_run):
     mock_readable.side_effect = [{"result": False}, {"result": True}]
     parser = argparse.ArgumentParser()
     ansible.add_args(parser)
     kolla_ansible.add_args(parser)
     vault.add_args(parser)
     parsed_args = parser.parse_args([])
     kolla_ansible.run(parsed_args, "command", "overcloud")
     expected_cmd = [
         ".",
         "/path/to/cwd/venvs/kolla-ansible/bin/activate",
         "&&",
         "kolla-ansible",
         "command",
         "--inventory",
         "/etc/kolla/inventory/overcloud",
     ]
     expected_cmd = " ".join(expected_cmd)
     expected_env = {"ANSIBLE_CONFIG": "/etc/kayobe/ansible.cfg"}
     mock_run.assert_called_once_with(expected_cmd,
                                      shell=True,
                                      quiet=False,
                                      env=expected_env)
     expected_calls = [
         mock.call("/etc/kayobe/kolla/ansible.cfg"),
         mock.call("/etc/kayobe/ansible.cfg"),
     ]
     self.assertEqual(mock_readable.call_args_list, expected_calls)
예제 #5
0
 def test_run_all_the_args(self, mock_validate, mock_run):
     parser = argparse.ArgumentParser()
     ansible.add_args(parser)
     kolla_ansible.add_args(parser)
     vault.add_args(parser)
     args = [
         "-C",
         "-D",
         "--kolla-config-path", "/path/to/config",
         "-ke", "ev_name1=ev_value1",
         "-ki", "/path/to/inventory",
         "-kl", "host1:host2",
         "-kt", "tag1,tag2",
     ]
     parsed_args = parser.parse_args(args)
     kolla_ansible.run(parsed_args, "command", "overcloud")
     expected_cmd = [
         ".", "/path/to/cwd/venvs/kolla-ansible/bin/activate", "&&",
         "kolla-ansible", "command",
         "--inventory", "/path/to/inventory",
         "--configdir", "/path/to/config",
         "--passwords", "/path/to/config/passwords.yml",
         "-e", "ev_name1=ev_value1",
         "--limit", "'host1:host2'",
         "--tags", "tag1,tag2",
     ]
     expected_cmd = " ".join(expected_cmd)
     expected_env = {"EXTRA_OPTS": " --check --diff"}
     mock_run.assert_called_once_with(expected_cmd, shell=True, quiet=False,
                                      env=expected_env)
예제 #6
0
 def test_run_all_the_long_args(self, mock_validate, mock_run):
     parser = argparse.ArgumentParser()
     kolla_ansible.add_args(parser)
     vault.add_args(parser)
     args = [
         "--ask-vault-pass",
         "--kolla-config-path", "/path/to/config",
         "--kolla-extra-vars", "ev_name1=ev_value1",
         "--kolla-inventory", "/path/to/inventory",
         "--kolla-limit", "host1:host2",
         "--kolla-skip-tags", "tag3,tag4",
         "--kolla-tags", "tag1,tag2",
     ]
     parsed_args = parser.parse_args(args)
     kolla_ansible.run(parsed_args, "command", "overcloud")
     expected_cmd = [
         ".", "/path/to/cwd/venvs/kolla-ansible/bin/activate", "&&",
         "kolla-ansible", "command",
         "--inventory", "/path/to/inventory",
         "--configdir", "/path/to/config",
         "--passwords", "/path/to/config/passwords.yml",
         "-e", "ev_name1=ev_value1",
         "--limit", "host1:host2",
         "--skip-tags", "tag3,tag4",
         "--tags", "tag1,tag2",
     ]
     expected_cmd = " ".join(expected_cmd)
     mock_run.assert_called_once_with(expected_cmd, shell=True, quiet=False)
예제 #7
0
 def test_run_func_args(self, mock_validate, mock_run):
     parser = argparse.ArgumentParser()
     kolla_ansible.add_args(parser)
     vault.add_args(parser)
     args = [
         "--kolla-extra-vars", "ev_name1=ev_value1",
         "--kolla-tags", "tag1,tag2",
     ]
     parsed_args = parser.parse_args(args)
     kwargs = {
         "extra_vars": {"ev_name2": "ev_value2"},
         "tags": "tag3,tag4",
         "verbose_level": 1,
         "extra_args": ["--arg1", "--arg2"],
     }
     kolla_ansible.run(parsed_args, "command", "overcloud", **kwargs)
     expected_cmd = [
         ".", "/path/to/cwd/venvs/kolla-ansible/bin/activate", "&&",
         "kolla-ansible", "command",
         "-v",
         "--inventory", "/etc/kolla/inventory/overcloud",
         "-e", "ev_name1=ev_value1",
         "-e", "ev_name2=ev_value2",
         "--tags", "tag1,tag2,tag3,tag4",
         "--arg1", "--arg2",
     ]
     expected_cmd = " ".join(expected_cmd)
     mock_run.assert_called_once_with(expected_cmd, shell=True, quiet=False)
예제 #8
0
 def test_run_custom_ansible_cfg_env(self, mock_validate, mock_readable,
                                     mock_run):
     mock_readable.return_value = {"result": True}
     os.environ["ANSIBLE_CONFIG"] = "/path/to/ansible.cfg"
     parser = argparse.ArgumentParser()
     ansible.add_args(parser)
     kolla_ansible.add_args(parser)
     vault.add_args(parser)
     parsed_args = parser.parse_args([])
     kolla_ansible.run(parsed_args, "command", "overcloud")
     expected_cmd = [
         ".",
         "/path/to/cwd/venvs/kolla-ansible/bin/activate",
         "&&",
         "kolla-ansible",
         "command",
         "--inventory",
         "/etc/kolla/inventory/overcloud",
     ]
     expected_cmd = " ".join(expected_cmd)
     expected_env = {"ANSIBLE_CONFIG": "/path/to/ansible.cfg"}
     mock_run.assert_called_once_with(expected_cmd,
                                      shell=True,
                                      quiet=False,
                                      env=expected_env)
     mock_readable.assert_called_once_with("/etc/kayobe/kolla/ansible.cfg")
예제 #9
0
 def test_run_failure(self, mock_validate, mock_run):
     parser = argparse.ArgumentParser()
     kolla_ansible.add_args(parser)
     vault.add_args(parser)
     parsed_args = parser.parse_args([])
     mock_run.side_effect = subprocess.CalledProcessError(1, "dummy")
     self.assertRaises(SystemExit, kolla_ansible.run, parsed_args,
                       "command", "overcloud")
예제 #10
0
 def test_run_failure(self, mock_validate, mock_run):
     parser = argparse.ArgumentParser()
     kolla_ansible.add_args(parser)
     vault.add_args(parser)
     parsed_args = parser.parse_args([])
     mock_run.side_effect = subprocess.CalledProcessError(1, "dummy")
     self.assertRaises(SystemExit,
                       kolla_ansible.run, parsed_args, "command",
                       "overcloud")
예제 #11
0
 def test_run_all_the_long_args(self, mock_ask, mock_validate, mock_run):
     parser = argparse.ArgumentParser()
     ansible.add_args(parser)
     kolla_ansible.add_args(parser)
     vault.add_args(parser)
     mock_ask.return_value = "test-pass"
     args = [
         "--ask-vault-pass",
         "--kolla-config-path",
         "/path/to/config",
         "--kolla-extra-vars",
         "ev_name1=ev_value1",
         "--kolla-inventory",
         "/path/to/inventory",
         "--kolla-limit",
         "host1:host2",
         "--kolla-skip-tags",
         "tag3,tag4",
         "--kolla-tags",
         "tag1,tag2",
     ]
     parsed_args = parser.parse_args(args)
     mock_run.return_value = "/path/to/kayobe-vault-password-helper"
     kolla_ansible.run(parsed_args, "command", "overcloud")
     expected_cmd = [
         ".",
         "/path/to/cwd/venvs/kolla-ansible/bin/activate",
         "&&",
         "kolla-ansible",
         "command",
         "--key",
         "/path/to/kayobe-vault-password-helper",
         "--inventory",
         "/path/to/inventory",
         "--configdir",
         "/path/to/config",
         "--passwords",
         "/path/to/config/passwords.yml",
         "-e",
         "ev_name1=ev_value1",
         "--limit",
         "'host1:host2'",
         "--skip-tags",
         "tag3,tag4",
         "--tags",
         "tag1,tag2",
     ]
     expected_cmd = " ".join(expected_cmd)
     expected_env = {"KAYOBE_VAULT_PASSWORD": "******"}
     expected_calls = [
         mock.call(["which", "kayobe-vault-password-helper"],
                   check_output=True,
                   universal_newlines=True),
         mock.call(expected_cmd, shell=True, quiet=False, env=expected_env)
     ]
     self.assertEqual(expected_calls, mock_run.mock_calls)
예제 #12
0
 def test_run(self, mock_validate, mock_run):
     parser = argparse.ArgumentParser()
     kolla_ansible.add_args(parser)
     vault.add_args(parser)
     parsed_args = parser.parse_args([])
     kolla_ansible.run(parsed_args, "command", "overcloud")
     expected_cmd = [
         ".", "/path/to/cwd/venvs/kolla-ansible/bin/activate", "&&",
         "kolla-ansible", "command",
         "--inventory", "/etc/kolla/inventory/overcloud",
     ]
     expected_cmd = " ".join(expected_cmd)
     mock_run.assert_called_once_with(expected_cmd, shell=True, quiet=False)
예제 #13
0
 def test_run(self, mock_validate, mock_run):
     parser = argparse.ArgumentParser()
     ansible.add_args(parser)
     kolla_ansible.add_args(parser)
     vault.add_args(parser)
     parsed_args = parser.parse_args([])
     kolla_ansible.run(parsed_args, "command", "overcloud")
     expected_cmd = [
         ".", "/path/to/cwd/venvs/kolla-ansible/bin/activate", "&&",
         "kolla-ansible", "command",
         "--inventory", "/etc/kolla/inventory/overcloud",
     ]
     expected_cmd = " ".join(expected_cmd)
     mock_run.assert_called_once_with(expected_cmd, shell=True, quiet=False,
                                      env={})
예제 #14
0
 def test_run_all_the_long_args(self, mock_validate, mock_run):
     parser = argparse.ArgumentParser()
     kolla_ansible.add_args(parser)
     vault.add_args(parser)
     args = [
         "--ask-vault-pass",
         "--kolla-config-path",
         "/path/to/config",
         "--kolla-extra-vars",
         "ev_name1=ev_value1",
         "--kolla-inventory",
         "/path/to/inventory",
         "--kolla-limit",
         "host1:host2",
         "--kolla-skip-tags",
         "tag3,tag4",
         "--kolla-tags",
         "tag1,tag2",
     ]
     parsed_args = parser.parse_args(args)
     kolla_ansible.run(parsed_args, "command", "overcloud")
     expected_cmd = [
         ".",
         "/path/to/cwd/venvs/kolla-ansible/bin/activate",
         "&&",
         "kolla-ansible",
         "command",
         "--inventory",
         "/path/to/inventory",
         "--configdir",
         "/path/to/config",
         "--passwords",
         "/path/to/config/passwords.yml",
         "-e",
         "ev_name1=ev_value1",
         "--limit",
         "host1:host2",
         "--skip-tags",
         "tag3,tag4",
         "--tags",
         "tag1,tag2",
     ]
     expected_cmd = " ".join(expected_cmd)
     mock_run.assert_called_once_with(expected_cmd, shell=True, quiet=False)
예제 #15
0
 def test_run_vault_password_helper(self, mock_vars, mock_run):
     mock_vars.return_value = []
     parser = argparse.ArgumentParser()
     mock_run.return_value = "/path/to/kayobe-vault-password-helper"
     kolla_ansible.add_args(parser)
     vault.add_args(parser)
     mock_run.assert_called_once_with(
         ["which", "kayobe-vault-password-helper"], check_output=True)
     mock_run.reset_mock()
     parsed_args = parser.parse_args([])
     kolla_ansible.run(parsed_args, "command", "overcloud")
     expected_cmd = [
         ".", "/path/to/cwd/venvs/kolla-ansible/bin/activate", "&&",
         "kolla-ansible", "command",
         "--key", "/path/to/kayobe-vault-password-helper",
         "--inventory", "/etc/kolla/inventory/overcloud",
     ]
     expected_cmd = " ".join(expected_cmd)
     mock_run.assert_called_once_with(expected_cmd, shell=True, quiet=False)
예제 #16
0
 def add_kolla_ansible_args(self, group):
     kolla_ansible.add_args(group)
예제 #17
0
파일: commands.py 프로젝트: pforai/kayobe
 def add_kolla_ansible_args(self, group):
     kolla_ansible.add_args(group)