Beispiel #1
0
 def test_get_volumes_no_explicit_root_setup_other_fullsize_volume(self):
     description = XMLDescription(
         '../data/example_lvm_no_root_full_usr_config.xml'
     )
     xml_data = description.load()
     state = XMLState(xml_data)
     volume_type = namedtuple(
         'volume_type', [
             'name',
             'size',
             'realpath',
             'mountpoint',
             'fullsize'
         ]
     )
     assert state.get_volumes() == [
         volume_type(
             name='LVusr', size=None, realpath='usr',
             mountpoint=None, fullsize=True
         ),
         volume_type(
             name='LVRoot', size='freespace:30', realpath='/',
             mountpoint=None, fullsize=False
         )
     ]
Beispiel #2
0
 def test_get_build_type_vmconfig_entries_for_vmx_type(self):
     description = XMLDescription('../data/example_config.xml')
     xml_data = description.load()
     state = XMLState(xml_data, ['vmxFlavour'], 'vmx')
     assert state.get_build_type_vmconfig_entries() == [
         'numvcpus = "4"', 'cpuid.coresPerSocket = "2"'
     ]
Beispiel #3
0
 def test_get_volumes(self):
     description = XMLDescription('../data/example_lvm_default_config.xml')
     xml_data = description.load()
     state = XMLState(xml_data)
     volume_type = namedtuple(
         'volume_type', [
             'name',
             'size',
             'realpath',
             'mountpoint',
             'fullsize'
         ]
     )
     assert state.get_volumes() == [
         volume_type(
             name='LVusr_lib', size='size:1024',
             realpath='usr/lib',
             mountpoint=None, fullsize=False
         ),
         volume_type(
             name='LVRoot', size='freespace:500',
             realpath='/',
             mountpoint=None, fullsize=False
         ),
         volume_type(
             name='etc_volume', size='freespace:30',
             realpath='etc',
             mountpoint='LVetc', fullsize=False
         ),
         volume_type(
             name='bin_volume', size=None,
             realpath='/usr/bin',
             mountpoint='LVusr_bin', fullsize=True
         )
     ]
Beispiel #4
0
 def setup(self, mock_machine):
     mock_machine.return_value = 'x86_64'
     self.xml_state = mock.MagicMock()
     self.xml_state.build_type.get_filesystem = mock.Mock(
         return_value='ext3'
     )
     self.xml_state.xml_data.get_name = mock.Mock(
         return_value='some-image'
     )
     self.xml_state.get_image_version = mock.Mock(
         return_value='1.2.3'
     )
     self.xml_state.xml_data.description_dir = 'description_dir'
     self.setup = SystemSetup(
         self.xml_state, 'root_dir'
     )
     description = XMLDescription(
         description='../data/example_config.xml',
         derived_from='derived/description'
     )
     self.setup_with_real_xml = SystemSetup(
         XMLState(description.load()), 'root_dir'
     )
     command_run = namedtuple(
         'command', ['output', 'error', 'returncode']
     )
     self.run_result = command_run(
         output='password-hash\n',
         error='stderr',
         returncode=0
     )
 def test_check_boot_description_exists_does_not_exist(self):
     description = XMLDescription(
         '../data/example_runtime_checker_boot_desc_not_found.xml'
     )
     xml_state = XMLState(description.load())
     runtime_checker = RuntimeChecker(xml_state)
     runtime_checker.check_boot_description_exists()
 def test_check_boot_description_exists_no_boot_ref(self):
     description = XMLDescription(
         '../data/example_runtime_checker_no_boot_reference.xml'
     )
     xml_state = XMLState(description.load())
     runtime_checker = RuntimeChecker(xml_state)
     runtime_checker.check_boot_description_exists()
Beispiel #7
0
    def setup(self, mock_root_bind, mock_root_init):
        description = XMLDescription(
            description='../data/example_config.xml',
            derived_from='derived/description'
        )
        self.xml = description.load()

        self.manager = mock.MagicMock(
            return_value=mock.MagicMock()
        )
        self.manager.package_requests = ['foo']
        self.manager.collection_requests = ['foo']
        self.manager.product_requests = ['foo']

        root_init = mock.MagicMock()
        mock_root_init.return_value = root_init
        root_bind = mock.MagicMock()
        root_bind.root_dir = 'root_dir'
        mock_root_bind.return_value = root_bind
        self.state = XMLState(
            self.xml
        )
        self.system = SystemPrepare(
            xml_state=self.state, root_dir='root_dir',
            allow_existing=True
        )
        mock_root_init.assert_called_once_with(
            'root_dir', True
        )
        root_init.create.assert_called_once_with()
        mock_root_bind.assert_called_once_with(
            root_init
        )
        root_bind.setup_intermediate_config.assert_called_once_with()
        root_bind.mount_kernel_file_systems.assert_called_once_with()
Beispiel #8
0
 def setup(self):
     self.tmpfile = mock.Mock()
     self.tmpfile.name = 'tmpfile'
     description = XMLDescription('../data/example_dot_profile_config.xml')
     self.profile = Profile(
         XMLState(description.load())
     )
Beispiel #9
0
    def setup(self, mock_machine, mock_exists, mock_mkdtemp):
        mock_machine.return_value = 'x86_64'
        mock_exists.return_value = True
        description = XMLDescription('../data/example_config.xml')
        self.xml_state = XMLState(
            description.load()
        )

        self.manager = mock.Mock()
        self.system_prepare = mock.Mock()
        self.setup = mock.Mock()
        self.profile = mock.Mock()
        self.system_prepare.setup_repositories = mock.Mock(
            return_value=self.manager
        )
        kiwi.boot.image.kiwi.SystemPrepare = mock.Mock(
            return_value=self.system_prepare
        )
        kiwi.boot.image.kiwi.SystemSetup = mock.Mock(
            return_value=self.setup
        )
        kiwi.boot.image.kiwi.Profile = mock.Mock(
            return_value=self.profile
        )
        mock_mkdtemp.return_value = 'boot-directory'
        self.boot_image = BootImageKiwi(
            self.xml_state, 'some-target-dir'
        )
Beispiel #10
0
 def test_create_cpio(self, mock_shell_quote, mock_open, mock_temp):
     mock_temp.return_value = self.tmpfile
     description = XMLDescription('../data/example_dot_profile_config.xml')
     profile = Profile(
         XMLState(description.load(), None, 'cpio')
     )
     profile.create()
     assert profile.dot_profile['kiwi_cpio_name'] == 'LimeJeOS-openSUSE-13.2'
Beispiel #11
0
    def load_xml_description(self, description_directory):
        """
        Load, upgrade, validate XML description

        Attributes

        * :attr:`xml_data`
            instance of XML data toplevel domain (image), stateless data

        * :attr:`config_file`
            used config file path

        * :attr:`xml_state`
            Instance of XMLState, stateful data
        """
        from ..logger import log

        log.info('Loading XML description')
        config_file = description_directory + '/config.xml'
        if not os.path.exists(config_file):
            # alternative config file lookup location
            config_file = description_directory + '/image/config.xml'
        if not os.path.exists(config_file):
            # glob config file search, first match wins
            glob_match = description_directory + '/*.kiwi'
            for kiwi_file in glob.iglob(glob_match):
                config_file = kiwi_file
                break

        if not os.path.exists(config_file):
            raise KiwiConfigFileNotFound(
                'no XML description found in %s' % description_directory
            )

        description = XMLDescription(
            config_file
        )
        self.xml_data = description.load()
        self.config_file = config_file.replace('//', '/')
        self.xml_state = XMLState(
            self.xml_data,
            self.global_args['--profile'],
            self.global_args['--type']
        )

        log.info('--> loaded %s', self.config_file)
        if self.xml_state.build_type:
            log.info(
                '--> Selected build type: %s',
                self.xml_state.get_build_type_name()
            )
        if self.xml_state.profiles:
            log.info(
                '--> Selected profiles: %s',
                ','.join(self.xml_state.profiles)
            )

        self.runtime_checker = RuntimeChecker(self.xml_state)
Beispiel #12
0
 def test_setup_ix86(self, mock_machine, mock_exists):
     mock_machine.return_value = 'i686'
     description = XMLDescription(
         '../data/example_disk_config.xml'
     )
     disk_builder = DiskBuilder(
         XMLState(description.load()), 'target_dir', 'root_dir'
     )
     assert disk_builder.arch == 'ix86'
Beispiel #13
0
 def test_get_users(self):
     description = XMLDescription('../data/example_multiple_users_config.xml')
     xml_data = description.load()
     state = XMLState(xml_data)
     users = state.get_users()
     assert len(users) == 3
     assert any(u.get_name() == 'root' for u in users)
     assert any(u.get_name() == 'tux' for u in users)
     assert any(u.get_name() == 'kiwi' for u in users) 
 def setup(self, mock_machine, mock_exists):
     mock_machine.return_value = 'x86_64'
     mock_exists.return_value = True
     description = XMLDescription('../data/example_config.xml')
     self.xml_state = XMLState(
         description.load()
     )
     self.boot_image = BootImageDracut(
         self.xml_state, 'some-target-dir', 'system-directory'
     )
 def setup(self):
     description = XMLDescription(
         '../data/example_config.xml'
     )
     self.state = XMLState(
         description.load()
     )
     self.bootloader = BootLoaderConfigBase(
         self.state, 'root_dir'
     )
Beispiel #16
0
 def test_create_displayname_is_image_name(self, mock_which, mock_temp):
     mock_which.return_value = 'cp'
     mock_temp.return_value = self.tmpfile
     description = XMLDescription('../data/example_pxe_config.xml')
     profile = Profile(
         XMLState(description.load())
     )
     profile.create()
     os.remove(self.tmpfile.name)
     assert profile.dot_profile['kiwi_displayname'] == 'LimeJeOS-openSUSE-13.2'
Beispiel #17
0
 def test_copy_bootdelete_packages_no_delete_section_in_boot_descr(self):
     boot_description = XMLDescription(
         '../data/isoboot/example-distribution-no-delete-section/config.xml'
     )
     boot_state = XMLState(
         boot_description.load()
     )
     self.state.copy_bootdelete_packages(boot_state)
     to_delete_packages = boot_state.get_to_become_deleted_packages()
     assert 'vim' in to_delete_packages
Beispiel #18
0
 def test_get_user_groups(self):
     description = XMLDescription('../data/example_multiple_users_config.xml')
     xml_data = description.load()
     state = XMLState(xml_data)
     
     assert len(state.get_user_groups('root')) == 0
     assert len(state.get_user_groups('tux')) == 1
     assert any(grp == 'users' for grp in state.get_user_groups('tux'))
     assert len(state.get_user_groups('kiwi')) == 3
     assert any(grp == 'users' for grp in state.get_user_groups('kiwi'))
     assert any(grp == 'kiwi' for grp in state.get_user_groups('kiwi'))
     assert any(grp == 'admin' for grp in state.get_user_groups('kiwi'))
Beispiel #19
0
 def test_copy_bootincluded_packages_with_image_packages(self):
     boot_description = XMLDescription(
         '../data/isoboot/example-distribution/config.xml'
     )
     boot_state = XMLState(boot_description.load(), ['std'])
     self.state.copy_bootincluded_packages(boot_state)
     image_packages = boot_state.get_system_packages()
     assert 'plymouth-branding-openSUSE' in image_packages
     assert 'grub2-branding-openSUSE' in image_packages
     assert 'gfxboot-branding-openSUSE' in image_packages
     to_delete_packages = boot_state.get_to_become_deleted_packages()
     assert 'gfxboot-branding-openSUSE' not in to_delete_packages
Beispiel #20
0
 def setup(self, mock_machine):
     mock_machine.return_value = 'x86_64'
     description = XMLDescription(
         '../data/example_config.xml'
     )
     self.state = XMLState(
         description.load()
     )
     boot_description = XMLDescription(
         '../data/isoboot/example-distribution/config.xml'
     )
     self.boot_state = XMLState(
         boot_description.load()
     )
Beispiel #21
0
class TestSchema(object):
    def setup(self):
        self.description = XMLDescription('description')

    @raises(KiwiSchemaImportError)
    @patch('lxml.etree.RelaxNG')
    @patch('kiwi.command.Command.run')
    def test_load_schema_import_error(self, mock_xslt, mock_relax):
        mock_relax.side_effect = KiwiSchemaImportError(
            'ImportError'
        )
        self.description.load()

    @raises(KiwiValidationError)
    @patch('lxml.etree.RelaxNG')
    @patch('lxml.etree.parse')
    @patch('kiwi.command.Command.run')
    def test_load_schema_validation_error(
        self, mock_xslt, mock_parse, mock_relax
    ):
        mock_validate = mock.Mock()
        mock_validate.validate.side_effect = KiwiValidationError(
            'ValidationError'
        )
        mock_relax.return_value = mock_validate
        self.description.load()

    @raises(KiwiDescriptionInvalid)
    @patch('lxml.etree.RelaxNG')
    @patch('lxml.etree.parse')
    @patch('kiwi.command.Command.run')
    def test_load_schema_description_invalid(
        self, mock_xslt, mock_parse, mock_relax
    ):
        mock_validate = mock.Mock()
        mock_validate.validate = mock.Mock(
            return_value=False
        )
        mock_relax.return_value = mock_validate
        self.description.load()

    @raises(KiwiDataStructureError)
    @patch('lxml.etree.RelaxNG')
    @patch('lxml.etree.parse')
    @patch('kiwi.xml_parse.parse')
    @patch('kiwi.command.Command.run')
    def test_load_data_structure_error(
        self, mock_xslt, mock_xml_parse, mock_etree_parse, mock_relax
    ):
        mock_validate = mock.Mock()
        mock_validate.validate = mock.Mock(
            return_value=True
        )
        mock_relax.return_value = mock_validate
        mock_xml_parse.side_effect = KiwiDataStructureError(
            'DataStructureError'
        )
        self.description.load()
Beispiel #22
0
 def setup(self):
     self.description = XMLDescription(
         '../data/example_runtime_checker_config.xml'
     )
     self.xml_state = XMLState(
         self.description.load()
     )
     self.runtime_checker = RuntimeChecker(self.xml_state)
    def setup(self, mock_machine, mock_exists):
        self.context_manager_mock = mock.Mock()
        self.file_mock = mock.Mock()
        self.enter_mock = mock.Mock()
        self.exit_mock = mock.Mock()
        self.enter_mock.return_value = self.file_mock
        setattr(self.context_manager_mock, '__enter__', self.enter_mock)
        setattr(self.context_manager_mock, '__exit__', self.exit_mock)

        mock_machine.return_value = 'x86_64'
        mock_exists.return_value = True
        description = XMLDescription('../data/example_config.xml')
        self.xml_state = XMLState(
            description.load()
        )
        self.boot_image = BootImageDracut(
            self.xml_state, 'some-target-dir', 'system-directory'
        )
