Ejemplo n.º 1
0
 def test_disk_format_gce(self, mock_gce):
     self.xml_state.build_type.get_gcelicense = Mock(
         return_value='gce_license_tag')
     DiskFormat.new('gce', self.xml_state, 'root_dir', 'target_dir')
     mock_gce.assert_called_once_with(self.xml_state, 'root_dir',
                                      'target_dir',
                                      {'--tag': 'gce_license_tag'})
Ejemplo n.º 2
0
 def test_disk_format_vhdfixed(self, mock_vhdfixed):
     self.xml_state.build_type.get_vhdfixedtag = Mock(
         return_value='disk-tag')
     DiskFormat.new('vhd-fixed', self.xml_state, 'root_dir', 'target_dir')
     mock_vhdfixed.assert_called_once_with(self.xml_state, 'root_dir',
                                           'target_dir',
                                           {'--tag': 'disk-tag'})
Ejemplo n.º 3
0
 def test_disk_format_ova(self, mock_ova):
     vmdisk = Mock()
     vmdisk.get_controller = Mock(return_value='controller')
     vmdisk.get_diskmode = Mock(return_value='disk-mode')
     self.xml_state.get_build_type_vmdisk_section = Mock(
         return_value=vmdisk)
     DiskFormat.new('ova', self.xml_state, 'root_dir', 'target_dir')
     mock_ova.assert_called_once_with(self.xml_state, 'root_dir',
                                      'target_dir', {
                                          'adapter_type=controller': None,
                                          'subformat=disk-mode': None
                                      })
Ejemplo n.º 4
0
 def test_disk_format_vagrant_libvirt(self, mock_vagrant_libvirt,
                                      mock_vagrant_virt_box):
     for provider_name, provider_mock in (('libvirt', mock_vagrant_libvirt),
                                          ('virtualbox',
                                           mock_vagrant_virt_box)):
         vagrant_config = Mock()
         vagrant_config.get_provider = Mock(return_value=provider_name)
         self.xml_state.get_build_type_vagrant_config_section = Mock(
             return_value=vagrant_config)
         DiskFormat.new('vagrant', self.xml_state, 'root_dir', 'target_dir')
         provider_mock.assert_called_once_with(
             self.xml_state, 'root_dir', 'target_dir',
             {'vagrantconfig': vagrant_config})
Ejemplo n.º 5
0
    def create_disk_format(self, result_instance):
        """
        Create a bootable disk format from a previously
        created raw disk image
        """
        if self.image_format:
            log.info('Creating %s Disk Format', self.image_format)
            disk_format = DiskFormat(
                self.image_format, self.xml_state,
                self.root_dir, self.target_dir
            )
            disk_format.create_image_format()
            disk_format.store_to_result(result_instance)

        return result_instance
Ejemplo n.º 6
0
 def append_unpartitioned_space(self):
     """
     Extends the raw disk if an unpartitioned area is specified
     """
     if self.unpartitioned_bytes:
         log.info('Expanding disk with %d bytes of unpartitioned space',
                  self.unpartitioned_bytes)
         disk_format = DiskFormat('raw', self.xml_state, self.root_dir,
                                  self.target_dir)
         disk_format.resize_raw_disk(self.unpartitioned_bytes, append=True)
         firmware = FirmWare(self.xml_state)
         loop_provider = LoopDevice(disk_format.diskname)
         loop_provider.create(overwrite=False)
         partitioner = Partitioner(firmware.get_partition_table_type(),
                                   loop_provider)
         partitioner.resize_table()
Ejemplo n.º 7
0
 def test_disk_format_vagrant_not_implemented(self):
     self.xml_state.get_build_type_vagrant_config_section = mock.Mock(
         return_value=None
     )
     DiskFormat(
         'vagrant', self.xml_state, 'root_dir', 'target_dir'
     )
