def test_wait_for_discovery_success(self): mock_discoverd = mock.Mock() self.node_uuids = [ 'NODE1', 'NODE2', ] mock_discoverd.get_status.return_value = { 'finished': True, 'error': None } result = utils.wait_for_node_discovery(mock_discoverd, "TOKEN", "URL", self.node_uuids, loops=4, sleep=0.01) self.assertEqual(list(result), [('NODE1', { 'error': None, 'finished': True }), ('NODE2', { 'error': None, 'finished': True })])
def test_wait_for_discovery_partial_success(self): mock_discoverd = mock.Mock() self.node_uuids = [ 'NODE1', 'NODE2', ] mock_discoverd.get_status.side_effect = [{ 'finished': True, 'error': None }, { 'finished': True, 'error': "Failed" }] result = utils.wait_for_node_discovery(mock_discoverd, "TOKEN", "URL", self.node_uuids, loops=4, sleep=0.01) self.assertEqual(list(result), [('NODE1', { 'error': None, 'finished': True }), ('NODE2', { 'error': "Failed", 'finished': True })])
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.rdomanager_oscplugin.baremetal() auth_token = self.app.client_manager.auth_ref.auth_token node_uuids = [] print("Setting available nodes to manageable...") self.log.debug("Moving available nodes to manageable state.") available_nodes = [node for node in client.node.list() if node.provision_state == "available"] for uuid in utils.set_nodes_state(client, available_nodes, 'manage', 'manageable'): self.log.debug("Node {0} has been set to manageable.".format(uuid)) for node in client.node.list(): node_uuids.append(node.uuid) print("Starting introspection of node: {0}".format(node.uuid)) discoverd_client.introspect( node.uuid, base_url=parsed_args.discoverd_url, auth_token=auth_token) # NOTE(dtantsur): PXE firmware on virtual machines misbehaves when # a lot of nodes start DHCPing simultaneously: it ignores NACK from # DHCP server, tries to get the same address, then times out. Work # around it by using sleep, anyway introspection takes much longer. time.sleep(5) print("Waiting for discovery to finish...") for uuid, status in utils.wait_for_node_discovery( discoverd_client, auth_token, parsed_args.discoverd_url, node_uuids): if status['error'] is None: print("Discovery for UUID {0} finished successfully." .format(uuid)) else: print("Discovery for UUID {0} finished with error: {1}" .format(uuid, status['error'])) clients = self.app.client_manager baremetal_client = clients.rdomanager_oscplugin.baremetal() print("Setting manageable nodes to available...") self.log.debug("Moving manageable nodes to available state.") available_nodes = [node for node in client.node.list() if node.provision_state == "manageable"] for uuid in utils.set_nodes_state( baremetal_client, baremetal_client.node.list(), 'provide', 'available', skipped_states=("available", "active")): print("Node {0} has been set to available.".format(uuid)) print("Discovery completed.")
def test_wait_for_discovery_timeout(self): mock_discoverd = mock.Mock() self.node_uuids = [ 'NODE1', 'NODE2', ] mock_discoverd.get_status.return_value = { 'finished': False, 'error': None } result = utils.wait_for_node_discovery(mock_discoverd, "TOKEN", "URL", self.node_uuids, loops=4, sleep=0.01) self.assertEqual(list(result), [])
def _run_introspection(self, nodes): auth_token = self.app.client_manager.auth_ref.auth_token node_uuids = [] for node in nodes: print("Starting introspection on node {0}".format(node.uuid)) discoverd_client.introspect(node.uuid, base_url=self.discoverd_url, auth_token=auth_token) node_uuids.append(node.uuid) print("Waiting for discovery to finish") for uuid, status in utils.wait_for_node_discovery( discoverd_client, auth_token, self.discoverd_url, node_uuids): if status['error'] is None: print("Discovery for node {0} finished successfully.".format( uuid)) else: print("Discovery for node {0} finished with error: {1}".format( uuid, status['error']))
def _run_introspection(self, nodes): auth_token = self.app.client_manager.auth_ref.auth_token node_uuids = [] for node in nodes: print("Starting introspection on node {0}".format(node.uuid)) discoverd_client.introspect( node.uuid, base_url=self.discoverd_url, auth_token=auth_token) node_uuids.append(node.uuid) print("Waiting for discovery to finish") for uuid, status in utils.wait_for_node_discovery( discoverd_client, auth_token, self.discoverd_url, node_uuids): if status['error'] is None: print("Discovery for node {0} finished successfully." .format(uuid)) else: print("Discovery for node {0} finished with error: {1}" .format(uuid, status['error']))
def test_wait_for_discovery_partial_success(self): mock_discoverd = mock.Mock() self.node_uuids = [ 'NODE1', 'NODE2', ] mock_discoverd.get_status.side_effect = [{ 'finished': True, 'error': None }, { 'finished': True, 'error': "Failed" }] result = utils.wait_for_node_discovery(mock_discoverd, "TOKEN", "URL", self.node_uuids, loops=4, sleep=0.01) self.assertEqual(list(result), [ ('NODE1', {'error': None, 'finished': True}), ('NODE2', {'error': "Failed", 'finished': True}) ])