コード例 #1
0
    def test_pack_image_to_file(self, mock_OCI, mock_RuntimeConfig,
                                mock_command, mock_compress):
        oci = Mock()
        oci.container_name = 'kiwi_oci_dir.XXXX/oci_layout:latest'
        mock_OCI.return_value = oci
        compressor = Mock()
        compressor.xz = Mock(return_value='result.tar.xz')
        mock_compress.return_value = compressor
        docker = ContainerImageDocker('root_dir', {
            'container_name': 'foo/bar',
            'additional_tags': ['current', 'foobar']
        })
        docker.runtime_config.get_container_compression = Mock(
            return_value='xz')

        assert docker.pack_image_to_file('result.tar') == 'result.tar.xz'

        assert mock_command.call_args_list == [
            call(['rm', '-r', '-f', 'result.tar']),
            call([
                'skopeo', 'copy', 'oci:kiwi_oci_dir.XXXX/oci_layout:latest',
                'docker-archive:result.tar:foo/bar:latest', '--additional-tag',
                'foo/bar:current', '--additional-tag', 'foo/bar:foobar'
            ])
        ]
        mock_compress.assert_called_once_with('result.tar')
        compressor.xz.assert_called_once_with(
            docker.runtime_config.get_xz_options.return_value)

        docker.runtime_config.get_container_compression = Mock(
            return_value=None)

        assert docker.pack_image_to_file('result.tar') == 'result.tar'
コード例 #2
0
    def test_pack_image_to_file(self, mock_command, mock_compress):
        docker = ContainerImageDocker('root_dir', {'container_name': 'foo/bar'})
        docker.oci_dir = 'kiwi_oci_dir'
        docker.pack_image_to_file('result.tar.xz')

        assert mock_command.call_args_list == [
            call(['rm', '-r', '-f', 'result.tar']),
            call([
                'skopeo', 'copy', 'oci:kiwi_oci_dir/umoci_layout:latest',
                'docker-archive:result.tar:foo/bar:latest'
            ])
        ]
        mock_compress.assert_called_once_with('result.tar')
コード例 #3
0
class TestContainerImageDocker(object):
    def setup(self):
        self.docker = ContainerImageDocker('root_dir')

    @patch('kiwi.container.docker.ArchiveTar')
    def test_create(self, mock_archive):
        archive = mock.Mock()
        mock_archive.return_value = archive
        self.docker.create('result.tar.xz')
        mock_archive.assert_called_once_with('result.tar')
        archive.create_xz_compressed.assert_called_once_with(
            exclude=[
                'image', '.profile', '.kconfig', 'var/cache/kiwi', 'boot'
            ], source_dir='root_dir'
        )
コード例 #4
0
class TestContainerImageDocker(object):
    def setup(self):
        self.docker = ContainerImageDocker('root_dir')

    @patch('kiwi.container.docker.ArchiveTar')
    def test_create(self, mock_archive):
        archive = mock.Mock()
        mock_archive.return_value = archive
        self.docker.create('result.tar.xz')
        mock_archive.assert_called_once_with('result.tar')
        archive.create_xz_compressed.assert_called_once_with(
            exclude=[
                'image', '.profile', '.kconfig', 'boot', 'var/cache/kiwi'
            ], source_dir='root_dir'
        )
コード例 #5
0
 def test_init_custom_args(self):
     docker = ContainerImageDocker(
         'root_dir', {
             'container_name': 'foo',
             'container_tag': 'bar',
             'entry_command': [
                 "--config.entrypoint=/bin/bash",
                 "--config.entrypoint=-x"
              ],
             'entry_subcommand': [
                 "--config.cmd=ls",
                 "--config.cmd=-l"
              ],
              'maintainer': ['--author=tux'],
              'user': ['--config.user=root'],
              'workingdir': ['--config.workingdir=/root'],
              'expose_ports': [
                  "--config.exposedports=80",
                  "--config.exposedports=42"
              ],
              'volumes': [
                  "--config.volume=/var/log",
                  "--config.volume=/tmp"
              ],
              'environment': [
                  "--config.env=PATH=/bin'",
                  "--config.env=FOO=bar"
              ],
              'labels': [
                  "--config.label=a=value",
                  "--config.label=b=value"
              ]
         }
     )
コード例 #6
0
 def __new__(self, name, root_dir, custom_args=None):
     if name == 'docker':
         return ContainerImageDocker(root_dir, custom_args)
     elif name == 'oci':
         return ContainerImageOCI(root_dir, custom_args)
     else:
         raise KiwiContainerImageSetupError(
             'Support for %s container not implemented' % name)
コード例 #7
0
    def test_pack_image_to_file(
        self, mock_RuntimeConfig, mock_command, mock_compress
    ):
        compressor = Mock()
        compressor.xz = Mock(
            return_value='result.tar.xz'
        )
        mock_compress.return_value = compressor
        docker = ContainerImageDocker(
            'root_dir', {
                'container_name': 'foo/bar',
                'additional_tags': ['current', 'foobar']
            }
        )
        docker.oci_dir = 'kiwi_oci_dir'
        docker.runtime_config.get_container_compression = Mock(
            return_value='xz'
        )

        assert docker.pack_image_to_file('result.tar') == 'result.tar.xz'

        assert mock_command.call_args_list == [
            call(['rm', '-r', '-f', 'result.tar']),
            call([
                'skopeo', 'copy', 'oci:kiwi_oci_dir/umoci_layout:latest',
                'docker-archive:result.tar:foo/bar:latest',
                '--additional-tag', 'foo/bar:current',
                '--additional-tag', 'foo/bar:foobar'
            ])
        ]
        mock_compress.assert_called_once_with('result.tar')
        compressor.xz.assert_called_once_with(
            docker.runtime_config.get_xz_options.return_value
        )

        docker.runtime_config.get_container_compression = Mock(
            return_value=None
        )

        assert docker.pack_image_to_file('result.tar') == 'result.tar'
