From a3d1b07652e8f3d07078b8d0d7d8dc05b3331a4e Mon Sep 17 00:00:00 2001 From: John Garbutt Date: Thu, 17 Aug 2017 17:22:27 +0100 Subject: [PATCH 1/3] Fix kolla-ansible unit test failures Seems like default path was changed and broke the tests: 19ceec45cd36c6b086c519a183e545db0a811e3e --- kayobe/tests/unit/test_kolla_ansible.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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", From a97c41b2f449794797a196590bf896c6df16a04b Mon Sep 17 00:00:00 2001 From: John Garbutt Date: Thu, 17 Aug 2017 17:30:38 +0100 Subject: [PATCH 2/3] Fix test_utils error due unmocked subprocess call While I could have just added check_output=True in the call, it seemed good to check the other call path. Seems related to this change: cb7ed2f48c1b7b6e24e896707ea6f4d6b1a2c97d --- kayobe/tests/unit/test_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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"]) From f63861681841130d42e225c8e634f5ccfa9b76d5 Mon Sep 17 00:00:00 2001 From: John Garbutt Date: Thu, 17 Aug 2017 17:46:33 +0100 Subject: [PATCH 3/3] Add the ability to call --list-tasks This allows you to print out which tasks will be executed, without actually running the tasks. It could help debug using the tag and filtering features. When developing, it makes the feedback loop quicker because non of the tasks need to execute. Note this doesn't work for kolla-ansible, as their CLI doesn't support this command line. Which frankly makes this a little useless, but we could always push that upstream if it proves handy. --- kayobe/ansible.py | 6 ++++++ kayobe/tests/unit/test_ansible.py | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) 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",