Added ContainerImage class
Factory plus implementation for docker
This commit is contained in:
parent
febd69ec0f
commit
d7ded563f3
36
kiwi/container_image.py
Normal file
36
kiwi/container_image.py
Normal file
@ -0,0 +1,36 @@
|
||||
# Copyright (c) 2015 SUSE Linux GmbH. All rights reserved.
|
||||
#
|
||||
# This file is part of kiwi.
|
||||
#
|
||||
# kiwi is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# kiwi is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with kiwi. If not, see <http://www.gnu.org/licenses/>
|
||||
#
|
||||
# project
|
||||
from container_image_docker import ContainerImageDocker
|
||||
|
||||
from exceptions import (
|
||||
KiwiContainerImageSetupError
|
||||
)
|
||||
|
||||
|
||||
class ContainerImage(object):
|
||||
"""
|
||||
Container Image factory
|
||||
"""
|
||||
def __new__(self, name, root_dir):
|
||||
if name == 'docker':
|
||||
return ContainerImageDocker(root_dir)
|
||||
else:
|
||||
raise KiwiContainerImageSetupError(
|
||||
'Support for %s container not implemented' % name
|
||||
)
|
||||
41
kiwi/container_image_docker.py
Normal file
41
kiwi/container_image_docker.py
Normal file
@ -0,0 +1,41 @@
|
||||
# Copyright (c) 2015 SUSE Linux GmbH. All rights reserved.
|
||||
#
|
||||
# This file is part of kiwi.
|
||||
#
|
||||
# kiwi is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# kiwi is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with kiwi. If not, see <http://www.gnu.org/licenses/>
|
||||
#
|
||||
# project
|
||||
from command import Command
|
||||
from archive_tar import ArchiveTar
|
||||
|
||||
|
||||
class ContainerImageDocker(object):
|
||||
"""
|
||||
Create docker container from a root directory
|
||||
"""
|
||||
def __init__(self, root_dir):
|
||||
self.root_dir = root_dir
|
||||
|
||||
def create(self, filename):
|
||||
exclude_list = [
|
||||
'image', '.profile', '.kconfig', 'var/cache/kiwi', 'boot'
|
||||
]
|
||||
# replace potential suffix from filename because
|
||||
# it is added by the archive creation call
|
||||
archive = ArchiveTar(
|
||||
filename.replace('.xz', '')
|
||||
)
|
||||
archive.create_xz_compressed(
|
||||
source_dir=self.root_dir, exclude=exclude_list
|
||||
)
|
||||
@ -89,6 +89,10 @@ class KiwiContainerSetupError(KiwiError):
|
||||
pass
|
||||
|
||||
|
||||
class KiwiContainerImageSetupError(KiwiError):
|
||||
pass
|
||||
|
||||
|
||||
class KiwiDataStructureError(KiwiError):
|
||||
pass
|
||||
|
||||
|
||||
26
test/unit/container_image_docker_test.py
Normal file
26
test/unit/container_image_docker_test.py
Normal file
@ -0,0 +1,26 @@
|
||||
from nose.tools import *
|
||||
from mock import patch
|
||||
|
||||
import mock
|
||||
|
||||
import nose_helper
|
||||
|
||||
from kiwi.exceptions import *
|
||||
from kiwi.container_image_docker import ContainerImageDocker
|
||||
|
||||
|
||||
class TestContainerImageDocker(object):
|
||||
def setup(self):
|
||||
self.docker = ContainerImageDocker('root_dir')
|
||||
|
||||
@patch('kiwi.container_image_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'
|
||||
)
|
||||
20
test/unit/container_image_test.py
Normal file
20
test/unit/container_image_test.py
Normal file
@ -0,0 +1,20 @@
|
||||
from nose.tools import *
|
||||
from mock import patch
|
||||
|
||||
import mock
|
||||
|
||||
import nose_helper
|
||||
|
||||
from kiwi.exceptions import *
|
||||
from kiwi.container_image import ContainerImage
|
||||
|
||||
|
||||
class TestContainerImage(object):
|
||||
@raises(KiwiContainerImageSetupError)
|
||||
def test_container_image_not_implemented(self):
|
||||
ContainerImage('foo', 'root_dir')
|
||||
|
||||
@patch('kiwi.container_image.ContainerImageDocker')
|
||||
def test_container_image_docker(self, mock_docker):
|
||||
ContainerImage('docker', 'root_dir')
|
||||
mock_docker.assert_called_once_with('root_dir')
|
||||
Loading…
Reference in New Issue
Block a user