Пример #1
0
    def test_inter_alloc_suc_w_two_hw_allocatable_dev_one_has_unusable_serial(
            self, mock_logging, mock_dutdetection):
        # Test with two devices, both are allocatable, but the serial port for first is unusable
        dutdetect = mock.Mock()  # DutDetection instance mock
        mock_dutdetection.return_value = dutdetect
        mock_dutdetection.is_port_usable = mock.MagicMock(
            side_effect=iter([False, True]))

        devices = [{
            "state": "unknown",
            "platform_name": "K64F",
            "target_id": "ABCDEFG12345",
            "serial_port": "/dev/serial"
        }, {
            "state": "unknown",
            "platform_name": "K64F",
            "target_id": "ABCDEFG12345",
            "serial_port": "/dev/serial"
        }]
        dutdetect.get_available_devices = mock.MagicMock(return_value=devices)

        alloc = LocalAllocator()
        dut = ResourceRequirements({"type": "hardware"})
        mfunc = mock.MagicMock()
        mfunc.get_dut_configuration = mock.MagicMock()
        mfunc.get_dut_configuration.return_value = [dut]
        self.assertEqual(len(alloc.allocate(mfunc)), 1)
        self.assertEqual(mock_dutdetection.is_port_usable.call_count, 2)
Пример #2
0
    def test_inter_alloc_suc_one_hardware_device_with_undef_allowed_platf(
            self, mock_logging, mock_dutdetection):
        # Allocation should succeed if no allowed_platform defined in dut configuration,
        # and devices are available
        dutdetect = mock.Mock()  # DutDetection instance mock
        mock_dutdetection.return_value = dutdetect
        mock_dutdetection.is_port_usable = mock.MagicMock(return_value=True)

        device = {
            "state": "unknown",
            "platform_name": "K64F",
            "target_id": "ABCDEFG12345",
            "serial_port": "/dev/serial"
        }
        dutdetect.get_available_devices = mock.MagicMock(return_value=[device])

        alloc = LocalAllocator()
        dut = ResourceRequirements({"type": "hardware"})
        mfunc = mock.MagicMock()
        mfunc.get_dut_configuration = mock.MagicMock()
        mfunc.get_dut_configuration.return_value = [dut]
        self.assertEqual(len(alloc.allocate(mfunc)), 1)

        dutdetect.get_available_devices.assert_called_once_with()

        # Test correct format of resulting dut configuration
        mock_dutdetection.is_port_usable.assert_called_once_with(
            device["serial_port"])
Пример #3
0
 def test_internal_allocate_non_hardware_types_success_without_dutfactory(
         self, mock_logging, mock_dutdetection):
     alloc = LocalAllocator()
     dut = ResourceRequirements({"type": "process"})
     mfunc = mock.MagicMock()
     mfunc.get_dut_configuration = mock.MagicMock()
     mfunc.get_dut_configuration.return_value = [dut]
     self.assertTrue(alloc.allocate(mfunc))
Пример #4
0
    def test_can_allocate_unknown_type(self, mock_logging, mock_dutdetection):
        dutdetect = mock.Mock()
        mock_dutdetection.return_value = dutdetect
        dutdetect.get_available_devices = mock.MagicMock(return_value=None)

        alloc = LocalAllocator()
        data_unknown_type = {"type": "unknown"}
        self.assertFalse(alloc.can_allocate(data_unknown_type))

        mock_dutdetection.assert_not_called()
        dutdetect.get_available_devices.assert_not_called()

        data_unknown_type = {"type": None}
        self.assertFalse(alloc.can_allocate(data_unknown_type))