Ejemplo n.º 8
0
 def test_disk_format_vagrant_not_implemented(self):
     self.xml_state.get_build_type_vagrant_config_section = Mock(
         return_value=None
     )
     with raises(KiwiDiskFormatSetupError):
         DiskFormat(
             'vagrant', self.xml_state, 'root_dir', 'target_dir'
         )
Ejemplo n.º 9
0
 def test_disk_format_vagrant_libvirt(self, mock_vagrant):
     vagrant_config = mock.Mock()
     vagrant_config.get_provider = mock.Mock(return_value='libvirt')
     self.xml_state.get_build_type_vagrant_config_section = mock.Mock(
         return_value=vagrant_config)
     DiskFormat('vagrant', self.xml_state, 'root_dir', 'target_dir')
     mock_vagrant.assert_called_once_with(self.xml_state, 'root_dir',
                                          'target_dir',
                                          {'vagrantconfig': vagrant_config})
Ejemplo n.º 10
0
 def append_unpartitioned_space(self):
     """
     Extends the raw disk if an unpartitioned area is specified
     """
     if self.unpartitioned_bytes:
         log.info(
             'Expanding disk with %d bytes of unpartitioned space',
             self.unpartitioned_bytes
         )
         disk_format = DiskFormat(
             'raw', self.xml_state, self.root_dir, self.target_dir
         )
         disk_format.resize_raw_disk(self.unpartitioned_bytes, append=True)
         firmware = FirmWare(self.xml_state)
         loop_provider = LoopDevice(disk_format.diskname)
         loop_provider.create(overwrite=False)
         partitioner = Partitioner(
             firmware.get_partition_table_type(), loop_provider
         )
         partitioner.resize_table()
Ejemplo n.º 11
0
    def create_disk_format(self, result_instance):
        """
        Create a bootable disk format from a previously
        created raw disk image

        :param object result_instance: instance of :class:`Result`

        :return: updated result_instance

        :rtype: instance of :class:`Result`
        """
        if self.image_format:
            log.info('Creating %s Disk Format', self.image_format)
            disk_format = DiskFormat(
                self.image_format, self.xml_state,
                self.root_dir, self.target_dir
            )
            disk_format.create_image_format()
            disk_format.store_to_result(result_instance)

        return result_instance
Ejemplo n.º 12
0
    def process(self):
        """
        reformats raw disk image and its format to a new disk
        geometry using the qemu tool chain
        """
        self.manual = Help()
        if self.command_args.get('help') is True:
            return self.manual.show('kiwi::image::resize')

        abs_target_dir_path = os.path.abspath(
            self.command_args['--target-dir'])

        if self.command_args['--root']:
            image_root = os.path.abspath(
                os.path.normpath(self.command_args['--root']))
        else:
            image_root = os.sep.join(
                [abs_target_dir_path, 'build', 'image-root'])

        self.load_xml_description(image_root)

        disk_format = self.xml_state.build_type.get_format()

        image_format = DiskFormat.new(disk_format or 'raw', self.xml_state,
                                      image_root, abs_target_dir_path)
        if not image_format.has_raw_disk():
            raise KiwiImageResizeError(
                'no raw disk image {0} found in build results'.format(
                    image_format.diskname))

        new_disk_size = StringToSize.to_bytes(self.command_args['--size'])

        # resize raw disk
        log.info('Resizing raw disk to {0} bytes'.format(new_disk_size))
        resize_result = image_format.resize_raw_disk(new_disk_size)

        # resize raw disk partition table
        firmware = FirmWare(self.xml_state)
        loop_provider = LoopDevice(image_format.diskname)
        loop_provider.create(overwrite=False)
        partitioner = Partitioner(firmware.get_partition_table_type(),
                                  loop_provider)
        partitioner.resize_table()
        del loop_provider

        # resize disk format from resized raw disk
        if disk_format and resize_result is True:
            log.info('Creating {0} disk format from resized raw disk'.format(
                disk_format))
            image_format.create_image_format()
        elif resize_result is False:
            log.info('Raw disk is already at {0} bytes'.format(new_disk_size))
