Beispiel #1
0
    def get_boot_names(self):
        """
        Provides kernel and initrd names for kiwi boot image

        :return:
            Contains boot_names_type tuple

            .. code:: python

                boot_names_type(
                    kernel_name='INSTALLED_KERNEL',
                    initrd_name='DRACUT_OUTPUT_NAME'
                )

        :rtype: tuple
        """
        boot_names_type = namedtuple('boot_names_type',
                                     ['kernel_name', 'initrd_name'])
        kernel = Kernel(self.boot_root_directory)
        kernel_info = kernel.get_kernel()
        if not kernel_info:
            raise KiwiDiskBootImageError(
                'No kernel in boot image tree %s found' %
                self.boot_root_directory)
        dracut_output_format = self._get_dracut_output_file_format()
        return boot_names_type(kernel_name=kernel_info.name,
                               initrd_name=dracut_output_format.format(
                                   kernel_version=kernel_info.version))
Beispiel #2
0
    def create_initrd(self, mbrid=None, basename=None, install_initrd=False):
        """
        Call dracut as chroot operation to create the initrd and move
        the result into the image build target directory

        :param object mbrid: unused
        :param string basename: base initrd file name
        :param bool install_initrd: installation media initrd
        """
        if self.is_prepared():
            log.info('Creating generic dracut initrd archive')
            kernel_info = Kernel(self.boot_root_directory)
            kernel_details = kernel_info.get_kernel(raise_on_not_found=True)
            if basename:
                dracut_initrd_basename = basename
            else:
                dracut_initrd_basename = self.initrd_base_name
            if install_initrd:
                included_files = self.included_files_install
            else:
                included_files = self.included_files
            dracut_initrd_basename += '.xz'
            Command.run([
                'chroot', self.boot_root_directory, 'dracut', '--force',
                '--no-hostonly', '--no-hostonly-cmdline', '--xz'
            ] + self.dracut_options + included_files +
                        [dracut_initrd_basename, kernel_details.version])
            Command.run([
                'mv',
                os.sep.join([self.boot_root_directory,
                             dracut_initrd_basename]), self.target_dir
            ])
            self.initrd_filename = os.sep.join(
                [self.target_dir, dracut_initrd_basename])
Beispiel #3
0
    def get_boot_names(self) -> boot_names_type:
        """
        Provides kernel and initrd names for the boot image

        :return:
            Contains boot_names_type tuple

            .. code:: python

                boot_names_type(
                    kernel_name='INSTALLED_KERNEL',
                    initrd_name='DRACUT_OUTPUT_NAME'
                )

        :rtype: boot_names_type
        """
        kernel = Kernel(self.boot_root_directory)
        kernel_info = kernel.get_kernel()
        if not kernel_info:
            if self.xml_state.get_initrd_system() == 'none':
                return boot_names_type(kernel_name='none', initrd_name='none')
            raise KiwiDiskBootImageError(
                'No kernel in boot image tree %s found' %
                self.boot_root_directory)
        dracut_output_format = self._get_boot_image_output_file_format(
            kernel_info.version)
        return boot_names_type(kernel_name=kernel_info.name,
                               initrd_name=dracut_output_format.format(
                                   kernel_version=kernel_info.version))
Beispiel #4
0
    def get_boot_names(self):
        """
        Provides kernel and initrd names for kiwi boot image

        :return:
            Contains boot_names_type tuple

            .. code:: python

                boot_names_type(
                    kernel_name='INSTALLED_KERNEL',
                    initrd_name='DRACUT_OUTPUT_NAME'
                )

        :rtype: tuple
        """
        boot_names_type = namedtuple(
            'boot_names_type', ['kernel_name', 'initrd_name']
        )
        kernel = Kernel(
            self.boot_root_directory
        )
        kernel_info = kernel.get_kernel()
        if not kernel_info:
            raise KiwiDiskBootImageError(
                'No kernel in boot image tree %s found' %
                self.boot_root_directory
            )
        dracut_output_format = self._get_dracut_output_file_format()
        return boot_names_type(
            kernel_name=kernel_info.name,
            initrd_name=dracut_output_format.format(
                kernel_version=kernel_info.version
            )
        )
Beispiel #5
0
 def _get_boot_names(self):
     boot_names_type = namedtuple(
         'boot_names_type', ['kernel_name', 'initrd_name']
     )
     kernel = Kernel(
         self.boot_image.boot_root_directory
     )
     kernel_info = kernel.get_kernel()
     if not kernel_info:
         raise KiwiDiskBootImageError(
             'No kernel in boot image tree %s found' %
             self.boot_image.boot_root_directory
         )
     if self.initrd_system and self.initrd_system == 'dracut':
         dracut_output_format = self._get_dracut_output_file_format()
         return boot_names_type(
             kernel_name=kernel_info.name,
             initrd_name=dracut_output_format.format(
                 kernel_version=kernel_info.version
             )
         )
     else:
         return boot_names_type(
             kernel_name='linux.vmx',
             initrd_name='initrd.vmx'
         )
Beispiel #6
0
 def setup(self, mock_listdir):
     mock_listdir.return_value = ['1.2.3-default']
     self.kernel = Kernel('root-dir')
     assert self.kernel.kernel_names == [
         'uImage-1.2.3-default', 'Image-1.2.3-default',
         'zImage-1.2.3-default', 'vmlinuz-1.2.3-default',
         'image-1.2.3-default'
     ]
Beispiel #7
0
    def create_initrd(self,
                      mbrid: Optional[SystemIdentifier] = None,
                      basename: Optional[str] = None,
                      install_initrd: bool = False) -> None:
        """
        Create kiwi .profile environment to be included in dracut initrd.
        Call dracut as chroot operation to create the initrd and move
        the result into the image build target directory

        :param SystemIdentifier mbrid: unused
        :param str basename: base initrd file name
        :param bool install_initrd: unused
        """
        if self.is_prepared():
            log.info('Creating generic dracut initrd archive')
            self._create_profile_environment()
            kernel_info = Kernel(self.boot_root_directory)
            kernel_details = kernel_info.get_kernel(raise_on_not_found=True)
            if basename:
                dracut_initrd_basename = basename
            else:
                dracut_initrd_basename = self.initrd_base_name
            included_files = self.included_files
            modules_args = [
                '--modules', ' {0} '.format(' '.join(self.modules))
            ] if self.modules else []
            modules_args += [
                '--add', ' {0} '.format(' '.join(self.add_modules))
            ] if self.add_modules else []
            modules_args += [
                '--omit', ' {0} '.format(' '.join(self.omit_modules))
            ] if self.omit_modules else []
            dracut_initrd_basename += '.xz'
            options = self.dracut_options + modules_args + included_files
            if kernel_details:
                self.device_mount = MountManager(
                    device='/dev',
                    mountpoint=self.boot_root_directory + '/dev')
                self.device_mount.bind_mount()
                self.proc_mount = MountManager(
                    device='/proc',
                    mountpoint=self.boot_root_directory + '/proc')
                self.proc_mount.bind_mount()
                dracut_call = Command.run([
                    'chroot', self.boot_root_directory, 'dracut', '--verbose',
                    '--no-hostonly', '--no-hostonly-cmdline', '--xz'
                ] + options + [dracut_initrd_basename, kernel_details.version],
                                          stderr_to_stdout=True)
                self.device_mount.umount()
                self.proc_mount.umount()
            log.debug(dracut_call.output)
            Command.run([
                'mv',
                os.sep.join([self.boot_root_directory,
                             dracut_initrd_basename]), self.target_dir
            ])
            self.initrd_filename = os.sep.join(
                [self.target_dir, dracut_initrd_basename])