Beispiel #24
0
    def load_boot_xml_description(self):
        """
        Load the boot image description referenced by the system image
        description boot attribute
        """
        log.info('Loading Boot XML description')
        boot_description_directory = self.get_boot_description_directory()
        if not boot_description_directory:
            raise KiwiConfigFileNotFound(
                'no boot reference specified in XML description'
            )
        boot_config_file = boot_description_directory + '/config.xml'
        if not os.path.exists(boot_config_file):
            raise KiwiConfigFileNotFound(
                'no Boot XML description found in %s' %
                boot_description_directory
            )
        boot_description = XMLDescription(
            description=boot_config_file,
            derived_from=self.xml_state.xml_data.description_dir
        )

        boot_image_profile = self.xml_state.build_type.get_bootprofile()
        if not boot_image_profile:
            boot_image_profile = 'default'
        boot_kernel_profile = self.xml_state.build_type.get_bootkernel()
        if not boot_kernel_profile:
            boot_kernel_profile = 'std'

        self.boot_xml_state = XMLState(
            boot_description.load(), [boot_image_profile, boot_kernel_profile]
        )
        log.info('--> loaded %s', boot_config_file)
        if self.boot_xml_state.build_type:
            log.info(
                '--> Selected build type: %s',
                self.boot_xml_state.get_build_type_name()
            )
        if self.boot_xml_state.profiles:
            log.info(
                '--> Selected boot profiles: image: %s, kernel: %s',
                boot_image_profile, boot_kernel_profile
            )
    def test_init_with_derived_from_image(
        self, mock_root_bind, mock_root_init, mock_root_import
    ):
        description = XMLDescription(
            description='../data/example_config.xml',
            derived_from='derived/description'
        )
        xml = description.load()

        root_init = mock.MagicMock()
        mock_root_init.return_value = root_init
        root_import = mock.Mock()
        root_import.sync_data = mock.Mock()
        mock_root_import.return_value = root_import
        root_bind = mock.MagicMock()
        root_bind.root_dir = 'root_dir'
        mock_root_bind.return_value = root_bind
        state = XMLState(
            xml, profiles=['vmxFlavour'], build_type='docker'
        )
        uri = mock.Mock()
        get_derived_from_image_uri = mock.Mock(
            return_value=uri
        )
        state.get_derived_from_image_uri = get_derived_from_image_uri
        SystemPrepare(
            xml_state=state, root_dir='root_dir',
        )
        mock_root_init.assert_called_once_with(
            'root_dir', False
        )
        root_init.create.assert_called_once_with()
        mock_root_import.assert_called_once_with(
            'root_dir', uri,
            state.build_type.get_image()
        )
        root_import.sync_data.assert_called_once_with()
        mock_root_bind.assert_called_once_with(
            root_init
        )
        root_bind.setup_intermediate_config.assert_called_once_with()
        root_bind.mount_kernel_file_systems.assert_called_once_with()
Beispiel #26
0
 def setup(self):
     self.xml_state = mock.MagicMock()
     self.xml_state.build_type.get_filesystem = mock.Mock(
         return_value='ext3'
     )
     self.setup = SystemSetup(
         self.xml_state, 'description_dir', 'root_dir'
     )
     description = XMLDescription('../data/example_config.xml')
     self.setup_with_real_xml = SystemSetup(
         XMLState(description.load()), 'description_dir', 'root_dir'
     )
     command_run = namedtuple(
         'command', ['output', 'error', 'returncode']
     )
     self.run_result = command_run(
         output='password-hash',
         error='stderr',
         returncode=0
     )
Beispiel #27
0
 def test_get_volumes_no_explicit_root_setup(self):
     description = XMLDescription('../data/example_lvm_no_root_config.xml')
     xml_data = description.load()
     state = XMLState(xml_data)
     volume_type = namedtuple(
         'volume_type', [
             'name',
             'size',
             'realpath',
             'mountpoint',
             'fullsize',
             'attributes'
         ]
     )
     assert state.get_volumes() == [
         volume_type(
             name='LVRoot', size=None, realpath='/',
             mountpoint=None, fullsize=True,
             attributes=[]
         )
     ]
 def setup(self, mock_machine, mock_exists):
     mock_machine.return_value = 'x86_64'
     mock_exists.return_value = True
     description = XMLDescription(
         '../data/example_config.xml'
     )
     self.state = XMLState(
         description.load()
     )
     kiwi.bootloader_config_isolinux.Path = mock.Mock()
     kiwi.bootloader_config_base.Path = mock.Mock()
     self.isolinux = mock.Mock()
     kiwi.bootloader_config_isolinux.BootLoaderTemplateIsoLinux = mock.Mock(
         return_value=self.isolinux
     )
     self.bootloader = BootLoaderConfigIsoLinux(
         self.state, 'root_dir'
     )
     self.bootloader.get_hypervisor_domain = mock.Mock(
         return_value='domU'
     )
Beispiel #29
0
 def setup(self):
     test_xml = bytes(
         b"""<?xml version="1.0" encoding="utf-8"?>
         <image schemaversion="1.4" name="bob">
             <description type="system">
                 <author>John Doe</author>
                 <contact>[email protected]</contact>
                 <specification>
                     say hello
                 </specification>
             </description>
             <preferences>
                 <packagemanager>zypper</packagemanager>
                 <version>1.1.1</version>
                 <type image="ext3"/>
             </preferences>
             <repository type="rpm-md">
                 <source path="repo"/>
             </repository>
         </image>"""
     )
     self.description_from_file = XMLDescription(description='description')
     self.description_from_data = XMLDescription(xml_content=test_xml)
Beispiel #30
0
 def setup(self):
     description = XMLDescription('../data/example_config.xml')
     self.state = XMLState(description.load())
     self.bootloader = BootLoaderConfigBase(self.state, 'root_dir')
Beispiel #31
0
 def test_set_derived_from_image_uri(self):
     description = XMLDescription('../data/example_config.xml')
     xml_data = description.load()
     state = XMLState(xml_data, ['derivedContainer'], 'docker')
     state.set_derived_from_image_uri('file:///new_uri')
     assert state.get_derived_from_image_uri().translate() == '/new_uri'
Beispiel #32
0
 def test_setup_ix86(self):
     Defaults.set_platform_name('i686')
     description = XMLDescription('../data/example_disk_config.xml')
     disk_builder = DiskBuilder(XMLState(description.load()), 'target_dir',
                                'root_dir')
     assert disk_builder.arch == 'ix86'
Beispiel #33
0
    def check_consistent_kernel_in_boot_and_system_image(self):
        """
        If a kiwi initrd is used, the kernel used to build the kiwi
        initrd and the kernel used in the system image must be the
        same in order to avoid an inconsistent boot setup
        """
        message = dedent('''\n
            Possible kernel mismatch between kiwi initrd and system image

            The selected '{0}' boot image kernel is '{1}'. However this
            kernel package was not explicitly listed in the package list
            of the system image. Please fixup your system image
            description:

            1) Add <package name="{1}"/> to your system XML description

            2) Inherit kernel from system description to initrd via
               the custom kernel profile:

               <type ... bootkernel="custom" .../>

               <packages type="image"/>
                   <package name="desired-kernel" bootinclude="true"/>
               </packages>
        ''')
        boot_image_reference = self.xml_state.build_type.get_boot()
        boot_kernel_package_name = None
        if boot_image_reference:
            if not boot_image_reference[0] == '/':
                boot_image_reference = os.sep.join([
                    Defaults.get_boot_image_description_path(),
                    boot_image_reference
                ])
            boot_config_file = os.sep.join(
                [boot_image_reference, 'config.xml'])
            if os.path.exists(boot_config_file):
                boot_description = XMLDescription(
                    description=boot_config_file,
                    derived_from=self.xml_state.xml_data.description_dir)
                boot_kernel_profile = \
                    self.xml_state.build_type.get_bootkernel()
                if not boot_kernel_profile:
                    boot_kernel_profile = 'std'
                boot_xml_state = XMLState(boot_description.load(),
                                          [boot_kernel_profile])
                kernel_package_sections = []
                for packages_section in boot_xml_state.xml_data.get_packages():
                    # lookup package sections matching kernel profile in kiwi
                    # boot description. By definition this must be a packages
                    # section with a single profile name whereas the default
                    # profile name is 'std'. The section itself must contain
                    # one matching kernel package name for the desired
                    # architecture
                    if packages_section.get_profiles() == boot_kernel_profile:
                        for package in packages_section.get_package():
                            kernel_package_sections.append(package)

                for package in kernel_package_sections:
                    if boot_xml_state.package_matches_host_architecture(
                            package):
                        boot_kernel_package_name = package.get_name()

        if boot_kernel_package_name:
            # A kernel package name was found in the kiwi boot image
            # description. Let's check if this kernel is also used
            # in the system image
            image_package_names = self.xml_state.get_system_packages()
            if boot_kernel_package_name not in image_package_names:
                raise KiwiRuntimeError(
                    message.format(self.xml_state.build_type.get_boot(),
                                   boot_kernel_package_name))
Beispiel #34
0
class TestRuntimeChecker:
    @fixture(autouse=True)
    def inject_fixtures(self, caplog):
        self._caplog = caplog

    def setup(self):
        self.description = XMLDescription(
            '../data/example_runtime_checker_config.xml')
        self.xml_state = XMLState(self.description.load())
        self.runtime_config = Mock()
        self.runtime_config.get_oci_archive_tool.return_value = 'umoci'
        kiwi.runtime_checker.RuntimeConfig = Mock(
            return_value=self.runtime_config)
        self.runtime_checker = RuntimeChecker(self.xml_state)

    @patch('kiwi.runtime_checker.Uri')
    def test_check_image_include_repos_publicly_resolvable(self, mock_Uri):
        uri = Mock()
        uri.is_public.return_value = False
        mock_Uri.return_value = uri
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_image_include_repos_publicly_resolvable(
            )

    def test_invalid_target_dir_pointing_to_shared_cache_1(self):
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_target_directory_not_in_shared_cache(
                '/var/cache//kiwi/foo')

    def test_invalid_target_dir_pointing_to_shared_cache_2(self):
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_target_directory_not_in_shared_cache(
                '/var/cache/kiwi')

    @patch('os.getcwd')
    def test_invalid_target_dir_pointing_to_shared_cache_3(self, mock_getcwd):
        mock_getcwd.return_value = '/'
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_target_directory_not_in_shared_cache(
                'var/cache/kiwi')

    def test_invalid_target_dir_pointing_to_shared_cache_4(self):
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_target_directory_not_in_shared_cache(
                '//var/cache//kiwi/foo')

    @patch('os.path.isdir')
    def test_check_dracut_module_versions_compatible_to_kiwi_no_dracut(
            self, mock_os_path_isdir):
        mock_os_path_isdir.return_value = False
        self.runtime_checker.\
            check_dracut_module_versions_compatible_to_kiwi('root_dir')
        # does not raise if no dracut is installed

    @patch('os.listdir')
    @patch('os.path.isdir')
    @patch('kiwi.runtime_checker.Command.run')
    def test_check_dracut_module_versions_compatible_to_kiwi(
            self, mock_Command_run, mock_os_path_isdir, mock_os_listdir):
        mock_os_path_isdir.return_value = True
        command = Mock()
        command.output = '1.2.3-1.2'
        mock_Command_run.return_value = command
        mock_os_listdir.return_value = ['90kiwi-dump']
        package_manager = Mock()
        package_manager.return_value = 'zypper'
        self.xml_state.get_package_manager = package_manager
        with raises(KiwiRuntimeError) as exception_data:
            self.runtime_checker.\
                check_dracut_module_versions_compatible_to_kiwi('root_dir')
        assert "'dracut-kiwi-oem-dump': 'got:1.2.3, need:>=9.20.1'" in str(
            exception_data.value)
        mock_Command_run.assert_called_once_with([
            'chroot', 'root_dir', 'rpm', '-q', '--qf', '%{VERSION}',
            'dracut-kiwi-oem-dump'
        ])
        package_manager.return_value = 'apt'
        mock_Command_run.reset_mock()
        with raises(KiwiRuntimeError) as exception_data:
            self.runtime_checker.\
                check_dracut_module_versions_compatible_to_kiwi('root_dir')
        assert "'dracut-kiwi-oem-dump': 'got:1.2.3, need:>=9.20.1'" in str(
            exception_data.value)
        mock_Command_run.assert_called_once_with([
            'chroot', 'root_dir', 'dpkg-query', '-W', '-f', '${Version}',
            'dracut-kiwi-oem-dump'
        ])
        mock_Command_run.side_effect = Exception
        # If the package manager call failed with an exception
        # the expected behavior is the runtime check to just pass
        # because there is no data to operate on. Best guess approach
        with self._caplog.at_level(logging.DEBUG):
            self.runtime_checker.\
                check_dracut_module_versions_compatible_to_kiwi('root_dir')

    def test_valid_target_dir_1(self):
        assert self.runtime_checker.check_target_directory_not_in_shared_cache(
            '/var/cache/kiwi-fast-tmpsystemdir') is None

    def test_valid_target_dir_2(self):
        assert self.runtime_checker.check_target_directory_not_in_shared_cache(
            '/foo/bar') is None

    def test_check_repositories_configured(self):
        self.xml_state.delete_repository_sections()
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_repositories_configured()

    def test_check_volume_setup_defines_reserved_labels(self):
        xml_state = XMLState(self.description.load(), ['vmxSimpleFlavour'],
                             'oem')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_volume_setup_defines_reserved_labels()

    def test_appx_invalid_name(self):
        xml_state = XMLState(self.description.load(), ['wsl_launcher'], 'appx')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_appx_naming_conventions_valid()

    def test_appx_invalid_id(self):
        xml_state = XMLState(self.description.load(), ['wsl_id'], 'appx')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_appx_naming_conventions_valid()

    def test_check_volume_setup_defines_multiple_fullsize_volumes(self):
        with raises(KiwiRuntimeError):
            self.runtime_checker.\
                check_volume_setup_defines_multiple_fullsize_volumes()

    def test_check_volume_setup_has_no_root_definition(self):
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_volume_setup_has_no_root_definition()

    @patch('kiwi.runtime_checker.Path.which')
    def test_check_container_tool_chain_installed(self, mock_which):
        mock_which.return_value = False
        xml_state = XMLState(self.description.load(), ['docker'], 'docker')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_container_tool_chain_installed()

    @patch('kiwi.runtime_checker.Path.which')
    def test_check_container_tool_chain_installed_unknown_tool(
            self, mock_which):
        self.runtime_config.get_oci_archive_tool.return_value = 'budah'
        mock_which.return_value = False
        xml_state = XMLState(self.description.load(), ['docker'], 'docker')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_container_tool_chain_installed()

    @patch('kiwi.runtime_checker.Path.which')
    def test_check_container_tool_chain_installed_buildah(self, mock_which):
        self.runtime_config.get_oci_archive_tool.return_value = 'buildah'
        mock_which.return_value = False
        xml_state = XMLState(self.description.load(), ['docker'], 'docker')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_container_tool_chain_installed()

    @patch('kiwi.runtime_checker.Path.which')
    @patch('kiwi.runtime_checker.CommandCapabilities.check_version')
    def test_check_container_tool_chain_installed_with_version(
            self, mock_cmdver, mock_which):
        mock_which.return_value = True
        mock_cmdver.return_value = False
        xml_state = XMLState(self.description.load(), ['docker'], 'docker')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_container_tool_chain_installed()

    @patch('kiwi.runtime_checker.Path.which')
    @patch('kiwi.runtime_checker.CommandCapabilities.check_version')
    @patch('kiwi.runtime_checker.CommandCapabilities.has_option_in_help')
    def test_check_container_tool_chain_installed_with_multitags(
            self, mock_cmdoptions, mock_cmdver, mock_which):
        mock_which.return_value = True
        mock_cmdver.return_value = True
        mock_cmdoptions.return_value = False
        xml_state = XMLState(self.description.load(), ['docker'], 'docker')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_container_tool_chain_installed()

    @patch('kiwi.runtime_checker.Defaults.get_boot_image_description_path')
    def test_check_consistent_kernel_in_boot_and_system_image(
            self, mock_boot_path):
        Defaults.set_platform_name('x86_64')
        mock_boot_path.return_value = '../data'
        xml_state = XMLState(self.description.load(), ['vmxFlavour'], 'oem')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_consistent_kernel_in_boot_and_system_image()

    def test_check_initrd_selection_required(self):
        description = XMLDescription(
            '../data/example_runtime_checker_no_initrd_system_reference.xml')
        xml_state = XMLState(description.load())
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_initrd_selection_required()

    def test_check_boot_description_exists_no_boot_ref(self):
        description = XMLDescription(
            '../data/example_runtime_checker_no_boot_reference.xml')
        xml_state = XMLState(description.load())
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_boot_description_exists()

    def test_check_boot_description_exists_does_not_exist(self):
        description = XMLDescription(
            '../data/example_runtime_checker_boot_desc_not_found.xml')
        xml_state = XMLState(description.load())
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_boot_description_exists()

    def test_check_xen_uniquely_setup_as_server_or_guest_for_ec2(self):
        self.xml_state.build_type.get_firmware = Mock(return_value='ec2')
        self.xml_state.is_xen_server = Mock(return_value=True)
        self.xml_state.is_xen_guest = Mock(return_value=True)
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_xen_uniquely_setup_as_server_or_guest()

    def test_check_xen_uniquely_setup_as_server_or_guest_for_xen(self):
        self.xml_state.build_type.get_firmware = Mock(return_value=None)
        self.xml_state.is_xen_server = Mock(return_value=True)
        self.xml_state.is_xen_guest = Mock(return_value=True)
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_xen_uniquely_setup_as_server_or_guest()

    def test_check_dracut_module_for_disk_overlay_in_package_list(self):
        xml_state = XMLState(self.description.load(), ['vmxFlavour'], 'iso')
        xml_state.build_type.get_overlayroot = Mock(return_value=True)
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.\
                check_dracut_module_for_disk_overlay_in_package_list()

    def test_check_efi_mode_for_disk_overlay_correctly_setup(self):
        self.xml_state.build_type.get_overlayroot = Mock(return_value=True)
        self.xml_state.build_type.get_firmware = Mock(return_value='uefi')
        with raises(KiwiRuntimeError):
            self.runtime_checker.\
                check_efi_mode_for_disk_overlay_correctly_setup()

    @patch('kiwi.runtime_checker.Path.which')
    def test_check_mediacheck_installed_tagmedia_missing(self, mock_which):
        mock_which.return_value = False
        xml_state = XMLState(self.description.load(), ['vmxFlavour'], 'iso')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_mediacheck_installed()

    def test_check_dracut_module_for_live_iso_in_package_list(self):
        xml_state = XMLState(self.description.load(), ['vmxFlavour'], 'iso')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_dracut_module_for_live_iso_in_package_list()

    def test_check_dracut_module_for_disk_oem_in_package_list(self):
        xml_state = XMLState(self.description.load(), ['vmxFlavour'], 'oem')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_dracut_module_for_disk_oem_in_package_list()

    def test_check_dracut_module_for_oem_install_in_package_list(self):
        xml_state = XMLState(self.description.load(), ['vmxFlavour'], 'oem')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.\
                check_dracut_module_for_oem_install_in_package_list()

    def test_check_volume_label_used_with_lvm(self):
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_volume_label_used_with_lvm()

    def test_check_swap_name_used_with_lvm(self):
        xml_state = XMLState(self.description.load(), ['vmxFlavour'], 'oem')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_swap_name_used_with_lvm()

    def test_check_preferences_data_no_version(self):
        xml_state = XMLState(self.description.load(), ['docker'], 'docker')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_image_version_provided()

    def test_check_architecture_supports_iso_firmware_setup(self):
        Defaults.set_platform_name('aarch64')
        xml_state = XMLState(self.description.load(), ['vmxFlavour'], 'iso')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_architecture_supports_iso_firmware_setup()
        xml_state = XMLState(self.description.load(), ['xenDom0Flavour'],
                             'oem')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_architecture_supports_iso_firmware_setup()

    @patch('kiwi.runtime_checker.Path.which')
    def test_check_syslinux_installed_if_isolinux_is_used(
            self, mock_Path_which):
        Defaults.set_platform_name('x86_64')
        mock_Path_which.return_value = None
        xml_state = XMLState(self.description.load(), ['vmxFlavour'], 'iso')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_syslinux_installed_if_isolinux_is_used()
        xml_state = XMLState(self.description.load(), ['xenDom0Flavour'],
                             'oem')
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_syslinux_installed_if_isolinux_is_used()

    def test_check_image_type_unique(self):
        description = XMLDescription(
            '../data/example_runtime_checker_conflicting_types.xml')
        xml_state = XMLState(description.load())
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_image_type_unique()

    def test_check_include_references_unresolvable(self):
        description = XMLDescription(
            '../data/example_runtime_checker_include_nested_reference.xml')
        xml_state = XMLState(description.load())
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_include_references_unresolvable()

    def teardown(self):
        sys.argv = argv_kiwi_tests
