From 068ebe03067334c4d3180f66ffa40ae37a6818cc Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Wed, 14 Feb 2018 09:53:57 +1300 Subject: [PATCH] Add --dry-run option to undercloud install This will help greatly with the development of the --use-heat path by printing the underlying "undercloud deploy" command instead of executing it. This may also help debug undercloud install issues in the field. Change-Id: I42ce297e5663ff782cfb6afa9058daf8abdf389b Blueprint: containerized-undercloud --- .../undercloud-dry-run-30264c62d6d44626.yaml | 5 +++++ .../tests/v1/undercloud/test_undercloud.py | 2 +- tripleoclient/v1/undercloud.py | 19 ++++++++++++++----- 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/undercloud-dry-run-30264c62d6d44626.yaml diff --git a/releasenotes/notes/undercloud-dry-run-30264c62d6d44626.yaml b/releasenotes/notes/undercloud-dry-run-30264c62d6d44626.yaml new file mode 100644 index 000000000..f2a6853ea --- /dev/null +++ b/releasenotes/notes/undercloud-dry-run-30264c62d6d44626.yaml @@ -0,0 +1,5 @@ +--- +features: + - The ``openstack undercloud install`` command now has a ``--dry-run`` + argument which will print the resulting install command instead of + executing it. diff --git a/tripleoclient/tests/v1/undercloud/test_undercloud.py b/tripleoclient/tests/v1/undercloud/test_undercloud.py index 738f4e258..2b5443d44 100644 --- a/tripleoclient/tests/v1/undercloud/test_undercloud.py +++ b/tripleoclient/tests/v1/undercloud/test_undercloud.py @@ -44,7 +44,7 @@ class TestUndercloudInstall(TestPluginV1): # DisplayCommandBase.take_action() returns two tuples self.cmd.take_action(parsed_args) - mock_subprocess.assert_called_with('instack-install-undercloud') + mock_subprocess.assert_called_with(['instack-install-undercloud']) @mock.patch('subprocess.check_call', autospec=True) def test_undercloud_install_with_heat(self, mock_subprocess): diff --git a/tripleoclient/v1/undercloud.py b/tripleoclient/v1/undercloud.py index 5f58cad3f..b47c89be8 100644 --- a/tripleoclient/v1/undercloud.py +++ b/tripleoclient/v1/undercloud.py @@ -52,6 +52,13 @@ class InstallUndercloud(command.Command): default=False, help=_("Do not perform undercloud configuration validations"), ) + parser.add_argument( + '--dry-run', + dest='dry_run', + action='store_true', + default=False, + help=_("Print the install command instead of running it"), + ) return parser def take_action(self, parsed_args): @@ -59,13 +66,15 @@ class InstallUndercloud(command.Command): utils.ensure_run_as_normal_user() if parsed_args.use_heat: + no_validations = parsed_args.dry_run or parsed_args.no_validations cmd = undercloud_config.\ - prepare_undercloud_deploy(no_validations=parsed_args. - no_validations) - print("Running: %s" % ' '.join(cmd)) - subprocess.check_call(cmd) + prepare_undercloud_deploy(no_validations=no_validations) else: - subprocess.check_call("instack-install-undercloud") + cmd = ["instack-install-undercloud"] + if parsed_args.dry_run: + print(' '.join(cmd)) + else: + subprocess.check_call(cmd) class UpgradeUndercloud(InstallUndercloud):