Beispiel #8
0
    def create_initrd(self, mbrid=None, basename=None, install_initrd=False):
        """
        Create kiwi .profile environment to be included in dracut initrd.
        Call dracut as chroot operation to create the initrd and move
        the result into the image build target directory

        :param object mbrid: unused
        :param string basename: base initrd file name
        :param bool install_initrd: installation media initrd
        """
        if self.is_prepared():
            log.info('Creating generic dracut initrd archive')
            self._create_profile_environment()
            kernel_info = Kernel(self.boot_root_directory)
            kernel_details = kernel_info.get_kernel(raise_on_not_found=True)
            if basename:
                dracut_initrd_basename = basename
            else:
                dracut_initrd_basename = self.initrd_base_name
            if install_initrd:
                included_files = self.included_files_install
                modules_args = [
                    '--modules', ' {0} '.format(' '.join(self.install_modules))
                ] if self.install_modules else []
                modules_args += [
                    '--add', ' {0} '.format(' '.join(self.add_install_modules))
                ] if self.add_install_modules else []
                modules_args += [
                    '--omit', ' {0} '.format(' '.join(
                        self.omit_install_modules))
                ] if self.omit_install_modules else []
            else:
                included_files = self.included_files
                modules_args = [
                    '--modules', ' {0} '.format(' '.join(self.modules))
                ] if self.modules else []
                modules_args += [
                    '--add', ' {0} '.format(' '.join(self.add_modules))
                ] if self.add_modules else []
                modules_args += [
                    '--omit', ' {0} '.format(' '.join(self.omit_modules))
                ] if self.omit_modules else []
            dracut_initrd_basename += '.xz'
            options = self.dracut_options + modules_args + included_files
            dracut_call = Command.run([
                'chroot', self.boot_root_directory, 'dracut', '--verbose',
                '--no-hostonly', '--no-hostonly-cmdline', '--xz'
            ] + options + [dracut_initrd_basename, kernel_details.version],
                                      stderr_to_stdout=True)
            log.debug(dracut_call.output)
            Command.run([
                'mv',
                os.sep.join([self.boot_root_directory,
                             dracut_initrd_basename]), self.target_dir
            ])
            self.initrd_filename = os.sep.join(
                [self.target_dir, dracut_initrd_basename])
Beispiel #9
0
 def _create_pxe_install_kernel_and_initrd(self):
     kernel = Kernel(self.boot_image_task.boot_root_directory)
     if kernel.get_kernel():
         kernel.copy_kernel(self.pxe_dir, '/pxeboot.kernel')
         os.symlink(
             'pxeboot.kernel', ''.join([
                 self.pxe_dir, '/',
                 self.xml_state.xml_data.get_name(), '.kernel'
             ]))
     else:
         raise KiwiInstallBootImageError(
             'No kernel in boot image tree %s found' %
             self.boot_image_task.boot_root_directory)
     if self.xml_state.is_xen_server():
         if kernel.get_xen_hypervisor():
             kernel.copy_xen_hypervisor(self.pxe_dir, '/pxeboot.xen.gz')
         else:
             raise KiwiInstallBootImageError(
                 'No hypervisor in boot image tree %s found' %
                 self.boot_image_task.boot_root_directory)
     if self.initrd_system == 'dracut':
         self._create_dracut_install_config()
         self._add_system_image_boot_options_to_boot_image()
     self.boot_image_task.create_initrd(self.mbrid, 'initrd_kiwi_install')
     Command.run([
         'mv', self.boot_image_task.initrd_filename,
         self.pxe_dir + '/pxeboot.initrd.xz'
     ])
     os.chmod(self.pxe_dir + '/pxeboot.initrd.xz', 420)
Beispiel #10
0
 def _create_pxe_install_kernel_and_initrd(self):
     kernelname = 'pxeboot.{0}.kernel'.format(self.pxename)
     initrdname = 'pxeboot.{0}.initrd.xz'.format(self.pxename)
     kernel = Kernel(self.boot_image_task.boot_root_directory)
     if kernel.get_kernel():
         kernel.copy_kernel(self.pxe_dir, kernelname)
         os.symlink(kernelname,
                    ''.join([self.pxe_dir, '/', self.pxename, '.kernel']))
     else:
         raise KiwiInstallBootImageError(
             'No kernel in boot image tree %s found' %
             self.boot_image_task.boot_root_directory)
     if self.xml_state.is_xen_server():
         if kernel.get_xen_hypervisor():
             kernel.copy_xen_hypervisor(
                 self.pxe_dir, '/pxeboot.{0}.xen.gz'.format(self.pxename))
         else:
             raise KiwiInstallBootImageError(
                 'No hypervisor in boot image tree %s found' %
                 self.boot_image_task.boot_root_directory)
     if self.initrd_system == 'dracut':
         self.boot_image_task.include_module('kiwi-dump',
                                             install_media=True)
         if self.root_filesystem_is_multipath is False:
             self.boot_image_task.omit_module('multipath',
                                              install_media=True)
         self._add_system_image_boot_options_to_boot_image()
     self.boot_image_task.create_initrd(self.mbrid,
                                        'initrd_kiwi_install',
                                        install_initrd=True)
     Command.run([
         'mv', self.boot_image_task.initrd_filename,
         self.pxe_dir + '/{0}'.format(initrdname)
     ])
     os.chmod(self.pxe_dir + '/{0}'.format(initrdname), 420)
Beispiel #11
0
 def _create_iso_install_kernel_and_initrd(self):
     boot_path = self.media_dir + '/boot/' + self.arch + '/loader'
     Path.create(boot_path)
     kernel = Kernel(self.boot_image_task.boot_root_directory)
     if kernel.get_kernel():
         kernel.copy_kernel(boot_path, '/linux')
     else:
         raise KiwiInstallBootImageError(
             'No kernel in boot image tree %s found' %
             self.boot_image_task.boot_root_directory)
     if self.xml_state.is_xen_server():
         if kernel.get_xen_hypervisor():
             kernel.copy_xen_hypervisor(boot_path, '/xen.gz')
         else:
             raise KiwiInstallBootImageError(
                 'No hypervisor in boot image tree %s found' %
                 self.boot_image_task.boot_root_directory)
     if self.initrd_system == 'dracut':
         self._create_dracut_install_config()
         self._add_system_image_boot_options_to_boot_image()
     self.boot_image_task.create_initrd(self.mbrid,
                                        'initrd_kiwi_install',
                                        install_initrd=True)
     Command.run([
         'mv', self.boot_image_task.initrd_filename, boot_path + '/initrd'
     ])
Beispiel #12
0
Datei: live.py Projekt: isbm/kiwi
    def _setup_live_iso_kernel_and_initrd(self):
        """
        Copy kernel and initrd from the root tree into the iso boot structure
        """
        boot_path = ''.join([self.media_dir, '/boot/', self.arch, '/loader'])
        Path.create(boot_path)

        # Move kernel files to iso filesystem structure
        kernel = Kernel(self.boot_image.boot_root_directory)
        if kernel.get_kernel():
            kernel.copy_kernel(boot_path, '/linux')
        else:
            raise KiwiLiveBootImageError(
                'No kernel in boot image tree {0} found'.format(
                    self.boot_image.boot_root_directory))
        if self.xml_state.is_xen_server():
            if kernel.get_xen_hypervisor():
                kernel.copy_xen_hypervisor(boot_path, '/xen.gz')
            else:
                raise KiwiLiveBootImageError(
                    'No hypervisor in boot image tree {0} found'.format(
                        self.boot_image.boot_root_directory))

        # Move initrd to iso filesystem structure
        if os.path.exists(self.boot_image.initrd_filename):
            shutil.move(self.boot_image.initrd_filename, boot_path + '/initrd')
        else:
            raise KiwiLiveBootImageError(
                'No boot image {0} in boot image tree {1} found'.format(
                    self.boot_image.initrd_filename,
                    self.boot_image.boot_root_directory))
