Skip to content
Snippets Groups Projects
Commit 844202d2 authored by Mark Goddard's avatar Mark Goddard
Browse files

Don't list tasks for config dump

kayobe executed with --list-tasks often fails due to passing this
argument through to the config dump, which causes it to not generate the
required dump file.

Ignore list-tasks for configuration dump.

Change-Id: I5dccd7d8eab8d46ef5e8cd97a601510a3d8db177
Story: 2006530
Task: 36584
parent 1f83d69a
No related branches found
No related tags found
No related merge requests found
...@@ -118,12 +118,12 @@ def _get_vars_files(config_path): ...@@ -118,12 +118,12 @@ def _get_vars_files(config_path):
def build_args(parsed_args, playbooks, def build_args(parsed_args, playbooks,
extra_vars=None, limit=None, tags=None, verbose_level=None, extra_vars=None, limit=None, tags=None, verbose_level=None,
check=None, ignore_limit=False): check=None, ignore_limit=False, list_tasks=None):
"""Build arguments required for running Ansible playbooks.""" """Build arguments required for running Ansible playbooks."""
cmd = ["ansible-playbook"] cmd = ["ansible-playbook"]
if verbose_level: if verbose_level:
cmd += ["-" + "v" * verbose_level] cmd += ["-" + "v" * verbose_level]
if parsed_args.list_tasks: if list_tasks or (parsed_args.list_tasks and list_tasks is None):
cmd += ["--list-tasks"] cmd += ["--list-tasks"]
cmd += vault.build_args(parsed_args, "--vault-password-file") cmd += vault.build_args(parsed_args, "--vault-password-file")
inventory = _get_inventory_path(parsed_args) inventory = _get_inventory_path(parsed_args)
...@@ -160,13 +160,13 @@ def build_args(parsed_args, playbooks, ...@@ -160,13 +160,13 @@ def build_args(parsed_args, playbooks,
def run_playbooks(parsed_args, playbooks, def run_playbooks(parsed_args, playbooks,
extra_vars=None, limit=None, tags=None, quiet=False, extra_vars=None, limit=None, tags=None, quiet=False,
check_output=False, verbose_level=None, check=None, check_output=False, verbose_level=None, check=None,
ignore_limit=False): ignore_limit=False, list_tasks=None):
"""Run a Kayobe Ansible playbook.""" """Run a Kayobe Ansible playbook."""
_validate_args(parsed_args, playbooks) _validate_args(parsed_args, playbooks)
cmd = build_args(parsed_args, playbooks, cmd = build_args(parsed_args, playbooks,
extra_vars=extra_vars, limit=limit, tags=tags, extra_vars=extra_vars, limit=limit, tags=tags,
verbose_level=verbose_level, check=check, verbose_level=verbose_level, check=check,
ignore_limit=ignore_limit) ignore_limit=ignore_limit, list_tasks=list_tasks)
env = os.environ.copy() env = os.environ.copy()
vault.update_environment(parsed_args, env) vault.update_environment(parsed_args, env)
# If the configuration path has been specified via --config-path, ensure # If the configuration path has been specified via --config-path, ensure
...@@ -201,12 +201,13 @@ def config_dump(parsed_args, host=None, hosts=None, var_name=None, ...@@ -201,12 +201,13 @@ def config_dump(parsed_args, host=None, hosts=None, var_name=None,
extra_vars["dump_var_name"] = var_name extra_vars["dump_var_name"] = var_name
if facts is not None: if facts is not None:
extra_vars["dump_facts"] = facts extra_vars["dump_facts"] = facts
# Don't use check mode for configuration dumps as we won't get any # Don't use check mode or list tasks for configuration dumps as we
# results back. # won't get any results back.
playbook_path = utils.get_data_files_path("ansible", "dump-config.yml") playbook_path = utils.get_data_files_path("ansible", "dump-config.yml")
run_playbook(parsed_args, playbook_path, run_playbook(parsed_args, playbook_path,
extra_vars=extra_vars, tags=tags, check_output=True, extra_vars=extra_vars, tags=tags, check_output=True,
verbose_level=verbose_level, check=False) verbose_level=verbose_level, check=False,
list_tasks=False)
hostvars = {} hostvars = {}
for path in os.listdir(dump_dir): for path in os.listdir(dump_dir):
LOG.debug("Found dump file %s", path) LOG.debug("Found dump file %s", path)
......
...@@ -293,6 +293,35 @@ class TestCase(unittest.TestCase): ...@@ -293,6 +293,35 @@ class TestCase(unittest.TestCase):
quiet=False, env=expected_env) quiet=False, env=expected_env)
mock_vars.assert_called_once_with("/etc/kayobe") mock_vars.assert_called_once_with("/etc/kayobe")
@mock.patch.object(utils, "run_command")
@mock.patch.object(ansible, "_get_vars_files")
@mock.patch.object(ansible, "_validate_args")
def test_run_playbooks_list_tasks_arg(self, mock_validate, mock_vars,
mock_run):
mock_vars.return_value = []
parser = argparse.ArgumentParser()
ansible.add_args(parser)
vault.add_args(parser)
args = [
"--list-tasks",
]
parsed_args = parser.parse_args(args)
kwargs = {
"list_tasks": False
}
ansible.run_playbooks(parsed_args, ["playbook1.yml", "playbook2.yml"],
**kwargs)
expected_cmd = [
"ansible-playbook",
"--inventory", "/etc/kayobe/inventory",
"playbook1.yml",
"playbook2.yml",
]
expected_env = {"KAYOBE_CONFIG_PATH": "/etc/kayobe"}
mock_run.assert_called_once_with(expected_cmd, check_output=False,
quiet=False, env=expected_env)
mock_vars.assert_called_once_with("/etc/kayobe")
@mock.patch.object(utils, "run_command") @mock.patch.object(utils, "run_command")
@mock.patch.object(ansible, "_get_vars_files") @mock.patch.object(ansible, "_get_vars_files")
@mock.patch.object(ansible, "_validate_args") @mock.patch.object(ansible, "_validate_args")
...@@ -335,7 +364,8 @@ class TestCase(unittest.TestCase): ...@@ -335,7 +364,8 @@ class TestCase(unittest.TestCase):
"dump_path": dump_dir, "dump_path": dump_dir,
}, },
check_output=True, tags=None, check_output=True, tags=None,
verbose_level=None, check=False) verbose_level=None, check=False,
list_tasks=False)
mock_rmtree.assert_called_once_with(dump_dir) mock_rmtree.assert_called_once_with(dump_dir)
mock_listdir.assert_any_call(dump_dir) mock_listdir.assert_any_call(dump_dir)
mock_read.assert_has_calls([ mock_read.assert_has_calls([
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment