示例#1
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
示例#2
0
    def GetDeviceData(self, name: Str) -> Structure:
        """Get the device data.

        :param name: a device name
        :return: a structure with device data
        :raise: UnknownDeviceError if the device is not found
        """
        return DeviceData.to_structure(self.implementation.get_device_data(name))
示例#3
0
    def GetDeviceData(self, name: Str) -> Structure:
        """Get the device data.

        :param name: a device name
        :return: a structure with device data
        :raise: UnknownDeviceError if the device is not found
        """
        return DeviceData.to_structure(self.implementation.get_device_data(name))
示例#4
0
    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()
示例#5
0
    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."
示例#7
0
    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")
示例#8
0
        def _find_device_by_name(name):
            for dev in devices:
                if dev.name == name:
                    return DeviceData.to_structure(dev)

            return None