Beispiel #13
0
 def _create_iso_install_kernel_and_initrd(self) -> None:
     boot_path = self.media_dir.name + '/boot/' + self.arch + '/loader'
     Path.create(boot_path)
     kernel = Kernel(self.boot_image_task.boot_root_directory)
     if kernel.get_kernel():
         kernel.copy_kernel(boot_path, '/linux')
     else:
         raise KiwiInstallBootImageError(
             'No kernel in boot image tree %s found' %
             self.boot_image_task.boot_root_directory)
     if self.xml_state.is_xen_server():
         if kernel.get_xen_hypervisor():
             kernel.copy_xen_hypervisor(boot_path, '/xen.gz')
         else:
             raise KiwiInstallBootImageError(
                 'No hypervisor in boot image tree %s found' %
                 self.boot_image_task.boot_root_directory)
     if self.initrd_system == 'dracut':
         self.boot_image_task.include_module('kiwi-dump')
         self.boot_image_task.include_module('kiwi-dump-reboot')
         if self.root_filesystem_is_multipath is False:
             self.boot_image_task.omit_module('multipath')
         for mod in self.xml_state.get_installmedia_initrd_modules('add'):
             self.boot_image_task.include_module(mod)
         for mod in self.xml_state.get_installmedia_initrd_modules('omit'):
             self.boot_image_task.omit_module(mod)
         self.boot_image_task.set_static_modules(
             self.xml_state.get_installmedia_initrd_modules('set'))
         self._add_system_image_boot_options_to_boot_image()
     self.boot_image_task.create_initrd(self.mbrid,
                                        'initrd_kiwi_install',
                                        install_initrd=True)
     Command.run([
         'mv', self.boot_image_task.initrd_filename, boot_path + '/initrd'
     ])
Beispiel #14
0
 def _create_iso_install_kernel_and_initrd(self):
     boot_path = self.media_dir + '/boot/' + self.arch + '/loader'
     Path.create(boot_path)
     kernel = Kernel(self.boot_image_task.boot_root_directory)
     if kernel.get_kernel():
         kernel.copy_kernel(boot_path, '/linux')
     else:
         raise KiwiInstallBootImageError(
             'No kernel in boot image tree %s found' %
             self.boot_image_task.boot_root_directory
         )
     if self.machine and self.machine.get_domain() == 'dom0':
         if kernel.get_xen_hypervisor():
             kernel.copy_xen_hypervisor(boot_path, '/xen.gz')
         else:
             raise KiwiInstallBootImageError(
                 'No hypervisor in boot image tree %s found' %
                 self.boot_image_task.boot_root_directory
             )
     self.boot_image_task.create_initrd(self.mbrid)
     Command.run(
         [
             'mv', self.boot_image_task.initrd_filename,
             boot_path + '/initrd'
         ]
     )
Beispiel #15
0
class TestKernel(object):
    def setup(self):
        self.kernel = Kernel('root-dir')

    @patch('os.path.exists')
    @patch('kiwi.command.Command.run')
    def test_get_kernel(self, mock_run, mock_os):
        run = namedtuple('run', ['output'])
        result = run(output='42')
        mock_os.return_value = True
        mock_run.return_value = result
        data = self.kernel.get_kernel()
        mock_run.assert_called_once_with(
            command=['kversion', 'root-dir/boot/vmlinux'],
            raise_on_error=False)
        assert data.filename == 'root-dir/boot/vmlinux'
        assert data.version == '42'

    @patch('os.path.exists')
    @patch('kiwi.command.Command.run')
    def test_get_kernel_no_version(self, mock_run, mock_os):
        run = namedtuple('run', ['output'])
        result = run(output=None)
        mock_os.return_value = True
        mock_run.return_value = result
        data = self.kernel.get_kernel()
        mock_run.assert_called_once_with(
            command=['kversion', 'root-dir/boot/vmlinux'],
            raise_on_error=False)
        assert data.filename == 'root-dir/boot/vmlinux'
        assert data.version == 'no-version-found'

    @patch('os.path.exists')
    def test_get_xen_hypervisor(self, mock_os):
        mock_os.return_value = True
        data = self.kernel.get_xen_hypervisor()
        assert data.filename == 'root-dir/boot/xen.gz'
        assert data.name == 'xen.gz'

    @patch('kiwi.system.kernel.Kernel.get_kernel')
    @patch('kiwi.command.Command.run')
    def test_copy_kernel(self, mock_run, mock_get_kernel):
        result = mock.MagicMock()
        result.version = '42'
        result.filename = 'kernel'
        mock_get_kernel.return_value = result
        self.kernel.copy_kernel('target-dir')
        mock_run.assert_called_once_with(
            ['cp', 'kernel', 'target-dir/kernel-42.kernel'])

    @patch('kiwi.system.kernel.Kernel.get_xen_hypervisor')
    @patch('kiwi.command.Command.run')
    def test_copy_xen_hypervisor(self, mock_run, mock_get_xen):
        result = mock.MagicMock()
        result.name = 'xen.gz'
        result.filename = 'some/xen.gz'
        mock_get_xen.return_value = result
        self.kernel.copy_xen_hypervisor('target-dir')
        mock_run.assert_called_once_with(
            ['cp', 'some/xen.gz', 'target-dir/hypervisor-xen.gz'])
Beispiel #16
0
 def _create_iso_install_kernel_and_initrd(self):
     boot_path = self.media_dir + '/boot/' + self.arch + '/loader'
     Path.create(boot_path)
     kernel = Kernel(self.boot_image_task.boot_root_directory)
     if kernel.get_kernel():
         kernel.copy_kernel(boot_path, '/linux')
     else:
         raise KiwiInstallBootImageError(
             'No kernel in boot image tree %s found' %
             self.boot_image_task.boot_root_directory
         )
     if self.xml_state.is_xen_server():
         if kernel.get_xen_hypervisor():
             kernel.copy_xen_hypervisor(boot_path, '/xen.gz')
         else:
             raise KiwiInstallBootImageError(
                 'No hypervisor in boot image tree %s found' %
                 self.boot_image_task.boot_root_directory
             )
     if self.initrd_system == 'dracut':
         self._create_dracut_install_config()
         self._add_system_image_boot_options_to_boot_image()
     self.boot_image_task.create_initrd(self.mbrid, 'initrd_kiwi_install')
     Command.run(
         [
             'mv', self.boot_image_task.initrd_filename,
             boot_path + '/initrd'
         ]
     )
Beispiel #17
0
    def _copy_first_boot_files_to_system_image(self):
        boot_names = self.boot_image.get_boot_names()
        if self.initrd_system == 'kiwi':
            log.info('Copy boot files to system image')
            kernel = Kernel(self.boot_image.boot_root_directory)

            log.info('--> boot image kernel as %s', boot_names.kernel_name)
            kernel.copy_kernel(
                self.root_dir, ''.join(['/boot/', boot_names.kernel_name])
            )

            if self.xen_server:
                if kernel.get_xen_hypervisor():
                    log.info('--> boot image Xen hypervisor as xen.gz')
                    kernel.copy_xen_hypervisor(
                        self.root_dir, '/boot/xen.gz'
                    )
                else:
                    raise KiwiDiskBootImageError(
                        'No hypervisor in boot image tree %s found' %
                        self.boot_image.boot_root_directory
                    )

        log.info('--> initrd archive as %s', boot_names.initrd_name)
        Command.run(
            [
                'mv', self.boot_image.initrd_filename,
                self.root_dir + ''.join(['/boot/', boot_names.initrd_name])
            ]
        )
