From b0e61917d1a2c8dc81feb31cf623fd86761c5430 Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Mon, 19 Dec 2016 14:52:34 +0800 Subject: [PATCH] Fix node NotFound issue when getting an instance We should check whether an instance is really associate with a ironic node before issuing a request to get the node. Change-Id: Icd416107f486c285339edbdece104bf87ab72ba4 Closes-Bug: #1649767 --- nimble/api/controllers/v1/instances.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nimble/api/controllers/v1/instances.py b/nimble/api/controllers/v1/instances.py index 8fb5e134..7ef61860 100644 --- a/nimble/api/controllers/v1/instances.py +++ b/nimble/api/controllers/v1/instances.py @@ -310,7 +310,8 @@ class InstanceController(rest.RestController): node_list = [] if node_list: - node_dict = {node['instance_uuid']: node for node in node_list} + node_dict = {node['instance_uuid']: node for node in node_list + if node['instance_uuid']} # Merge nimble instance info with ironic node power state for instance_data in instances_data: uuid = instance_data['uuid'] @@ -348,9 +349,11 @@ class InstanceController(rest.RestController): """ rpc_instance = self._resource or self._get_resource(instance_uuid) instance_data = rpc_instance.as_dict() - if fields is None or 'power_state' in fields: + if (fields is None or 'power_state' in fields and + instance_data['node_uuid']): # Only fetch node info if fields parameter is not specified - # or node fields is not requested. + # or node fields is not requested and when instance is really + # associated with a ironic node. try: node = self.engine_api.get_ironic_node(pecan.request.context, instance_uuid,