Beispiel #35
0
 def test_get_oemconfig_swap_mbytes_default(self):
     description = XMLDescription('../data/example_btrfs_config.xml')
     xml_data = description.load()
     state = XMLState(xml_data)
     assert state.get_oemconfig_swap_mbytes() == 128
Beispiel #36
0
 def test_get_initrd_system(self):
     description = XMLDescription('../data/example_config.xml')
     xml_data = description.load()
     state = XMLState(xml_data, ['vmxFlavour'], 'vmx')
     assert state.get_initrd_system() == 'dracut'
Beispiel #37
0
Datei: base.py Projekt: isbm/kiwi
class CliTask:
    """
    Base class for all task classes, loads the task and provides
    the interface to the command options and the XML description

    Attributes

    * :attr:`should_perform_task_setup`
        Indicates if the task should perform the setup steps
        which covers the following task configurations:
        * setup debug level
        * setup logfile
        * setup color output
    """
    def __init__(self, should_perform_task_setup=True):
        self.cli = Cli()

        # initialize runtime checker
        self.runtime_checker = None

        # initialize runtime configuration
        self.runtime_config = RuntimeConfig()

        # help requested
        self.cli.show_and_exit_on_help_request()

        # load/import task module
        self.task = self.cli.load_command()

        # get command specific args
        self.command_args = self.cli.get_command_args()

        # get global args
        self.global_args = self.cli.get_global_args()

        # initialize generic runtime check dicts
        self.checks_before_command_args = {
            'check_minimal_required_preferences': [],
            'check_efi_mode_for_disk_overlay_correctly_setup': [],
            'check_boot_description_exists': [],
            'check_consistent_kernel_in_boot_and_system_image': [],
            'check_container_tool_chain_installed': [],
            'check_volume_setup_defines_reserved_labels': [],
            'check_volume_setup_defines_multiple_fullsize_volumes': [],
            'check_volume_setup_has_no_root_definition': [],
            'check_volume_label_used_with_lvm': [],
            'check_xen_uniquely_setup_as_server_or_guest': [],
            'check_mediacheck_installed': [],
            'check_dracut_module_for_live_iso_in_package_list': [],
            'check_dracut_module_for_disk_overlay_in_package_list': [],
            'check_dracut_module_for_disk_oem_in_package_list': [],
            'check_dracut_module_for_oem_install_in_package_list': [],
            'check_architecture_supports_iso_firmware_setup': [],
            'check_appx_naming_conventions_valid': [],
            'check_syslinux_installed_if_isolinux_is_used': []
        }
        self.checks_after_command_args = {
            'check_repositories_configured': [],
            'check_image_include_repos_publicly_resolvable': []
        }

        if should_perform_task_setup:
            # set log level
            if self.global_args['--debug']:
                log.setLogLevel(logging.DEBUG)
            else:
                log.setLogLevel(logging.INFO)

            # set log file
            if self.global_args['--logfile']:
                log.set_logfile(
                    self.global_args['--logfile']
                )

            if self.global_args['--color-output']:
                log.set_color_format()

    def load_xml_description(self, description_directory):
        """
        Load, upgrade, validate XML description

        Attributes

        * :attr:`xml_data`
            instance of XML data toplevel domain (image), stateless data

        * :attr:`config_file`
            used config file path

        * :attr:`xml_state`
            Instance of XMLState, stateful data
        """
        log.info('Loading XML description')
        config_file = description_directory + '/config.xml'
        if not os.path.exists(config_file):
            # alternative config file lookup location
            config_file = description_directory + '/image/config.xml'
        if not os.path.exists(config_file):
            # glob config file search, first match wins
            glob_match = description_directory + '/*.kiwi'
            for kiwi_file in sorted(glob.iglob(glob_match)):
                config_file = kiwi_file
                break

        if not os.path.exists(config_file):
            raise KiwiConfigFileNotFound(
                'no XML description found in %s' % description_directory
            )

        self.description = XMLDescription(
            config_file
        )
        self.xml_data = self.description.load()
        self.config_file = config_file.replace('//', '/')
        self.xml_state = XMLState(
            self.xml_data,
            self.global_args['--profile'],
            self.global_args['--type']
        )

        log.info('--> loaded %s', self.config_file)
        if self.xml_state.build_type:
            log.info(
                '--> Selected build type: %s',
                self.xml_state.get_build_type_name()
            )
        if self.xml_state.profiles:
            log.info(
                '--> Selected profiles: %s',
                ','.join(self.xml_state.profiles)
            )

        self.runtime_checker = RuntimeChecker(self.xml_state)

    def quadruple_token(self, option):
        """
        Helper method for commandline options of the form --option a,b,c,d

        Make sure to provide a common result for option values which
        separates the information in a comma separated list of values

        :return: common option value representation
        :rtype: str
        """
        tokens = option.split(',', 3)
        return [
            self._pop_token(tokens) if len(tokens) else None for _ in range(
                0, 4
            )
        ]

    def sextuple_token(self, option):
        """
        Helper method for commandline options of the form --option a,b,c,d,e,f

        Make sure to provide a common result for option values which
        separates the information in a comma separated list of values

        :return: common option value representation
        :rtype: str
        """
        tokens = option.split(',', 5)
        return [
            self._pop_token(tokens) if len(tokens) else None for _ in range(
                0, 6
            )
        ]

    def run_checks(self, checks):
        """
        This method runs the given runtime checks excluding the ones disabled
        in the runtime configuration file.

        :param dict checks: A dictionary with the runtime method names as keys
            and their arguments list as the values.
        """
        exclude_list = self.runtime_config.get_disabled_runtime_checks()
        if self.runtime_checker is not None:
            for method, args in {
                key: value for key, value in checks.items()
                    if key not in exclude_list
            }.items():
                attrgetter(method)(self.runtime_checker)(*args)

    def _pop_token(self, tokens):
        token = tokens.pop(0)
        if len(token) > 0 and token == 'true':
            return True
        elif len(token) > 0 and token == 'false':
            return False
        else:
            return token
Beispiel #38
0
 def setup(self):
     self.description = XMLDescription('description')
Beispiel #39
0
 def test_is_xen_guest_by_firmware_setup(self):
     description = XMLDescription('../data/example_config.xml')
     xml_data = description.load()
     state = XMLState(xml_data, ['ec2Flavour'], 'vmx')
     assert state.is_xen_guest() is True
Beispiel #40
0
 def test_get_volume_management_lvm_default(self):
     description = XMLDescription('../data/example_lvm_default_config.xml')
     xml_data = description.load()
     state = XMLState(xml_data)
     assert state.get_volume_management() == 'lvm'
Beispiel #41
0
    def setup(self, mock_machine, mock_exists):
        mock_machine.return_value = 'x86_64'

        def side_effect(filename):
            if filename.endswith('.config/kiwi/config.yml'):
                return False
            elif filename.endswith('etc/kiwi.yml'):
                return False
            else:
                return True

        mock_exists.side_effect = side_effect
        description = XMLDescription('../data/example_disk_config.xml')
        self.context_manager_mock = mock.Mock()
        self.file_mock = mock.Mock()
        self.enter_mock = mock.Mock()
        self.exit_mock = mock.Mock()
        self.enter_mock.return_value = self.file_mock
        setattr(self.context_manager_mock, '__enter__', self.enter_mock)
        setattr(self.context_manager_mock, '__exit__', self.exit_mock)
        self.device_map = {
            'root': MappedDevice('/dev/root-device', mock.Mock()),
            'readonly': MappedDevice('/dev/readonly-root-device', mock.Mock()),
            'boot': MappedDevice('/dev/boot-device', mock.Mock()),
            'prep': MappedDevice('/dev/prep-device', mock.Mock()),
            'efi': MappedDevice('/dev/efi-device', mock.Mock()),
            'spare': MappedDevice('/dev/spare-device', mock.Mock())
        }
        self.id_map = {'kiwi_RootPart': 1, 'kiwi_BootPart': 1}
        self.id_map_sorted = OrderedDict(sorted(self.id_map.items()))
        self.boot_names_type = namedtuple('boot_names_type',
                                          ['kernel_name', 'initrd_name'])
        self.block_operation = mock.Mock()
        self.block_operation.get_blkid = mock.Mock(return_value='blkid_result')
        self.block_operation.get_filesystem = mock.Mock(
            return_value='blkid_result_fs')
        kiwi.builder.disk.BlockID = mock.Mock(
            return_value=self.block_operation)
        self.loop_provider = mock.Mock()
        kiwi.builder.disk.LoopDevice = mock.Mock(
            return_value=self.loop_provider)
        self.disk = mock.Mock()
        provider = mock.Mock()
        provider.get_device = mock.Mock(return_value='/dev/some-loop')
        self.disk.storage_provider = provider
        self.partitioner = mock.Mock()
        self.partitioner.get_id = mock.Mock(return_value=1)
        self.disk.partitioner = self.partitioner
        self.disk.get_uuid = mock.Mock(return_value='0815')
        self.disk.get_public_partition_id_map = mock.Mock(
            return_value=self.id_map_sorted)
        self.disk.get_device = mock.Mock(return_value=self.device_map)
        kernel_info = mock.Mock()
        kernel_info.version = '1.2.3'
        kernel_info.name = 'vmlinuz-1.2.3-default'
        self.kernel = mock.Mock()
        self.kernel.get_kernel = mock.Mock(return_value=kernel_info)
        self.kernel.get_xen_hypervisor = mock.Mock()
        self.kernel.copy_kernel = mock.Mock()
        self.kernel.copy_xen_hypervisor = mock.Mock()
        kiwi.builder.disk.Kernel = mock.Mock(return_value=self.kernel)
        self.disk.subformat = mock.Mock()
        self.disk.subformat.get_target_file_path_for_format = mock.Mock(
            return_value='some-target-format-name')
        kiwi.builder.disk.DiskFormat = mock.Mock(
            return_value=self.disk.subformat)
        kiwi.builder.disk.Disk = mock.Mock(return_value=self.disk)
        self.disk_setup = mock.Mock()
        self.disk_setup.get_disksize_mbytes.return_value = 1024
        self.disk_setup.boot_partition_size.return_value = 0
        self.disk_setup.get_efi_label = mock.Mock(return_value='EFI')
        self.disk_setup.get_root_label = mock.Mock(return_value='ROOT')
        self.disk_setup.get_boot_label = mock.Mock(return_value='BOOT')
        self.disk_setup.need_boot_partition = mock.Mock(return_value=True)
        self.bootloader_install = mock.Mock()
        kiwi.builder.disk.BootLoaderInstall = mock.MagicMock(
            return_value=self.bootloader_install)
        self.bootloader_config = mock.Mock()
        self.bootloader_config.get_boot_cmdline = mock.Mock(
            return_value='boot_cmdline')
        kiwi.builder.disk.BootLoaderConfig = mock.MagicMock(
            return_value=self.bootloader_config)
        kiwi.builder.disk.DiskSetup = mock.MagicMock(
            return_value=self.disk_setup)
        self.boot_image_task = mock.Mock()
        self.boot_image_task.boot_root_directory = 'boot_dir'
        self.boot_image_task.kernel_filename = 'kernel'
        self.boot_image_task.initrd_filename = 'initrd'
        self.boot_image_task.xen_hypervisor_filename = 'xen_hypervisor'
        self.boot_image_task.get_boot_names.return_value = self.boot_names_type(
            kernel_name='linux.vmx', initrd_name='initrd.vmx')
        kiwi.builder.disk.BootImage = mock.Mock(
            return_value=self.boot_image_task)
        self.firmware = mock.Mock()
        self.firmware.get_legacy_bios_partition_size.return_value = 0
        self.firmware.get_efi_partition_size.return_value = 0
        self.firmware.get_prep_partition_size.return_value = 0
        self.firmware.efi_mode = mock.Mock(return_value='efi')
        kiwi.builder.disk.FirmWare = mock.Mock(return_value=self.firmware)
        self.setup = mock.Mock()
        kiwi.builder.disk.SystemSetup = mock.Mock(return_value=self.setup)
        self.install_image = mock.Mock()
        kiwi.builder.disk.InstallImageBuilder = mock.Mock(
            return_value=self.install_image)
        self.raid_root = mock.Mock()
        self.raid_root.get_device.return_value = MappedDevice(
            '/dev/md0', mock.Mock())
        kiwi.builder.disk.RaidDevice = mock.Mock(return_value=self.raid_root)
        self.luks_root = mock.Mock()
        kiwi.builder.disk.LuksDevice = mock.Mock(return_value=self.luks_root)
        self.disk_builder = DiskBuilder(
            XMLState(description.load()),
            'target_dir',
            'root_dir',
            custom_args={'signing_keys': ['key_file_a', 'key_file_b']})
        self.disk_builder.root_filesystem_is_overlay = False
        self.disk_builder.build_type_name = 'oem'
        self.disk_builder.image_format = None