Beispiel #18
0
class TestKernel:
    @patch('os.listdir')
    def setup(self, mock_listdir):
        mock_listdir.return_value = ['1.2.3-default']
        self.kernel = Kernel('root-dir')
        assert self.kernel.kernel_names == [
            'uImage-1.2.3-default', 'Image-1.2.3-default',
            'zImage-1.2.3-default', 'vmlinuz-1.2.3-default',
            'image-1.2.3-default'
        ]

    def test_get_kernel_raises_if_no_kernel_found(self):
        self.kernel.kernel_names = []
        with raises(KiwiKernelLookupError):
            self.kernel.get_kernel(raise_on_not_found=True)

    @patch('os.path.exists')
    @patch('os.path.realpath')
    def test_get_kernel(self, mock_os_path_realpath, mock_os_path_exists):
        mock_os_path_exists.return_value = True
        kernel = self.kernel.get_kernel()
        assert kernel.filename == 'root-dir/boot/uImage-1.2.3-default'
        assert kernel.version == '1.2.3-default'
        assert kernel.name == os.path.basename(
            mock_os_path_realpath.return_value)

    @patch('os.path.exists')
    def test_get_xen_hypervisor(self, mock_os):
        mock_os.return_value = True
        data = self.kernel.get_xen_hypervisor()
        assert data.filename == 'root-dir/boot/xen.gz'
        assert data.name == 'xen.gz'

    @patch('kiwi.system.kernel.Kernel.get_kernel')
    @patch('kiwi.command.Command.run')
    def test_copy_kernel(self, mock_run, mock_get_kernel):
        result = mock.MagicMock()
        result.version = '42'
        result.filename = 'kernel'
        mock_get_kernel.return_value = result
        self.kernel.copy_kernel('target-dir')
        mock_run.assert_called_once_with(
            ['cp', 'kernel', 'target-dir/kernel-42.kernel'])

    @patch('kiwi.system.kernel.Kernel.get_xen_hypervisor')
    @patch('kiwi.command.Command.run')
    def test_copy_xen_hypervisor(self, mock_run, mock_get_xen):
        result = mock.MagicMock()
        result.name = 'xen.gz'
        result.filename = 'some/xen.gz'
        mock_get_xen.return_value = result
        self.kernel.copy_xen_hypervisor('target-dir')
        mock_run.assert_called_once_with(
            ['cp', 'some/xen.gz', 'target-dir/hypervisor-xen.gz'])
Beispiel #19
0
 def get_boot_names(self):
     boot_names_type = namedtuple(
         'boot_names_type', ['kernel_name', 'initrd_name']
     )
     kernel = Kernel(
         self.boot_root_directory
     )
     kernel_info = kernel.get_kernel()
     if not kernel_info:
         raise KiwiDiskBootImageError(
             'No kernel in boot image tree %s found' %
             self.boot_root_directory
         )
     dracut_output_format = self._get_dracut_output_file_format()
     return boot_names_type(
         kernel_name=kernel_info.name,
         initrd_name=dracut_output_format.format(
             kernel_version=kernel_info.version
         )
     )
Beispiel #20
0
    def create_initrd(self, mbrid=None, basename=None):
        """
        Call dracut as chroot operation to create the initrd and move
        the result into the image build target directory

        :param object mbrid: unused
        :param string basename: base initrd file name
        """
        if self.is_prepared():
            log.info('Creating generic dracut initrd archive')
            kernel_info = Kernel(self.boot_root_directory)
            kernel_details = kernel_info.get_kernel(raise_on_not_found=True)
            if basename:
                dracut_initrd_basename = basename
            else:
                dracut_initrd_basename = self.initrd_base_name
            dracut_initrd_basename += '.xz'
            Command.run(
                [
                    'chroot', self.boot_root_directory,
                    'dracut', '--force',
                    '--no-hostonly',
                    '--no-hostonly-cmdline',
                    '--xz'
                ] + self.dracut_options + [
                    dracut_initrd_basename,
                    kernel_details.version
                ]
            )
            Command.run(
                [
                    'mv',
                    os.sep.join(
                        [self.boot_root_directory, dracut_initrd_basename]
                    ),
                    self.target_dir
                ]
            )
            self.initrd_filename = os.sep.join(
                [self.target_dir, dracut_initrd_basename]
            )
Beispiel #21
0
    def _copy_first_boot_files_to_system_image(self):
        boot_names = self.boot_image.get_boot_names()
        if self.initrd_system == 'kiwi':
            log.info('Copy boot files to system image')
            kernel = Kernel(self.boot_image.boot_root_directory)

            log.info('--> boot image kernel as %s', boot_names.kernel_name)
            kernel.copy_kernel(
                self.root_dir, ''.join(['/boot/', boot_names.kernel_name])
            )

            if self.xen_server:
                if kernel.get_xen_hypervisor():
                    log.info('--> boot image Xen hypervisor as xen.gz')
                    kernel.copy_xen_hypervisor(
                        self.root_dir, '/boot/xen.gz'
                    )
                else:
                    raise KiwiDiskBootImageError(
                        'No hypervisor in boot image tree %s found' %
                        self.boot_image.boot_root_directory
                    )

        log.info('--> initrd archive as %s', boot_names.initrd_name)
        Command.run(
            [
                'mv', self.boot_image.initrd_filename,
                self.root_dir + ''.join(['/boot/', boot_names.initrd_name])
            ]
        )
Beispiel #22
0
 def setup(self, mock_listdir):
     mock_listdir.return_value = ['1.2.3-default']
     self.kernel = Kernel('root-dir')
     assert self.kernel.kernel_names == [
         'vmlinux',
         'vmlinuz',
         'uImage-1.2.3-default',
         'Image-1.2.3-default',
         'zImage-1.2.3-default',
         'vmlinuz-1.2.3-default',
         'vmlinux-1.2.3-default',
         'image-1.2.3-default'
     ]
Beispiel #23
0
    def create_initrd(self, mbrid=None):
        """
        Call dracut as chroot operation to create the initrd and move
        the result into the image build target directory

        :param object mbrid: unused
        """
        if self.is_prepared():
            log.info('Creating generic dracut initrd archive')
            kernel_info = Kernel(self.boot_root_directory)
            kernel_details = kernel_info.get_kernel(raise_on_not_found=True)
            dracut_initrd_basename = self.initrd_base_name + '.xz'
            Command.run([
                'chroot', self.boot_root_directory, 'dracut', '--force',
                '--no-hostonly', '--no-hostonly-cmdline', '--xz',
                dracut_initrd_basename, kernel_details.version
            ])
            Command.run([
                'mv',
                os.sep.join([self.boot_root_directory,
                             dracut_initrd_basename]), self.target_dir
            ])
            self.initrd_filename = os.sep.join(
                [self.target_dir, dracut_initrd_basename])
Beispiel #24
0
 def _create_pxe_install_kernel_and_initrd(self):
     kernel = Kernel(self.boot_image_task.boot_root_directory)
     if kernel.get_kernel():
         kernel.copy_kernel(self.pxe_dir, '/pxeboot.kernel')
     else:
         raise KiwiInstallBootImageError(
             'No kernel in boot image tree %s found' %
             self.boot_image_task.boot_root_directory)
     if self.xml_state.is_xen_server():
         if kernel.get_xen_hypervisor():
             kernel.copy_xen_hypervisor(self.pxe_dir, '/pxeboot.xen.gz')
         else:
             raise KiwiInstallBootImageError(
                 'No hypervisor in boot image tree %s found' %
                 self.boot_image_task.boot_root_directory)
     self.boot_image_task.create_initrd(self.mbrid)
     Command.run([
         'mv', self.boot_image_task.initrd_filename,
         self.pxe_dir + '/pxeboot.initrd.xz'
     ])
