Use distro.id() instead of distro.name() (#52199)
* Update sys_info unit tests * Correct distribution values in hostname.py * Normalize Rhel to Redhat
This commit is contained in:
parent
85ba4d7c73
commit
bf28b5ceca
4 changed files with 104 additions and 86 deletions
|
@ -29,12 +29,12 @@ def get_distribution():
|
|||
distribution = None
|
||||
|
||||
if platform.system() == 'Linux':
|
||||
distribution = distro.name().capitalize()
|
||||
distribution = distro.id().capitalize()
|
||||
|
||||
# FIXME: Would we need to normalize these if we used: id() instead of name()?
|
||||
distribution_words = distribution.split()
|
||||
if 'Amazon' in distribution_words:
|
||||
if distribution == 'Amzn':
|
||||
distribution = 'Amazon'
|
||||
elif distribution == 'Rhel':
|
||||
distribution = 'Redhat'
|
||||
elif not distribution:
|
||||
distribution = 'OtherLinux'
|
||||
|
||||
|
|
|
@ -579,13 +579,7 @@ class SLESHostname(Hostname):
|
|||
|
||||
class OpenSUSEHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Opensuse leap'
|
||||
strategy_class = SystemdStrategy
|
||||
|
||||
|
||||
class TumbleweedHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Opensuse tumbleweed'
|
||||
distribution = 'Opensuse'
|
||||
strategy_class = SystemdStrategy
|
||||
|
||||
|
||||
|
@ -595,33 +589,9 @@ class ArchHostname(Hostname):
|
|||
strategy_class = SystemdStrategy
|
||||
|
||||
|
||||
class RedHat5Hostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Redhat'
|
||||
strategy_class = RedHatStrategy
|
||||
|
||||
|
||||
class RHELHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Red hat enterprise linux'
|
||||
strategy_class = RedHatStrategy
|
||||
|
||||
|
||||
class RedHatServerHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Red hat enterprise linux server'
|
||||
strategy_class = RedHatStrategy
|
||||
|
||||
|
||||
class RedHatWorkstationHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Red hat enterprise linux workstation'
|
||||
strategy_class = RedHatStrategy
|
||||
|
||||
|
||||
class RedHatAtomicHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Red hat enterprise linux atomic host'
|
||||
distribution = 'Redhat'
|
||||
strategy_class = RedHatStrategy
|
||||
|
||||
|
||||
|
@ -631,51 +601,27 @@ class CentOSHostname(Hostname):
|
|||
strategy_class = RedHatStrategy
|
||||
|
||||
|
||||
class CentOSLinuxHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Centos linux'
|
||||
strategy_class = RedHatStrategy
|
||||
|
||||
|
||||
class CloudlinuxHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Cloudlinux'
|
||||
strategy_class = RedHatStrategy
|
||||
|
||||
|
||||
class CloudlinuxServerHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Cloudlinux server'
|
||||
strategy_class = RedHatStrategy
|
||||
|
||||
|
||||
class ScientificHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Scientific'
|
||||
strategy_class = RedHatStrategy
|
||||
|
||||
|
||||
class ScientificLinuxHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Scientific linux'
|
||||
strategy_class = RedHatStrategy
|
||||
|
||||
|
||||
class ScientificLinuxCERNHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Scientific linux cern slc'
|
||||
strategy_class = RedHatStrategy
|
||||
|
||||
|
||||
class OracleLinuxHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Oracle linux server'
|
||||
distribution = 'Oracle'
|
||||
strategy_class = RedHatStrategy
|
||||
|
||||
|
||||
class VirtuozzoLinuxHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Virtuozzo linux'
|
||||
distribution = 'Virtuozzo'
|
||||
strategy_class = RedHatStrategy
|
||||
|
||||
|
||||
|
@ -685,12 +631,6 @@ class AmazonLinuxHostname(Hostname):
|
|||
strategy_class = RedHatStrategy
|
||||
|
||||
|
||||
class SangomaLinuxHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Derived from red hat enterprise linux '
|
||||
strategy_class = RedHatStrategy
|
||||
|
||||
|
||||
class DebianHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Debian'
|
||||
|
@ -729,13 +669,13 @@ class DevuanHostname(Hostname):
|
|||
|
||||
class RaspbianHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Raspbian gnu/linux'
|
||||
distribution = 'Raspbian'
|
||||
strategy_class = DebianStrategy
|
||||
|
||||
|
||||
class GentooHostname(Hostname):
|
||||
platform = 'Linux'
|
||||
distribution = 'Gentoo base system'
|
||||
distribution = 'Gentoo'
|
||||
strategy_class = OpenRCStrategy
|
||||
|
||||
|
||||
|
|
|
@ -52,21 +52,60 @@ def test_get_distribution_not_linux():
|
|||
|
||||
@pytest.mark.usefixtures("platform_linux")
|
||||
class TestGetDistribution:
|
||||
""" Tests for get_distribution that have to find somethine"""
|
||||
"""Tests for get_distribution that have to find something"""
|
||||
def test_distro_known(self):
|
||||
with patch('ansible.module_utils.distro.name', return_value="foo"):
|
||||
with patch('ansible.module_utils.distro.id', return_value="alpine"):
|
||||
assert get_distribution() == "Alpine"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="arch"):
|
||||
assert get_distribution() == "Arch"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="centos"):
|
||||
assert get_distribution() == "Centos"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="clear-linux-os"):
|
||||
assert get_distribution() == "Clear-linux-os"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="coreos"):
|
||||
assert get_distribution() == "Coreos"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="debian"):
|
||||
assert get_distribution() == "Debian"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="linuxmint"):
|
||||
assert get_distribution() == "Linuxmint"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="opensuse"):
|
||||
assert get_distribution() == "Opensuse"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="oracle"):
|
||||
assert get_distribution() == "Oracle"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="raspian"):
|
||||
assert get_distribution() == "Raspian"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="rhel"):
|
||||
assert get_distribution() == "Redhat"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="ubuntu"):
|
||||
assert get_distribution() == "Ubuntu"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="virtuozzo"):
|
||||
assert get_distribution() == "Virtuozzo"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="foo"):
|
||||
assert get_distribution() == "Foo"
|
||||
|
||||
def test_distro_unknown(self):
|
||||
with patch('ansible.module_utils.distro.name', return_value=""):
|
||||
with patch('ansible.module_utils.distro.id', return_value=""):
|
||||
assert get_distribution() == "OtherLinux"
|
||||
|
||||
def test_distro_amazon_part_of_another_name(self):
|
||||
with patch('ansible.module_utils.distro.name', return_value="AmazonFooBar"):
|
||||
assert get_distribution() == "Amazonfoobar"
|
||||
def test_distro_amazon_linux_short(self):
|
||||
with patch('ansible.module_utils.distro.id', return_value="amzn"):
|
||||
assert get_distribution() == "Amazon"
|
||||
|
||||
def test_distro_amazon_linux(self):
|
||||
with patch('ansible.module_utils.distro.name', return_value="Amazon Linux AMI"):
|
||||
def test_distro_amazon_linux_long(self):
|
||||
with patch('ansible.module_utils.distro.id', return_value="amazon"):
|
||||
assert get_distribution() == "Amazon"
|
||||
|
||||
|
||||
|
|
|
@ -39,21 +39,60 @@ def test_get_distribution_not_linux():
|
|||
|
||||
@pytest.mark.usefixtures("platform_linux")
|
||||
class TestGetDistribution:
|
||||
""" Tests for get_distribution that have to find somethine"""
|
||||
"""Tests for get_distribution that have to find something"""
|
||||
def test_distro_known(self):
|
||||
with patch('ansible.module_utils.distro.name', return_value="foo"):
|
||||
with patch('ansible.module_utils.distro.id', return_value="alpine"):
|
||||
assert get_distribution() == "Alpine"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="arch"):
|
||||
assert get_distribution() == "Arch"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="centos"):
|
||||
assert get_distribution() == "Centos"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="clear-linux-os"):
|
||||
assert get_distribution() == "Clear-linux-os"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="coreos"):
|
||||
assert get_distribution() == "Coreos"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="debian"):
|
||||
assert get_distribution() == "Debian"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="linuxmint"):
|
||||
assert get_distribution() == "Linuxmint"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="opensuse"):
|
||||
assert get_distribution() == "Opensuse"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="oracle"):
|
||||
assert get_distribution() == "Oracle"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="raspian"):
|
||||
assert get_distribution() == "Raspian"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="rhel"):
|
||||
assert get_distribution() == "Redhat"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="ubuntu"):
|
||||
assert get_distribution() == "Ubuntu"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="virtuozzo"):
|
||||
assert get_distribution() == "Virtuozzo"
|
||||
|
||||
with patch('ansible.module_utils.distro.id', return_value="foo"):
|
||||
assert get_distribution() == "Foo"
|
||||
|
||||
def test_distro_unknown(self):
|
||||
with patch('ansible.module_utils.distro.name', return_value=""):
|
||||
with patch('ansible.module_utils.distro.id', return_value=""):
|
||||
assert get_distribution() == "OtherLinux"
|
||||
|
||||
def test_distro_amazon_part_of_another_name(self):
|
||||
with patch('ansible.module_utils.distro.name', return_value="AmazonFooBar"):
|
||||
assert get_distribution() == "Amazonfoobar"
|
||||
def test_distro_amazon_linux_short(self):
|
||||
with patch('ansible.module_utils.distro.id', return_value="amzn"):
|
||||
assert get_distribution() == "Amazon"
|
||||
|
||||
def test_distro_amazon_linux(self):
|
||||
with patch('ansible.module_utils.distro.name', return_value="Amazon Linux AMI"):
|
||||
def test_distro_amazon_linux_long(self):
|
||||
with patch('ansible.module_utils.distro.id', return_value="amazon"):
|
||||
assert get_distribution() == "Amazon"
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue