From 9cc5a41fe46319f56b9fe7507d31e875f977182e Mon Sep 17 00:00:00 2001 From: Luigi Toscano Date: Fri, 29 Dec 2017 17:17:06 +0100 Subject: [PATCH] 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 --- sahara/plugins/mapr/domain/distro.py | 13 +++++++++++-- sahara/plugins/mapr/resources/add_mapr_repo.sh | 4 +++- sahara/tests/unit/plugins/mapr/test_distro.py | 3 ++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/sahara/plugins/mapr/domain/distro.py b/sahara/plugins/mapr/domain/distro.py index 5b260aa182..e8ff9ae762 100644 --- a/sahara/plugins/mapr/domain/distro.py +++ b/sahara/plugins/mapr/domain/distro.py @@ -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 diff --git a/sahara/plugins/mapr/resources/add_mapr_repo.sh b/sahara/plugins/mapr/resources/add_mapr_repo.sh index 9da04bd511..cd4ecde67c 100644 --- a/sahara/plugins/mapr/resources/add_mapr_repo.sh +++ b/sahara/plugins/mapr/resources/add_mapr_repo.sh @@ -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 diff --git a/sahara/tests/unit/plugins/mapr/test_distro.py b/sahara/tests/unit/plugins/mapr/test_distro.py index a717fd63f3..8432d0bdeb 100644 --- a/sahara/tests/unit/plugins/mapr/test_distro.py +++ b/sahara/tests/unit/plugins/mapr/test_distro.py @@ -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')]