Beispiel #25
0
    def _setup_live_iso_kernel_and_initrd(self):
        """
        Copy kernel and initrd from the root tree into the iso boot structure
        """
        boot_path = ''.join(
            [self.media_dir, '/boot/', self.arch, '/loader']
        )
        Path.create(boot_path)

        # Move kernel files to iso filesystem structure
        kernel = Kernel(self.boot_image.boot_root_directory)
        if kernel.get_kernel():
            kernel.copy_kernel(boot_path, '/linux')
        else:
            raise KiwiLiveBootImageError(
                'No kernel in boot image tree {0} found'.format(
                    self.boot_image.boot_root_directory
                )
            )
        if self.xml_state.is_xen_server():
            if kernel.get_xen_hypervisor():
                kernel.copy_xen_hypervisor(boot_path, '/xen.gz')
            else:
                raise KiwiLiveBootImageError(
                    'No hypervisor in boot image tree {0} found'.format(
                        self.boot_image.boot_root_directory
                    )
                )

        # Move initrd to iso filesystem structure
        if os.path.exists(self.boot_image.initrd_filename):
            shutil.move(
                self.boot_image.initrd_filename, boot_path + '/initrd'
            )
        else:
            raise KiwiLiveBootImageError(
                'No boot image {0} in boot image tree {1} found'.format(
                    self.boot_image.initrd_filename,
                    self.boot_image.boot_root_directory
                )
            )
Beispiel #26
0
 def _create_pxe_install_kernel_and_initrd(self):
     kernel = Kernel(self.boot_image_task.boot_root_directory)
     if kernel.get_kernel():
         kernel.copy_kernel(self.pxe_dir, '/pxeboot.kernel')
         os.symlink(
             'pxeboot.kernel', ''.join(
                 [
                     self.pxe_dir, '/',
                     self.xml_state.xml_data.get_name(), '.kernel'
                 ]
             )
         )
     else:
         raise KiwiInstallBootImageError(
             'No kernel in boot image tree %s found' %
             self.boot_image_task.boot_root_directory
         )
     if self.xml_state.is_xen_server():
         if kernel.get_xen_hypervisor():
             kernel.copy_xen_hypervisor(self.pxe_dir, '/pxeboot.xen.gz')
         else:
             raise KiwiInstallBootImageError(
                 'No hypervisor in boot image tree %s found' %
                 self.boot_image_task.boot_root_directory
             )
     if self.initrd_system == 'dracut':
         self._create_dracut_install_config()
         self._add_system_image_boot_options_to_boot_image()
     self.boot_image_task.create_initrd(self.mbrid, 'initrd_kiwi_install')
     Command.run(
         [
             'mv', self.boot_image_task.initrd_filename,
             self.pxe_dir + '/pxeboot.initrd.xz'
         ]
     )
     os.chmod(self.pxe_dir + '/pxeboot.initrd.xz', 420)
Beispiel #27
0
    def create(self):
        """
        Build a pxe image set consisting out of a boot image(initrd)
        plus its appropriate kernel files and the root filesystem
        image with a checksum. The result can be used within the kiwi
        PXE boot infrastructure

        Image types which triggers this builder are:

        * image="pxe"

        :raises KiwiPxeBootImageError: if no kernel or hipervisor is found
            in boot image tree
        :return: result

        :rtype: instance of :class:`Result`
        """
        log.info('Creating PXE root filesystem image')
        self.filesystem.create()
        os.rename(
            self.filesystem.filename, self.image_name
        )
        self.image = self.image_name
        if self.compressed:
            log.info('xz compressing root filesystem image')
            compress = Compress(self.image)
            compress.xz(self.xz_options)
            self.image = compress.compressed_filename

        log.info('Creating PXE root filesystem MD5 checksum')
        self.filesystem_checksum = ''.join([self.image, '.md5'])
        checksum = Checksum(self.image)
        checksum.md5(self.filesystem_checksum)

        # prepare boot(initrd) root system
        log.info('Creating PXE boot image')
        self.boot_image_task.prepare()

        # export modprobe configuration to boot image
        self.system_setup.export_modprobe_setup(
            self.boot_image_task.boot_root_directory
        )

        # extract kernel from boot(initrd) root system
        kernel = Kernel(self.boot_image_task.boot_root_directory)
        kernel_data = kernel.get_kernel()
        if kernel_data:
            self.kernel_filename = ''.join(
                [
                    os.path.basename(self.image_name), '-',
                    kernel_data.version, '.kernel'
                ]
            )
            kernel.copy_kernel(
                self.target_dir, self.kernel_filename
            )
        else:
            raise KiwiPxeBootImageError(
                'No kernel in boot image tree %s found' %
                self.boot_image_task.boot_root_directory
            )

        # extract hypervisor from boot(initrd) root system
        if self.xen_server:
            kernel_data = kernel.get_xen_hypervisor()
            if kernel_data:
                self.hypervisor_filename = ''.join(
                    [os.path.basename(self.image_name), '-', kernel_data.name]
                )
                kernel.copy_xen_hypervisor(
                    self.target_dir, self.hypervisor_filename
                )
                self.result.add(
                    key='xen_hypervisor',
                    filename=self.target_dir + '/' + self.hypervisor_filename,
                    use_for_bundle=True,
                    compress=False,
                    shasum=True
                )
            else:
                raise KiwiPxeBootImageError(
                    'No hypervisor in boot image tree %s found' %
                    self.boot_image_task.boot_root_directory
                )

        # create initrd for pxe boot
        self.boot_image_task.create_initrd()

        # put results into a tarball
        if not self.xz_options:
            self.xz_options = Defaults.get_xz_compression_options()
        bash_command = [
            'tar', '-C', self.target_dir, '-c', '--to-stdout'
        ] + [
            self.kernel_filename,
            os.path.basename(self.boot_image_task.initrd_filename),
            os.path.basename(self.image),
            os.path.basename(self.filesystem_checksum)
        ] + [
            '|', 'xz', '-f'
        ] + self.xz_options + [
            '>', self.archive_name
        ]
        Command.run(['bash', '-c', ' '.join(bash_command)])

        self.result.verify_image_size(
            self.runtime_config.get_max_size_constraint(),
            self.archive_name
        )
        # store results
        self.result.add(
            key='pxe_archive',
            filename=self.archive_name,
            use_for_bundle=True,
            compress=False,
            shasum=True
        )

        # create image root metadata
        self.result.add(
            key='image_packages',
            filename=self.system_setup.export_package_list(
                self.target_dir
            ),
            use_for_bundle=True,
            compress=False,
            shasum=False
        )
        self.result.add(
            key='image_verified',
            filename=self.system_setup.export_package_verification(
                self.target_dir
            ),
            use_for_bundle=True,
            compress=False,
            shasum=False
        )

        if self.pxedeploy:
            log.warning(
                'Creation of client config file from pxedeploy not implemented'
            )

        return self.result
