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_docker_tool_chain_installed(self, mock_which):
     mock_which.return_value = False
     xml_state = XMLState(
         self.description.load(), ['docker'], 'docker'
     )
     runtime_checker = RuntimeChecker(xml_state)
     runtime_checker.check_docker_tool_chain_installed()
Exemple #3
0
 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_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()
Exemple #5
0
 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()
Exemple #6
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)
     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)
     runtime_checker.check_boot_description_exists()
Exemple #8
0
 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 test_check_docker_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)
     runtime_checker.check_docker_tool_chain_installed()
 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()
 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)
     runtime_checker.check_consistent_kernel_in_boot_and_system_image()
 def test_check_mediacheck_only_for_x86_arch_tagmedia_missing(
         self, mock_which, mock_machine):
     mock_machine.return_value = 'x86_64'
     mock_which.return_value = False
     xml_state = XMLState(self.description.load(), ['vmxFlavour'], 'iso')
     runtime_checker = RuntimeChecker(xml_state)
     runtime_checker.check_mediacheck_only_for_x86_arch()
 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)
     runtime_checker.check_container_tool_chain_installed()
 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()
Exemple #15
0
 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()
Exemple #16
0
 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()
Exemple #17
0
 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()
Exemple #18
0
 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()
Exemple #19
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 test_check_grub_efi_installed_for_efi_firmware_is_uefi_suse(self):
     self.xml_state.build_type.get_firmware = mock.Mock(return_value='uefi')
     self.xml_state.get_bootstrap_packages = mock.Mock(
         return_value=['grub2-x86_64-efi'])
     self.xml_state.get_system_packages = mock.Mock(return_value=['bar'])
     runtime_checker = RuntimeChecker(self.xml_state)
     assert runtime_checker.check_grub_efi_installed_for_efi_firmware() \
         is True
 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)
     runtime_checker.check_dracut_module_for_disk_overlay_in_package_list()
 def test_check_mediacheck_only_for_x86_arch_invalid_arch(
     self, mock_machine
 ):
     mock_machine.return_value = 'aarch64'
     xml_state = XMLState(
         self.description.load(), ['vmxFlavour'], 'iso'
     )
     runtime_checker = RuntimeChecker(xml_state)
     runtime_checker.check_mediacheck_only_for_x86_arch()
Exemple #23
0
 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)
 def test_check_docker_tool_chain_installed_with_version(
         self, mock_command, mock_which):
     tool_version_call = mock.Mock()
     tool_version_call.output = 'umoci version 2.2.3'
     mock_which.return_value = True
     mock_command.return_value = tool_version_call
     xml_state = XMLState(self.description.load(), ['docker'], 'docker')
     runtime_checker = RuntimeChecker(xml_state)
     runtime_checker.check_docker_tool_chain_installed()
 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)
     runtime_checker.check_consistent_kernel_in_boot_and_system_image()
 def test_check_mediacheck_only_for_x86_arch_tagmedia_missing(
     self, mock_which, mock_machine
 ):
     mock_machine.return_value = 'x86_64'
     mock_which.return_value = False
     xml_state = XMLState(
         self.description.load(), ['vmxFlavour'], 'iso'
     )
     runtime_checker = RuntimeChecker(xml_state)
     runtime_checker.check_mediacheck_only_for_x86_arch()
 def test_check_docker_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)
     runtime_checker.check_docker_tool_chain_installed()
 def test_check_docker_tool_chain_installed_with_version(
     self, mock_command, mock_which
 ):
     tool_version_call = mock.Mock()
     tool_version_call.output = 'umoci version 2.2.3'
     mock_which.return_value = True
     mock_command.return_value = tool_version_call
     xml_state = XMLState(
         self.description.load(), ['docker'], 'docker'
     )
     runtime_checker = RuntimeChecker(xml_state)
     runtime_checker.check_docker_tool_chain_installed()
 def test_check_grub_efi_installed_for_efi_firmware_is_uefi(self):
     self.xml_state.build_type.get_firmware = mock.Mock(
         return_value='uefi'
     )
     self.xml_state.get_bootstrap_packages = mock.Mock(
         return_value=['foo']
     )
     self.xml_state.get_system_packages = mock.Mock(
         return_value=['bar']
     )
     runtime_checker = RuntimeChecker(self.xml_state)
     runtime_checker.check_grub_efi_installed_for_efi_firmware()
 def test_check_grub_efi_installed_for_efi_firmware_is_efi_suse(self):
     self.xml_state.build_type.get_firmware = mock.Mock(
         return_value='efi'
     )
     self.xml_state.get_bootstrap_packages = mock.Mock(
         return_value=['grub2-x86_64-efi']
     )
     self.xml_state.get_system_packages = mock.Mock(
         return_value=['bar']
     )
     runtime_checker = RuntimeChecker(self.xml_state)
     assert runtime_checker.check_grub_efi_installed_for_efi_firmware() \
         is True
 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()