Пример #5
0
    def test_alloc_twice_suc_when_two_dev_available(self, mock_logging,
                                                    mock_dutdetection):
        # Test with two devices, both are allocatable, but the serial port for first is unusable
        dutdetect = mock.Mock()  # DutDetection instance mock
        mock_dutdetection.return_value = dutdetect
        mock_dutdetection.is_port_usable = mock.MagicMock(return_value=True)

        devices = [{
            "state": "unknown",
            "platform_name": "K64F",
            "target_id": "1234",
            "serial_port": "/dev/serial1"
        }, {
            "state": "unknown",
            "platform_name": "K64F",
            "target_id": "5678",
            "serial_port": "/dev/serial2"
        }]
        dutdetect.get_available_devices = mock.MagicMock(return_value=devices)

        alloc = LocalAllocator()
        duts = [
            ResourceRequirements({
                "type": "hardware",
                "allowed_platforms": ["K64F"]
            }),
            ResourceRequirements({
                "type": "hardware",
                "allowed_platforms": ["K64F"]
            })
        ]
        mfunc = mock.MagicMock()
        mfunc.get_dut_configuration = mock.MagicMock()
        mfunc.get_dut_configuration.return_value = duts
        self.assertEqual(len(alloc.allocate(mfunc)), 2)

        # Result of first dut allocation
        resultingdut1 = duts[0]
        resultingdevice1 = devices[0]
        resultingdevice1["state"] = "allocated"
        resultingdut1.set("allocated", resultingdevice1)
        # Result of second dut allocation
        resultingdut2 = duts[1]
        resultingdevice2 = devices[1]
        resultingdevice2["state"] = "allocated"
        resultingdut2.set("allocated", resultingdevice2)
        mock_dutdetection.is_port_usable.assert_has_calls([
            mock.call(resultingdevice1["serial_port"]),
            mock.call(resultingdevice2["serial_port"])
        ])
Пример #6
0
 def test_allocate_raises_devices_not_available(self, mock_logging,
                                                mock_dutdetection):
     detected = [1]
     mock_dutdetection.get_available_devices = mock.MagicMock(
         return_value=detected)
     alloc = LocalAllocator()
     mfunc = mock.MagicMock()
     mfunc.get_dut_configuration = mock.MagicMock()
     mfunc.get_dut_configuration.return_value = [{
         "type": "hardware"
     }, {
         "type": "hardware"
     }]
     with self.assertRaises(AllocationError):
         alloc.allocate(mfunc)
Пример #7
0
    def test_internal_allocate_non_hardware_types_success(
            self, mock_logging, mock_dutdetection):
        dutdetect = mock.Mock()
        mock_dutdetection.return_value = dutdetect
        dutdetect.get_available_devices = mock.MagicMock(return_value=None)

        alloc = LocalAllocator()
        dut = ResourceRequirements({"type": "process"})
        mfunc = mock.MagicMock()
        mfunc.get_dut_configuration = mock.MagicMock()
        mfunc.get_dut_configuration.return_value = [dut]
        self.assertTrue(alloc.allocate(mfunc))

        mock_dutdetection.assert_not_called()
        dutdetect.get_available_devices.assert_not_called()
Пример #8
0
 def test_allocate_raises_on_invalid_dut_format(self, mock_logging,
                                                mock_dutdetection):
     alloc = LocalAllocator()
     mfunc = mock.MagicMock()
     mfunc.get_dut_configuration = mock.MagicMock()
     mfunc.get_dut_configuration.return_value = "Not a list"
     self.assertRaises(AllocationError, alloc.allocate, mfunc)
Пример #9
0
    def test_alloc_fail_w_two_hw_allocatable_dev_both_already_allocated(
            self, mock_logging, mock_dutdetection):
        # Allocation should raise AllocationError if no unallocated devices
        dutdetect = mock.Mock()  # DutDetection instance mock
        mock_dutdetection.return_value = dutdetect
        mfunc = mock.MagicMock()
        mfunc.get_dut_configuration = mock.MagicMock()
        mfunc.get_dut_configuration.return_value = [
            ResourceRequirements({"type": "hardware"})
        ]
        devices = [{
            "state": "allocated",
            "platform_name": "K64F",
            "target_id": "ABCDEFG12345",
            "serial_port": "/dev/serial"
        }, {
            "state": "allocated",
            "platform_name": "K64F",
            "target_id": "ABCDEFG12345",
            "serial_port": "/dev/serial"
        }]
        dutdetect.get_available_devices = mock.MagicMock(return_value=devices)

        alloc = LocalAllocator()
        self.assertRaises(AllocationError, alloc.allocate, mfunc)
