Exemple #1
0
def get_os():
    dist, release = linux_distribution_id(), linux_distribution_version()
    major_release = release.partition('.')[0]

    os_string = ''
    if dist.lower().startswith('redhat'):
        os_string += 'rhel'
    elif dist.lower().startswith('suse'):
        os_string += 'suse'

    os_string += major_release

    return os_string
Exemple #2
0
    def test_linux_distribution_is_ubuntu_20_04(self):
        with tempfile.NamedTemporaryFile(mode='w+t') as f:
            #taken from /etc/os-release on an Ubuntu system.
            f.writelines([
                'NAME="Ubuntu"\n', 'VERSION="20.04.1 LTS (Focal Fossa)"\n',
                'ID=ubuntu\n', 'ID_LIKE=debian\n',
                'PRETTY_NAME="Ubuntu 20.04.1 LTS"\n', 'VERSION_ID="20.04"\n',
                'HOME_URL="https://www.ubuntu.com/"\n',
                'SUPPORT_URL="https://help.ubuntu.com/"\n',
                'BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"\n',
                'PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"\n',
                'VERSION_CODENAME=focal\n', 'UBUNTU_CODENAME=focal\n'
            ])
            f.seek(0)

            self.assertEqual(linux_distribution_id(f.name), 'ubuntu')
            self.assertEqual(linux_distribution_version(f.name), '20.04')
Exemple #3
0
    def test_linux_distribution_is_centos_8(self):
        with tempfile.NamedTemporaryFile(mode='w+t') as f:
            #taken from /etc/os-release on an centos system.
            f.writelines([
                'NAME="CentOS Linux"\n', 'VERSION="8"\n', 'ID="centos"\n',
                'ID_LIKE="rhel fedora"\n', 'VERSION_ID="8"\n',
                'PLATFORM_ID="platform:el8"\n',
                'PRETTY_NAME="CentOS Linux 8"\n', 'ANSI_COLOR="0;31"\n',
                'CPE_NAME="cpe:/o:centos:centos:8"\n',
                'HOME_URL="https://centos.org/"\n',
                'BUG_REPORT_URL="https://bugs.centos.org/"\n',
                'CENTOS_MANTISBT_PROJECT="CentOS-8"\n',
                'CENTOS_MANTISBT_PROJECT_VERSION="8"\n'
            ])
            f.seek(0)

            self.assertEqual(linux_distribution_id(f.name), 'centos')
            self.assertEqual(linux_distribution_version(f.name), '8')
Exemple #4
0
 def test_linux_distribuion_unknown_if_os_release_file_empty(self):
     self.assertEqual(linux_distribution_id('non_existent_file'), 'unknown')
     self.assertEqual(linux_distribution_version('non_existent_file'),
                      'unknown')