Exemple #32
0
    def load_xml_description(
        self, description_directory: str, kiwi_file: str = ''
    ) -> None:
        """
        Load, upgrade, validate XML description

        :param str description_directory:
            Path to the image description

        :param str kiwi_file:
            Basename of kiwi file which contains the main
            image configuration elements. If not specified
            kiwi searches for a file named config.xml or
            a file matching .kiwi
        """
        log.info('Loading XML description')
        if kiwi_file:
            config_file = os.sep.join([description_directory, kiwi_file])
        else:
            config_file = os.sep.join([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 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)
Exemple #34
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)
Exemple #35
0
 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()
 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()
Exemple #37
0
 def test_check_syslinux_installed_if_isolinux_is_used(
         self, mock_Path_which, mock_machine):
     mock_Path_which.return_value = None
     mock_machine.return_value = 'x86_64'
     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(), ['xenFlavour'], 'oem')
     runtime_checker = RuntimeChecker(xml_state)
     with raises(KiwiRuntimeError):
         runtime_checker.check_syslinux_installed_if_isolinux_is_used()
Exemple #38
0
 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()
Exemple #39
0
class TestRuntimeChecker(object):
    def setup(self):
        description = XMLDescription(
            '../data/example_runtime_checker_config.xml'
        )
        self.xml_state = XMLState(
            description.load()
        )
        self.runtime_checker = RuntimeChecker(self.xml_state)

    @raises(KiwiRuntimeError)
    def test_check_image_include_repos_http_resolvable(self):
        self.runtime_checker.check_image_include_repos_http_resolvable()

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

    @raises(KiwiRuntimeError)
    def test_check_target_directory_not_in_shared_cache_2(self):
        self.runtime_checker.check_target_directory_not_in_shared_cache(
            '/var/cache/kiwi'
        )

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

    @raises(KiwiRuntimeError)
    def test_check_target_directory_not_in_shared_cache_4(self):
        self.runtime_checker.check_target_directory_not_in_shared_cache(
            '//var/cache//kiwi/foo'
        )
Exemple #40
0
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_reserved_labels(self):
        xml_state = XMLState(
            self.description.load(), ['vmxFlavour'], 'vmx'
        )
        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.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()

    @patch('platform.machine')
    @patch('kiwi.runtime_checker.Path.which')
    def test_check_syslinux_installed_if_isolinux_is_used(
        self, mock_Path_which, mock_machine
    ):
        mock_Path_which.return_value = None
        mock_machine.return_value = 'x86_64'
        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(), ['xenFlavour'], 'oem'
        )
        runtime_checker = RuntimeChecker(xml_state)
        with raises(KiwiRuntimeError):
            runtime_checker.check_syslinux_installed_if_isolinux_is_used()

    def teardown(self):
        sys.argv = argv_kiwi_tests
 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)
     runtime_checker.check_dracut_module_for_oem_install_in_package_list()
Exemple #42
0
class TestRuntimeChecker:
    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(
            [
                'rpm', '--root', 'root_dir', '-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(
            [
                'dpkg-query', '--admindir', 'root_dir/var/lib/dpkg',
                '-W', '-f', '${Version}', 'dracut-kiwi-oem-dump'
            ]
        )

    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 teardown(self):
        sys.argv = argv_kiwi_tests
 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)
     runtime_checker.check_dracut_module_for_live_iso_in_package_list()
