Fix manage_rdo function for CentOS8

In CentOS 8 the rdo-release package uses %dist in the name, which is
currently breaking the regular expresion used to parse it.

Also, in CentOS 8, yum-config-manager is not providing the full repo
configuration by stdout when enabling a repo, so instead of parsing it,
let's just trust on standard return value from command which works as
expected. For CentOS 7 we need to keep the same behavior.

This patch is fixing it to work with both centos7 and 8

Change-Id: Iafd6d6373d608c1b0fb797895a9969da28049fec
This commit is contained in:
Alfredo Moralejo 2020-04-16 11:23:50 +02:00
parent 322e746f3d
commit 5e94e1ad5d
1 changed files with 12 additions and 7 deletions

View File

@ -1133,10 +1133,14 @@ def manage_rdo(host, config):
# RDO repo is not installed, so we don't need to continue
return
match = re.match(r'^(?P<version>\w+)\-(?P<release>\d+\.[\d\w]+)\n', out)
version, release = match.group('version'), match.group('release')
match = re.match(r'^(?P<version>\w+)\-.*\n', out)
version = match.group('version')
if re.match(r'^(.*\.el8.*\n)', out):
dist_tag = '.el8'
else:
dist_tag = ''
rdo_url = ("https://www.rdoproject.org/repos/openstack-%(version)s/"
"rdo-release-%(version)s.rpm" % locals())
"rdo-release-%(version)s%(dist_tag)s.rpm" % locals())
server = utils.ScriptRunner(host)
server.append("(rpm -q 'rdo-release-%(version)s' ||"
@ -1156,12 +1160,13 @@ def manage_rdo(host, config):
server.append('yum-config-manager --disable %(reponame)s' % locals())
server.append('yum-config-manager --enable %(reponame)s-testing' % locals())
# yum-config-manager returns 0 always, but returns current setup
# if succeeds
rc, out = server.execute()
match = re.search('enabled\s*=\s*(1|True)', out)
if not match:
# In CentOS 7 yum-config-manager returns 0 always, but returns current setup
# if succeeds
# In CentOS 8 yum-config-manager returns 1 when failing but doesn't return current
# setup if succeeds
if (dist_tag == '.el8' and rc != 0) or (dist_tag == '' and not match):
msg = ('Failed to set RDO repo on host %s:\nRPM file seems to be '
'installed, but appropriate repo file is probably missing '
'in /etc/yum.repos.d/' % host)