Beispiel #28
0
    def create(self):
        """
        Build a pxe image set consisting out of a boot image(initrd)
        plus its appropriate kernel files and the root filesystem
        image with a checksum. The result can be used within the kiwi
        PXE boot infrastructure

        Image types which triggers this builder are:

        * image="pxe"

        :raises KiwiPxeBootImageError: if no kernel or hipervisor is found
            in boot image tree
        :return: result

        :rtype: instance of :class:`Result`
        """
        log.info('Creating PXE root filesystem image')
        self.filesystem.create()
        os.rename(self.filesystem.filename, self.image_name)
        self.image = self.image_name
        if self.compressed:
            log.info('xz compressing root filesystem image')
            compress = Compress(self.image)
            compress.xz(self.xz_options)
            self.image = compress.compressed_filename

        log.info('Creating PXE root filesystem MD5 checksum')
        checksum = Checksum(self.image)
        checksum.md5(self.checksum_name)

        # prepare boot(initrd) root system
        log.info('Creating PXE boot image')
        self.boot_image_task.prepare()

        # export modprobe configuration to boot image
        self.system_setup.export_modprobe_setup(
            self.boot_image_task.boot_root_directory)

        # extract kernel from boot(initrd) root system
        kernel = Kernel(self.boot_image_task.boot_root_directory)
        kernel_data = kernel.get_kernel()
        if kernel_data:
            self.kernel_filename = ''.join([
                os.path.basename(self.image_name), '-', kernel_data.version,
                '.kernel'
            ])
            kernel.copy_kernel(self.target_dir, self.kernel_filename)
        else:
            raise KiwiPxeBootImageError(
                'No kernel in boot image tree %s found' %
                self.boot_image_task.boot_root_directory)

        # extract hypervisor from boot(initrd) root system
        if self.xen_server:
            kernel_data = kernel.get_xen_hypervisor()
            if kernel_data:
                self.hypervisor_filename = ''.join(
                    [os.path.basename(self.image_name), '-', kernel_data.name])
                kernel.copy_xen_hypervisor(self.target_dir,
                                           self.hypervisor_filename)
                self.result.add(key='xen_hypervisor',
                                filename=self.target_dir + '/' +
                                self.hypervisor_filename,
                                use_for_bundle=True,
                                compress=False,
                                shasum=True)
            else:
                raise KiwiPxeBootImageError(
                    'No hypervisor in boot image tree %s found' %
                    self.boot_image_task.boot_root_directory)

        # create initrd for pxe boot
        self.boot_image_task.create_initrd()

        # put results into a tarball
        if not self.xz_options:
            self.xz_options = Defaults.get_xz_compression_options()
        bash_command = ['tar', '-C', self.target_dir, '-c', '--to-stdout'] + [
            self.kernel_filename,
            os.path.basename(self.boot_image_task.initrd_filename),
            os.path.basename(self.image),
            os.path.basename(self.checksum_name)
        ] + ['|', 'xz', '-f'] + self.xz_options + ['>', self.archive_name]
        Command.run(['bash', '-c', ' '.join(bash_command)])

        self.result.verify_image_size(
            self.runtime_config.get_max_size_constraint(), self.archive_name)
        # store results
        self.result.add(
            key='pxe_archive',
            filename=self.archive_name,
            use_for_bundle=True,
            compress=self.runtime_config.get_bundle_compression(default=False),
            shasum=True)

        # create image root metadata
        self.result.add(key='image_packages',
                        filename=self.system_setup.export_package_list(
                            self.target_dir),
                        use_for_bundle=True,
                        compress=False,
                        shasum=False)
        self.result.add(key='image_verified',
                        filename=self.system_setup.export_package_verification(
                            self.target_dir),
                        use_for_bundle=True,
                        compress=False,
                        shasum=False)
        return self.result
Beispiel #29
0
class TestKernel(object):
    @patch('os.listdir')
    def setup(self, mock_listdir):
        mock_listdir.return_value = ['1.2.3-default']
        self.kernel = Kernel('root-dir')
        assert self.kernel.kernel_names == [
            'vmlinux', 'vmlinuz', 'uImage-1.2.3-default',
            'Image-1.2.3-default', 'zImage-1.2.3-default',
            'vmlinuz-1.2.3-default', 'vmlinux-1.2.3-default',
            'image-1.2.3-default'
        ]

    @raises(KiwiKernelLookupError)
    def test_get_kernel_raises_if_no_kernel_found(self):
        self.kernel.kernel_names = []
        self.kernel.get_kernel(raise_on_not_found=True)

    @patch('os.path.exists')
    @patch('os.path.realpath')
    @patch('kiwi.command.Command.run')
    def test_get_kernel(self, mock_run, mock_realpath, mock_os):
        run = namedtuple('run', ['output'])
        result = run(output='42')
        mock_os.return_value = True
        mock_run.return_value = result
        mock_realpath.return_value = 'vmlinux-realpath'
        data = self.kernel.get_kernel()
        mock_run.assert_called_once_with(
            command=['kversion', 'root-dir/boot/vmlinux-1.2.3-default.gz'],
            raise_on_error=False)
        assert data.filename == 'root-dir/boot/vmlinux'
        assert data.version == '42'
        assert data.name == 'vmlinux-realpath'

    @patch('os.path.exists')
    @patch('os.path.realpath')
    @patch('kiwi.command.Command.run')
    def test_get_kernel_from_arbitrary_kernel_image(self, mock_run,
                                                    mock_realpath, mock_os):
        def path_exists(path):
            return False if 'vmlinux.gz' in path else True

        self.kernel.kernel_names = ['zImage']
        run = namedtuple('run', ['output'])
        result = run(output='42')
        mock_os.side_effect = path_exists
        mock_run.return_value = result
        mock_realpath.return_value = 'vmlinux.gz'
        data = self.kernel.get_kernel()
        mock_run.assert_called_once_with(
            command=['kversion', 'root-dir/boot/zImage'], raise_on_error=False)
        assert data.filename == 'root-dir/boot/zImage'
        assert data.version == '42'
        assert data.name == mock_realpath.return_value

    @patch('os.path.exists')
    @patch('kiwi.command.Command.run')
    def test_get_kernel_no_version(self, mock_run, mock_os):
        run = namedtuple('run', ['output'])
        result = run(output=None)
        mock_os.return_value = True
        mock_run.return_value = result
        data = self.kernel.get_kernel()
        mock_run.assert_called_once_with(
            command=['kversion', 'root-dir/boot/vmlinux-1.2.3-default.gz'],
            raise_on_error=False)
        assert data.filename == 'root-dir/boot/vmlinux'
        assert data.version == 'no-version-found'

    @patch('os.path.exists')
    def test_get_xen_hypervisor(self, mock_os):
        mock_os.return_value = True
        data = self.kernel.get_xen_hypervisor()
        assert data.filename == 'root-dir/boot/xen.gz'
        assert data.name == 'xen.gz'

    @patch('kiwi.system.kernel.Kernel.get_kernel')
    @patch('kiwi.command.Command.run')
    def test_copy_kernel(self, mock_run, mock_get_kernel):
        result = mock.MagicMock()
        result.version = '42'
        result.filename = 'kernel'
        mock_get_kernel.return_value = result
        self.kernel.copy_kernel('target-dir')
        mock_run.assert_called_once_with(
            ['cp', 'kernel', 'target-dir/kernel-42.kernel'])

    @patch('kiwi.system.kernel.Kernel.get_xen_hypervisor')
    @patch('kiwi.command.Command.run')
    def test_copy_xen_hypervisor(self, mock_run, mock_get_xen):
        result = mock.MagicMock()
        result.name = 'xen.gz'
        result.filename = 'some/xen.gz'
        mock_get_xen.return_value = result
        self.kernel.copy_xen_hypervisor('target-dir')
        mock_run.assert_called_once_with(
            ['cp', 'some/xen.gz', 'target-dir/hypervisor-xen.gz'])
