class TestDeviceProvider(object):
    def setup(self):
        self.provider = DeviceProvider()

    @raises(KiwiDeviceProviderError)
    def test_get_device(self):
        self.provider.get_device()

    @patch('kiwi.storage.device_provider.Command.run')
    def test_get_uuid(self, mock_command):
        uuid_call = mock.Mock()
        uuid_call.output = '0815\n'
        mock_command.return_value = uuid_call
        assert self.provider.get_uuid('/dev/some-device') == '0815'
        mock_command.assert_called_once_with(
            ['blkid', '/dev/some-device', '-s', 'UUID', '-o', 'value']
        )

    @patch('kiwi.storage.device_provider.Command.run')
    def test_get_byte_size(self, mock_command):
        blockdev_call = mock.Mock()
        blockdev_call.output = '1024\n'
        mock_command.return_value = blockdev_call
        assert self.provider.get_byte_size('/dev/some-device') == 1024
        mock_command.assert_called_once_with(
            ['blockdev', '--getsize64', '/dev/some-device']
        )

    def test_is_loop(self):
        assert self.provider.is_loop() is False
예제 #2
0
class TestDeviceProvider:
    def setup(self):
        self.provider = DeviceProvider()

    def setup_method(self, cls):
        self.setup()

    def test_get_device(self):
        with raises(KiwiDeviceProviderError):
            self.provider.get_device()

    @patch('kiwi.storage.device_provider.Command.run')
    def test_get_uuid(self, mock_command):
        uuid_call = Mock()
        uuid_call.output = '0815\n'
        mock_command.return_value = uuid_call
        assert self.provider.get_uuid('/dev/some-device') == '0815'
        mock_command.assert_called_once_with(
            ['blkid', '/dev/some-device', '-s', 'UUID', '-o', 'value'])

    @patch('kiwi.storage.device_provider.Command.run')
    def test_get_byte_size(self, mock_command):
        blockdev_call = Mock()
        blockdev_call.output = '1024\n'
        mock_command.return_value = blockdev_call
        assert self.provider.get_byte_size('/dev/some-device') == 1024
        mock_command.assert_called_once_with(
            ['blockdev', '--getsize64', '/dev/some-device'])

    def test_is_loop(self):
        assert self.provider.is_loop() is False
예제 #3
0
    def write_to_disk(self, device_provider: DeviceProvider) -> None:
        """
        Write current hex identifier to MBR at offset 0x1b8 on disk

        :param object device_provider: Instance based on DeviceProvider
        """
        if self.image_id:
            packed_id = struct.pack('<I', int(self.image_id, 16))
            with open(device_provider.get_device(), 'wb') as disk:
                disk.seek(440, 0)
                disk.write(packed_id)
예제 #4
0
    def __init__(self,
                 disk_provider: DeviceProvider,
                 start_sector: int = None,
                 extended_layout: bool = False) -> None:
        """
        Base class constructor for partitioners

        :param object disk_provider: Instance of DeviceProvider
        :param int start_sector: sector number
        :param bool extended_layout:
            If set to true and on msdos table type when creating
            more than 4 partitions, this will cause the fourth
            partition to be an extended partition and all following
            partitions will be placed as logical partitions inside
            of that extended partition
        """
        self.disk_device = disk_provider.get_device()
        self.partition_id = 0
        self.start_sector = start_sector
        self.extended_layout = extended_layout

        self.flag_map: Dict[str, Union[bool, str, None]] = {}

        self.post_init()