コード例 #8
0
 def test_del(self, mock_wipe):
     docker = ContainerImageDocker('root_dir')
     docker.docker_dir = 'dir_a'
     docker.docker_root_dir = 'dir_b'
     docker.__del__()
     assert mock_wipe.call_args_list == [
         call('dir_a'), call('dir_b')
     ]
コード例 #9
0
 def setup(self):
     self.docker = ContainerImageDocker(
         'root_dir', {
             'container_name': 'foo'
         }
     )
コード例 #10
0
class TestContainerImageDocker(object):
    def setup(self):
        self.docker = ContainerImageDocker(
            'root_dir', {
                'container_name': 'foo'
            }
        )

    def test_init_custom_args(self):
        docker = ContainerImageDocker(
            'root_dir', {
                'container_name': 'foo',
                'container_tag': 'bar',
                'entry_command': [
                    "--config.entrypoint=/bin/bash",
                    "--config.entrypoint=-x"
                 ],
                'entry_subcommand': [
                    "--config.cmd=ls",
                    "--config.cmd=-l"
                 ],
                 'maintainer': ['--author=tux'],
                 'user': ['--config.user=root'],
                 'workingdir': ['--config.workingdir=/root'],
                 'expose_ports': [
                     "--config.exposedports=80",
                     "--config.exposedports=42"
                 ],
                 'volumes': [
                     "--config.volume=/var/log",
                     "--config.volume=/tmp"
                 ],
                 'environment': [
                     "--config.env=PATH=/bin'",
                     "--config.env=FOO=bar"
                 ],
                 'labels': [
                     "--config.label=a=value",
                     "--config.label=b=value"
                 ]
            }
        )

    @patch('kiwi.container.docker.Path.wipe')
    def test_del(self, mock_wipe):
        docker = ContainerImageDocker('root_dir')
        docker.docker_dir = 'dir_a'
        docker.docker_root_dir = 'dir_b'
        docker.__del__()
        assert mock_wipe.call_args_list == [
            call('dir_a'), call('dir_b')
        ]

    @patch('kiwi.container.docker.Compress')
    @patch('kiwi.container.docker.Command.run')
    @patch('kiwi.container.docker.DataSync')
    @patch('kiwi.container.docker.mkdtemp')
    @patch('kiwi.container.docker.Path.wipe')
    def test_create(
        self, mock_wipe, mock_mkdtemp, mock_sync, mock_command, mock_compress
    ):
        compressor = mock.Mock()
        mock_compress.return_value = compressor
        docker_root = mock.Mock()
        mock_sync.return_value = docker_root
        tmpdirs = ['kiwi_docker_root_dir', 'kiwi_docker_dir']

        def call_mkdtemp(prefix):
            return tmpdirs.pop()

        mock_mkdtemp.side_effect = call_mkdtemp

        self.docker.create('result.tar.xz')

        mock_wipe.assert_called_once_with('result.tar')

        assert mock_command.call_args_list == [
            call([
                'umoci', 'init', '--layout',
                'kiwi_docker_dir/umoci_layout'
            ]),
            call([
                'umoci', 'new', '--image',
                'kiwi_docker_dir/umoci_layout:foo'
            ]),
            call([
                'umoci', 'unpack', '--image',
                'kiwi_docker_dir/umoci_layout:foo', 'kiwi_docker_root_dir'
            ]),
            call([
                'umoci', 'repack', '--image',
                'kiwi_docker_dir/umoci_layout:foo', 'kiwi_docker_root_dir'
            ]),
            call([
                'umoci', 'config', '--config.cmd=/bin/bash', '--image',
                'kiwi_docker_dir/umoci_layout:foo', '--tag', 'latest'
            ]),
            call([
                'umoci', 'gc', '--layout', 'kiwi_docker_dir/umoci_layout'
            ]),
            call([
                 'skopeo', 'copy', 'oci:kiwi_docker_dir/umoci_layout:foo',
                 'docker-archive:result.tar:foo:latest'
            ])
        ]
        mock_sync.assert_called_once_with(
            'root_dir/', 'kiwi_docker_root_dir/rootfs'
        )
        docker_root.sync_data.assert_called_once_with(
            exclude=[
                'image', '.profile', '.kconfig', 'boot', 'dev', 'sys', 'proc',
                'var/cache/kiwi'
            ],
            options=['-a', '-H', '-X', '-A']
        )
        mock_compress.assert_called_once_with('result.tar')
        compressor.xz.assert_called_once_with()
コード例 #11
0
 def setup(self):
     self.docker = ContainerImageDocker('root_dir')
コード例 #12
0
 def setup(self):
     self.docker = ContainerImageDocker('root_dir')