示例#1
0
    def test_symlink(self):
        self._check_item(
            SymlinkToDirItem(from_target='t', source='x', dest='y'),
            {ProvidesDirectory(path='y')},
            {require_directory('/'), require_directory('/x')},
        )

        self._check_item(
            SymlinkToFileItem(
                from_target='t', source='source_file', dest='dest_symlink'
            ),
            {ProvidesFile(path='dest_symlink')},
            {require_directory('/'), require_file('/source_file')},
        )
示例#2
0
 def test_tarball_generator(self):
     with temp_filesystem() as fs_path, tempfile.NamedTemporaryFile() as t, \
             ExitStack() as exit_stack:
         with tarfile.TarFile(t.name, 'w') as tar_obj:
             tar_obj.add(fs_path, filter=_tarinfo_strip_dir_prefix(fs_path))
         self._check_item(
             image_source_item(
                 TarballItem,
                 exit_stack=exit_stack,
                 layer_opts=DUMMY_LAYER_OPTS,
             )(
                 from_target='t',
                 into_dir='y',
                 source={
                     'generator': '/bin/bash',
                     'generator_args': [
                         '-c',
                         'cp "$1" "$2"; basename "$1"',
                         'test_tarball_generator',  # $0
                         t.name,  # $1, making $2 the output directory
                     ],
                     'content_hash':
                         'sha256:' + _hash_path(t.name, 'sha256'),
                 },
                 force_root_ownership=False,
             ),
             temp_filesystem_provides('y'),
             {require_directory('y')},
         )
示例#3
0
    def test_tarball(self):
        with temp_filesystem() as fs_path, tempfile.TemporaryDirectory() as td:
            tar_path = os.path.join(td, 'test.tar')
            zst_path = os.path.join(td, 'test.tar.zst')

            with tarfile.TarFile(tar_path, 'w') as tar_obj:
                tar_obj.add(fs_path, filter=_tarinfo_strip_dir_prefix(fs_path))
            subprocess.check_call(['zstd', tar_path, '-o', zst_path])

            for path in (tar_path, zst_path):
                self._check_item(
                    _tarball_item(path, 'y'),
                    temp_filesystem_provides('y'),
                    {require_directory('y')},
                )

            # Test a hash validation failure, follows the item above
            with self.assertRaisesRegex(AssertionError, 'failed hash vali'):
                image_source_item(
                    TarballItem, exit_stack=None, layer_opts=DUMMY_LAYER_OPTS,
                )(
                    from_target='t',
                    into_dir='y',
                    source={
                        'source': tar_path,
                        'content_hash': 'sha256:deadbeef',
                    },
                    force_root_ownership=False,
                )
示例#4
0
    def test_install_file(self):
        with tempfile.NamedTemporaryFile() as tf:
            os.chmod(tf.name, stat.S_IXUSR)
            exe_item = _install_file_item(
                from_target='t',
                source={'source': tf.name},
                dest='d/c',
            )
        self.assertEqual(0o555, exe_item.mode)
        self.assertEqual(tf.name.encode(), exe_item.source)
        self._check_item(
            exe_item,
            {ProvidesFile(path='d/c')},
            {require_directory('d')},
        )

        # Checks `image.source(path=...)`
        data_item = _install_file_item(
            from_target='t',
            source={
                'source': 'a',
                'path': '/b/q'
            },
            dest='d',
        )
        self.assertEqual(0o444, data_item.mode)
        self.assertEqual(b'a/b/q', data_item.source)
        self.assertEqual(b'a/b/q', data_item.source)
        self._check_item(
            data_item,
            {ProvidesFile(path='d')},
            {require_directory('/')},
        )

        # NB: We don't need to get coverage for this check on ALL the items
        # because the presence of the ProvidesDoNotAccess items it the real
        # safeguard -- e.g. that's what prevents TarballItem from writing
        # to /meta/ or other protected paths.
        with self.assertRaisesRegex(AssertionError, 'cannot start with meta/'):
            _install_file_item(
                from_target='t',
                source={'source': 'a/b/c'},
                dest='/meta/foo',
            )
示例#5
0
 def test_stat_options(self):
     self._check_item(
         MakeDirsItem(
             from_target='t',
             into_dir='x',
             path_to_make='y/z',
             mode=0o733,
             user_group='cat:dog',
         ),
         {ProvidesDirectory(path='x/y'),
          ProvidesDirectory(path='x/y/z')},
         {require_directory('x')},
     )
示例#6
0
 def test_install_file_from_layer(self):
     layer = find_built_subvol(
         Path(__file__).dirname() / 'test-with-one-local-rpm')
     path_in_layer = b'usr/share/rpm_test/cheese2.txt'
     item = _install_file_item(
         from_target='t',
         source={
             'layer': layer,
             'path': '/' + path_in_layer.decode()
         },
         dest='cheese2',
     )
     self.assertEqual(0o444, item.mode)
     self.assertEqual(Path(layer.path(path_in_layer)), item.source)
     self.assertEqual(layer.path(path_in_layer), item.source)
     self._check_item(
         item,
         {ProvidesFile(path='cheese2')},
         {require_directory('/')},
     )
示例#7
0
 def requires(self):
     yield require_directory(os.path.dirname(self.dest))
示例#8
0
 def requires(self):
     if not _whitelisted_symlink_source(self.source):
         yield require_file(self.source)
     yield require_directory(os.path.dirname(self.dest))
示例#9
0
 def requires(self):
     yield require_directory(self.into_dir)
示例#10
0
 def test_make_dirs(self):
     self._check_item(
         MakeDirsItem(from_target='t', into_dir='x', path_to_make='y/z'),
         {ProvidesDirectory(path='x/y'), ProvidesDirectory(path='x/y/z')},
         {require_directory('x')},
     )
示例#11
0
 def requires(self):
     # We don't require the mountpoint itself since it will be shadowed,
     # so this item just makes it with default permissions.
     yield require_directory(os.path.dirname(self.mountpoint))