Add output printing to host-command-run

Change-Id: I50f75f8f8ed200b1c70f834973463c2f7343ed1a
This commit is contained in:
Michał Nasiadka 2021-02-18 15:32:57 +01:00 committed by Pierre Riteau
parent f8575af9c0
commit 847bb8666d
4 changed files with 38 additions and 9 deletions

View File

@ -5,3 +5,12 @@
tasks:
- name: Run a command
shell: "{{ host_command_to_run }}"
register: command_output
- name: Print stdout
debug:
msg: "{{ command_output.stdout }}"
when: show_output | bool
- name: Print stderr
debug:
msg: "{{ command_output.stderr }}"
when: show_output | bool

View File

@ -494,12 +494,15 @@ class SeedHypervisorHostCommandRun(KayobeAnsibleMixin, VaultMixin, Command):
group = parser.add_argument_group("Host Command Run")
group.add_argument("--command", required=True,
help="Command to run (required).")
group.add_argument("--show-output", action='store_true',
help="Show command output")
return parser
def take_action(self, parsed_args):
self.app.LOG.debug("Run command on seed hypervisor host")
extra_vars = {
"host_command_to_run": utils.escape_jinja(parsed_args.command)}
"host_command_to_run": utils.escape_jinja(parsed_args.command),
"show_output": parsed_args.show_output}
playbooks = _build_playbook_list("host-command-run")
self.run_kayobe_playbooks(parsed_args, playbooks,
limit="seed-hypervisor",
@ -659,12 +662,15 @@ class SeedHostCommandRun(KayobeAnsibleMixin, VaultMixin, Command):
group = parser.add_argument_group("Host Command Run")
group.add_argument("--command", required=True,
help="Command to run (required).")
group.add_argument("--show-output", action='store_true',
help="Show command output")
return parser
def take_action(self, parsed_args):
self.app.LOG.debug("Run command on seed host")
extra_vars = {
"host_command_to_run": utils.escape_jinja(parsed_args.command)}
"host_command_to_run": utils.escape_jinja(parsed_args.command),
"show_output": parsed_args.show_output}
playbooks = _build_playbook_list("host-command-run")
self.run_kayobe_playbooks(parsed_args, playbooks, limit="seed",
extra_vars=extra_vars)
@ -1018,12 +1024,15 @@ class OvercloudHostCommandRun(KayobeAnsibleMixin, VaultMixin, Command):
group = parser.add_argument_group("Host Command Run")
group.add_argument("--command", required=True,
help="Command to run (required).")
group.add_argument("--show-output", action='store_true',
help="Show command output")
return parser
def take_action(self, parsed_args):
self.app.LOG.debug("Run command on overcloud host")
extra_vars = {
"host_command_to_run": utils.escape_jinja(parsed_args.command)}
"host_command_to_run": utils.escape_jinja(parsed_args.command),
"show_output": parsed_args.show_output}
playbooks = _build_playbook_list("host-command-run")
self.run_kayobe_playbooks(parsed_args, playbooks, limit="overcloud",
extra_vars=extra_vars)

View File

@ -342,7 +342,8 @@ class TestCase(unittest.TestCase):
def test_seed_hypervisor_host_command_run(self, mock_run):
command = commands.SeedHypervisorHostCommandRun(TestApp(), [])
parser = command.get_parser("test")
parsed_args = parser.parse_args(["--command", "ls -a"])
parsed_args = parser.parse_args(["--command", "ls -a",
"--show-output"])
result = command.run(parsed_args)
self.assertEqual(0, result)
@ -356,7 +357,8 @@ class TestCase(unittest.TestCase):
],
limit="seed-hypervisor",
extra_vars={
"host_command_to_run": utils.escape_jinja("ls -a")},
"host_command_to_run": utils.escape_jinja("ls -a"),
"show_output": True}
),
]
self.assertEqual(expected_calls, mock_run.call_args_list)
@ -551,7 +553,8 @@ class TestCase(unittest.TestCase):
def test_seed_host_command_run(self, mock_run):
command = commands.SeedHostCommandRun(TestApp(), [])
parser = command.get_parser("test")
parsed_args = parser.parse_args(["--command", "ls -a"])
parsed_args = parser.parse_args(["--command", "ls -a",
"--show-output"])
result = command.run(parsed_args)
self.assertEqual(0, result)
@ -565,7 +568,8 @@ class TestCase(unittest.TestCase):
],
limit="seed",
extra_vars={
"host_command_to_run": utils.escape_jinja("ls -a")},
"host_command_to_run": utils.escape_jinja("ls -a"),
"show_output": True}
),
]
self.assertEqual(expected_calls, mock_run.call_args_list)
@ -1057,7 +1061,8 @@ class TestCase(unittest.TestCase):
def test_overcloud_host_command_run(self, mock_run):
command = commands.OvercloudHostCommandRun(TestApp(), [])
parser = command.get_parser("test")
parsed_args = parser.parse_args(["--command", "ls -a"])
parsed_args = parser.parse_args(["--command", "ls -a",
"--show-output"])
result = command.run(parsed_args)
self.assertEqual(0, result)
@ -1071,7 +1076,8 @@ class TestCase(unittest.TestCase):
],
limit="overcloud",
extra_vars={
"host_command_to_run": utils.escape_jinja("ls -a")},
"host_command_to_run": utils.escape_jinja("ls -a"),
"show_output": True}
),
]
self.assertEqual(expected_calls, mock_run.call_args_list)

View File

@ -0,0 +1,5 @@
---
features:
- |
The ``kayobe * host command run`` commands now support ``--show-output``
which displays both standard output and standard error.