Esempio n. 1
0
 def test_distro_from_rootfs_raise_exception_if_different_base_distro_os(
         self):
     base = Distro(os='freebsd')
     test_dir = self.extract_test_tar('distro/windows-container-rootfs.tar')
     try:
         Distro.from_rootfs(test_dir, base_distro=base)
     except Exception as e:
         assert str(
             e
         ) == 'Inconsistent base distro OS: freebsd and found distro OS : windows'
Esempio n. 2
0
 def test_distro_from_os_release_returns_None_on_empty_or_missing_location(
         self):
     assert Distro.from_os_release_file('') is None
     assert Distro.from_os_release_file(None) is None
     assert Distro.from_os_release_file('THIS/dir/does/exists') is None
     try:
         assert Distro.from_os_release_file(__file__) is None
         self.fail('An exception should be raised.')
     except:
         pass
Esempio n. 3
0
 def test_distro_from_rootfs_has_base_distro_merged(self):
     base = Distro(os='windows', architecture='amd64')
     test_dir = self.extract_test_tar('distro/windows-container-rootfs.tar')
     distro = Distro.from_rootfs(test_dir, base_distro=base)
     expected = {
         'architecture': 'amd64',
         'identifier': 'windows',
         'os': 'windows',
     }
     results = {k: v for k, v in sorted(distro.to_dict().items()) if v}
     assert results == expected
Esempio n. 4
0
    def parse(cls, location):
        distro = Distro.from_os_release_file(location)
        distro_identifier = distro.identifier
        pretty_name = distro.pretty_name and distro.pretty_name.lower() or ''

        if distro_identifier == 'debian':
            namespace = 'debian'

            if 'distroless' in pretty_name:
                name = 'distroless'
            elif pretty_name.startswith('debian'):
                name = 'distroless'

        elif distro_identifier == 'ubuntu' and distro.id_like == 'debian':
            namespace = 'debian'
            name = 'ubuntu'
        else:
            namespace = distro_identifier
            name = 'ubuntu'

        version = distro.version_id

        yield models.PackageData(
            datasource_id=cls.datasource_id,
            type=cls.default_package_type,
            namespace=namespace,
            name=name,
            version=version,
        )
Esempio n. 5
0
    def test_distro_from_os_release_file(self):
        test_dir = self.get_test_loc('distro/os-release')

        for test_file in resource_iter(test_dir, with_dirs=False):
            if test_file.endswith('-expected.json'):
                continue
            expected = test_file + '-distro-expected.json'
            result = Distro.from_os_release_file(test_file).to_dict()
            check_expected(result, expected, regen=False)
Esempio n. 6
0
    def get_and_set_distro(self):
        """
        Return a Distro object for this image. Raise exceptions if it cannot be built.
        """
        bottom_layer = self.bottom_layer
        if not bottom_layer.extracted_to_location:
            raise Exception('The image has not been extracted.')

        self.distro = Distro.from_rootfs(bottom_layer.extracted_to_location)
        return self.distro
Esempio n. 7
0
    def test_distro_from_file(self):
        test_dir = self.get_test_loc('distro/chef-os-release/os-release')
        expected_dir = self.get_test_loc(
            'distro/chef-os-release/expected-distro')

        for os_release in listdir(test_dir):
            test_file = path.join(test_dir, os_release)
            expected = path.join(expected_dir, os_release + '-expected.json')
            result = Distro.from_file(test_file).to_dict()
            check_expected(result, expected, regen=False)
Esempio n. 8
0
    def get_and_set_distro(self):
        """
        Return a Distro object for this image. Raise exceptions if it cannot be
        built.
        """
        bottom_layer = self.bottom_layer
        if not bottom_layer.extracted_location:
            raise Exception('The image has not been extracted.')

        distro = Distro(
            os=self.os,
            architecture=self.architecture,
        )
        if self.os_version:
            distro.version = self.os_version

        self.distro = Distro.from_rootfs(
            location=bottom_layer.extracted_location,
            base_distro=distro,
        )

        return self.distro
Esempio n. 9
0
 def __attrs_post_init__(self, *args, **kwargs):
     self.distro = Distro.from_rootfs(self.location)
Esempio n. 10
0
 def test_distro_from_rootfs_detects_windows(self):
     test_dir = self.extract_test_tar('distro/windows-container-rootfs.tar')
     distro = Distro.from_rootfs(test_dir)
     expected = {'identifier': 'windows', 'os': 'windows'}
     results = {k: v for k, v in sorted(distro.to_dict().items()) if v}
     assert results == expected
Esempio n. 11
0
 def test_distro_does_not_default_to_linux(self):
     # we want to ensure that no attributes values contains linux by default
     distro = repr(Distro().to_dict().values()).lower()
     assert 'linux' not in distro
Esempio n. 12
0
 def test_distro_from_rootfs_return_None_if_base_distro_not_found(self):
     base = Distro(os='freebsd', architecture='amd64')
     not_a_rootfs = os.path.dirname(__file__)
     distro = Distro.from_rootfs(not_a_rootfs, base_distro=base)
     assert distro is None
Esempio n. 13
0
 def test_distro_from_rootfs_returns_a_distro_even_if_not_found(self):
     not_a_rootfs = os.path.dirname(__file__)
     distro = Distro.from_rootfs(not_a_rootfs)
     # all distro attributes should be empty
     assert not distro
Esempio n. 14
0
 def test_distro_from_rootfs_returns_None_on_empty_or_missing_location(
         self):
     assert Distro.from_rootfs('') is None
     assert Distro.from_rootfs(None) is None
     assert Distro.from_rootfs('THIS/dir/does/exists') is None