示例#1
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'})
示例#2
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'})
示例#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
                                      })
示例#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})
示例#5
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))
示例#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.new('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()
示例#7
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
示例#8
0
 def test_disk_format_vhdx(self, mock_vhdx):
     DiskFormat.new('vhdx', self.xml_state, 'root_dir', 'target_dir')
     mock_vhdx.assert_called_once_with(self.xml_state, 'root_dir',
                                       'target_dir', {})
示例#9
0
 def test_disk_format_qcow2(self, mock_qcow2):
     DiskFormat.new('qcow2', self.xml_state, 'root_dir', 'target_dir')
     mock_qcow2.assert_called_once_with(self.xml_state, 'root_dir',
                                        'target_dir', {})
示例#10
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.new('vagrant', self.xml_state, 'root_dir', 'target_dir')
示例#11
0
 def test_format_not_implemented(self):
     with raises(KiwiDiskFormatSetupError):
         DiskFormat.new('foo', self.xml_state, 'root_dir', 'target_dir')
示例#12
0
 def test_disk_format_base(self, mock_base):
     DiskFormat.new('raw', self.xml_state, 'root_dir', 'target_dir')
     mock_base.assert_called_once_with(self.xml_state, 'root_dir',
                                       'target_dir', {})