Esempio n. 1
0
    def test_check_version_failure_exception(self, mock_run):
        def side_effect():
            raise Exception("Something went wrong")

        mock_run.side_effect = side_effect
        CommandCapabilities.check_version('command_that_fails',
                                          '--non-existing-flag')
    def test_check_version_failure_warning(self, mock_run):
        def side_effect():
            raise Exception("Something went wrong")

        mock_run.side_effect = side_effect
        with self._caplog.at_level(logging.WARNING):
            CommandCapabilities.check_version('command_that_fails', (1, 2),
                                              raise_on_error=False)
Esempio n. 3
0
    def test_check_version_failure_warning(self, mock_warn, mock_run):
        def side_effect():
            raise Exception("Something went wrong")

        mock_run.side_effect = side_effect
        CommandCapabilities.check_version('command_that_fails', (1, 2),
                                          raise_on_error=False)
        assert mock_warn.called
    def test_check_version_failure_exception(self, mock_run):
        def side_effect():
            raise Exception("Something went wrong")

        mock_run.side_effect = side_effect
        CommandCapabilities.check_version(
            'command_that_fails', '--non-existing-flag'
        )
    def test_check_version_failure_warning(self, mock_warn, mock_run):
        def side_effect():
            raise Exception("Something went wrong")

        mock_run.side_effect = side_effect
        CommandCapabilities.check_version(
            'command_that_fails', (1, 2), raise_on_error=False
        )
        assert mock_warn.called
Esempio n. 6
0
    def __init__(self, filename, create_from_file_list=True, file_list=None):
        self.filename = filename
        self.create_from_file_list = create_from_file_list
        self.file_list = file_list

        if CommandCapabilities.check_version('tar', (1, 27)):
            self.xattrs_options = ['--xattrs', '--xattrs-include=*']
        else:
            self.xattrs_options = []
 def test_check_version(self, mock_run):
     command_type = namedtuple('command', ['output'])
     mock_run.return_value = command_type(
         output="Dummy line\ncommand v1.2.3\n")
     assert CommandCapabilities.check_version('command', (1, 2, 3))
     assert CommandCapabilities.check_version('command', (1, 1, 3))
     assert not CommandCapabilities.check_version('command', (1, 3))
     assert CommandCapabilities.check_version('command', (1, 2, 3),
                                              version_flags=['-v'])
     assert CommandCapabilities.check_version('command', (1, 2, 3),
                                              version_flags=['-v'],
                                              root='root_dir')
     mock_run.assert_has_calls([
         call(['command', '--version']),
         call(['command', '--version']),
         call(['command', '--version']),
         call(['command', '-v']),
         call(['chroot', 'root_dir', 'command', '-v'])
     ])
Esempio n. 8
0
    def __init__(self, filename, create_from_file_list=True, file_list=None):
        self.filename = filename
        self.create_from_file_list = create_from_file_list
        self.file_list = file_list

        if CommandCapabilities.check_version('tar', (1, 27)):
            self.xattrs_options = [
                '--xattrs', '--xattrs-include=*'
            ]
        else:
            self.xattrs_options = []
 def test_check_version(self, mock_run):
     command_type = namedtuple('command', ['output'])
     mock_run.return_value = command_type(
         output="Dummy line\ncommand v1.2.3\n"
     )
     assert CommandCapabilities.check_version('command', (1, 2, 3))
     assert CommandCapabilities.check_version('command', (1, 1, 3))
     assert not CommandCapabilities.check_version('command', (1, 3))
     assert CommandCapabilities.check_version(
         'command', (1, 2, 3), version_flags=['-v']
     )
     assert CommandCapabilities.check_version(
         'command', (1, 2, 3), version_flags=['-v'], root='root_dir'
     )
     mock_run.assert_has_calls([
         call(['command', '--version']),
         call(['command', '--version']),
         call(['command', '--version']),
         call(['command', '-v']),
         call(['chroot', 'root_dir', 'command', '-v'])
     ])
Esempio n. 10
0
    def check_container_tool_chain_installed(self) -> None:
        """
        When creating container images the specific tools are used in order
        to import and export OCI or Docker compatible images. This check
        searches for those tools to be installed in the build system and
        fails if it can't find them
        """
        message_tool_not_found = dedent('''\n
            Required tool {name} not found in caller environment

            Creation of OCI or Docker images requires the tools {name} and
            skopeo to be installed on the build system. For SUSE based systems
            you can find the tools at:

            http://download.opensuse.org/repositories/Virtualization:/containers
        ''')
        message_version_unsupported = dedent('''\n
            {name} tool found with unknown version
        ''')
        message_unknown_tool = dedent('''\n
            Unknown tool: {0}.

            Please configure KIWI with an appropriate value (umoci or buildah).
            Consider this runtime configuration file syntax (/etc/kiwi.yml):

            oci:
                - archive_tool: umoci | buildah
        ''')

        expected_version = (0, 1, 0)

        if self.xml_state.get_build_type_name() in ['docker', 'oci']:
            runtime_config = RuntimeConfig()
            tool_name = runtime_config.get_oci_archive_tool()
            if tool_name == 'buildah':
                oci_tools = ['buildah', 'skopeo']
            elif tool_name == 'umoci':
                oci_tools = ['umoci', 'skopeo']
            else:
                raise KiwiRuntimeError(message_unknown_tool.format(tool_name))
            for tool in oci_tools:
                if not Path.which(filename=tool, access_mode=os.X_OK):
                    raise KiwiRuntimeError(
                        message_tool_not_found.format(name=tool)
                    )
                elif not CommandCapabilities.check_version(
                    tool, expected_version, raise_on_error=False
                ):
                    raise KiwiRuntimeError(
                        message_version_unsupported.format(name=tool)
                    )
            self._check_multitag_support()
