def get_device_data(self, name): """Get the device data. :param name: a device name :return: an instance of DeviceData :raise: UnknownDeviceError if the device is not found """ # Find the device. device = self._get_device(name) # Collect the device data. data = DeviceData() data.type = device.type data.name = device.name data.path = device.path data.size = device.size.get_bytes() data.parents = [d.name for d in device.parents] data.is_disk = device.is_disk # Get the device description. # FIXME: We should generate the description from the device data. data.description = getattr(device, "description", "") # Collect the additional attributes. attrs = self._get_attributes(device, DeviceData.SUPPORTED_ATTRIBUTES) data.attrs = attrs return data
def get_device_data(self, name): """Get the device data. :param name: a device name :return: an instance of DeviceData :raise: UnknownDeviceError if the device is not found """ # Find the device. device = self._get_device(name) if not device: raise UnknownDeviceError(name) # Collect the device data. data = DeviceData() data.type = device.type data.name = device.name data.path = device.path data.size = device.size.get_bytes() data.is_disk = device.is_disk # Collect the additional attributes. attrs = self._get_device_attrs(device) data.attrs = attrs return data
def set_up_device_tree(num_cdroms): """Set up a mock device tree with a specified amount of CD-ROMs. Mocks FindOpticalMedia() and GetDeviceData() suitable for testing SetUpCdromSourceTask.run() :param int num_cdroms: Amount od CD-ROMs :return: mock for the device tree :rtype: unittest.mock.Mock """ devices = [] for n in range(num_cdroms): device = DeviceData() device.name = "test{}".format(n) device.path = "/dev/cdrom-test{}".format(n) devices.append(device) device_tree = Mock() device_tree.FindOpticalMedia = Mock() device_tree.FindOpticalMedia.return_value = [dev.name for dev in devices] device_tree.GetDeviceData = Mock() device_tree.GetDeviceData.side_effect = [DeviceData.to_structure(dev) for dev in devices] return device_tree
def setup_install_source_task_failed_to_mount_test(self, proxy_getter, os_stat, stat, mount): """Test Live OS setup installation source task mount error.""" device_tree = Mock() proxy_getter.return_value = device_tree device_tree.ResolveDevice = Mock() device_tree.ResolveDevice.return_value = "resolvedDeviceName" device = DeviceData() device.path = "/resolved/path/to/base/image" device_tree.GetDeviceData = Mock() device_tree.GetDeviceData.return_value = get_native(DeviceData.to_structure(device)) mount.return_value = -20 with self.assertRaises(SourceSetupError): SetupInstallationSourceTask( "/path/to/base/image", "/path/to/mount/source/image" ).run()
def test_setup_install_source_task_invalid_block_dev( self, proxy_getter, os_stat, stat_mock): """Test Live OS Source setup installation source task with invalid block device error.""" device_tree = Mock() proxy_getter.return_value = device_tree device_tree.ResolveDevice = Mock() device_tree.ResolveDevice.return_value = "resolvedDeviceName" device = DeviceData() device.path = "/resolved/path/to/base/image" device_tree.GetDeviceData = Mock() device_tree.GetDeviceData.return_value = DeviceData.to_structure( device) stat_mock.S_ISBLK = Mock() stat_mock.S_ISBLK.return_value = False with pytest.raises(SourceSetupError): SetUpLiveOSSourceTask("/path/to/base/image", "/path/to/mount/source/image").run()
def test_setup_install_source_task_failed_to_mount(self, proxy_getter, os_stat, stat, mount): """Test Live OS Source setup installation source task mount error.""" device_tree = Mock() proxy_getter.return_value = device_tree device_tree.ResolveDevice = Mock() device_tree.ResolveDevice.return_value = "dev1" device = DeviceData() device.path = "/dev/dev1" device_tree.GetDeviceData = Mock() device_tree.GetDeviceData.return_value = DeviceData.to_structure( device) mount.return_value = -20 with pytest.raises(SourceSetupError) as cm: SetUpLiveOSSourceTask("/path/to/base/image", "/path/to/mount/source/image").run() assert str(cm.value) == "Failed to mount the Live OS image."
def setup_install_source_task_test(self, proxy_getter, os_stat, stat, mount): """Test Live OS setup installation source task.""" device_tree = Mock() proxy_getter.return_value = device_tree device_tree.ResolveDevice = Mock() device_tree.ResolveDevice.return_value = "resolvedDeviceName" device = DeviceData() device.path = "/resolved/path/to/base/image" device_tree.GetDeviceData = Mock() device_tree.GetDeviceData.return_value = get_native(DeviceData.to_structure(device)) mount.return_value = 0 SetupInstallationSourceTask( "/path/to/base/image", "/path/to/mount/source/image" ).run() device_tree.ResolveDevice.assert_called_once_with("/path/to/base/image") os_stat.assert_called_once_with("/resolved/path/to/base/image")