diff --git a/tripleoclient/constants.py b/tripleoclient/constants.py index 5bd6d4033..9775b18fb 100644 --- a/tripleoclient/constants.py +++ b/tripleoclient/constants.py @@ -177,3 +177,11 @@ UNUSED_PARAMETER_EXCLUDES_RE = ['^(Docker|Container).*Image$', EXPORT_PASSWORD_EXCLUDE_PATTERNS = [ 'ceph.*' ] + +# Package that need to be to the latest before undercloud +# update/update/ffwd. +UNDERCLOUD_EXTRA_PACKAGES = [ + "openstack-tripleo-heat-templates", + "openstack-tripleo-validations", + "tripleo-ansible" +] diff --git a/tripleoclient/tests/v1/undercloud/test_install_upgrade.py b/tripleoclient/tests/v1/undercloud/test_install_upgrade.py index c08e64497..4702b5973 100644 --- a/tripleoclient/tests/v1/undercloud/test_install_upgrade.py +++ b/tripleoclient/tests/v1/undercloud/test_install_upgrade.py @@ -581,7 +581,9 @@ class TestUndercloudUpgrade(TestPluginV1): @mock.patch('os.mkdir') @mock.patch('tripleoclient.utils.write_env_file', autospec=True) @mock.patch('subprocess.check_call', autospec=True) - def test_undercloud_upgrade_default(self, mock_subprocess, + @mock.patch('tripleoclient.utils.run_command', autospec=True) + def test_undercloud_upgrade_default(self, mock_run_command, + mock_subprocess, mock_wr, mock_os, mock_copy, mock_user, mock_getuid): @@ -591,6 +593,13 @@ class TestUndercloudUpgrade(TestPluginV1): # DisplayCommandBase.take_action() returns two tuples self.cmd.take_action(parsed_args) + mock_run_command.assert_called_with( + ['sudo', 'dnf', 'upgrade', '-y', + 'openstack-tripleo-heat-templates', + 'openstack-tripleo-validations', + 'tripleo-ansible'], + name='Update extra packages' + ) mock_subprocess.assert_called_with( ['sudo', '--preserve-env', 'openstack', 'tripleo', 'deploy', @@ -648,7 +657,9 @@ class TestUndercloudUpgrade(TestPluginV1): @mock.patch('os.mkdir') @mock.patch('tripleoclient.utils.write_env_file', autospec=True) @mock.patch('subprocess.check_call', autospec=True) - def test_undercloud_upgrade_with_heat_enabled(self, mock_subprocess, + @mock.patch('tripleoclient.utils.run_command', autospec=True) + def test_undercloud_upgrade_with_heat_enabled(self, mock_run_command, + mock_subprocess, mock_wr, mock_os, mock_copy, mock_user, mock_getuid): @@ -659,6 +670,14 @@ class TestUndercloudUpgrade(TestPluginV1): # DisplayCommandBase.take_action() returns two tuples self.cmd.take_action(parsed_args) + mock_run_command.assert_called_with( + ['sudo', 'dnf', 'upgrade', '-y', + 'openstack-tripleo-heat-templates', + 'openstack-tripleo-validations', + 'tripleo-ansible'], + name='Update extra packages' + ) + mock_subprocess.assert_called_with( ['sudo', '--preserve-env', 'openstack', 'tripleo', 'deploy', '--standalone', '--standalone-role', 'Undercloud', '--stack', @@ -714,7 +733,9 @@ class TestUndercloudUpgrade(TestPluginV1): @mock.patch('os.mkdir') @mock.patch('tripleoclient.utils.write_env_file', autospec=True) @mock.patch('subprocess.check_call', autospec=True) - def test_undercloud_upgrade_with_heat_true(self, mock_subprocess, + @mock.patch('tripleoclient.utils.run_command', autospec=True) + def test_undercloud_upgrade_with_heat_true(self, mock_run_command, + mock_subprocess, mock_wr, mock_os, mock_copy, mock_user, mock_getuid): @@ -725,6 +746,14 @@ class TestUndercloudUpgrade(TestPluginV1): # DisplayCommandBase.take_action() returns two tuples self.cmd.take_action(parsed_args) + mock_run_command.assert_called_with( + ['sudo', 'dnf', 'upgrade', '-y', + 'openstack-tripleo-heat-templates', + 'openstack-tripleo-validations', + 'tripleo-ansible'], + name='Update extra packages' + ) + mock_subprocess.assert_called_with( ['sudo', '--preserve-env', 'openstack', 'tripleo', 'deploy', '--standalone', '--standalone-role', 'Undercloud', '--stack', @@ -780,7 +809,9 @@ class TestUndercloudUpgrade(TestPluginV1): @mock.patch('os.mkdir') @mock.patch('tripleoclient.utils.write_env_file', autospec=True) @mock.patch('subprocess.check_call', autospec=True) - def test_undercloud_upgrade_with_heat_and_yes(self, mock_subprocess, + @mock.patch('tripleoclient.utils.run_command', autospec=True) + def test_undercloud_upgrade_with_heat_and_yes(self, mock_run_command, + mock_subprocess, mock_wr, mock_os, mock_copy, mock_user, mock_getuid): @@ -791,6 +822,14 @@ class TestUndercloudUpgrade(TestPluginV1): # DisplayCommandBase.take_action() returns two tuples self.cmd.take_action(parsed_args) + mock_run_command.assert_called_with( + ['sudo', 'dnf', 'upgrade', '-y', + 'openstack-tripleo-heat-templates', + 'openstack-tripleo-validations', + 'tripleo-ansible'], + name='Update extra packages' + ) + mock_subprocess.assert_called_with( ['sudo', '--preserve-env', 'openstack', 'tripleo', 'deploy', '--standalone', '--standalone-role', 'Undercloud', '--stack', @@ -847,7 +886,9 @@ class TestUndercloudUpgrade(TestPluginV1): @mock.patch('os.mkdir') @mock.patch('tripleoclient.utils.write_env_file', autospec=True) @mock.patch('subprocess.check_call', autospec=True) - def test_undercloud_upgrade_with_heat_and_debug(self, mock_subprocess, + @mock.patch('tripleoclient.utils.run_command', autospec=True) + def test_undercloud_upgrade_with_heat_and_debug(self, mock_run_command, + mock_subprocess, mock_wr, mock_os, mock_copy, mock_user, mock_getuid): @@ -861,6 +902,14 @@ class TestUndercloudUpgrade(TestPluginV1): self.cmd.take_action(parsed_args) self.cmd.app_args.verbose_level = old_verbose + mock_run_command.assert_called_with( + ['sudo', 'dnf', 'upgrade', '-y', + 'openstack-tripleo-heat-templates', + 'openstack-tripleo-validations', + 'tripleo-ansible'], + name='Update extra packages' + ) + mock_subprocess.assert_called_with( ['sudo', '--preserve-env', 'openstack', 'tripleo', 'deploy', '--standalone', '--standalone-role', 'Undercloud', '--stack', diff --git a/tripleoclient/v1/undercloud.py b/tripleoclient/v1/undercloud.py index 53249db71..1d97aacdb 100644 --- a/tripleoclient/v1/undercloud.py +++ b/tripleoclient/v1/undercloud.py @@ -165,6 +165,29 @@ class UpgradeUndercloud(InstallUndercloud): log = logging.getLogger(__name__ + ".UpgradeUndercloud") osloconfig = cfg.CONF + def _update_extra_packages(self, packages=[], dry_run=False): + """Necessary packages to be updated before undercloud upgrade.""" + + cmd = [] + if packages: + cmd = ['sudo', 'dnf', 'upgrade', '-y'] + packages + + if cmd: + if not dry_run: + self.log.warning( + "Updating necessary packages: {}\n{}".format( + " ".join(packages), + ("Note that tripleoclient and tripleo-common " + "still need to be updated manually.") + ), + ) + output = utils.run_command(cmd, name="Update extra packages") + self.log.warning("{}".format(output)) + else: + self.log.warning( + "Would update necessary packages: {}".format(" ".join(cmd)) + ) + def take_action(self, parsed_args): # Fetch configuration used to add logging to a file utils.load_config(self.osloconfig, constants.UNDERCLOUD_CONF_PATH) @@ -173,6 +196,10 @@ class UpgradeUndercloud(InstallUndercloud): self.log.debug("take action(%s)" % parsed_args) utils.ensure_run_as_normal_user() + + self._update_extra_packages(constants.UNDERCLOUD_EXTRA_PACKAGES, + parsed_args.dry_run) + cmd = undercloud_config.\ prepare_undercloud_deploy( upgrade=True, @@ -182,6 +209,7 @@ class UpgradeUndercloud(InstallUndercloud): verbose_level=self.app_args.verbose_level, force_stack_update=parsed_args.force_stack_update) self.log.warning("Running: %s" % ' '.join(cmd)) + if not parsed_args.dry_run: try: subprocess.check_call(cmd)