Beispiel #30
0
Datei: kis.py Projekt: jfkw/kiwi
    def create(self) -> Result:
        """
        Build a component image consisting out of a boot image(initrd)
        plus its appropriate kernel files and the root filesystem
        image with a checksum.

        Image types which triggers this builder are:

        * image="kis"
        * image="pxe"

        :raises KiwiKisBootImageError: if no kernel or hipervisor is found
            in boot image tree
        :return: result

        :rtype: instance of :class:`Result`
        """
        if self.filesystem:
            log.info('Creating root filesystem image')
            self.filesystem.create()
            os.rename(
                self.filesystem.filename, self.image_name
            )
            self.image = self.image_name
            if self.compressed:
                log.info('xz compressing root filesystem image')
                compress = Compress(self.image)
                compress.xz(self.xz_options)
                self.image = compress.compressed_filename

            log.info('Creating root filesystem MD5 checksum')
            checksum = Checksum(self.image)
            checksum.md5(self.checksum_name)

        # prepare boot(initrd) root system
        log.info('Creating boot image')
        self.boot_image_task.prepare()

        # export modprobe configuration to boot image
        self.system_setup.export_modprobe_setup(
            self.boot_image_task.boot_root_directory
        )

        # extract kernel from boot(initrd) root system
        kernel = Kernel(self.boot_image_task.boot_root_directory)
        kernel_data = kernel.get_kernel()
        if kernel_data:
            self.kernel_filename = ''.join(
                [
                    os.path.basename(self.image_name), '-',
                    kernel_data.version, '.kernel'
                ]
            )
            kernel.copy_kernel(
                self.target_dir, self.kernel_filename
            )
        else:
            raise KiwiKisBootImageError(
                'No kernel in boot image tree %s found' %
                self.boot_image_task.boot_root_directory
            )

        # extract hypervisor from boot(initrd) root system
        if self.xen_server:
            hypervisor_data = kernel.get_xen_hypervisor()
            if hypervisor_data:
                self.hypervisor_filename = ''.join(
                    [
                        os.path.basename(self.image_name),
                        '-', hypervisor_data.name
                    ]
                )
                kernel.copy_xen_hypervisor(
                    self.target_dir, self.hypervisor_filename
                )
                self.result.add(
                    key='xen_hypervisor',
                    filename=self.target_dir + '/' + self.hypervisor_filename,
                    use_for_bundle=True,
                    compress=False,
                    shasum=True
                )
            else:
                raise KiwiKisBootImageError(
                    'No hypervisor in boot image tree %s found' %
                    self.boot_image_task.boot_root_directory
                )

        # create initrd
        self.boot_image_task.create_initrd()

        # create append information
        # this information helps to configure the deployment infrastructure
        if self.filesystem and self.filesystem.root_uuid \
           and self.initrd_system == 'dracut':
            cmdline = 'root=UUID={}'.format(self.filesystem.root_uuid)
            if self.custom_cmdline:
                cmdline += ' {}'.format(self.custom_cmdline)
            with open(self.append_file, 'w') as append:
                append.write(cmdline)

        # put results into a tarball
        if not self.xz_options:
            self.xz_options = Defaults.get_xz_compression_options()

        kis_tarball_files = [
            self.kernel_filename,
            os.path.basename(self.boot_image_task.initrd_filename),
            os.path.basename(self.checksum_name),
        ]

        if self.image:
            kis_tarball_files.append(os.path.basename(self.image))

        if self.filesystem and self.filesystem.root_uuid \
           and self.initrd_system == 'dracut':
            kis_tarball_files.append(os.path.basename(self.append_file))

        kis_tarball = ArchiveTar(
            self.archive_name,
            create_from_file_list=True,
            file_list=kis_tarball_files
        )

        if self.compressed:
            self.archive_name = kis_tarball.create(self.target_dir)
        else:
            self.archive_name = kis_tarball.create_xz_compressed(
                self.target_dir, xz_options=self.xz_options
            )

        Result.verify_image_size(
            self.runtime_config.get_max_size_constraint(),
            self.archive_name
        )
        # store results
        self.result.add(
            key='kis_archive',
            filename=self.archive_name,
            use_for_bundle=True,
            compress=self.runtime_config.get_bundle_compression(
                default=False
            ),
            shasum=True
        )

        # create image root metadata
        self.result.add(
            key='image_packages',
            filename=self.system_setup.export_package_list(
                self.target_dir
            ),
            use_for_bundle=True,
            compress=False,
            shasum=False
        )
        self.result.add(
            key='image_changes',
            filename=self.system_setup.export_package_changes(
                self.target_dir
            ),
            use_for_bundle=True,
            compress=True,
            shasum=False
        )
        self.result.add(
            key='image_verified',
            filename=self.system_setup.export_package_verification(
                self.target_dir
            ),
            use_for_bundle=True,
            compress=False,
            shasum=False
        )
        return self.result
Beispiel #31
0
    def create(self):
        """
        Build a pxe image set consisting out of a boot image(initrd)
        plus its appropriate kernel files and the root filesystem
        image with a checksum. The result can be used within the kiwi
        PXE boot infrastructure

        Image types which triggers this builder are:

        * image="pxe"
        """
        log.info('Creating PXE root filesystem image')
        self.filesystem.create()
        os.rename(
            self.filesystem.filename, self.image_name
        )
        self.image = self.image_name
        if self.compressed:
            log.info('xz compressing root filesystem image')
            compress = Compress(self.image)
            compress.xz(self.xz_options)
            self.image = compress.compressed_filename

        log.info('Creating PXE root filesystem MD5 checksum')
        self.filesystem_checksum = ''.join([self.image, '.md5'])
        checksum = Checksum(self.image)
        checksum.md5(self.filesystem_checksum)

        # prepare boot(initrd) root system
        log.info('Creating PXE boot image')
        self.boot_image_task.prepare()

        # export modprobe configuration to boot image
        self.system_setup.export_modprobe_setup(
            self.boot_image_task.boot_root_directory
        )

        # extract kernel from boot(initrd) root system
        kernel = Kernel(self.boot_image_task.boot_root_directory)
        kernel_data = kernel.get_kernel()
        if kernel_data:
            self.kernel_filename = ''.join(
                [
                    os.path.basename(self.image_name), '-',
                    kernel_data.version, '.kernel'
                ]
            )
            kernel.copy_kernel(
                self.target_dir, self.kernel_filename
            )
        else:
            raise KiwiPxeBootImageError(
                'No kernel in boot image tree %s found' %
                self.boot_image_task.boot_root_directory
            )

        # extract hypervisor from boot(initrd) root system
        if self.xen_server:
            kernel_data = kernel.get_xen_hypervisor()
            if kernel_data:
                self.hypervisor_filename = ''.join(
                    [os.path.basename(self.image_name), '-', kernel_data.name]
                )
                kernel.copy_xen_hypervisor(
                    self.target_dir, self.hypervisor_filename
                )
                self.result.add(
                    key='xen_hypervisor',
                    filename=self.target_dir + '/' + self.hypervisor_filename,
                    use_for_bundle=True,
                    compress=False,
                    shasum=True
                )
            else:
                raise KiwiPxeBootImageError(
                    'No hypervisor in boot image tree %s found' %
                    self.boot_image_task.boot_root_directory
                )

        # create initrd for pxe boot
        self.boot_image_task.create_initrd()

        # put results into a tarball
        Command.run(
            [
                'tar', '-C', self.target_dir, '-cJf', self.archive_name,
                self.kernel_filename,
                os.path.basename(self.boot_image_task.initrd_filename),
                os.path.basename(self.image),
                os.path.basename(self.filesystem_checksum)
            ]
        )

        # store results
        self.result.add(
            key='pxe_archive',
            filename=self.archive_name,
            use_for_bundle=True,
            compress=False,
            shasum=True
        )

        # create image root metadata
        self.result.add(
            key='image_packages',
            filename=self.system_setup.export_package_list(
                self.target_dir
            ),
            use_for_bundle=True,
            compress=False,
            shasum=False
        )
        self.result.add(
            key='image_verified',
            filename=self.system_setup.export_package_verification(
                self.target_dir
            ),
            use_for_bundle=True,
            compress=False,
            shasum=False
        )

        if self.pxedeploy:
            log.warning(
                'Creation of client config file from pxedeploy not implemented'
            )

        return self.result
