Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Fix package manager used during undercloud packages update
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marios committed Jul 15, 2020
1 parent 2c6dc2f commit 9c53cb3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
27 changes: 23 additions & 4 deletions tripleoclient/tests/v1/undercloud/test_install_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@ def setUp(self):
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')
Expand All @@ -587,14 +589,30 @@ def setUp(self):
@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(
Expand All @@ -606,6 +624,7 @@ def test_undercloud_upgrade_default(self, mock_run_command,
'tripleo-ansible'],
name='Update extra packages'
)

mock_subprocess.assert_called_with([
'openstack', 'undercloud', 'upgrade', '--skip-package-updates',
'--no-validations'])
Expand Down
6 changes: 5 additions & 1 deletion tripleoclient/v1/undercloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ def _update_extra_packages(self, packages=[], dry_run=False):
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(
Expand Down

0 comments on commit 9c53cb3

Please sign in to comment.