RHEL: fix distro detection and EPEL configuration

Distribution detection was working and it probably broke with RHEL 7.4.
This issue affects at least the MapR plugin, which installs few packages
at run-time and it fails to find the distribution.
A new field was added (internal_name) and used only for the comparison
because the 'name' proprty is used as parameter in other scripts and
changing it would touch a lot of code.

Also, fix the installation of EPEL repository, which was fixed
some time ago (from Pike) so that it did not depend on a specific
hardcoded version, but the fix worked only on CentOS, not on RHEL
where the epel-release package is not available.

Closes-Bug: #1740511
Related-Bug: #1657048
Change-Id: I21dc029f7bf556cd7dc0150ac2d7609494dba2fc
This commit is contained in:
Luigi Toscano 2017-12-29 17:17:06 +01:00
parent 1d04958131
commit 9cc5a41fe4
3 changed files with 16 additions and 4 deletions

View File

@ -14,8 +14,9 @@
class Distro(object):
def __init__(self, name, install_cmd, version_separator):
def __init__(self, name, internal_name, install_cmd, version_separator):
self._name = name
self._internal_name = internal_name
self._install_command = install_cmd
self._version_separator = version_separator
@ -23,6 +24,10 @@ class Distro(object):
def name(self):
return self._name
@property
def internal_name(self):
return self._internal_name
@property
def install_command(self):
return self._install_command
@ -46,24 +51,28 @@ class Distro(object):
UBUNTU = Distro(
name='Ubuntu',
internal_name='Ubuntu',
install_cmd='apt-get install --force-yes -y',
version_separator='=',
)
CENTOS = Distro(
name='CentOS',
internal_name='CentOS',
install_cmd='yum install -y',
version_separator='-',
)
RHEL = Distro(
name='RedHatEnterpriseServer',
internal_name='RedHat',
install_cmd='yum install -y',
version_separator='-',
)
SUSE = Distro(
name='Suse',
internal_name='Suse',
install_cmd='zypper',
version_separator=':',
)
@ -77,7 +86,7 @@ def get(instance):
with instance.remote() as r:
name = r.get_os_distrib()
for d in get_all():
if d.name.lower() in name:
if d.internal_name.lower() in name:
return d

View File

@ -28,7 +28,9 @@ protect=1
EOF
rpm --import http://package.mapr.com/releases/pub/maprgpg.key
yum install -y wget
yum install -y epel-release
if [ ! -e /etc/yum.repos.d/epel.repo ]; then
rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
fi
else
echo "Unknown distribution"
exit 1

View File

@ -21,7 +21,8 @@ class TestDistro(b.SaharaTestCase):
super(TestDistro, self).__init__(*args, **kwds)
self.install_cmd = 'foo_bar'
self.separator = '-'
self.distro = distro.Distro('foo', self.install_cmd, self.separator)
self.distro = distro.Distro('foo', 'foo', self.install_cmd,
self.separator)
def test_create_install_cmd(self):
pkgs = [('foo',), ('bar', 'version')]