Define a new InstanceNotMapped exception

In get_node_by_instance_uuid, an exception ComputeNodeNotFound
will be thrown if can't find a node through instance uuid.
But the exception information replaces the node name with
instance uuid, which is misleading, so we define a new exception.

Closes-Bug: #1832156

Change-Id: Ic6c44ae44da7c3b9a1c20e9b24a036063af266ba
This commit is contained in:
licanwei 2019-06-06 14:42:40 +08:00
parent 6495e42a60
commit a4d978b893
3 changed files with 8 additions and 3 deletions

View File

@ -447,6 +447,11 @@ class InstanceNotFound(ComputeResourceNotFound):
msg_fmt = _("The instance '%(name)s' could not be found") msg_fmt = _("The instance '%(name)s' could not be found")
class InstanceNotMapped(ComputeResourceNotFound):
msg_fmt = _("The mapped compute node for instance '%(uuid)s' "
"could not be found.")
class ComputeNodeNotFound(ComputeResourceNotFound): class ComputeNodeNotFound(ComputeResourceNotFound):
msg_fmt = _("The compute node %(name)s could not be found") msg_fmt = _("The compute node %(name)s could not be found")

View File

@ -170,7 +170,7 @@ class ModelRoot(nx.DiGraph, base.Model):
node = self._get_by_uuid(node_uuid) node = self._get_by_uuid(node_uuid)
if isinstance(node, element.ComputeNode): if isinstance(node, element.ComputeNode):
return node return node
raise exception.ComputeNodeNotFound(name=instance_uuid) raise exception.InstanceNotMapped(uuid=instance_uuid)
@lockutils.synchronized("model_root") @lockutils.synchronized("model_root")
def get_all_instances(self): def get_all_instances(self):
@ -211,7 +211,7 @@ class ModelRoot(nx.DiGraph, base.Model):
key=lambda inst: inst.uuid): key=lambda inst: inst.uuid):
try: try:
self.get_node_by_instance_uuid(instance.uuid) self.get_node_by_instance_uuid(instance.uuid)
except (exception.InstanceNotFound, exception.ComputeNodeNotFound): except exception.ComputeResourceNotFound:
root.append(instance.as_xml_element()) root.append(instance.as_xml_element())
return etree.tostring(root, pretty_print=True).decode('utf-8') return etree.tostring(root, pretty_print=True).decode('utf-8')

View File

@ -160,7 +160,7 @@ class NovaNotification(base.NotificationEndpoint):
current_node = ( current_node = (
self.cluster_data_model.get_node_by_instance_uuid( self.cluster_data_model.get_node_by_instance_uuid(
instance.uuid)) instance.uuid))
except exception.ComputeNodeNotFound as exc: except exception.ComputeResourceNotFound as exc:
LOG.exception(exc) LOG.exception(exc)
# If we can't create the node, # If we can't create the node,
# we consider the instance as unmapped # we consider the instance as unmapped