def testLocateDeviceSuccess_MixedBuildsMultiBoards(self):
        """Test locate_device call can allocate devices by given builds for
        multiple boards.
        """
        serials = ['s1', 's2', 's3', 's4']
        testbed_1 = testbed.TestBed(adb_serials=serials)
        hosts = [
            self.mox.CreateMockAnything(),
            self.mox.CreateMockAnything(),
            self.mox.CreateMockAnything(),
            self.mox.CreateMockAnything()
        ]
        for i in [0, 1]:
            self.mox.StubOutWithMock(hosts[i], 'get_device_aliases')
            hosts[i].get_device_aliases().MultipleTimes().AndReturn([BOARD_1])
        for i in [2, 3]:
            self.mox.StubOutWithMock(hosts[i], 'get_device_aliases')
            hosts[i].get_device_aliases().MultipleTimes().AndReturn([BOARD_2])
        self.mox.StubOutWithMock(testbed_1, 'get_adb_devices')
        testbed_1.get_adb_devices().AndReturn(dict(zip(serials, hosts)))
        images = [(BOARD_1_BUILD_1, None), (BOARD_1_BUILD_1, None),
                  (BOARD_2_BUILD_1, None), (BOARD_2_BUILD_1, None)]
        self.mox.ReplayAll()

        devices = testbed_1.locate_devices(images)
        expected = dict(zip(serials[0:2], [BOARD_1_BUILD_1] * 2))
        expected.update(dict(zip(serials[2:], [BOARD_2_BUILD_1] * 2)))
        self.assertEqual(devices, expected)
Exemple #2
0
def create_testbed(machine, **kwargs):
    """Create the testbed object.

    @param machine: A dict representing the test bed under test or a String
                    representing the testbed hostname (for legacy caller
                    support).
                    If it is a machine dict, the 'hostname' key is required.
                    Optional 'afe_host' key will pipe in afe_host from
                    the afe_host object from the autoserv runtime or the AFE.
    @param kwargs: Keyword args to pass to the testbed initialization.

    @returns: The testbed object with all associated host objects instantiated.
    """
    detected_args = _get_host_arguments(machine)
    hostname = detected_args.pop('hostname')
    kwargs.update(detected_args)
    return testbed.TestBed(hostname, **kwargs)
def create_testbed(machine, **kwargs):
    """Create the testbed object.

    @param machine: A dict representing the test bed under test or a String
                    representing the testbed hostname (for legacy caller
                    support).
                    If it is a machine dict, the 'hostname' key is required.
                    Optional 'host_attributes' key will pipe in host_attributes
                    from the autoserv runtime or the AFE.
    @param kwargs: Keyword args to pass to the testbed initialization.

    @returns: The testbed object with all associated host objects instantiated.
    """
    hostname, host_attributes = server_utils.get_host_info_from_machine(
        machine)
    kwargs['host_attributes'] = host_attributes
    return testbed.TestBed(hostname, **kwargs)
    def testLocateDeviceSuccess_SingleBuild(self):
        """Test locate_device call can allocate devices by given builds.
        """
        serials = ['s1', 's2', 's3']
        testbed_1 = testbed.TestBed(adb_serials=serials)
        hosts = [
            self.mox.CreateMockAnything(),
            self.mox.CreateMockAnything(),
            self.mox.CreateMockAnything()
        ]
        for host in hosts:
            self.mox.StubOutWithMock(host, 'get_device_aliases')
            host.get_device_aliases().MultipleTimes().AndReturn([BOARD_1])
        self.mox.StubOutWithMock(testbed_1, 'get_adb_devices')
        testbed_1.get_adb_devices().AndReturn(dict(zip(serials, hosts)))
        images = [(BOARD_1_BUILD_1, None)] * 3
        self.mox.ReplayAll()

        devices = testbed_1.locate_devices(images)
        self.assertEqual(devices, dict(zip(serials, [BOARD_1_BUILD_1] * 3)))
    def testLocateDeviceFail_TooManyBuilds(self):
        """Test locate_device call cannot allocate devices by given builds.

        If the given builds are more than the number of devices the testbed has,
        it should fail to locate devices for the test.
        """
        serials = ['s1', 's2', 's3']
        testbed_1 = testbed.TestBed(adb_serials=serials)
        hosts = [
            self.mox.CreateMockAnything(),
            self.mox.CreateMockAnything(),
            self.mox.CreateMockAnything()
        ]
        for host in hosts:
            self.mox.StubOutWithMock(host, 'get_device_aliases')
            host.get_device_aliases().MultipleTimes().AndReturn([BOARD_1])
        self.mox.StubOutWithMock(testbed_1, 'get_adb_devices')
        testbed_1.get_adb_devices().AndReturn(dict(zip(serials, hosts)))
        # Request 4 images but the testbed has only 3 duts.
        images = [(BOARD_1_BUILD_1, None)] * 4
        self.mox.ReplayAll()

        self.assertRaises(error.InstallError, testbed_1.locate_devices, images)
    def testLocateDeviceSuccess_MixedBuildsSingleBoard(self):
        """Test locate_device call can allocate devices by given builds.

        If the given builds are the same and the number of duts required is
        less than the number of devices the testbed has, it should return all
        devices with the same build.
        """
        serials = ['s1', 's2', 's3']
        testbed_1 = testbed.TestBed(adb_serials=serials)
        hosts = [
            self.mox.CreateMockAnything(),
            self.mox.CreateMockAnything(),
            self.mox.CreateMockAnything()
        ]
        for host in hosts:
            self.mox.StubOutWithMock(host, 'get_device_aliases')
            host.get_device_aliases().MultipleTimes().AndReturn([BOARD_1])
        self.mox.StubOutWithMock(testbed_1, 'get_adb_devices')
        testbed_1.get_adb_devices().AndReturn(dict(zip(serials, hosts)))
        images = [(BOARD_1_BUILD_1, None), (BOARD_1_BUILD_1, None)]
        self.mox.ReplayAll()

        devices = testbed_1.locate_devices(images)
        self.assertEqual(devices, dict(zip(serials, [BOARD_1_BUILD_1] * 3)))