Exemple #44
0
class TestRuntimeChecker(object):
    def setup(self):
        description = XMLDescription("../data/example_runtime_checker_config.xml")
        self.xml_state = XMLState(description.load())
        self.runtime_checker = RuntimeChecker(self.xml_state)

    @raises(KiwiRuntimeError)
    def test_check_image_include_repos_http_resolvable(self):
        self.runtime_checker.check_image_include_repos_http_resolvable()

    @raises(KiwiRuntimeError)
    def test_check_target_directory_not_in_shared_cache_1(self):
        self.runtime_checker.check_target_directory_not_in_shared_cache("/var/cache//kiwi/foo")

    @raises(KiwiRuntimeError)
    def test_check_target_directory_not_in_shared_cache_2(self):
        self.runtime_checker.check_target_directory_not_in_shared_cache("/var/cache/kiwi")

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

    @raises(KiwiRuntimeError)
    def test_check_target_directory_not_in_shared_cache_4(self):
        self.runtime_checker.check_target_directory_not_in_shared_cache("//var/cache//kiwi/foo")

    @raises(KiwiRuntimeError)
    def test_check_repositories_configured(self):
        self.xml_state.delete_repository_sections()
        self.runtime_checker.check_repositories_configured()
class TestRuntimeChecker(object):
    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)

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

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

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

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

    @raises(KiwiRuntimeError)
    def test_invalid_target_dir_pointing_to_shared_cache_4(self):
        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

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

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

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

    @patch('kiwi.runtime_checker.Path.which')
    @patch('kiwi.runtime_checker.CommandCapabilities.check_version')
    @raises(KiwiRuntimeError)
    def test_check_docker_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)
        runtime_checker.check_docker_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')
    @raises(KiwiRuntimeError)
    def test_check_docker_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)
        runtime_checker.check_docker_tool_chain_installed()

    @raises(KiwiRuntimeError)
    @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)
        runtime_checker.check_consistent_kernel_in_boot_and_system_image()

    @raises(KiwiRuntimeError)
    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()

    @raises(KiwiRuntimeError)
    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()

    @raises(KiwiRuntimeError)
    def test_check_grub_efi_installed_for_efi_firmware_is_efi(self):
        self.xml_state.build_type.get_firmware = mock.Mock(
            return_value='efi'
        )
        self.xml_state.get_bootstrap_packages = mock.Mock(
            return_value=['foo']
        )
        self.xml_state.get_system_packages = mock.Mock(
            return_value=['bar']
        )
        runtime_checker = RuntimeChecker(self.xml_state)
        runtime_checker.check_grub_efi_installed_for_efi_firmware()

    def test_check_grub_efi_installed_for_efi_firmware_is_efi_debian(self):
        self.xml_state.build_type.get_firmware = mock.Mock(
            return_value='efi'
        )
        self.xml_state.get_bootstrap_packages = mock.Mock(
            return_value=['grub-efi-amd64']
        )
        self.xml_state.get_system_packages = mock.Mock(
            return_value=['bar']
        )
        runtime_checker = RuntimeChecker(self.xml_state)
        assert runtime_checker.check_grub_efi_installed_for_efi_firmware() \
            is True

    def test_check_grub_efi_installed_for_efi_firmware_is_efi_rhel(self):
        self.xml_state.build_type.get_firmware = mock.Mock(
            return_value='efi'
        )
        self.xml_state.get_bootstrap_packages = mock.Mock(
            return_value=['grub2-efi-x64']
        )
        self.xml_state.get_system_packages = mock.Mock(
            return_value=['bar']
        )
        runtime_checker = RuntimeChecker(self.xml_state)
        assert runtime_checker.check_grub_efi_installed_for_efi_firmware() \
            is True

    def test_check_grub_efi_installed_for_efi_firmware_is_efi_suse(self):
        self.xml_state.build_type.get_firmware = mock.Mock(
            return_value='efi'
        )
        self.xml_state.get_bootstrap_packages = mock.Mock(
            return_value=['grub2-x86_64-efi']
        )
        self.xml_state.get_system_packages = mock.Mock(
            return_value=['bar']
        )
        runtime_checker = RuntimeChecker(self.xml_state)
        assert runtime_checker.check_grub_efi_installed_for_efi_firmware() \
            is True

    @raises(KiwiRuntimeError)
    def test_check_grub_efi_installed_for_efi_firmware_is_uefi(self):
        self.xml_state.build_type.get_firmware = mock.Mock(
            return_value='uefi'
        )
        self.xml_state.get_bootstrap_packages = mock.Mock(
            return_value=['foo']
        )
        self.xml_state.get_system_packages = mock.Mock(
            return_value=['bar']
        )
        runtime_checker = RuntimeChecker(self.xml_state)
        runtime_checker.check_grub_efi_installed_for_efi_firmware()

    def test_check_grub_efi_installed_for_efi_firmware_is_uefi_debian(self):
        self.xml_state.build_type.get_firmware = mock.Mock(
            return_value='uefi'
        )
        self.xml_state.get_bootstrap_packages = mock.Mock(
            return_value=['grub-efi-amd64']
        )
        self.xml_state.get_system_packages = mock.Mock(
            return_value=['bar']
        )
        runtime_checker = RuntimeChecker(self.xml_state)
        assert runtime_checker.check_grub_efi_installed_for_efi_firmware() \
            is True

    def test_check_grub_efi_installed_for_efi_firmware_is_uefi_rhel(self):
        self.xml_state.build_type.get_firmware = mock.Mock(
            return_value='uefi'
        )
        self.xml_state.get_bootstrap_packages = mock.Mock(
            return_value=['grub2-efi-x64']
        )
        self.xml_state.get_system_packages = mock.Mock(
            return_value=['bar']
        )
        runtime_checker = RuntimeChecker(self.xml_state)
        assert runtime_checker.check_grub_efi_installed_for_efi_firmware() \
            is True

    def test_check_grub_efi_installed_for_efi_firmware_is_uefi_suse(self):
        self.xml_state.build_type.get_firmware = mock.Mock(
            return_value='uefi'
        )
        self.xml_state.get_bootstrap_packages = mock.Mock(
            return_value=['grub2-x86_64-efi']
        )
        self.xml_state.get_system_packages = mock.Mock(
            return_value=['bar']
        )
        runtime_checker = RuntimeChecker(self.xml_state)
        assert runtime_checker.check_grub_efi_installed_for_efi_firmware() \
            is True

    @raises(KiwiRuntimeError)
    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
        )
        self.runtime_checker.check_xen_uniquely_setup_as_server_or_guest()

    @raises(KiwiRuntimeError)
    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
        )
        self.runtime_checker.check_xen_uniquely_setup_as_server_or_guest()

    @raises(KiwiRuntimeError)
    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)
        runtime_checker.check_dracut_module_for_disk_overlay_in_package_list()

    @raises(KiwiRuntimeError)
    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'
        )
        self.runtime_checker.check_efi_mode_for_disk_overlay_correctly_setup()

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

    @raises(KiwiRuntimeError)
    @patch('platform.machine')
    @patch('kiwi.runtime_checker.Path.which')
    def test_check_mediacheck_only_for_x86_arch_tagmedia_missing(
        self, mock_which, mock_machine
    ):
        mock_machine.return_value = 'x86_64'
        mock_which.return_value = False
        xml_state = XMLState(
            self.description.load(), ['vmxFlavour'], 'iso'
        )
        runtime_checker = RuntimeChecker(xml_state)
        runtime_checker.check_mediacheck_only_for_x86_arch()

    @raises(KiwiRuntimeError)
    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)
        runtime_checker.check_dracut_module_for_live_iso_in_package_list()

    @raises(KiwiRuntimeError)
    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)
        runtime_checker.check_dracut_module_for_disk_oem_in_package_list()

    @raises(KiwiRuntimeError)
    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)
        runtime_checker.check_dracut_module_for_oem_install_in_package_list()