Пример #10
0
    def test_internal_allocate_hardware_platform_no_devices_raises_error(
            self, mock_logging, mock_dutdetection):
        dutdetect = mock.Mock()
        mock_dutdetection.return_value = dutdetect
        dutdetect.get_available_devices = mock.MagicMock(return_value=None)

        alloc = LocalAllocator()
        self.assertRaises(AllocationError, alloc._allocate,
                          {"type": "hardware"})
Пример #11
0
    def test_init_with_no_logger(self, mock_logging, mock_dutdetection):
        dutdetect = mock.Mock()
        mock_dutdetection.return_value = dutdetect
        dutdetect.get_available_devices = mock.MagicMock(return_value=None)
        mock_logger = mock.Mock()
        mock_logging.get_logger = mock.MagicMock(return_value=mock_logger)
        mock_logging.NullHandler = mock.MagicMock()

        LocalAllocator()

        mock_dutdetection.assert_not_called()
        dutdetect.get_available_devices.assert_not_called()
        mock_logging.assert_called_once_with("LocalAllocator", "LAL")
Пример #12
0
    def test_inter_alloc_suc_w_two_hw_allocatabl_dev_w_match_platf_one_alloc(
            self, mock_logging, mock_dutdetection):
        # Test with two devices, both are allocatable, but the serial port for first is unusable
        dutdetect = mock.Mock()  # DutDetection instance mock
        mock_dutdetection.return_value = dutdetect
        mock_dutdetection.is_port_usable = mock.MagicMock(return_value=True)

        dut = ResourceRequirements({
            "type": "hardware",
            "allowed_platforms": ["K64F"]
        })
        devices = [{
            "state": "allocated",
            "platform_name": "K64F",
            "target_id": "ABCDEFG12345",
            "serial_port": "/dev/serial1"
        }, {
            "state": "unknown",
            "platform_name": "K64F",
            "target_id": "ABCDEFG12345",
            "serial_port": "/dev/serial2"
        }]
        dutdetect.get_available_devices = mock.MagicMock(return_value=devices)

        alloc = LocalAllocator()
        # Test correct format of resulting dut configuration
        mfunc = mock.MagicMock()
        mfunc.get_dut_configuration = mock.MagicMock()
        mfunc.get_dut_configuration.return_value = [dut]
        self.assertEqual(len(alloc.allocate(mfunc)), 1)

        resultingdut = dut
        resultingdevice = devices[1]
        resultingdevice["state"] = "allocated"
        resultingdut.set("allocated", resultingdevice)

        mock_dutdetection.is_port_usable.assert_called_once_with(
            resultingdevice["serial_port"])
Пример #13
0
 def test_can_allocate_missing_type(self, mock_logging, mock_dutdetection):
     alloc = LocalAllocator()
     data_no_type = {"notype": None}
     self.assertFalse(alloc.can_allocate(data_no_type))
Пример #14
0
 def test_can_allocate_success(self, mock_logging, mock_dutdetection):
     alloc = LocalAllocator()
     data1 = {"type": "hardware"}
     self.assertTrue(alloc.can_allocate(data1))
Пример #15
0
 def test_local_allocator_release(self, mock_logging, mock_dutdetection):
     alloc = LocalAllocator()
     alloc.release()
Пример #16
0
 def test_internal_allocate_no_type_raises(self, mock_logging,
                                           mock_dutdetection):
     alloc = LocalAllocator()
     data = {"notype": None}
     self.assertRaises(KeyError, alloc._allocate, data)