Esempio n. 11
0
    def setup_disk_image_config(
        self, boot_uuid=None, root_uuid=None, hypervisor=None,
        kernel=None, initrd=None, boot_options={}
    ):
        """
        Create grub2 config file to boot from disk using grub2-mkconfig

        :param string boot_uuid: unused
        :param string root_uuid: unused
        :param string hypervisor: unused
        :param string kernel: unused
        :param string initrd: unused
        :param dict boot_options:

        options dictionary that has to contain the root and boot
        device and optional volume configuration. KIWI has to
        mount the system prior to run grub2-mkconfig.

        .. code:: python

            {
                'root_device': string,
                'boot_device': string,
                'efi_device': string,
                'system_volumes': volume_manager_instance.get_volumes()
            }
        """
        self._mount_system(
            boot_options.get('root_device'),
            boot_options.get('boot_device'),
            boot_options.get('efi_device'),
            boot_options.get('system_volumes')
        )
        config_file = os.sep.join(
            [
                self.root_mount.mountpoint, 'boot',
                self.boot_directory_name, 'grub.cfg'
            ]
        )
        Command.run(
            [
                'chroot', self.root_mount.mountpoint,
                os.path.basename(self._get_grub2_mkconfig_tool()), '-o',
                config_file.replace(self.root_mount.mountpoint, '')
            ]
        )

        if self.validate_use_of_linuxefi:
            # On systems that uses GRUB_USE_LINUXEFI with grub2 version
            # less than 2.04 there is no support for dynamic EFI
            # environment checking. In this condition we change the
            # grub config to add this support as follows:
            #
            # * Apply only on grub < 2.04
            #    1. Modify grub.cfg to set linux/initrd as variables
            #    2. Prepend hybrid setup to select linux vs. linuxefi on demand
            #
            # Please note this is a one time modification done by kiwi
            # Any subsequent call of the grub config tool will overwrite
            # the setup and disables dynamic EFI environment checking
            # at boot time
            if not CommandCapabilities.check_version(
                self._get_grub2_mkconfig_tool(),
                version_waterline=(2, 4), raise_on_error=False
            ):
                with open(config_file) as grub_config_file:
                    grub_config = grub_config_file.read()
                    grub_config = re.sub(
                        r'([ \t]+)linux[efi]*([ \t]+)', r'\1$linux\2',
                        grub_config
                    )
                    grub_config = re.sub(
                        r'([ \t]+)initrd[efi]*([ \t]+)', r'\1$initrd\2',
                        grub_config
                    )
                with open(config_file, 'w') as grub_config_file:
                    grub_config_file.write(
                        Template(self.grub2.header_hybrid).substitute()
                    )
                    grub_config_file.write(grub_config)

        if self.root_reference:
            if self.root_filesystem_is_overlay or \
               Defaults.is_buildservice_worker():
                # grub2-mkconfig has no idea how the correct root= setup is
                # for disk images created with overlayroot enabled or in a
                # buildservice worker environment. Because of that the mkconfig
                # tool just finds the raw partition loop device and includes it
                # which is wrong. In this particular case we have to patch the
                # written config file and replace the wrong root= reference with
                # the correct value.
                with open(config_file) as grub_config_file:
                    grub_config = grub_config_file.read()
                    grub_config = grub_config.replace(
                        'root={0}'.format(boot_options.get('root_device')),
                        self.root_reference
                    )
                with open(config_file, 'w') as grub_config_file:
                    grub_config_file.write(grub_config)

        if self.firmware.efi_mode():
            self._copy_grub_config_to_efi_path(
                self.efi_mount.mountpoint, config_file
            )
 def test_check_version_no_match(self, mock_run):
     command_type = namedtuple('command', ['output'])
     mock_run.return_value = command_type(
         output="Dummy line\ncommand someother stuff\n")
     with raises(KiwiCommandCapabilitiesError):
         CommandCapabilities.check_version('command', (1, 2, 3))
Esempio n. 13
0
 def test_check_version_complex_pattern(self, mock_run):
     command_type = namedtuple('command', ['output'])
     mock_run.return_value = command_type(
         output="grub2-mkconfig (GRUB2) 2.02\n")
     assert CommandCapabilities.check_version('command', (2, 2)) is True
     assert CommandCapabilities.check_version('command', (2, 4)) is False
 def test_check_version_no_match(self, mock_run):
     command_type = namedtuple('command', ['output'])
     mock_run.return_value = command_type(
         output="Dummy line\ncommand someother stuff\n"
     )
     CommandCapabilities.check_version('command', (1, 2, 3))