示例#1
0
    def test_handles_timeout(self):
        node, power_info = yield deferToDatabase(
            self.make_node_with_power_info)

        def defer_way_later(*args, **kwargs):
            # Create a defer that will finish in 1 minute.
            return deferLater(reactor, 60 * 60, lambda: None)

        rack_id = factory.make_name("system_id")
        client = Mock()
        client.ident = rack_id
        client.side_effect = defer_way_later

        self.patch(power_module, "getAllClients").return_value = [client]
        power_state, success_racks, failed_racks = yield power_query_all(
            node.system_id, node.hostname, power_info, timeout=0.5)

        self.assertEqual(POWER_STATE.UNKNOWN, power_state)
        self.assertItemsEqual([], success_racks)
        self.assertItemsEqual([rack_id], failed_racks)
示例#2
0
    def test__calls_PowerQuery_on_all_clients(self):
        node, power_info = yield deferToDatabase(
            self.make_node_with_power_info)

        successful_rack_ids = [
            factory.make_name("system_id") for _ in range(3)
        ]
        error_rack_ids = [factory.make_name("system_id") for _ in range(3)]
        failed_rack_ids = [factory.make_name("system_id") for _ in range(3)]
        clients = []
        power_states = []
        for rack_id in successful_rack_ids:
            power_state = random.choice([POWER_STATE.ON, POWER_STATE.OFF])
            power_states.append(power_state)
            client = Mock()
            client.ident = rack_id
            client.return_value = succeed({
                "state": power_state,
            })
            clients.append(client)
        for rack_id in error_rack_ids:
            client = Mock()
            client.ident = rack_id
            client.return_value = succeed({
                "state": POWER_STATE.ERROR,
            })
            clients.append(client)
        for rack_id in failed_rack_ids:
            client = Mock()
            client.ident = rack_id
            client.return_value = fail(factory.make_exception())
            clients.append(client)

        self.patch(power_module, "getAllClients").return_value = clients
        power_state, success_racks, failed_racks = yield power_query_all(
            node.system_id, node.hostname, power_info)

        self.assertEqual(pick_best_power_state(power_states), power_state)
        self.assertItemsEqual(successful_rack_ids, success_racks)
        self.assertItemsEqual(error_rack_ids + failed_rack_ids, failed_racks)