Beispiel #32
0
 def setup(self):
     self.kernel = Kernel('root-dir')
Beispiel #33
0
class TestKernel(object):
    def setup(self):
        self.kernel = Kernel('root-dir')

    @patch('os.path.exists')
    @patch('kiwi.command.Command.run')
    def test_get_kernel(self, mock_run, mock_os):
        run = namedtuple(
            'run', ['output']
        )
        result = run(output='42')
        mock_os.return_value = True
        mock_run.return_value = result
        data = self.kernel.get_kernel()
        mock_run.assert_called_once_with(
            command=['kversion', 'root-dir/boot/vmlinux'],
            raise_on_error=False
        )
        assert data.filename == 'root-dir/boot/vmlinux'
        assert data.version == '42'

    @patch('os.path.exists')
    @patch('kiwi.command.Command.run')
    def test_get_kernel_no_version(self, mock_run, mock_os):
        run = namedtuple(
            'run', ['output']
        )
        result = run(output=None)
        mock_os.return_value = True
        mock_run.return_value = result
        data = self.kernel.get_kernel()
        mock_run.assert_called_once_with(
            command=['kversion', 'root-dir/boot/vmlinux'],
            raise_on_error=False
        )
        assert data.filename == 'root-dir/boot/vmlinux'
        assert data.version == 'no-version-found'

    @patch('os.path.exists')
    def test_get_xen_hypervisor(self, mock_os):
        mock_os.return_value = True
        data = self.kernel.get_xen_hypervisor()
        assert data.filename == 'root-dir/boot/xen.gz'
        assert data.name == 'xen.gz'

    @patch('kiwi.system.kernel.Kernel.get_kernel')
    @patch('kiwi.command.Command.run')
    def test_copy_kernel(self, mock_run, mock_get_kernel):
        result = mock.MagicMock()
        result.version = '42'
        result.filename = 'kernel'
        mock_get_kernel.return_value = result
        self.kernel.copy_kernel('target-dir')
        mock_run.assert_called_once_with(
            ['cp', 'kernel', 'target-dir/kernel-42.kernel']
        )

    @patch('kiwi.system.kernel.Kernel.get_xen_hypervisor')
    @patch('kiwi.command.Command.run')
    def test_copy_xen_hypervisor(self, mock_run, mock_get_xen):
        result = mock.MagicMock()
        result.name = 'xen.gz'
        result.filename = 'some/xen.gz'
        mock_get_xen.return_value = result
        self.kernel.copy_xen_hypervisor('target-dir')
        mock_run.assert_called_once_with(
            ['cp', 'some/xen.gz', 'target-dir/hypervisor-xen.gz']
        )
Beispiel #34
0
 def setup(self):
     self.kernel = Kernel('root-dir')
Beispiel #35
0
class TestKernel(object):
    @patch('os.listdir')
    def setup(self, mock_listdir):
        mock_listdir.return_value = ['1.2.3-default']
        self.kernel = Kernel('root-dir')
        assert self.kernel.kernel_names == [
            'vmlinux',
            'vmlinuz',
            'uImage-1.2.3-default',
            'Image-1.2.3-default',
            'zImage-1.2.3-default',
            'vmlinuz-1.2.3-default',
            'vmlinux-1.2.3-default',
            'image-1.2.3-default'
        ]

    @raises(KiwiKernelLookupError)
    def test_get_kernel_raises_if_no_kernel_found(self):
        self.kernel.kernel_names = []
        self.kernel.get_kernel(raise_on_not_found=True)

    @patch('os.path.exists')
    @patch('os.path.realpath')
    @patch('kiwi.command.Command.run')
    def test_get_kernel(self, mock_run, mock_realpath, mock_os):
        run = namedtuple(
            'run', ['output']
        )
        result = run(output='42')
        mock_os.return_value = True
        mock_run.return_value = result
        mock_realpath.return_value = 'vmlinux-realpath'
        data = self.kernel.get_kernel()
        mock_run.assert_called_once_with(
            command=['kversion', 'root-dir/boot/vmlinux'],
            raise_on_error=False
        )
        assert data.filename == 'root-dir/boot/vmlinux'
        assert data.version == '42'
        assert data.name == 'vmlinux-realpath'

    @patch('os.path.exists')
    @patch('os.path.realpath')
    @patch('kiwi.command.Command.run')
    def test_get_kernel_from_zImage(self, mock_run, mock_realpath, mock_os):
        self.kernel.kernel_names = ['zImage-1.2.3-default']
        run = namedtuple(
            'run', ['output']
        )
        result = run(output='42')
        mock_os.return_value = True
        mock_run.return_value = result
        mock_realpath.return_value = 'zImage-realpath'
        data = self.kernel.get_kernel()
        mock_run.assert_called_once_with(
            command=['kversion', 'root-dir/boot/vmlinux-1.2.3-default.gz'],
            raise_on_error=False
        )
        assert data.filename == 'root-dir/boot/zImage-1.2.3-default'
        assert data.version == '42'
        assert data.name == 'zImage-realpath'

    @patch('os.path.exists')
    @patch('kiwi.command.Command.run')
    def test_get_kernel_no_version(self, mock_run, mock_os):
        run = namedtuple(
            'run', ['output']
        )
        result = run(output=None)
        mock_os.return_value = True
        mock_run.return_value = result
        data = self.kernel.get_kernel()
        mock_run.assert_called_once_with(
            command=['kversion', 'root-dir/boot/vmlinux'],
            raise_on_error=False
        )
        assert data.filename == 'root-dir/boot/vmlinux'
        assert data.version == 'no-version-found'

    @patch('os.path.exists')
    def test_get_xen_hypervisor(self, mock_os):
        mock_os.return_value = True
        data = self.kernel.get_xen_hypervisor()
        assert data.filename == 'root-dir/boot/xen.gz'
        assert data.name == 'xen.gz'

    @patch('kiwi.system.kernel.Kernel.get_kernel')
    @patch('kiwi.command.Command.run')
    def test_copy_kernel(self, mock_run, mock_get_kernel):
        result = mock.MagicMock()
        result.version = '42'
        result.filename = 'kernel'
        mock_get_kernel.return_value = result
        self.kernel.copy_kernel('target-dir')
        mock_run.assert_called_once_with(
            ['cp', 'kernel', 'target-dir/kernel-42.kernel']
        )

    @patch('kiwi.system.kernel.Kernel.get_xen_hypervisor')
    @patch('kiwi.command.Command.run')
    def test_copy_xen_hypervisor(self, mock_run, mock_get_xen):
        result = mock.MagicMock()
        result.name = 'xen.gz'
        result.filename = 'some/xen.gz'
        mock_get_xen.return_value = result
        self.kernel.copy_xen_hypervisor('target-dir')
        mock_run.assert_called_once_with(
            ['cp', 'some/xen.gz', 'target-dir/hypervisor-xen.gz']
        )