Ejemplo n.º 13
0
 def test_disk_format_vmdk(self, mock_vmdk):
     xml_state = mock.Mock()
     vmdisk = mock.Mock()
     vmdisk.get_controller = mock.Mock(
         return_value='controller'
     )
     vmdisk.get_diskmode = mock.Mock(
         return_value='disk-mode'
     )
     xml_state.get_build_type_vmdisk_section = mock.Mock(
         return_value=vmdisk
     )
     DiskFormat('vmdk', xml_state, 'root_dir', 'target_dir')
     mock_vmdk.assert_called_once_with(
         xml_state, 'root_dir', 'target_dir',
         {'adapter_type=controller': None, 'subformat=disk-mode': None}
     )
Ejemplo n.º 14
0
    def create_disk_format(self, result_instance):
        """
        Create a bootable disk format from a previously
        created raw disk image
        """
        if self.image_format:
            log.info('Creating %s Disk Format', self.image_format)
            disk_format = DiskFormat(self.image_format, self.xml_state,
                                     self.root_dir, self.target_dir)
            disk_format.create_image_format()
            disk_format.store_to_result(result_instance)

        return result_instance
Ejemplo n.º 15
0
    def create_disk_format(self, result_instance):
        """
        Create a bootable disk format from a previously
        created raw disk image

        :param object result_instance: instance of :class:`Result`

        :return: updated result_instance

        :rtype: instance of :class:`Result`
        """
        if self.image_format:
            log.info('Creating %s Disk Format', self.image_format)
            disk_format = DiskFormat.new(self.image_format, self.xml_state,
                                         self.root_dir, self.target_dir)
            disk_format.create_image_format()
            disk_format.store_to_result(result_instance)

        return result_instance
Ejemplo n.º 16
0
    def process(self):
        """
        reformats raw disk image and its format to a new disk
        geometry using the qemu tool chain
        """
        self.manual = Help()
        if self.command_args.get('help') is True:
            return self.manual.show('kiwi::image::resize')

        abs_target_dir_path = os.path.abspath(
            self.command_args['--target-dir'])

        if self.command_args['--root']:
            image_root = os.path.abspath(
                os.path.normpath(self.command_args['--root']))
        else:
            image_root = os.sep.join(
                [abs_target_dir_path, 'build', 'image-root'])

        self.load_xml_description(image_root)

        disk_format = self.xml_state.build_type.get_format()

        image_format = DiskFormat(disk_format or 'raw', self.xml_state,
                                  image_root, abs_target_dir_path)
        if not image_format.has_raw_disk():
            raise KiwiImageResizeError(
                'no raw disk image {0} found in build results'.format(
                    image_format.diskname))

        new_disk_size = self._to_bytes(self.command_args['--size'])

        log.info('Resizing raw disk to {0} bytes'.format(new_disk_size))
        resize_result = image_format.resize_raw_disk(new_disk_size)
        if disk_format and resize_result is True:
            log.info('Creating {0} disk format from resized raw disk'.format(
                disk_format))
            image_format.create_image_format()
        elif resize_result is False:
            log.info('Raw disk is already at {0} bytes'.format(new_disk_size))
Ejemplo n.º 17
0
 def test_format_not_implemented(self):
     with raises(KiwiDiskFormatSetupError):
         DiskFormat('foo', self.xml_state, 'root_dir', 'target_dir')
Ejemplo n.º 18
0
 def test_disk_format_vhdx(self, mock_vhdx):
     DiskFormat('vhdx', self.xml_state, 'root_dir', 'target_dir')
     mock_vhdx.assert_called_once_with(
         self.xml_state, 'root_dir', 'target_dir', {}
     )
