diff --git a/kayobe/ansible.py b/kayobe/ansible.py index 6a2570761..b93d40c02 100644 --- a/kayobe/ansible.py +++ b/kayobe/ansible.py @@ -58,6 +58,10 @@ def add_args(parser): parser.add_argument("-t", "--tags", metavar="TAGS", help="only run plays and tasks tagged with these " "values") + parser.add_argument("-lt", "--list-tasks", + action="store_true", + help="only print names of tasks, don't run them, " + "note this has no affect on kolla-ansible.") def _get_inventory_path(parsed_args): @@ -110,6 +114,8 @@ def build_args(parsed_args, playbooks, cmd = ["ansible-playbook"] if verbose_level: cmd += ["-" + "v" * verbose_level] + if parsed_args.list_tasks: + cmd += ["--list-tasks"] cmd += vault.build_args(parsed_args) inventory = _get_inventory_path(parsed_args) cmd += ["--inventory", inventory] diff --git a/kayobe/tests/unit/test_ansible.py b/kayobe/tests/unit/test_ansible.py index c379ac4e1..1113cb84d 100644 --- a/kayobe/tests/unit/test_ansible.py +++ b/kayobe/tests/unit/test_ansible.py @@ -68,11 +68,17 @@ class TestCase(unittest.TestCase): "-i", "/path/to/inventory", "-l", "group1:host", "-t", "tag1,tag2", + "-lt", ] parsed_args = parser.parse_args(args) - ansible.run_playbooks(parsed_args, ["playbook1.yml", "playbook2.yml"]) + ansible.run_playbooks( + parsed_args, + ["playbook1.yml", "playbook2.yml"], + verbose_level=2) expected_cmd = [ "ansible-playbook", + "-vv", + "--list-tasks", "--inventory", "/path/to/inventory", "-e", "@/path/to/config/vars-file1.yml", "-e", "@/path/to/config/vars-file2.yaml", @@ -106,11 +112,13 @@ class TestCase(unittest.TestCase): "--inventory", "/path/to/inventory", "--limit", "group1:host1", "--tags", "tag1,tag2", + "--list-tasks", ] parsed_args = parser.parse_args(args) ansible.run_playbooks(parsed_args, ["playbook1.yml", "playbook2.yml"]) expected_cmd = [ "ansible-playbook", + "--list-tasks", "--ask-vault-pass", "--inventory", "/path/to/inventory", "-e", "@/path/to/config/vars-file1.yml", diff --git a/kayobe/tests/unit/test_kolla_ansible.py b/kayobe/tests/unit/test_kolla_ansible.py index 70ab888b0..87a62b54d 100644 --- a/kayobe/tests/unit/test_kolla_ansible.py +++ b/kayobe/tests/unit/test_kolla_ansible.py @@ -35,7 +35,7 @@ class TestCase(unittest.TestCase): parsed_args = parser.parse_args([]) kolla_ansible.run(parsed_args, "command", "overcloud") expected_cmd = [ - "source", "ansible/kolla-venv/bin/activate", "&&", + "source", "/opt/kayobe/venvs/kolla/bin/activate", "&&", "kolla-ansible", "command", "--inventory", "/etc/kolla/inventory/overcloud", ] @@ -57,7 +57,7 @@ class TestCase(unittest.TestCase): parsed_args = parser.parse_args(args) kolla_ansible.run(parsed_args, "command", "overcloud") expected_cmd = [ - "source", "ansible/kolla-venv/bin/activate", "&&", + "source", "/opt/kayobe/venvs/kolla/bin/activate", "&&", "kolla-ansible", "command", "--inventory", "/path/to/inventory", "--configdir", "/path/to/config", @@ -84,7 +84,7 @@ class TestCase(unittest.TestCase): parsed_args = parser.parse_args(args) kolla_ansible.run(parsed_args, "command", "overcloud") expected_cmd = [ - "source", "ansible/kolla-venv/bin/activate", "&&", + "source", "/opt/kayobe/venvs/kolla/bin/activate", "&&", "kolla-ansible", "command", "--inventory", "/path/to/inventory", "--configdir", "/path/to/config", @@ -107,7 +107,7 @@ class TestCase(unittest.TestCase): parsed_args = parser.parse_args(args) kolla_ansible.run(parsed_args, "command", "overcloud") expected_cmd = [ - "source", "ansible/kolla-venv/bin/activate", "&&", + "source", "/opt/kayobe/venvs/kolla/bin/activate", "&&", "kolla-ansible", "command", "--key", "/path/to/vault/pw", "--inventory", "/etc/kolla/inventory/overcloud", @@ -130,7 +130,7 @@ class TestCase(unittest.TestCase): parsed_args = parser.parse_args([]) kolla_ansible.run(parsed_args, "command", "overcloud") expected_cmd = [ - "source", "ansible/kolla-venv/bin/activate", "&&", + "source", "/opt/kayobe/venvs/kolla/bin/activate", "&&", "kolla-ansible", "command", "--key", "/path/to/kayobe-vault-password-helper", "--inventory", "/etc/kolla/inventory/overcloud", @@ -157,7 +157,7 @@ class TestCase(unittest.TestCase): } kolla_ansible.run(parsed_args, "command", "overcloud", **kwargs) expected_cmd = [ - "source", "ansible/kolla-venv/bin/activate", "&&", + "source", "/opt/kayobe/venvs/kolla/bin/activate", "&&", "kolla-ansible", "command", "-v", "--inventory", "/etc/kolla/inventory/overcloud", diff --git a/kayobe/tests/unit/test_utils.py b/kayobe/tests/unit/test_utils.py index 2feb93cc1..1c748955a 100644 --- a/kayobe/tests/unit/test_utils.py +++ b/kayobe/tests/unit/test_utils.py @@ -91,8 +91,8 @@ key2: value2 mock_output.assert_called_once_with(["command", "to", "run"]) self.assertEqual(output, "command output") - @mock.patch.object(subprocess, "check_output") - def test_run_command_failure(self, mock_output): - mock_output.side_effect = subprocess.CalledProcessError(1, "command") + @mock.patch.object(subprocess, "check_call") + def test_run_command_failure(self, mock_call): + mock_call.side_effect = subprocess.CalledProcessError(1, "command") self.assertRaises(subprocess.CalledProcessError, utils.run_command, ["command", "to", "run"])