From c20dcf9aeab45cd062c5cbe82c9c5baf9dc20684 Mon Sep 17 00:00:00 2001 From: Marios Andreou Date: Wed, 8 Jul 2020 18:27:01 +0300 Subject: [PATCH] Fix package manager used during undercloud packages update As described in the related bug we need to use dnf instead of yum for centos8 otherwise it fails in the undercloud packages update. I am using the python version to determine - py3 is dnf. As part of discussion here when dnf isn't available fall back to yum. Found as part of the work in [1]. Related-Bug: 1886837 [1] https://tree.taiga.io/project/tripleo-ci-board/task/1817 Change-Id: Idac62d37a19ee49f30936e20021a9dab5af40eec (cherry picked from commit 9c53cb3ef5ad513b05d4888552a3280e0eec43ca) --- .../v1/undercloud/test_install_upgrade.py | 27 ++++++++++++++++--- tripleoclient/v1/undercloud.py | 6 ++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/tripleoclient/tests/v1/undercloud/test_install_upgrade.py b/tripleoclient/tests/v1/undercloud/test_install_upgrade.py index 7e6f0020a..cd960aa60 100644 --- a/tripleoclient/tests/v1/undercloud/test_install_upgrade.py +++ b/tripleoclient/tests/v1/undercloud/test_install_upgrade.py @@ -575,6 +575,8 @@ class TestUndercloudUpgrade(TestPluginV1): app_args.verbose_level = 1 self.cmd = undercloud.UpgradeUndercloud(self.app, app_args) + @mock.patch('os.system') + @mock.patch('sys.version_info') @mock.patch('tripleoclient.utils.prompt_user_for_confirmation', return_value=True) @mock.patch.object(sys, 'executable', 'python2') @@ -587,14 +589,30 @@ class TestUndercloudUpgrade(TestPluginV1): @mock.patch('subprocess.check_call', autospec=True) @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, mock_confirm): + mock_subprocess, mock_wr, + mock_os_mkdir, mock_copy, mock_user, + mock_getuid, mock_confirm, mock_sys, + mock_os_sys): arglist = ['--no-validations'] verifylist = [] parsed_args = self.check_parser(self.cmd, arglist, verifylist) + mock_sys.major = 3 + mock_os_sys.return_value = 0 + # DisplayCommandBase.take_action() returns two tuples + self.cmd.take_action(parsed_args) + mock_run_command.assert_called_with( + ['sudo', 'dnf', 'upgrade', '-y', + 'python2-tripleoclient', + 'openstack-tripleo-common', + 'openstack-tripleo-heat-templates', + 'openstack-tripleo-validations', + 'tripleo-ansible'], + name='Update extra packages' + ) + mock_os_sys.assert_called_with("which dnf") + + mock_sys.major = 2 # DisplayCommandBase.take_action() returns two tuples self.cmd.take_action(parsed_args) mock_run_command.assert_called_with( @@ -606,6 +624,7 @@ class TestUndercloudUpgrade(TestPluginV1): 'tripleo-ansible'], name='Update extra packages' ) + mock_subprocess.assert_called_with([ 'openstack', 'undercloud', 'upgrade', '--skip-package-updates', '--no-validations']) diff --git a/tripleoclient/v1/undercloud.py b/tripleoclient/v1/undercloud.py index 46a8f81d8..3954196bd 100644 --- a/tripleoclient/v1/undercloud.py +++ b/tripleoclient/v1/undercloud.py @@ -183,7 +183,11 @@ class UpgradeUndercloud(InstallUndercloud): if not packages: return - cmd = ['sudo', 'yum', 'upgrade', '-y'] + packages + pkg_manager = 'yum' + if sys.version_info.major >= 3 and os.system('which dnf') == 0: + pkg_manager = 'dnf' + + cmd = ['sudo', pkg_manager, 'upgrade', '-y'] + packages if not dry_run: self.log.warning("Updating necessary packages: {}".format(