Ejemplo n.º 1
0
    def _guess_distribution(self):
        # try to find out which linux distribution this is
        dist = (get_distribution(), get_distribution_version(),
                get_distribution_codename())
        distribution_guess = {
            'distribution': dist[0] or 'NA',
            'distribution_version': dist[1] or 'NA',
            # distribution_release can be the empty string
            'distribution_release': 'NA' if dist[2] is None else dist[2]
        }

        distribution_guess['distribution_major_version'] = distribution_guess[
            'distribution_version'].split('.')[0] or 'NA'
        return distribution_guess
Ejemplo n.º 2
0
    def parse_distribution_file_Flatcar(self, name, data, path,
                                        collected_facts):
        flatcar_facts = {}
        distro = get_distribution()

        if distro.lower() == 'flatcar':
            if not data:
                return False, flatcar_facts
            release = re.search("^GROUP=(.*)", data)
            if release:
                flatcar_facts['distribution_release'] = release.group(1).strip(
                    '"')
        else:
            return False, flatcar_facts

        return True, flatcar_facts
Ejemplo n.º 3
0
    def parse_distribution_file_Coreos(self, name, data, path,
                                       collected_facts):
        coreos_facts = {}
        # FIXME: pass in ro copy of facts for this kind of thing
        distro = get_distribution()

        if distro.lower() == 'coreos':
            if not data:
                # include fix from #15230, #15228
                # TODO: verify this is ok for above bugs
                return False, coreos_facts
            release = re.search("^GROUP=(.*)", data)
            if release:
                coreos_facts['distribution_release'] = release.group(1).strip(
                    '"')
        else:
            return False, coreos_facts  # TODO: remove if tested without this

        return True, coreos_facts
Ejemplo n.º 4
0
 def test_distro_amazon_linux_long(self):
     with patch('assible.module_utils.distro.id', return_value="amazon"):
         assert get_distribution() == "Amazon"
Ejemplo n.º 5
0
 def test_distro_unknown(self):
     with patch('assible.module_utils.distro.id', return_value=""):
         assert get_distribution() == "OtherLinux"
Ejemplo n.º 6
0
    def test_distro_known(self):
        with patch('assible.module_utils.distro.id', return_value="alpine"):
            assert get_distribution() == "Alpine"

        with patch('assible.module_utils.distro.id', return_value="arch"):
            assert get_distribution() == "Arch"

        with patch('assible.module_utils.distro.id', return_value="centos"):
            assert get_distribution() == "Centos"

        with patch('assible.module_utils.distro.id',
                   return_value="clear-linux-os"):
            assert get_distribution() == "Clear-linux-os"

        with patch('assible.module_utils.distro.id', return_value="coreos"):
            assert get_distribution() == "Coreos"

        with patch('assible.module_utils.distro.id', return_value="debian"):
            assert get_distribution() == "Debian"

        with patch('assible.module_utils.distro.id', return_value="flatcar"):
            assert get_distribution() == "Flatcar"

        with patch('assible.module_utils.distro.id', return_value="linuxmint"):
            assert get_distribution() == "Linuxmint"

        with patch('assible.module_utils.distro.id', return_value="opensuse"):
            assert get_distribution() == "Opensuse"

        with patch('assible.module_utils.distro.id', return_value="oracle"):
            assert get_distribution() == "Oracle"

        with patch('assible.module_utils.distro.id', return_value="raspian"):
            assert get_distribution() == "Raspian"

        with patch('assible.module_utils.distro.id', return_value="rhel"):
            assert get_distribution() == "Redhat"

        with patch('assible.module_utils.distro.id', return_value="ubuntu"):
            assert get_distribution() == "Ubuntu"

        with patch('assible.module_utils.distro.id', return_value="virtuozzo"):
            assert get_distribution() == "Virtuozzo"

        with patch('assible.module_utils.distro.id', return_value="foo"):
            assert get_distribution() == "Foo"
Ejemplo n.º 7
0
def test_get_distribution_not_linux():
    """If it's not Linux, then it has no distribution"""
    with patch('platform.system', return_value='Foo'):
        assert get_distribution() is None