Beispiel #42
0
 def test_setup_ix86(self, mock_machine):
     mock_machine.return_value = 'i686'
     description = XMLDescription('../data/example_disk_config.xml')
     disk_builder = DiskBuilder(XMLState(description.load()), 'target_dir',
                                'root_dir')
     assert disk_builder.arch == 'ix86'
Beispiel #43
0
 def test_get_derived_from_image_uri(self):
     description = XMLDescription('../data/example_config.xml')
     xml_data = description.load()
     state = XMLState(xml_data, ['derivedContainer'], 'docker')
     assert state.get_derived_from_image_uri().uri == \
         'obs://project/repo/image#mytag'
Beispiel #44
0
 def test_get_build_type_machine_section(self):
     description = XMLDescription('../data/example_config.xml')
     xml_data = description.load()
     state = XMLState(xml_data, None, 'vmx')
     assert state.get_build_type_machine_section().get_guestOS() == 'suse'
 def test_post_init_ix86_platform(self, mock_machine):
     xml_state = XMLState(
         XMLDescription('../data/example_config.xml').load())
     mock_machine.return_value = 'i686'
     bootloader = BootLoaderConfigIsoLinux(xml_state, 'root_dir')
     assert bootloader.arch == 'ix86'
Beispiel #46
0
 def test_get_build_type_pxedeploy_section(self):
     description = XMLDescription('../data/example_pxe_config.xml')
     xml_data = description.load()
     state = XMLState(xml_data, None, 'pxe')
     assert state.get_build_type_pxedeploy_section().get_server() == \
         '192.168.100.2'
Beispiel #47
0
 def setup(self, mock_machine, mock_exists):
     mock_machine.return_value = 'x86_64'
     mock_exists.return_value = True
     description = XMLDescription(
         '../data/example_disk_config.xml'
     )
     self.device_map = {
         'root': MappedDevice('/dev/root-device', mock.Mock()),
         'readonly': MappedDevice('/dev/readonly-root-device', mock.Mock()),
         'boot': MappedDevice('/dev/boot-device', mock.Mock()),
         'prep': MappedDevice('/dev/prep-device', mock.Mock()),
         'efi': MappedDevice('/dev/efi-device', mock.Mock())
     }
     self.id_map = {
         'kiwi_RootPart': 1,
         'kiwi_BootPart': 1
     }
     self.id_map_sorted = OrderedDict(
         sorted(self.id_map.items())
     )
     self.block_operation = mock.Mock()
     self.block_operation.get_blkid = mock.Mock(
         return_value='blkid_result'
     )
     self.block_operation.get_filesystem = mock.Mock(
         return_value='filesystem'
     )
     kiwi.builder.disk.BlockID = mock.Mock(
         return_value=self.block_operation
     )
     self.loop_provider = mock.Mock()
     kiwi.builder.disk.LoopDevice = mock.Mock(
         return_value=self.loop_provider
     )
     self.disk = mock.Mock()
     provider = mock.Mock()
     provider.get_device = mock.Mock(
         return_value='/dev/some-loop'
     )
     self.disk.storage_provider = provider
     self.partitioner = mock.Mock()
     self.partitioner.get_id = mock.Mock(
         return_value=1
     )
     self.disk.partitioner = self.partitioner
     self.disk.get_uuid = mock.Mock(
         return_value='0815'
     )
     self.disk.get_public_partition_id_map = mock.Mock(
         return_value=self.id_map_sorted
     )
     self.disk.get_device = mock.Mock(
         return_value=self.device_map
     )
     kernel_info = mock.Mock()
     kernel_info.version = '1.2.3'
     kernel_info.name = 'vmlinuz-1.2.3-default'
     self.kernel = mock.Mock()
     self.kernel.get_kernel = mock.Mock(
         return_value=kernel_info
     )
     self.kernel.get_xen_hypervisor = mock.Mock()
     self.kernel.copy_kernel = mock.Mock()
     self.kernel.copy_xen_hypervisor = mock.Mock()
     kiwi.builder.disk.Kernel = mock.Mock(
         return_value=self.kernel
     )
     self.disk.subformat = mock.Mock()
     self.disk.subformat.get_target_name_for_format = mock.Mock(
         return_value='some-target-format-name'
     )
     kiwi.builder.disk.DiskFormat = mock.Mock(
         return_value=self.disk.subformat
     )
     kiwi.builder.disk.Disk = mock.Mock(
         return_value=self.disk
     )
     self.disk_setup = mock.Mock()
     self.disk_setup.get_efi_label = mock.Mock(
         return_value='EFI'
     )
     self.disk_setup.get_root_label = mock.Mock(
         return_value='ROOT'
     )
     self.disk_setup.get_boot_label = mock.Mock(
         return_value='BOOT'
     )
     self.disk_setup.need_boot_partition = mock.Mock(
         return_value=True
     )
     self.bootloader_install = mock.Mock()
     kiwi.builder.disk.BootLoaderInstall = mock.MagicMock(
         return_value=self.bootloader_install
     )
     self.bootloader_config = mock.Mock()
     kiwi.builder.disk.BootLoaderConfig = mock.MagicMock(
         return_value=self.bootloader_config
     )
     kiwi.builder.disk.DiskSetup = mock.MagicMock(
         return_value=self.disk_setup
     )
     self.boot_image_task = mock.Mock()
     self.boot_image_task.boot_root_directory = 'boot_dir'
     self.boot_image_task.kernel_filename = 'kernel'
     self.boot_image_task.initrd_filename = 'initrd'
     self.boot_image_task.xen_hypervisor_filename = 'xen_hypervisor'
     kiwi.builder.disk.BootImage = mock.Mock(
         return_value=self.boot_image_task
     )
     self.firmware = mock.Mock()
     self.firmware.efi_mode = mock.Mock(
         return_value='efi'
     )
     kiwi.builder.disk.FirmWare = mock.Mock(
         return_value=self.firmware
     )
     self.setup = mock.Mock()
     kiwi.builder.disk.SystemSetup = mock.Mock(
         return_value=self.setup
     )
     self.boot_image_kiwi = mock.Mock()
     self.boot_image_kiwi.boot_root_directory = 'boot_dir_kiwi'
     kiwi.builder.disk.BootImageKiwi = mock.Mock(
         return_value=self.boot_image_kiwi
     )
     self.install_image = mock.Mock()
     kiwi.builder.disk.InstallImageBuilder = mock.Mock(
         return_value=self.install_image
     )
     self.raid_root = mock.Mock()
     kiwi.builder.disk.RaidDevice = mock.Mock(
         return_value=self.raid_root
     )
     self.luks_root = mock.Mock()
     kiwi.builder.disk.LuksDevice = mock.Mock(
         return_value=self.luks_root
     )
     self.disk_builder = DiskBuilder(
         XMLState(description.load()), 'target_dir', 'root_dir'
     )
     self.disk_builder.root_filesystem_is_overlay = False
     self.disk_builder.build_type_name = 'oem'
     self.machine = mock.Mock()
     self.machine.get_domain = mock.Mock(
         return_value='dom0'
     )
     self.disk_builder.machine = self.machine
     self.disk_builder.image_format = None
Beispiel #48
0
 def test_get_build_type_oemconfig_section(self):
     description = XMLDescription('../data/example_config.xml')
     xml_data = description.load()
     state = XMLState(xml_data, None, 'oem')
     assert state.get_build_type_oemconfig_section().get_oem_swap()[0] is \
         True
Beispiel #49
0
 def test_this_path_resolver(self):
     description = XMLDescription('../data/example_this_path_config.xml')
     xml_data = description.load()
     state = XMLState(xml_data)
     assert state.xml_data.get_repository()[0].get_source().get_path() \
         == 'dir://{0}/my_repo'.format(os.path.realpath('../data'))
Beispiel #50
0
 def test_get_build_type_vmconfig_entries_no_machine_section(self):
     description = XMLDescription('../data/example_disk_config.xml')
     xml_data = description.load()
     state = XMLState(xml_data)
     assert state.get_build_type_vmconfig_entries() == []