Ejemplo n.º 19
0
    def process(self):
        """
        reformats raw disk image and its format to a new disk
        geometry using the qemu tool chain
        """
        self.manual = Help()
        if self.command_args.get('help') is True:
            return self.manual.show('kiwi::image::resize')

        abs_target_dir_path = os.path.abspath(
            self.command_args['--target-dir']
        )

        if self.command_args['--root']:
            image_root = os.path.abspath(
                os.path.normpath(self.command_args['--root'])
            )
        else:
            image_root = os.sep.join(
                [abs_target_dir_path, 'build', 'image-root']
            )

        self.load_xml_description(
            image_root
        )

        disk_format = self.xml_state.build_type.get_format()

        image_format = DiskFormat(
            disk_format or 'raw', self.xml_state, image_root,
            abs_target_dir_path
        )
        if not image_format.has_raw_disk():
            raise KiwiImageResizeError(
                'no raw disk image {0} found in build results'.format(
                    image_format.diskname
                )
            )

        new_disk_size = StringToSize.to_bytes(self.command_args['--size'])

        # resize raw disk
        log.info(
            'Resizing raw disk to {0} bytes'.format(new_disk_size)
        )
        resize_result = image_format.resize_raw_disk(new_disk_size)

        # resize raw disk partition table
        firmware = FirmWare(self.xml_state)
        loop_provider = LoopDevice(image_format.diskname)
        loop_provider.create(overwrite=False)
        partitioner = Partitioner(
            firmware.get_partition_table_type(), loop_provider
        )
        partitioner.resize_table()
        del loop_provider

        # resize disk format from resized raw disk
        if disk_format and resize_result is True:
            log.info(
                'Creating {0} disk format from resized raw disk'.format(
                    disk_format
                )
            )
            image_format.create_image_format()
        elif resize_result is False:
            log.info(
                'Raw disk is already at {0} bytes'.format(new_disk_size)
            )
Ejemplo n.º 20
0
 def test_format_not_implemented(self):
     DiskFormat('foo', mock.Mock(), 'root_dir', 'target_dir')
Ejemplo n.º 21
0
 def test_disk_format_base(self, mock_base):
     DiskFormat('raw', self.xml_state, 'root_dir', 'target_dir')
     mock_base.assert_called_once_with(
         self.xml_state, 'root_dir', 'target_dir', {}
     )
Ejemplo n.º 22
0
 def test_format_not_implemented(self):
     DiskFormat('foo', self.xml_state, 'root_dir', 'target_dir')
Ejemplo n.º 23
0
 def test_disk_format_vhd(self, mock_vhd):
     xml_state = mock.Mock()
     DiskFormat('vhd', xml_state, 'root_dir', 'target_dir')
     mock_vhd.assert_called_once_with(
         xml_state, 'root_dir', 'target_dir'
     )
Ejemplo n.º 24
0
 def test_disk_format_qcow2(self, mock_qcow2):
     DiskFormat('qcow2', self.xml_state, 'root_dir', 'target_dir')
     mock_qcow2.assert_called_once_with(
         self.xml_state, 'root_dir', 'target_dir', {}
     )
Ejemplo n.º 25
0
 def test_disk_format_base(self, mock_base):
     xml_state = mock.Mock()
     DiskFormat('raw', xml_state, 'root_dir', 'target_dir')
     mock_base.assert_called_once_with(
         xml_state, 'root_dir', 'target_dir',
     )
Ejemplo n.º 26
0
 def test_disk_format_qcow2(self, mock_qcow2):
     xml_state = mock.Mock()
     DiskFormat('qcow2', xml_state, 'root_dir', 'target_dir')
     mock_qcow2.assert_called_once_with(
         xml_state, 'root_dir', 'target_dir'
     )
Ejemplo n.º 27
0
 def test_disk_format_vhd(self, mock_vhd):
     DiskFormat.new('vhd', self.xml_state, 'root_dir', 'target_dir')
     mock_vhd.assert_called_once_with(self.xml_state, 'root_dir',
                                      'target_dir', {})