Merge pull request #6 from JohnGarbutt/print-cmd-when-verbose
Print cmd when verbose
This commit is contained in:
commit
0d8a100a61
@ -58,6 +58,10 @@ def add_args(parser):
|
|||||||
parser.add_argument("-t", "--tags", metavar="TAGS",
|
parser.add_argument("-t", "--tags", metavar="TAGS",
|
||||||
help="only run plays and tasks tagged with these "
|
help="only run plays and tasks tagged with these "
|
||||||
"values")
|
"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):
|
def _get_inventory_path(parsed_args):
|
||||||
@ -110,6 +114,8 @@ def build_args(parsed_args, 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:
|
||||||
|
cmd += ["--list-tasks"]
|
||||||
cmd += vault.build_args(parsed_args)
|
cmd += vault.build_args(parsed_args)
|
||||||
inventory = _get_inventory_path(parsed_args)
|
inventory = _get_inventory_path(parsed_args)
|
||||||
cmd += ["--inventory", inventory]
|
cmd += ["--inventory", inventory]
|
||||||
|
@ -68,11 +68,17 @@ class TestCase(unittest.TestCase):
|
|||||||
"-i", "/path/to/inventory",
|
"-i", "/path/to/inventory",
|
||||||
"-l", "group1:host",
|
"-l", "group1:host",
|
||||||
"-t", "tag1,tag2",
|
"-t", "tag1,tag2",
|
||||||
|
"-lt",
|
||||||
]
|
]
|
||||||
parsed_args = parser.parse_args(args)
|
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 = [
|
expected_cmd = [
|
||||||
"ansible-playbook",
|
"ansible-playbook",
|
||||||
|
"-vv",
|
||||||
|
"--list-tasks",
|
||||||
"--inventory", "/path/to/inventory",
|
"--inventory", "/path/to/inventory",
|
||||||
"-e", "@/path/to/config/vars-file1.yml",
|
"-e", "@/path/to/config/vars-file1.yml",
|
||||||
"-e", "@/path/to/config/vars-file2.yaml",
|
"-e", "@/path/to/config/vars-file2.yaml",
|
||||||
@ -106,11 +112,13 @@ class TestCase(unittest.TestCase):
|
|||||||
"--inventory", "/path/to/inventory",
|
"--inventory", "/path/to/inventory",
|
||||||
"--limit", "group1:host1",
|
"--limit", "group1:host1",
|
||||||
"--tags", "tag1,tag2",
|
"--tags", "tag1,tag2",
|
||||||
|
"--list-tasks",
|
||||||
]
|
]
|
||||||
parsed_args = parser.parse_args(args)
|
parsed_args = parser.parse_args(args)
|
||||||
ansible.run_playbooks(parsed_args, ["playbook1.yml", "playbook2.yml"])
|
ansible.run_playbooks(parsed_args, ["playbook1.yml", "playbook2.yml"])
|
||||||
expected_cmd = [
|
expected_cmd = [
|
||||||
"ansible-playbook",
|
"ansible-playbook",
|
||||||
|
"--list-tasks",
|
||||||
"--ask-vault-pass",
|
"--ask-vault-pass",
|
||||||
"--inventory", "/path/to/inventory",
|
"--inventory", "/path/to/inventory",
|
||||||
"-e", "@/path/to/config/vars-file1.yml",
|
"-e", "@/path/to/config/vars-file1.yml",
|
||||||
|
@ -35,7 +35,7 @@ class TestCase(unittest.TestCase):
|
|||||||
parsed_args = parser.parse_args([])
|
parsed_args = parser.parse_args([])
|
||||||
kolla_ansible.run(parsed_args, "command", "overcloud")
|
kolla_ansible.run(parsed_args, "command", "overcloud")
|
||||||
expected_cmd = [
|
expected_cmd = [
|
||||||
"source", "ansible/kolla-venv/bin/activate", "&&",
|
"source", "/opt/kayobe/venvs/kolla/bin/activate", "&&",
|
||||||
"kolla-ansible", "command",
|
"kolla-ansible", "command",
|
||||||
"--inventory", "/etc/kolla/inventory/overcloud",
|
"--inventory", "/etc/kolla/inventory/overcloud",
|
||||||
]
|
]
|
||||||
@ -57,7 +57,7 @@ class TestCase(unittest.TestCase):
|
|||||||
parsed_args = parser.parse_args(args)
|
parsed_args = parser.parse_args(args)
|
||||||
kolla_ansible.run(parsed_args, "command", "overcloud")
|
kolla_ansible.run(parsed_args, "command", "overcloud")
|
||||||
expected_cmd = [
|
expected_cmd = [
|
||||||
"source", "ansible/kolla-venv/bin/activate", "&&",
|
"source", "/opt/kayobe/venvs/kolla/bin/activate", "&&",
|
||||||
"kolla-ansible", "command",
|
"kolla-ansible", "command",
|
||||||
"--inventory", "/path/to/inventory",
|
"--inventory", "/path/to/inventory",
|
||||||
"--configdir", "/path/to/config",
|
"--configdir", "/path/to/config",
|
||||||
@ -84,7 +84,7 @@ class TestCase(unittest.TestCase):
|
|||||||
parsed_args = parser.parse_args(args)
|
parsed_args = parser.parse_args(args)
|
||||||
kolla_ansible.run(parsed_args, "command", "overcloud")
|
kolla_ansible.run(parsed_args, "command", "overcloud")
|
||||||
expected_cmd = [
|
expected_cmd = [
|
||||||
"source", "ansible/kolla-venv/bin/activate", "&&",
|
"source", "/opt/kayobe/venvs/kolla/bin/activate", "&&",
|
||||||
"kolla-ansible", "command",
|
"kolla-ansible", "command",
|
||||||
"--inventory", "/path/to/inventory",
|
"--inventory", "/path/to/inventory",
|
||||||
"--configdir", "/path/to/config",
|
"--configdir", "/path/to/config",
|
||||||
@ -107,7 +107,7 @@ class TestCase(unittest.TestCase):
|
|||||||
parsed_args = parser.parse_args(args)
|
parsed_args = parser.parse_args(args)
|
||||||
kolla_ansible.run(parsed_args, "command", "overcloud")
|
kolla_ansible.run(parsed_args, "command", "overcloud")
|
||||||
expected_cmd = [
|
expected_cmd = [
|
||||||
"source", "ansible/kolla-venv/bin/activate", "&&",
|
"source", "/opt/kayobe/venvs/kolla/bin/activate", "&&",
|
||||||
"kolla-ansible", "command",
|
"kolla-ansible", "command",
|
||||||
"--key", "/path/to/vault/pw",
|
"--key", "/path/to/vault/pw",
|
||||||
"--inventory", "/etc/kolla/inventory/overcloud",
|
"--inventory", "/etc/kolla/inventory/overcloud",
|
||||||
@ -130,7 +130,7 @@ class TestCase(unittest.TestCase):
|
|||||||
parsed_args = parser.parse_args([])
|
parsed_args = parser.parse_args([])
|
||||||
kolla_ansible.run(parsed_args, "command", "overcloud")
|
kolla_ansible.run(parsed_args, "command", "overcloud")
|
||||||
expected_cmd = [
|
expected_cmd = [
|
||||||
"source", "ansible/kolla-venv/bin/activate", "&&",
|
"source", "/opt/kayobe/venvs/kolla/bin/activate", "&&",
|
||||||
"kolla-ansible", "command",
|
"kolla-ansible", "command",
|
||||||
"--key", "/path/to/kayobe-vault-password-helper",
|
"--key", "/path/to/kayobe-vault-password-helper",
|
||||||
"--inventory", "/etc/kolla/inventory/overcloud",
|
"--inventory", "/etc/kolla/inventory/overcloud",
|
||||||
@ -157,7 +157,7 @@ class TestCase(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
kolla_ansible.run(parsed_args, "command", "overcloud", **kwargs)
|
kolla_ansible.run(parsed_args, "command", "overcloud", **kwargs)
|
||||||
expected_cmd = [
|
expected_cmd = [
|
||||||
"source", "ansible/kolla-venv/bin/activate", "&&",
|
"source", "/opt/kayobe/venvs/kolla/bin/activate", "&&",
|
||||||
"kolla-ansible", "command",
|
"kolla-ansible", "command",
|
||||||
"-v",
|
"-v",
|
||||||
"--inventory", "/etc/kolla/inventory/overcloud",
|
"--inventory", "/etc/kolla/inventory/overcloud",
|
||||||
|
@ -91,8 +91,8 @@ key2: value2
|
|||||||
mock_output.assert_called_once_with(["command", "to", "run"])
|
mock_output.assert_called_once_with(["command", "to", "run"])
|
||||||
self.assertEqual(output, "command output")
|
self.assertEqual(output, "command output")
|
||||||
|
|
||||||
@mock.patch.object(subprocess, "check_output")
|
@mock.patch.object(subprocess, "check_call")
|
||||||
def test_run_command_failure(self, mock_output):
|
def test_run_command_failure(self, mock_call):
|
||||||
mock_output.side_effect = subprocess.CalledProcessError(1, "command")
|
mock_call.side_effect = subprocess.CalledProcessError(1, "command")
|
||||||
self.assertRaises(subprocess.CalledProcessError, utils.run_command,
|
self.assertRaises(subprocess.CalledProcessError, utils.run_command,
|
||||||
["command", "to", "run"])
|
["command", "to", "run"])
|
||||||
|
Loading…
Reference in New Issue
Block a user