Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
    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