Beispiel #51
0
class TestXMLState:
    @fixture(autouse=True)
    def inject_fixtures(self, caplog):
        self._caplog = caplog

    def setup(self):
        Defaults.set_platform_name('x86_64')
        self.description = XMLDescription('../data/example_config.xml')
        self.state = XMLState(self.description.load())
        boot_description = XMLDescription(
            '../data/isoboot/example-distribution/config.xml')
        self.boot_state = XMLState(boot_description.load())
        no_image_packages_description = XMLDescription(
            '../data/example_no_image_packages_config.xml')
        self.no_image_packages_boot_state = XMLState(
            no_image_packages_description.load())
        self.bootloader = Mock()
        self.bootloader.get_name.return_value = 'some-loader'
        self.bootloader.get_timeout.return_value = 'some-timeout'
        self.bootloader.get_timeout_style.return_value = 'some-style'
        self.bootloader.get_targettype.return_value = 'some-target'
        self.bootloader.get_console.return_value = 'some-console'
        self.bootloader.get_serial_line.return_value = 'some-serial'

    def test_get_description_section(self):
        description = self.state.get_description_section()
        assert description.author == 'Marcus'
        assert description.contact == '*****@*****.**'
        assert description.specification == \
            'Testing various configuration states'

    def test_get_preferences_by_architecture(self):
        Defaults.set_platform_name('aarch64')
        state = XMLState(self.description.load())
        preferences = state.get_preferences_sections()
        Defaults.set_platform_name('x86_64')
        assert len(preferences) == 3
        assert preferences[2].get_arch() == 'aarch64'
        assert state.get_build_type_name() == 'iso'

    def test_build_type_primary_selected(self):
        assert self.state.get_build_type_name() == 'oem'

    def test_build_type_first_selected(self):
        self.state.xml_data.get_preferences()[2].get_type()[0].set_primary(
            False)
        assert self.state.get_build_type_name() == 'oem'

    @patch('kiwi.xml_state.XMLState.get_preferences_sections')
    def test_get_rpm_excludedocs_without_entry(self, mock_preferences):
        mock_preferences.return_value = []
        assert self.state.get_rpm_excludedocs() is False

    def test_get_rpm_excludedocs(self):
        assert self.state.get_rpm_excludedocs() is True

    @patch('kiwi.xml_state.XMLState.get_preferences_sections')
    def test_get_rpm_check_signatures_without_entry(self, mock_preferences):
        mock_preferences.return_value = []
        assert self.state.get_rpm_check_signatures() is False

    def test_get_rpm_check_signatures(self):
        assert self.state.get_rpm_check_signatures() is True

    def test_get_package_manager(self):
        assert self.state.get_package_manager() == 'zypper'

    def get_release_version(self):
        assert self.state.get_release_version() == '15.3'

    @patch('kiwi.xml_state.XMLState.get_preferences_sections')
    def test_get_default_package_manager(self, mock_preferences):
        mock_preferences.return_value = []
        assert self.state.get_package_manager() == 'dnf'

    def test_get_image_version(self):
        assert self.state.get_image_version() == '1.13.2'

    def test_get_bootstrap_packages(self):
        assert self.state.get_bootstrap_packages() == ['filesystem', 'zypper']
        assert self.state.get_bootstrap_packages(plus_packages=['vim']) == [
            'filesystem', 'vim', 'zypper'
        ]
        assert self.no_image_packages_boot_state.get_bootstrap_packages() == [
            'patterns-openSUSE-base'
        ]

    def test_get_system_packages(self):
        assert self.state.get_system_packages() == [
            'gfxboot-branding-openSUSE', 'grub2-branding-openSUSE', 'ifplugd',
            'iputils', 'kernel-default', 'openssh',
            'plymouth-branding-openSUSE', 'vim'
        ]

    def test_get_system_packages_some_arch(self):
        Defaults.set_platform_name('s390')
        state = XMLState(self.description.load())
        assert state.get_system_packages() == [
            'foo', 'gfxboot-branding-openSUSE', 'grub2-branding-openSUSE',
            'ifplugd', 'iputils', 'kernel-default', 'openssh',
            'plymouth-branding-openSUSE', 'vim'
        ]
        Defaults.set_platform_name('x86_64')

    def test_get_system_collections(self):
        assert self.state.get_system_collections() == ['base']

    def test_get_system_products(self):
        assert self.state.get_system_products() == ['openSUSE']

    def test_get_system_archives(self):
        assert self.state.get_system_archives() == [
            '/absolute/path/to/image.tgz'
        ]

    def test_get_system_ignore_packages(self):
        assert self.state.get_system_ignore_packages() == ['bar', 'baz', 'foo']
        self.state.host_architecture = 'aarch64'
        assert self.state.get_system_ignore_packages() == ['baz', 'foo']
        self.state.host_architecture = 's390'
        assert self.state.get_system_ignore_packages() == ['baz']

    def test_get_system_collection_type(self):
        assert self.state.get_system_collection_type() == 'plusRecommended'

    def test_get_bootstrap_collections(self):
        assert self.state.get_bootstrap_collections() == [
            'bootstrap-collection'
        ]

    def test_get_bootstrap_products(self):
        assert self.state.get_bootstrap_products() == ['kiwi']

    def test_get_bootstrap_archives(self):
        assert self.state.get_bootstrap_archives() == ['bootstrap.tgz']

    def test_get_bootstrap_collection_type(self):
        assert self.state.get_bootstrap_collection_type() == 'onlyRequired'

    def test_set_repository(self):
        self.state.set_repository('repo', 'type', 'alias', 1, True, False)
        assert self.state.xml_data.get_repository()[0].get_source().get_path() \
            == 'repo'
        assert self.state.xml_data.get_repository()[0].get_type() == 'type'
        assert self.state.xml_data.get_repository()[0].get_alias() == 'alias'
        assert self.state.xml_data.get_repository()[0].get_priority() == 1
        assert self.state.xml_data.get_repository()[0] \
            .get_imageinclude() is True
        assert self.state.xml_data.get_repository()[0] \
            .get_package_gpgcheck() is False

    def test_add_repository(self):
        self.state.add_repository('repo', 'type', 'alias', 1, True)
        assert self.state.xml_data.get_repository()[3].get_source().get_path() \
            == 'repo'
        assert self.state.xml_data.get_repository()[3].get_type() == 'type'
        assert self.state.xml_data.get_repository()[3].get_alias() == 'alias'
        assert self.state.xml_data.get_repository()[3].get_priority() == 1
        assert self.state.xml_data.get_repository()[3] \
            .get_imageinclude() is True

    def test_add_repository_with_empty_values(self):
        self.state.add_repository('repo', 'type', '', '', True)
        assert self.state.xml_data.get_repository()[3].get_source().get_path() \
            == 'repo'
        assert self.state.xml_data.get_repository()[3].get_type() == 'type'
        assert self.state.xml_data.get_repository()[3].get_alias() == ''
        assert self.state.xml_data.get_repository()[3].get_priority() is None
        assert self.state.xml_data.get_repository()[3] \
            .get_imageinclude() is True

    def test_get_to_become_deleted_packages(self):
        assert self.state.get_to_become_deleted_packages() == ['kernel-debug']

    def test_get_build_type_vagrant_config_section(self):
        vagrant_config = self.state.get_build_type_vagrant_config_section()
        assert vagrant_config.get_provider() == 'libvirt'
        assert self.boot_state.get_build_type_vagrant_config_section() is None

    def test_virtualbox_guest_additions_vagrant_config_section(self):
        assert not self.state.get_vagrant_config_virtualbox_guest_additions()

    def test_virtualbox_guest_additions_vagrant_config_section_missing(self):
        self.state. \
            get_build_type_vagrant_config_section() \
            .virtualbox_guest_additions_present = True
        assert self.state.get_vagrant_config_virtualbox_guest_additions()

    def test_get_build_type_system_disk_section(self):
        assert self.state.get_build_type_system_disk_section().get_name() == \
            'mydisk'

    def test_get_build_type_vmdisk_section(self):
        assert self.state.get_build_type_vmdisk_section().get_id() == 0
        assert self.boot_state.get_build_type_vmdisk_section() is None

    def test_get_build_type_vmnic_entries(self):
        assert self.state.get_build_type_vmnic_entries()[0].get_interface() \
            == ''
        assert self.boot_state.get_build_type_vmnic_entries() == []

    def test_get_build_type_vmdvd_section(self):
        assert self.state.get_build_type_vmdvd_section().get_id() == 0
        assert self.boot_state.get_build_type_vmdvd_section() is None

    def test_get_volume_management(self):
        assert self.state.get_volume_management() == 'lvm'

    def test_get_volume_management_none(self):
        assert self.boot_state.get_volume_management() is None

    def test_get_volume_management_btrfs(self):
        description = XMLDescription('../data/example_btrfs_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_volume_management() == 'btrfs'

    def test_get_volume_management_lvm_prefer(self):
        description = XMLDescription(
            '../data/example_lvm_preferred_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_volume_management() == 'lvm'

    def test_get_volume_management_lvm_default(self):
        description = XMLDescription('../data/example_lvm_default_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_volume_management() == 'lvm'

    def test_build_type_explicitly_selected(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'oem')
        assert state.get_build_type_name() == 'oem'

    def test_build_type_not_found(self):
        xml_data = self.description.load()
        with raises(KiwiTypeNotFound):
            XMLState(xml_data, ['vmxFlavour'], 'foo')

    def test_build_type_not_found_no_default_type(self):
        description = XMLDescription('../data/example_no_default_type.xml')
        xml_data = description.load()
        with raises(KiwiTypeNotFound):
            XMLState(xml_data, ['minimal'])

    def test_profile_not_found(self):
        xml_data = self.description.load()
        with raises(KiwiProfileNotFound):
            XMLState(xml_data, ['foo'])

    def test_profile_requires(self):
        xml_data = self.description.load()
        xml_state = XMLState(xml_data, ['composedProfile'])
        assert xml_state.profiles == [
            'composedProfile', 'vmxSimpleFlavour', 'xenDomUFlavour'
        ]

    def test_get_partitions(self):
        description = XMLDescription('../data/example_partitions_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_partitions() == {
            'var':
            ptable_entry_type(mbsize=100,
                              partition_name='p.lxvar',
                              partition_type='t.linux',
                              mountpoint='/var',
                              filesystem='ext3')
        }

    def test_get_volumes_custom_root_volume_name(self):
        description = XMLDescription(
            '../data/example_lvm_custom_rootvol_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        volume_type = namedtuple('volume_type', [
            'name', 'size', 'realpath', 'mountpoint', 'fullsize', 'label',
            'attributes', 'is_root_volume'
        ])
        assert state.get_volumes() == [
            volume_type(name='myroot',
                        size='freespace:500',
                        realpath='/',
                        mountpoint=None,
                        fullsize=False,
                        label=None,
                        attributes=[],
                        is_root_volume=True)
        ]

    def test_get_volumes(self):
        description = XMLDescription('../data/example_lvm_default_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        volume_type = namedtuple('volume_type', [
            'name', 'size', 'realpath', 'mountpoint', 'fullsize', 'label',
            'attributes', 'is_root_volume'
        ])
        assert state.get_volumes() == [
            volume_type(name='usr_lib',
                        size='size:1024',
                        realpath='usr/lib',
                        mountpoint='usr/lib',
                        fullsize=False,
                        label='library',
                        attributes=[],
                        is_root_volume=False),
            volume_type(name='LVRoot',
                        size='freespace:500',
                        realpath='/',
                        mountpoint=None,
                        fullsize=False,
                        label=None,
                        attributes=[],
                        is_root_volume=True),
            volume_type(
                name='etc_volume',
                size='freespace:30',
                realpath='etc',
                mountpoint='etc',
                fullsize=False,
                label=None,
                attributes=['no-copy-on-write', 'enable-for-filesystem-check'],
                is_root_volume=False),
            volume_type(name='bin_volume',
                        size=None,
                        realpath='/usr/bin',
                        mountpoint='/usr/bin',
                        fullsize=True,
                        label=None,
                        attributes=[],
                        is_root_volume=False),
            volume_type(name='LVSwap',
                        size='size:128',
                        realpath='swap',
                        mountpoint=None,
                        fullsize=False,
                        label='SWAP',
                        attributes=[],
                        is_root_volume=False)
        ]

    def test_get_volumes_no_explicit_root_setup(self):
        description = XMLDescription('../data/example_lvm_no_root_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        volume_type = namedtuple('volume_type', [
            'name', 'size', 'realpath', 'mountpoint', 'fullsize', 'label',
            'attributes', 'is_root_volume'
        ])
        assert state.get_volumes() == [
            volume_type(name='LVRoot',
                        size=None,
                        realpath='/',
                        mountpoint=None,
                        fullsize=True,
                        label=None,
                        attributes=[],
                        is_root_volume=True),
            volume_type(name='LVSwap',
                        size='size:128',
                        realpath='swap',
                        mountpoint=None,
                        fullsize=False,
                        label='SWAP',
                        attributes=[],
                        is_root_volume=False)
        ]

    def test_get_volumes_no_explicit_root_setup_other_fullsize_volume(self):
        description = XMLDescription(
            '../data/example_lvm_no_root_full_usr_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        volume_type = namedtuple('volume_type', [
            'name', 'size', 'realpath', 'mountpoint', 'fullsize', 'label',
            'attributes', 'is_root_volume'
        ])
        assert state.get_volumes() == [
            volume_type(name='usr',
                        size=None,
                        realpath='usr',
                        mountpoint='usr',
                        fullsize=True,
                        label=None,
                        attributes=[],
                        is_root_volume=False),
            volume_type(name='LVRoot',
                        size='freespace:30',
                        realpath='/',
                        mountpoint=None,
                        fullsize=False,
                        label=None,
                        attributes=[],
                        is_root_volume=True),
            volume_type(name='LVSwap',
                        size='size:128',
                        realpath='swap',
                        mountpoint=None,
                        fullsize=False,
                        label='SWAP',
                        attributes=[],
                        is_root_volume=False)
        ]

    @patch('kiwi.xml_state.XMLState.get_build_type_system_disk_section')
    def test_get_empty_volumes(self, mock_system_disk):
        mock_system_disk.return_value = None
        assert self.state.get_volumes() == []

    def test_get_strip_files_to_delete(self):
        assert self.state.get_strip_files_to_delete() == ['del-a', 'del-b']

    def test_get_strip_tools_to_keep(self):
        assert self.state.get_strip_tools_to_keep() == ['tool-a', 'tool-b']

    def test_get_strip_libraries_to_keep(self):
        assert self.state.get_strip_libraries_to_keep() == ['lib-a', 'lib-b']

    def test_get_build_type_machine_section(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxSimpleFlavour'], 'oem')
        assert state.get_build_type_machine_section().get_guestOS() == 'suse'

    def test_get_drivers_list(self):
        assert self.state.get_drivers_list() == \
            ['crypto/*', 'drivers/acpi/*', 'bar']

    def test_get_build_type_oemconfig_section(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, None, 'oem')
        assert state.get_build_type_oemconfig_section().get_oem_swap()[0] is \
            True

    def test_get_oemconfig_oem_resize(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'oem')
        assert state.get_oemconfig_oem_resize() is True
        description = XMLDescription(
            '../data/example_multiple_users_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_oemconfig_oem_resize() is False

    def test_get_oemconfig_oem_multipath_scan(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'oem')
        assert state.get_oemconfig_oem_multipath_scan() is False
        description = XMLDescription('../data/example_disk_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_oemconfig_oem_multipath_scan() is False

    def test_get_oemconfig_swap_mbytes(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['containerFlavour'], 'docker')
        assert state.get_oemconfig_swap_mbytes() is None
        state = XMLState(xml_data, ['vmxFlavour'], 'oem')
        assert state.get_oemconfig_swap_mbytes() == 42

    def test_get_oemconfig_swap_name(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['containerFlavour'], 'docker')
        assert state.get_oemconfig_swap_name() == 'LVSwap'
        state = XMLState(xml_data, ['vmxFlavour'], 'oem')
        assert state.get_oemconfig_swap_name() == 'swap'

    def test_get_oemconfig_swap_mbytes_default(self):
        description = XMLDescription('../data/example_btrfs_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_oemconfig_swap_mbytes() == 128

    def test_get_users_sections(self):
        assert self.state.get_users_sections()[0].get_user()[0].get_name() == \
            'root'

    def test_get_users(self):
        description = XMLDescription(
            '../data/example_multiple_users_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        users = state.get_users()
        assert len(users) == 3
        assert any(u.get_name() == 'root' for u in users)
        assert any(u.get_name() == 'tux' for u in users)
        assert any(u.get_name() == 'kiwi' for u in users)

    def test_get_user_groups(self):
        description = XMLDescription(
            '../data/example_multiple_users_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)

        assert len(state.get_user_groups('root')) == 0
        assert len(state.get_user_groups('tux')) == 1
        assert any(grp == 'users' for grp in state.get_user_groups('tux'))
        assert len(state.get_user_groups('kiwi')) == 3
        assert any(grp == 'users' for grp in state.get_user_groups('kiwi'))
        assert any(grp == 'kiwi' for grp in state.get_user_groups('kiwi'))
        assert any(grp == 'admin' for grp in state.get_user_groups('kiwi'))

    def test_copy_displayname(self):
        self.state.copy_displayname(self.boot_state)
        assert self.boot_state.xml_data.get_displayname() == 'Bob'

    def test_copy_drivers_sections(self):
        self.state.copy_drivers_sections(self.boot_state)
        assert 'bar' in self.boot_state.get_drivers_list()

    def test_copy_systemdisk_section(self):
        self.state.copy_systemdisk_section(self.boot_state)
        systemdisk = self.boot_state.get_build_type_system_disk_section()
        assert systemdisk.get_name() == 'mydisk'

    @patch('kiwi.xml_parse.type_.get_bootloader')
    def test_copy_bootloader_section(self, mock_bootloader):
        mock_bootloader.return_value = [self.bootloader]
        self.state.copy_bootloader_section(self.boot_state)
        assert self.boot_state.get_build_type_bootloader_section() == \
            self.bootloader

    def test_copy_strip_sections(self):
        self.state.copy_strip_sections(self.boot_state)
        assert 'del-a' in self.boot_state.get_strip_files_to_delete()

    def test_copy_machine_section(self):
        self.state.copy_machine_section(self.boot_state)
        machine = self.boot_state.get_build_type_machine_section()
        assert machine.get_memory() == 512

    def test_copy_oemconfig_section(self):
        self.state.copy_oemconfig_section(self.boot_state)
        oemconfig = self.boot_state.get_build_type_oemconfig_section()
        assert oemconfig.get_oem_systemsize()[0] == 2048

    def test_copy_repository_sections(self):
        self.state.copy_repository_sections(self.boot_state, True)
        repository = self.boot_state.get_repository_sections()[0]
        assert repository.get_source().get_path() == 'iso:///image/CDs/dvd.iso'

    def test_copy_preferences_subsections(self):
        self.state.copy_preferences_subsections(['bootsplash_theme'],
                                                self.boot_state)
        preferences = self.boot_state.get_preferences_sections()[0]
        assert preferences.get_bootsplash_theme()[0] == 'openSUSE'

    def test_copy_build_type_attributes(self):
        self.state.copy_build_type_attributes(['firmware'], self.boot_state)
        assert self.boot_state.build_type.get_firmware() == 'efi'

    def test_copy_bootincluded_packages_with_no_image_packages(self):
        self.state.copy_bootincluded_packages(self.boot_state)
        bootstrap_packages = self.boot_state.get_bootstrap_packages()
        assert 'plymouth-branding-openSUSE' in bootstrap_packages
        assert 'grub2-branding-openSUSE' in bootstrap_packages
        assert 'gfxboot-branding-openSUSE' in bootstrap_packages
        to_delete_packages = self.boot_state.get_to_become_deleted_packages()
        assert 'gfxboot-branding-openSUSE' not in to_delete_packages

    def test_copy_bootincluded_packages_with_image_packages(self):
        boot_description = XMLDescription(
            '../data/isoboot/example-distribution/config.xml')
        boot_state = XMLState(boot_description.load(), ['std'])
        self.state.copy_bootincluded_packages(boot_state)
        image_packages = boot_state.get_system_packages()
        assert 'plymouth-branding-openSUSE' in image_packages
        assert 'grub2-branding-openSUSE' in image_packages
        assert 'gfxboot-branding-openSUSE' in image_packages
        to_delete_packages = boot_state.get_to_become_deleted_packages()
        assert 'gfxboot-branding-openSUSE' not in to_delete_packages

    def test_copy_bootincluded_archives(self):
        self.state.copy_bootincluded_archives(self.boot_state)
        bootstrap_archives = self.boot_state.get_bootstrap_archives()
        assert '/absolute/path/to/image.tgz' in bootstrap_archives

    def test_copy_bootdelete_packages(self):
        self.state.copy_bootdelete_packages(self.boot_state)
        to_delete_packages = self.boot_state.get_to_become_deleted_packages()
        assert 'vim' in to_delete_packages

    def test_copy_bootdelete_packages_no_delete_section_in_boot_descr(self):
        boot_description = XMLDescription(
            '../data/isoboot/example-distribution-no-delete-section/config.xml'
        )
        boot_state = XMLState(boot_description.load())
        self.state.copy_bootdelete_packages(boot_state)
        to_delete_packages = boot_state.get_to_become_deleted_packages()
        assert 'vim' in to_delete_packages

    def test_build_type_size(self):
        result = self.state.get_build_type_size()
        assert result.mbytes == 1024
        assert result.additive

    def test_build_type_size_with_unpartitioned(self):
        state = XMLState(self.description.load(), ['vmxSimpleFlavour'], 'oem')
        result = state.get_build_type_size()
        assert result.mbytes == 3072
        assert not result.additive
        result = state.get_build_type_size(include_unpartitioned=True)
        assert result.mbytes == 4096
        assert not result.additive

    def test_get_build_type_unpartitioned_bytes(self):
        assert self.state.get_build_type_unpartitioned_bytes() == 0
        state = XMLState(self.description.load(), ['vmxSimpleFlavour'], 'oem')
        assert state.get_build_type_unpartitioned_bytes() == 1073741824
        state = XMLState(self.description.load(), ['vmxFlavour'], 'oem')
        assert state.get_build_type_unpartitioned_bytes() == 0
        state = XMLState(self.description.load(), ['ec2Flavour'], 'oem')
        assert state.get_build_type_unpartitioned_bytes() == 0

    def test_get_volume_group_name(self):
        assert self.state.get_volume_group_name() == 'mydisk'

    def test_get_volume_group_name_default(self):
        assert self.boot_state.get_volume_group_name() == 'systemVG'

    def test_get_distribution_name_from_boot_attribute(self):
        assert self.state.get_distribution_name_from_boot_attribute() == \
            'distribution'

    def test_get_fs_mount_option_list(self):
        assert self.state.get_fs_mount_option_list() == ['async']

    def test_get_fs_create_option_list(self):
        assert self.state.get_fs_create_option_list() == ['-O', '^has_journal']

    @patch('kiwi.xml_parse.type_.get_boot')
    def test_get_distribution_name_from_boot_attribute_no_boot(
            self, mock_boot):
        mock_boot.return_value = None
        with raises(KiwiDistributionNameError):
            self.state.get_distribution_name_from_boot_attribute()

    @patch('kiwi.xml_parse.type_.get_boot')
    def test_get_distribution_name_from_boot_attribute_invalid_boot(
            self, mock_boot):
        mock_boot.return_value = 'invalid'
        with raises(KiwiDistributionNameError):
            self.state.get_distribution_name_from_boot_attribute()

    def test_delete_repository_sections(self):
        self.state.delete_repository_sections()
        assert self.state.get_repository_sections() == []

    def test_delete_repository_sections_used_for_build(self):
        self.state.delete_repository_sections_used_for_build()
        assert self.state.get_repository_sections()[0].get_imageonly()

    def test_get_build_type_vmconfig_entries(self):
        assert self.state.get_build_type_vmconfig_entries() == []

    def test_get_build_type_vmconfig_entries_for_simple_disk(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxSimpleFlavour'], 'oem')
        assert state.get_build_type_vmconfig_entries() == [
            'numvcpus = "4"', 'cpuid.coresPerSocket = "2"'
        ]

    def test_get_build_type_vmconfig_entries_no_machine_section(self):
        description = XMLDescription('../data/example_disk_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_build_type_vmconfig_entries() == []

    def test_get_build_type_docker_containerconfig_section(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['containerFlavour'], 'docker')
        containerconfig = state.get_build_type_containerconfig_section()
        assert containerconfig.get_name() == \
            'container_name'
        assert containerconfig.get_maintainer() == \
            'tux'
        assert containerconfig.get_workingdir() == \
            '/root'

    def test_set_container_tag(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['containerFlavour'], 'docker')
        state.set_container_config_tag('new_tag')
        config = state.get_container_config()
        assert config['container_tag'] == 'new_tag'

    def test_add_container_label(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['containerFlavour'], 'docker')
        state.add_container_config_label('somelabel', 'overwrittenvalue')
        state.add_container_config_label('new_label', 'new value')
        config = state.get_container_config()
        assert config['labels'] == {
            'somelabel': 'overwrittenvalue',
            'someotherlabel': 'anotherlabelvalue',
            'new_label': 'new value'
        }

    def test_add_container_label_without_contianerconfig(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['xenDom0Flavour'], 'docker')
        state.add_container_config_label('somelabel', 'newlabelvalue')
        config = state.get_container_config()
        assert config['labels'] == {'somelabel': 'newlabelvalue'}

    def test_add_container_label_no_container_image_type(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'oem')
        state.add_container_config_label('somelabel', 'newlabelvalue')
        with self._caplog.at_level(logging.WARNING):
            config = state.get_container_config()
            assert config == {
                'history': {
                    'author': 'Marcus <*****@*****.**>'
                },
                'maintainer': 'Marcus <*****@*****.**>'
            }

    def test_set_container_tag_not_applied(self):
        with self._caplog.at_level(logging.WARNING):
            self.state.set_container_config_tag('new_tag')

    def test_get_container_config(self):
        expected_config = {
            'labels': {
                'somelabel': 'labelvalue',
                'someotherlabel': 'anotherlabelvalue'
            },
            'maintainer': 'tux',
            'entry_subcommand': ['ls', '-l'],
            'container_name': 'container_name',
            'container_tag': 'container_tag',
            'additional_tags': ['current', 'foobar'],
            'workingdir': '/root',
            'environment': {
                'PATH': '/bin:/usr/bin:/home/user/bin',
                'SOMEVAR': 'somevalue'
            },
            'user': '******',
            'volumes': ['/tmp', '/var/log'],
            'entry_command': ['/bin/bash', '-x'],
            'expose_ports': ['80', '8080'],
            'history': {
                'author': 'history author',
                'comment': 'This is a comment',
                'created_by': 'created by text',
                'application_id': '123',
                'package_version': '2003.12.0.0',
                'launcher': 'app'
            }
        }
        xml_data = self.description.load()
        state = XMLState(xml_data, ['containerFlavour'], 'docker')
        assert state.get_container_config() == expected_config

    def test_get_container_config_clear_commands(self):
        expected_config = {
            'maintainer': 'tux',
            'entry_subcommand': [],
            'container_name': 'container_name',
            'container_tag': 'container_tag',
            'workingdir': '/root',
            'user': '******',
            'entry_command': [],
            'history': {
                'author': 'Marcus <*****@*****.**>'
            }
        }
        xml_data = self.description.load()
        state = XMLState(xml_data, ['derivedContainer'], 'docker')
        assert state.get_container_config() == expected_config

    def test_get_spare_part(self):
        assert self.state.get_build_type_spare_part_size() == 200
        assert self.state.get_build_type_spare_part_fs_attributes() == [
            'no-copy-on-write'
        ]

    def test_get_build_type_format_options(self):
        assert self.state.get_build_type_format_options() == {
            'super': 'man',
            'force_size': None
        }

    def test_get_derived_from_image_uri(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['derivedContainer'], 'docker')
        assert state.get_derived_from_image_uri().uri == \
            'obs://project/repo/image#mytag'

    def test_set_derived_from_image_uri(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['derivedContainer'], 'docker')
        state.set_derived_from_image_uri('file:///new_uri')
        assert state.get_derived_from_image_uri().translate() == '/new_uri'

    def test_set_derived_from_image_uri_not_applied(self):
        with self._caplog.at_level(logging.WARNING):
            self.state.set_derived_from_image_uri('file:///new_uri')

    def test_is_xen_server(self):
        assert self.state.is_xen_server() is True

    def test_is_xen_guest_by_machine_setup(self):
        assert self.state.is_xen_guest() is True

    def test_is_xen_guest_no_xen_guest_setup(self):
        assert self.boot_state.is_xen_guest() is False

    def test_is_xen_guest_by_firmware_setup(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['ec2Flavour'], 'oem')
        assert state.is_xen_guest() is True

    def test_is_xen_guest_by_architecture(self):
        Defaults.set_platform_name('unsupported')
        xml_data = self.description.load()
        state = XMLState(xml_data, ['ec2Flavour'], 'oem')
        assert state.is_xen_guest() is False
        Defaults.set_platform_name('x86_64')

    def test_get_initrd_system(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'oem')
        assert state.get_initrd_system() == 'dracut'
        state = XMLState(xml_data, ['vmxSimpleFlavour'], 'iso')
        assert state.get_initrd_system() == 'dracut'
        state = XMLState(xml_data, ['containerFlavour'], 'docker')
        assert state.get_initrd_system() == 'none'
        state = XMLState(xml_data, [], 'oem')
        assert state.get_initrd_system() == 'dracut'

    def test_get_rpm_locale_filtering(self):
        assert self.state.get_rpm_locale_filtering() is True
        assert self.boot_state.get_rpm_locale_filtering() is False

    def test_get_locale(self):
        assert self.state.get_locale() == ['en_US', 'de_DE']
        assert self.boot_state.get_locale() is None

    def test_get_rpm_locale(self):
        assert self.state.get_rpm_locale() == [
            'POSIX', 'C', 'C.UTF-8', 'en_US', 'de_DE'
        ]
        assert self.boot_state.get_rpm_locale() is None

    def test_set_root_partition_uuid(self):
        assert self.state.get_root_partition_uuid() is None
        self.state.set_root_partition_uuid('some-id')
        assert self.state.get_root_partition_uuid() == 'some-id'

    def test_set_root_filesystem_uuid(self):
        assert self.state.get_root_filesystem_uuid() is None
        self.state.set_root_filesystem_uuid('some-id')
        assert self.state.get_root_filesystem_uuid() == 'some-id'

    @patch('kiwi.xml_parse.type_.get_bootloader')
    def test_get_build_type_bootloader_name(self, mock_bootloader):
        mock_bootloader.return_value = [None]
        assert self.state.get_build_type_bootloader_name() == 'grub2'
        mock_bootloader.return_value = [self.bootloader]
        assert self.state.get_build_type_bootloader_name() == 'some-loader'

    @patch('kiwi.xml_parse.type_.get_bootloader')
    def test_get_build_type_bootloader_console(self, mock_bootloader):
        mock_bootloader.return_value = [self.bootloader]
        assert self.state.get_build_type_bootloader_console() == \
            'some-console'

    @patch('kiwi.xml_parse.type_.get_bootloader')
    def test_get_build_type_bootloader_serial_line_setup(
            self, mock_bootloader):
        mock_bootloader.return_value = [self.bootloader]
        assert self.state.get_build_type_bootloader_serial_line_setup() == \
            'some-serial'
        mock_bootloader.return_value = [None]
        assert self.state.get_build_type_bootloader_serial_line_setup() \
            is None

    @patch('kiwi.xml_parse.type_.get_bootloader')
    def test_get_build_type_bootloader_timeout(self, mock_bootloader):
        mock_bootloader.return_value = [self.bootloader]
        assert self.state.get_build_type_bootloader_timeout() == \
            'some-timeout'

    @patch('kiwi.xml_parse.type_.get_bootloader')
    def test_get_build_type_bootloader_timeout_style(self, mock_bootloader):
        mock_bootloader.return_value = [self.bootloader]
        assert self.state.get_build_type_bootloader_timeout_style() == \
            'some-style'
        mock_bootloader.return_value = [None]
        assert self.state.get_build_type_bootloader_timeout_style() \
            is None

    @patch('kiwi.xml_parse.type_.get_bootloader')
    def test_get_build_type_bootloader_targettype(self, mock_bootloader):
        mock_bootloader.return_value = [self.bootloader]
        assert self.state.get_build_type_bootloader_targettype() == \
            'some-target'

    def test_get_installintrd_modules(self):
        self.state.get_installmedia_initrd_modules('add') == ['network-legacy']
        self.state.get_installmedia_initrd_modules('set') == []
        self.state.get_installmedia_initrd_modules('omit') == []
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxSimpleFlavour'], 'oem')
        state.get_installmedia_initrd_modules('add') == []

    @patch('kiwi.system.uri.os.path.abspath')
    def test_get_repositories_signing_keys(self, mock_root_path):
        mock_root_path.side_effect = lambda x: f'/some/path/{x}'
        assert self.state.get_repositories_signing_keys() == [
            '/some/path/key_a', '/some/path/key_b'
        ]

    def test_this_path_resolver(self):
        description = XMLDescription('../data/example_this_path_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.xml_data.get_repository()[0].get_source().get_path() \
            == 'dir://{0}/my_repo'.format(os.path.realpath('../data'))
Beispiel #52
0
 def setup(self):
     self.profile_file = 'tmpfile.profile'
     description = XMLDescription('../data/example_dot_profile_config.xml')
     self.profile = Profile(XMLState(description.load()))
Beispiel #53
0
 def test_build_type_explicitly_selected(self):
     description = XMLDescription('../data/example_config.xml')
     xml_data = description.load()
     state = XMLState(xml_data, ['vmxFlavour'], 'vmx')
     assert state.get_build_type_name() == 'vmx'
Beispiel #54
0
class TestXMLState(object):
    @patch('platform.machine')
    def setup(self, mock_machine):
        mock_machine.return_value = 'x86_64'
        self.description = XMLDescription('../data/example_config.xml')
        self.state = XMLState(self.description.load())
        boot_description = XMLDescription(
            '../data/isoboot/example-distribution/config.xml')
        self.boot_state = XMLState(boot_description.load())
        no_image_packages_description = XMLDescription(
            '../data/example_no_image_packages_config.xml')
        self.no_image_packages_boot_state = XMLState(
            no_image_packages_description.load())

    def test_build_type_primary_selected(self):
        assert self.state.get_build_type_name() == 'oem'

    def test_build_type_first_selected(self):
        self.state.xml_data.get_preferences()[1].get_type()[0].set_primary(
            False)
        assert self.state.get_build_type_name() == 'oem'

    @patch('kiwi.xml_state.XMLState.get_preferences_sections')
    def test_get_rpm_excludedocs_without_entry(self, mock_preferences):
        mock_preferences.return_value = []
        assert self.state.get_rpm_excludedocs() is False

    def test_get_rpm_excludedocs(self):
        assert self.state.get_rpm_excludedocs() is True

    @patch('kiwi.xml_state.XMLState.get_preferences_sections')
    def test_get_rpm_check_signatures_without_entry(self, mock_preferences):
        mock_preferences.return_value = []
        assert self.state.get_rpm_check_signatures() is False

    def test_get_rpm_check_signatures(self):
        assert self.state.get_rpm_check_signatures() is True

    def test_get_package_manager(self):
        assert self.state.get_package_manager() == 'zypper'

    def test_get_image_version(self):
        assert self.state.get_image_version() == '1.13.2'

    def test_get_bootstrap_packages(self):
        assert self.state.get_bootstrap_packages() == ['filesystem', 'zypper']
        assert self.no_image_packages_boot_state.get_bootstrap_packages() == [
            'patterns-openSUSE-base'
        ]

    def test_get_system_packages(self):
        assert self.state.get_system_packages() == [
            'gfxboot-branding-openSUSE', 'grub2-branding-openSUSE', 'ifplugd',
            'iputils', 'kernel-default', 'openssh',
            'plymouth-branding-openSUSE', 'vim'
        ]

    @patch('platform.machine')
    def test_get_system_packages_some_arch(self, mock_machine):
        mock_machine.return_value = 's390'
        state = XMLState(self.description.load())
        assert state.get_system_packages() == [
            'foo', 'gfxboot-branding-openSUSE', 'grub2-branding-openSUSE',
            'ifplugd', 'iputils', 'kernel-default', 'openssh',
            'plymouth-branding-openSUSE', 'vim'
        ]

    def test_get_system_collections(self):
        assert self.state.get_system_collections() == ['base']

    def test_get_system_products(self):
        assert self.state.get_system_products() == ['openSUSE']

    def test_get_system_archives(self):
        assert self.state.get_system_archives() == [
            '/absolute/path/to/image.tgz'
        ]

    def test_get_system_ignore_packages(self):
        assert self.state.get_system_ignore_packages() == ['bar', 'baz', 'foo']
        self.state.host_architecture = 'aarch64'
        assert self.state.get_system_ignore_packages() == ['baz', 'foo']
        self.state.host_architecture = 's390'
        assert self.state.get_system_ignore_packages() == ['baz']

    def test_get_system_collection_type(self):
        assert self.state.get_system_collection_type() == 'plusRecommended'

    def test_get_bootstrap_collections(self):
        assert self.state.get_bootstrap_collections() == [
            'bootstrap-collection'
        ]

    def test_get_bootstrap_products(self):
        assert self.state.get_bootstrap_products() == ['kiwi']

    def test_get_bootstrap_archives(self):
        assert self.state.get_bootstrap_archives() == ['bootstrap.tgz']

    def test_get_bootstrap_collection_type(self):
        assert self.state.get_bootstrap_collection_type() == 'onlyRequired'

    def test_set_repository(self):
        self.state.set_repository('repo', 'type', 'alias', 1, True, False)
        assert self.state.xml_data.get_repository()[0].get_source().get_path() \
            == 'repo'
        assert self.state.xml_data.get_repository()[0].get_type() == 'type'
        assert self.state.xml_data.get_repository()[0].get_alias() == 'alias'
        assert self.state.xml_data.get_repository()[0].get_priority() == 1
        assert self.state.xml_data.get_repository()[0].get_imageinclude(
        ) is True
        assert self.state.xml_data.get_repository()[0].get_package_gpgcheck(
        ) is False

    def test_add_repository(self):
        self.state.add_repository('repo', 'type', 'alias', 1, True)
        assert self.state.xml_data.get_repository()[3].get_source().get_path() \
            == 'repo'
        assert self.state.xml_data.get_repository()[3].get_type() == 'type'
        assert self.state.xml_data.get_repository()[3].get_alias() == 'alias'
        assert self.state.xml_data.get_repository()[3].get_priority() == 1
        assert self.state.xml_data.get_repository()[3].get_imageinclude(
        ) is True

    def test_add_repository_with_empty_values(self):
        self.state.add_repository('repo', 'type', '', '', True)
        assert self.state.xml_data.get_repository()[3].get_source().get_path() \
            == 'repo'
        assert self.state.xml_data.get_repository()[3].get_type() == 'type'
        assert self.state.xml_data.get_repository()[3].get_alias() == ''
        assert self.state.xml_data.get_repository()[3].get_priority() is None
        assert self.state.xml_data.get_repository()[3].get_imageinclude(
        ) is True

    def test_get_to_become_deleted_packages(self):
        assert self.state.get_to_become_deleted_packages() == ['kernel-debug']

    def test_get_build_type_vagrant_config_section(self):
        vagrant_config = self.state.get_build_type_vagrant_config_section()
        assert vagrant_config.get_provider() == 'libvirt'

    def test_get_build_type_system_disk_section(self):
        assert self.state.get_build_type_system_disk_section().get_name() == \
            'mydisk'

    def test_get_build_type_vmdisk_section(self):
        assert self.state.get_build_type_vmdisk_section().get_id() == 0

    def test_get_build_type_vmnic_entries(self):
        assert self.state.get_build_type_vmnic_entries()[0].get_interface() \
            == ''
        assert self.boot_state.get_build_type_vmnic_entries() == []

    def test_get_build_type_vmdvd_section(self):
        assert self.state.get_build_type_vmdvd_section().get_id() == 0

    def test_get_volume_management(self):
        assert self.state.get_volume_management() == 'lvm'

    def test_get_volume_management_none(self):
        assert self.boot_state.get_volume_management() is None

    def test_get_volume_management_btrfs(self):
        description = XMLDescription('../data/example_btrfs_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_volume_management() == 'btrfs'

    def test_get_volume_management_lvm_prefer(self):
        description = XMLDescription(
            '../data/example_lvm_preferred_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_volume_management() == 'lvm'

    def test_get_volume_management_lvm_default(self):
        description = XMLDescription('../data/example_lvm_default_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_volume_management() == 'lvm'

    def test_build_type_explicitly_selected(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'vmx')
        assert state.get_build_type_name() == 'vmx'

    @raises(KiwiTypeNotFound)
    def test_build_type_not_found(self):
        xml_data = self.description.load()
        XMLState(xml_data, ['vmxFlavour'], 'foo')

    @raises(KiwiTypeNotFound)
    def test_build_type_not_found_no_default_type(self):
        description = XMLDescription('../data/example_no_default_type.xml')
        xml_data = description.load()
        XMLState(xml_data, ['minimal'])

    @raises(KiwiProfileNotFound)
    def test_profile_not_found(self):
        xml_data = self.description.load()
        XMLState(xml_data, ['foo'])

    def test_profile_requires(self):
        xml_data = self.description.load()
        xml_state = XMLState(xml_data, ['composedProfile'])
        assert xml_state.profiles == [
            'composedProfile', 'vmxFlavour', 'xenFlavour'
        ]

    def test_get_volumes(self):
        description = XMLDescription('../data/example_lvm_default_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        volume_type = namedtuple('volume_type', [
            'name', 'size', 'realpath', 'mountpoint', 'fullsize', 'label',
            'attributes'
        ])
        assert state.get_volumes() == [
            volume_type(name='usr_lib',
                        size='size:1024',
                        realpath='usr/lib',
                        mountpoint='usr/lib',
                        fullsize=False,
                        label='library',
                        attributes=[]),
            volume_type(name='LVRoot',
                        size='freespace:500',
                        realpath='/',
                        mountpoint=None,
                        fullsize=False,
                        label=None,
                        attributes=[]),
            volume_type(name='etc_volume',
                        size='freespace:30',
                        realpath='etc',
                        mountpoint='etc',
                        fullsize=False,
                        label=None,
                        attributes=['no-copy-on-write']),
            volume_type(name='bin_volume',
                        size=None,
                        realpath='/usr/bin',
                        mountpoint='/usr/bin',
                        fullsize=True,
                        label=None,
                        attributes=[])
        ]

    def test_get_volumes_no_explicit_root_setup(self):
        description = XMLDescription('../data/example_lvm_no_root_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        volume_type = namedtuple('volume_type', [
            'name', 'size', 'realpath', 'mountpoint', 'fullsize', 'label',
            'attributes'
        ])
        assert state.get_volumes() == [
            volume_type(name='LVRoot',
                        size=None,
                        realpath='/',
                        mountpoint=None,
                        fullsize=True,
                        label=None,
                        attributes=[])
        ]

    def test_get_volumes_no_explicit_root_setup_other_fullsize_volume(self):
        description = XMLDescription(
            '../data/example_lvm_no_root_full_usr_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        volume_type = namedtuple('volume_type', [
            'name', 'size', 'realpath', 'mountpoint', 'fullsize', 'label',
            'attributes'
        ])
        assert state.get_volumes() == [
            volume_type(name='usr',
                        size=None,
                        realpath='usr',
                        mountpoint='usr',
                        fullsize=True,
                        label=None,
                        attributes=[]),
            volume_type(name='LVRoot',
                        size='freespace:30',
                        realpath='/',
                        mountpoint=None,
                        fullsize=False,
                        label=None,
                        attributes=[])
        ]

    @patch('kiwi.xml_state.XMLState.get_build_type_system_disk_section')
    def test_get_empty_volumes(self, mock_system_disk):
        mock_system_disk.return_value = None
        assert self.state.get_volumes() == []

    def test_get_strip_files_to_delete(self):
        assert self.state.get_strip_files_to_delete() == ['del-a', 'del-b']

    def test_get_strip_tools_to_keep(self):
        assert self.state.get_strip_tools_to_keep() == ['tool-a', 'tool-b']

    def test_get_strip_libraries_to_keep(self):
        assert self.state.get_strip_libraries_to_keep() == ['lib-a', 'lib-b']

    def test_get_build_type_machine_section(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, None, 'vmx')
        assert state.get_build_type_machine_section().get_guestOS() == 'suse'

    def test_get_build_type_pxedeploy_section(self):
        description = XMLDescription('../data/example_pxe_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data, None, 'pxe')
        assert state.get_build_type_pxedeploy_section().get_server() == \
            '192.168.100.2'

    def test_get_drivers_list(self):
        assert self.state.get_drivers_list() == \
            ['crypto/*', 'drivers/acpi/*', 'bar']

    def test_get_build_type_oemconfig_section(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, None, 'oem')
        assert state.get_build_type_oemconfig_section().get_oem_swap()[0] is \
            True

    def test_get_users_sections(self):
        assert self.state.get_users_sections()[0].get_user()[0].get_name() == \
            'root'

    def test_get_users(self):
        description = XMLDescription(
            '../data/example_multiple_users_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        users = state.get_users()
        assert len(users) == 3
        assert any(u.get_name() == 'root' for u in users)
        assert any(u.get_name() == 'tux' for u in users)
        assert any(u.get_name() == 'kiwi' for u in users)

    def test_get_user_groups(self):
        description = XMLDescription(
            '../data/example_multiple_users_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)

        assert len(state.get_user_groups('root')) == 0
        assert len(state.get_user_groups('tux')) == 1
        assert any(grp == 'users' for grp in state.get_user_groups('tux'))
        assert len(state.get_user_groups('kiwi')) == 3
        assert any(grp == 'users' for grp in state.get_user_groups('kiwi'))
        assert any(grp == 'kiwi' for grp in state.get_user_groups('kiwi'))
        assert any(grp == 'admin' for grp in state.get_user_groups('kiwi'))

    def test_copy_displayname(self):
        self.state.copy_displayname(self.boot_state)
        assert self.boot_state.xml_data.get_displayname() == 'Bob'

    def test_copy_drivers_sections(self):
        self.state.copy_drivers_sections(self.boot_state)
        assert 'bar' in self.boot_state.get_drivers_list()

    def test_copy_systemdisk_section(self):
        self.state.copy_systemdisk_section(self.boot_state)
        systemdisk = self.boot_state.get_build_type_system_disk_section()
        assert systemdisk.get_name() == 'mydisk'

    def test_copy_strip_sections(self):
        self.state.copy_strip_sections(self.boot_state)
        assert 'del-a' in self.boot_state.get_strip_files_to_delete()

    def test_copy_machine_section(self):
        self.state.copy_machine_section(self.boot_state)
        machine = self.boot_state.get_build_type_machine_section()
        assert machine.get_memory() == 512

    def test_copy_oemconfig_section(self):
        self.state.copy_oemconfig_section(self.boot_state)
        oemconfig = self.boot_state.get_build_type_oemconfig_section()
        assert oemconfig.get_oem_systemsize()[0] == 2048

    def test_copy_repository_sections(self):
        self.state.copy_repository_sections(self.boot_state, True)
        repository = self.boot_state.get_repository_sections()[0]
        assert repository.get_source().get_path() == 'iso:///image/CDs/dvd.iso'

    def test_copy_preferences_subsections(self):
        self.state.copy_preferences_subsections(['bootsplash_theme'],
                                                self.boot_state)
        preferences = self.boot_state.get_preferences_sections()[0]
        assert preferences.get_bootsplash_theme()[0] == 'openSUSE'

    def test_copy_build_type_attributes(self):
        self.state.copy_build_type_attributes(['firmware'], self.boot_state)
        assert self.boot_state.build_type.get_firmware() == 'efi'

    def test_copy_bootincluded_packages_with_no_image_packages(self):
        self.state.copy_bootincluded_packages(self.boot_state)
        bootstrap_packages = self.boot_state.get_bootstrap_packages()
        assert 'plymouth-branding-openSUSE' in bootstrap_packages
        assert 'grub2-branding-openSUSE' in bootstrap_packages
        assert 'gfxboot-branding-openSUSE' in bootstrap_packages
        to_delete_packages = self.boot_state.get_to_become_deleted_packages()
        assert 'gfxboot-branding-openSUSE' not in to_delete_packages

    def test_copy_bootincluded_packages_with_image_packages(self):
        boot_description = XMLDescription(
            '../data/isoboot/example-distribution/config.xml')
        boot_state = XMLState(boot_description.load(), ['std'])
        self.state.copy_bootincluded_packages(boot_state)
        image_packages = boot_state.get_system_packages()
        assert 'plymouth-branding-openSUSE' in image_packages
        assert 'grub2-branding-openSUSE' in image_packages
        assert 'gfxboot-branding-openSUSE' in image_packages
        to_delete_packages = boot_state.get_to_become_deleted_packages()
        assert 'gfxboot-branding-openSUSE' not in to_delete_packages

    def test_copy_bootincluded_archives(self):
        self.state.copy_bootincluded_archives(self.boot_state)
        bootstrap_archives = self.boot_state.get_bootstrap_archives()
        assert '/absolute/path/to/image.tgz' in bootstrap_archives

    def test_copy_bootdelete_packages(self):
        self.state.copy_bootdelete_packages(self.boot_state)
        to_delete_packages = self.boot_state.get_to_become_deleted_packages()
        assert 'vim' in to_delete_packages

    def test_copy_bootdelete_packages_no_delete_section_in_boot_descr(self):
        boot_description = XMLDescription(
            '../data/isoboot/example-distribution-no-delete-section/config.xml'
        )
        boot_state = XMLState(boot_description.load())
        self.state.copy_bootdelete_packages(boot_state)
        to_delete_packages = boot_state.get_to_become_deleted_packages()
        assert 'vim' in to_delete_packages

    def test_build_type_size(self):
        result = self.state.get_build_type_size()
        assert result.mbytes == 1024
        assert result.additive

    def test_build_type_size_with_unpartitioned(self):
        state = XMLState(self.description.load(), ['vmxFlavour'], 'vmx')
        result = state.get_build_type_size()
        assert result.mbytes == 3072
        assert not result.additive
        result = state.get_build_type_size(include_unpartitioned=True)
        assert result.mbytes == 4096
        assert not result.additive

    def test_get_build_type_unpartitioned_bytes(self):
        assert self.state.get_build_type_unpartitioned_bytes() == 0
        state = XMLState(self.description.load(), ['vmxFlavour'], 'vmx')
        assert state.get_build_type_unpartitioned_bytes() == 1073741824
        state = XMLState(self.description.load(), ['vmxFlavour'], 'oem')
        assert state.get_build_type_unpartitioned_bytes() == 0
        state = XMLState(self.description.load(), ['ec2Flavour'], 'vmx')
        assert state.get_build_type_unpartitioned_bytes() == 0

    def test_get_volume_group_name(self):
        assert self.state.get_volume_group_name() == 'mydisk'

    def test_get_volume_group_name_default(self):
        assert self.boot_state.get_volume_group_name() == 'systemVG'

    def test_get_distribution_name_from_boot_attribute(self):
        assert self.state.get_distribution_name_from_boot_attribute() == \
            'distribution'

    def test_get_fs_mount_option_list(self):
        assert self.state.get_fs_mount_option_list() == ['async']

    @raises(KiwiDistributionNameError)
    @patch('kiwi.xml_parse.type_.get_boot')
    def test_get_distribution_name_from_boot_attribute_no_boot(
            self, mock_boot):
        mock_boot.return_value = None
        self.state.get_distribution_name_from_boot_attribute()

    @raises(KiwiDistributionNameError)
    @patch('kiwi.xml_parse.type_.get_boot')
    def test_get_distribution_name_from_boot_attribute_invalid_boot(
            self, mock_boot):
        mock_boot.return_value = 'invalid'
        self.state.get_distribution_name_from_boot_attribute()

    def test_delete_repository_sections(self):
        self.state.delete_repository_sections()
        assert self.state.get_repository_sections() == []

    def test_delete_repository_sections_used_for_build(self):
        self.state.delete_repository_sections_used_for_build()
        assert self.state.get_repository_sections()[0].get_imageonly()

    def test_get_build_type_vmconfig_entries(self):
        assert self.state.get_build_type_vmconfig_entries() == []

    def test_get_build_type_vmconfig_entries_for_vmx_type(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'vmx')
        assert state.get_build_type_vmconfig_entries() == [
            'numvcpus = "4"', 'cpuid.coresPerSocket = "2"'
        ]

    def test_get_build_type_vmconfig_entries_no_machine_section(self):
        description = XMLDescription('../data/example_disk_config.xml')
        xml_data = description.load()
        state = XMLState(xml_data)
        assert state.get_build_type_vmconfig_entries() == []

    def test_get_build_type_docker_containerconfig_section(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'docker')
        containerconfig = state.get_build_type_containerconfig_section()
        assert containerconfig.get_name() == \
            'container_name'
        assert containerconfig.get_maintainer() == \
            'tux'
        assert containerconfig.get_workingdir() == \
            '/root'

    def test_set_container_tag(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'docker')
        state.set_container_config_tag('new_tag')
        config = state.get_container_config()
        assert config['container_tag'] == 'new_tag'

    def test_add_container_label(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'docker')
        state.add_container_config_label('somelabel', 'overwrittenvalue')
        state.add_container_config_label('new_label', 'new value')
        config = state.get_container_config()
        assert config['labels'] == {
            'somelabel': 'overwrittenvalue',
            'someotherlabel': 'anotherlabelvalue',
            'new_label': 'new value'
        }

    def test_add_container_label_without_contianerconfig(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['xenFlavour'], 'docker')
        state.add_container_config_label('somelabel', 'newlabelvalue')
        config = state.get_container_config()
        assert config['labels'] == {'somelabel': 'newlabelvalue'}

    @patch('kiwi.logger.log.warning')
    def test_add_container_label_no_container_image_type(self, mock_log_warn):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'vmx')
        state.add_container_config_label('somelabel', 'newlabelvalue')
        config = state.get_container_config()
        assert not config
        assert mock_log_warn.called

    @patch('kiwi.logger.log.warning')
    def test_set_container_tag_not_applied(self, mock_log_warn):
        self.state.set_container_config_tag('new_tag')
        assert mock_log_warn.called

    def test_get_container_config(self):
        expected_config = {
            'labels': {
                'somelabel': 'labelvalue',
                'someotherlabel': 'anotherlabelvalue'
            },
            'maintainer': 'tux',
            'entry_subcommand': ['ls', '-l'],
            'container_name': 'container_name',
            'container_tag': 'container_tag',
            'additional_tags': ['current', 'foobar'],
            'workingdir': '/root',
            'environment': {
                'PATH': '/bin:/usr/bin:/home/user/bin',
                'SOMEVAR': 'somevalue'
            },
            'user': '******',
            'volumes': ['/tmp', '/var/log'],
            'entry_command': ['/bin/bash', '-x'],
            'expose_ports': ['80', '8080'],
            'history': {
                'author': 'history author',
                'comment': 'This is a comment',
                'created_by': 'created by text'
            }
        }
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'docker')
        assert state.get_container_config() == expected_config

    def test_get_container_config_clear_commands(self):
        expected_config = {
            'maintainer': 'tux',
            'entry_subcommand': [],
            'container_name': 'container_name',
            'container_tag': 'container_tag',
            'workingdir': '/root',
            'user': '******',
            'entry_command': [],
        }
        xml_data = self.description.load()
        state = XMLState(xml_data, ['derivedContainer'], 'docker')
        assert state.get_container_config() == expected_config

    def test_get_spare_part(self):
        assert self.state.get_build_type_spare_part_size() == 200

    def test_get_build_type_format_options(self):
        assert self.state.get_build_type_format_options() == {
            'super': 'man',
            'force_size': None
        }

    def test_get_derived_from_image_uri(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['derivedContainer'], 'docker')
        assert state.get_derived_from_image_uri().uri == \
            'obs://project/repo/image#mytag'

    def test_set_derived_from_image_uri(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['derivedContainer'], 'docker')
        state.set_derived_from_image_uri('file:///new_uri')
        assert state.get_derived_from_image_uri().translate() == '/new_uri'

    @patch('kiwi.logger.log.warning')
    def test_set_derived_from_image_uri_not_applied(self, mock_log_warn):
        self.state.set_derived_from_image_uri('file:///new_uri')
        assert mock_log_warn.called

    def test_is_xen_server(self):
        assert self.state.is_xen_server() is True

    def test_is_xen_guest_by_machine_setup(self):
        assert self.state.is_xen_guest() is True

    def test_is_xen_guest_no_xen_guest_setup(self):
        assert self.boot_state.is_xen_guest() is False

    @patch('platform.machine')
    def test_is_xen_guest_by_firmware_setup(self, mock_platform_machine):
        mock_platform_machine.return_value = 'x86_64'
        xml_data = self.description.load()
        state = XMLState(xml_data, ['ec2Flavour'], 'vmx')
        assert state.is_xen_guest() is True

    @patch('platform.machine')
    def test_is_xen_guest_by_architecture(self, mock_platform_machine):
        mock_platform_machine.return_value = 'unsupported'
        xml_data = self.description.load()
        state = XMLState(xml_data, ['ec2Flavour'], 'vmx')
        assert state.is_xen_guest() is False

    def test_get_initrd_system(self):
        xml_data = self.description.load()
        state = XMLState(xml_data, ['vmxFlavour'], 'vmx')
        assert state.get_initrd_system() == 'dracut'
        state = XMLState(xml_data, ['vmxFlavour'], 'iso')
        assert state.get_initrd_system() == 'dracut'
        state = XMLState(xml_data, ['vmxFlavour'], 'docker')
        assert state.get_initrd_system() is None
        state = XMLState(xml_data, [], 'oem')
        assert state.get_initrd_system() == 'kiwi'

    def test_get_rpm_locale_filtering(self):
        assert self.state.get_rpm_locale_filtering() is True
        assert self.boot_state.get_rpm_locale_filtering() is False

    def test_get_locale(self):
        assert self.state.get_locale() == ['en_US', 'de_DE']

    def test_get_rpm_locale(self):
        assert self.state.get_rpm_locale() == [
            'POSIX', 'C', 'C.UTF-8', 'en_US', 'de_DE'
        ]
Beispiel #55
0
 def test_build_type_not_found(self):
     description = XMLDescription('../data/example_config.xml')
     xml_data = description.load()
     XMLState(xml_data, ['vmxFlavour'], 'foo')
Beispiel #56
0
 def test_profile_not_found(self):
     description = XMLDescription('../data/example_config.xml')
     xml_data = description.load()
     XMLState(xml_data, ['foo'])
Beispiel #57
0
 def test_build_type_not_found_no_default_type(self):
     description = XMLDescription('../data/example_no_default_type.xml')
     xml_data = description.load()
     XMLState(xml_data, ['minimal'])
class TestRuntimeChecker:
    def setup(self):
        self.description = XMLDescription(
            '../data/example_runtime_checker_config.xml'
        )
        self.xml_state = XMLState(
            self.description.load()
        )
        self.runtime_checker = RuntimeChecker(self.xml_state)

    def test_check_image_include_repos_publicly_resolvable(self):
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_image_include_repos_publicly_resolvable()

    def test_invalid_target_dir_pointing_to_shared_cache_1(self):
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_target_directory_not_in_shared_cache(
                '/var/cache//kiwi/foo'
            )

    def test_invalid_target_dir_pointing_to_shared_cache_2(self):
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_target_directory_not_in_shared_cache(
                '/var/cache/kiwi'
            )

    @patch('os.getcwd')
    def test_invalid_target_dir_pointing_to_shared_cache_3(self, mock_getcwd):
        mock_getcwd.return_value = '/'
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_target_directory_not_in_shared_cache(
                'var/cache/kiwi'
            )

    def test_invalid_target_dir_pointing_to_shared_cache_4(self):
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_target_directory_not_in_shared_cache(
                '//var/cache//kiwi/foo'
            )

    def test_valid_target_dir_1(self):
        assert self.runtime_checker.check_target_directory_not_in_shared_cache(
            '/var/cache/kiwi-fast-tmpsystemdir'
        ) is None

    def test_valid_target_dir_2(self):
        assert self.runtime_checker.check_target_directory_not_in_shared_cache(
            '/foo/bar'
        ) is None

    def test_check_repositories_configured(self):
        self.xml_state.delete_repository_sections()
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_repositories_configured()

    def test_check_volume_setup_defines_multiple_fullsize_volumes(self):
        with raises(KiwiRuntimeError):
            self.runtime_checker.\
                check_volume_setup_defines_multiple_fullsize_volumes()

    def test_check_volume_setup_has_no_root_definition(self):
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_volume_setup_has_no_root_definition()

    @patch('kiwi.runtime_checker.Path.which')
    def test_check_container_tool_chain_installed(self, mock_which):
        mock_which.return_value = False
        xml_state = XMLState(
            self.description.load(), ['docker'], 'docker'
        )
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_container_tool_chain_installed()

    @patch('kiwi.runtime_checker.RuntimeConfig.get_oci_archive_tool')
    @patch('kiwi.runtime_checker.Path.which')
    def test_check_container_tool_chain_installed_unknown_tool(
        self, mock_which, mock_oci_tool
    ):
        mock_oci_tool.return_value = 'budah'
        mock_which.return_value = False
        xml_state = XMLState(
            self.description.load(), ['docker'], 'docker'
        )
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_container_tool_chain_installed()

    @patch('kiwi.runtime_checker.RuntimeConfig.get_oci_archive_tool')
    @patch('kiwi.runtime_checker.Path.which')
    def test_check_container_tool_chain_installed_buildah(
        self, mock_which, mock_oci_tool
    ):
        mock_oci_tool.return_value = 'buildah'
        mock_which.return_value = False
        xml_state = XMLState(
            self.description.load(), ['docker'], 'docker'
        )
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_container_tool_chain_installed()

    @patch('kiwi.runtime_checker.Path.which')
    @patch('kiwi.runtime_checker.CommandCapabilities.check_version')
    def test_check_container_tool_chain_installed_with_version(
        self, mock_cmdver, mock_which
    ):
        mock_which.return_value = True
        mock_cmdver.return_value = False
        xml_state = XMLState(
            self.description.load(), ['docker'], 'docker'
        )
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_container_tool_chain_installed()

    @patch('kiwi.runtime_checker.Path.which')
    @patch('kiwi.runtime_checker.CommandCapabilities.check_version')
    @patch('kiwi.runtime_checker.CommandCapabilities.has_option_in_help')
    def test_check_container_tool_chain_installed_with_multitags(
        self, mock_cmdoptions, mock_cmdver, mock_which
    ):
        mock_which.return_value = True
        mock_cmdver.return_value = True
        mock_cmdoptions.return_value = False
        xml_state = XMLState(
            self.description.load(), ['docker'], 'docker'
        )
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_container_tool_chain_installed()

    @patch('platform.machine')
    @patch('kiwi.runtime_checker.Defaults.get_boot_image_description_path')
    def test_check_consistent_kernel_in_boot_and_system_image(
        self, mock_boot_path, mock_machine
    ):
        mock_boot_path.return_value = '../data'
        mock_machine.return_value = 'x86_64'
        xml_state = XMLState(
            self.description.load(), ['vmxFlavour'], 'oem'
        )
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_consistent_kernel_in_boot_and_system_image()

    def test_check_boot_description_exists_no_boot_ref(self):
        description = XMLDescription(
            '../data/example_runtime_checker_no_boot_reference.xml'
        )
        xml_state = XMLState(description.load())
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_boot_description_exists()

    def test_check_boot_description_exists_does_not_exist(self):
        description = XMLDescription(
            '../data/example_runtime_checker_boot_desc_not_found.xml'
        )
        xml_state = XMLState(description.load())
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_boot_description_exists()

    def test_check_xen_uniquely_setup_as_server_or_guest_for_ec2(self):
        self.xml_state.build_type.get_firmware = mock.Mock(
            return_value='ec2'
        )
        self.xml_state.is_xen_server = mock.Mock(
            return_value=True
        )
        self.xml_state.is_xen_guest = mock.Mock(
            return_value=True
        )
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_xen_uniquely_setup_as_server_or_guest()

    def test_check_xen_uniquely_setup_as_server_or_guest_for_xen(self):
        self.xml_state.build_type.get_firmware = mock.Mock(
            return_value=None
        )
        self.xml_state.is_xen_server = mock.Mock(
            return_value=True
        )
        self.xml_state.is_xen_guest = mock.Mock(
            return_value=True
        )
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_xen_uniquely_setup_as_server_or_guest()

    def test_check_dracut_module_for_disk_overlay_in_package_list(self):
        xml_state = XMLState(
            self.description.load(), ['vmxFlavour'], 'iso'
        )
        xml_state.build_type.get_overlayroot = mock.Mock(
            return_value=True
        )
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.\
                check_dracut_module_for_disk_overlay_in_package_list()

    def test_check_efi_mode_for_disk_overlay_correctly_setup(self):
        self.xml_state.build_type.get_overlayroot = mock.Mock(
            return_value=True
        )
        self.xml_state.build_type.get_firmware = mock.Mock(
            return_value='uefi'
        )
        with raises(KiwiRuntimeError):
            self.runtime_checker.\
                check_efi_mode_for_disk_overlay_correctly_setup()

    @patch('kiwi.runtime_checker.Path.which')
    def test_check_mediacheck_installed_tagmedia_missing(self, mock_which):
        mock_which.return_value = False
        xml_state = XMLState(
            self.description.load(), ['vmxFlavour'], 'iso'
        )
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_mediacheck_installed()

    def test_check_dracut_module_for_live_iso_in_package_list(self):
        xml_state = XMLState(
            self.description.load(), ['vmxFlavour'], 'iso'
        )
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_dracut_module_for_live_iso_in_package_list()

    def test_check_dracut_module_for_disk_oem_in_package_list(self):
        xml_state = XMLState(
            self.description.load(), ['vmxFlavour'], 'oem'
        )
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_dracut_module_for_disk_oem_in_package_list()

    def test_check_dracut_module_for_oem_install_in_package_list(self):
        xml_state = XMLState(
            self.description.load(), ['vmxFlavour'], 'oem'
        )
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.\
                check_dracut_module_for_oem_install_in_package_list()

    def test_check_volume_label_used_with_lvm(self):
        with raises(KiwiRuntimeError):
            self.runtime_checker.check_volume_label_used_with_lvm()

    def test_check_preferences_data_no_version(self):
        xml_state = XMLState(
            self.description.load(), ['docker'], 'docker'
        )
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_minimal_required_preferences()

    def test_check_preferences_data_no_packagemanager(self):
        xml_state = XMLState(
            self.description.load(), ['xenFlavour'], 'vmx'
        )
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_minimal_required_preferences()

    @patch('platform.machine')
    def test_check_architecture_supports_iso_firmware_setup(
        self, mock_machine
    ):
        mock_machine.return_value = 'aarch64'
        xml_state = XMLState(
            self.description.load(), ['vmxFlavour'], 'iso'
        )
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_architecture_supports_iso_firmware_setup()
        xml_state = XMLState(
            self.description.load(), ['xenFlavour'], 'oem'
        )
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_architecture_supports_iso_firmware_setup()

    def teardown(self):
        sys.argv = argv_kiwi_tests
Beispiel #59
0
    def setup(self, mock_machine):
        mock_machine.return_value = 'x86_64'
        self.size = mock.Mock()
        self.size.customize = mock.Mock(
            return_value=42
        )
        self.size.accumulate_mbyte_file_sizes = mock.Mock(
            return_value=42
        )
        kiwi.storage.setup.SystemSize = mock.Mock(
            return_value=self.size
        )

        description = XMLDescription(
            '../data/example_disk_size_config.xml'
        )
        self.setup = DiskSetup(
            XMLState(description.load()), 'root_dir'
        )

        description = XMLDescription(
            '../data/example_disk_size_volume_config.xml'
        )
        self.setup_volumes = DiskSetup(
            XMLState(description.load()), 'root_dir'
        )

        description = XMLDescription(
            '../data/example_disk_size_oem_volume_config.xml'
        )
        self.setup_oem_volumes = DiskSetup(
            XMLState(description.load()), 'root_dir'
        )

        description = XMLDescription(
            '../data/example_disk_size_empty_vol_config.xml'
        )
        self.setup_empty_volumes = DiskSetup(
            XMLState(description.load()), 'root_dir'
        )

        description = XMLDescription(
            '../data/example_disk_size_vol_root_config.xml'
        )
        self.setup_root_volume = DiskSetup(
            XMLState(description.load()), 'root_dir'
        )

        mock_machine.return_value = 'ppc64'
        description = XMLDescription(
            '../data/example_ppc_disk_size_config.xml'
        )
        self.setup_ppc = DiskSetup(
            XMLState(description.load()), 'root_dir'
        )

        mock_machine.return_value = 'arm64'
        description = XMLDescription(
            '../data/example_arm_disk_size_config.xml'
        )
        self.setup_arm = DiskSetup(
            XMLState(description.load()), 'root_dir'
        )
Beispiel #60
0
    def setup(self, mock_machine):
        mock_machine.return_value = 'x86_64'
        self.size = mock.Mock()
        self.size.customize = mock.Mock(return_value=42)
        self.size.accumulate_mbyte_file_sizes = mock.Mock(return_value=42)
        kiwi.storage.setup.SystemSize = mock.Mock(return_value=self.size)

        description = XMLDescription('../data/example_disk_size_config.xml')
        self.setup = DiskSetup(XMLState(description.load()), 'root_dir')

        description = XMLDescription(
            '../data/example_disk_size_volume_config.xml')
        self.setup_volumes = DiskSetup(XMLState(description.load()),
                                       'root_dir')

        description = XMLDescription(
            '../data/example_disk_size_empty_vol_config.xml')
        self.setup_empty_volumes = DiskSetup(XMLState(description.load()),
                                             'root_dir')

        description = XMLDescription(
            '../data/example_disk_size_vol_root_config.xml')
        self.setup_root_volume = DiskSetup(XMLState(description.load()),
                                           'root_dir')

        mock_machine.return_value = 'ppc64'
        description = XMLDescription(
            '../data/example_ppc_disk_size_config.xml')
        self.setup_ppc = DiskSetup(XMLState(description.load()), 'root_dir')

        mock_machine.return_value = 'arm64'
        description = XMLDescription(
            '../data/example_arm_disk_size_config.xml')
        self.setup_arm = DiskSetup(XMLState(description.load()), 'root_dir')