From a4d978b8932e00f149b4fe432b4ba912de3e498b Mon Sep 17 00:00:00 2001 From: licanwei Date: Thu, 6 Jun 2019 14:42:40 +0800 Subject: [PATCH] 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 --- watcher/common/exception.py | 5 +++++ watcher/decision_engine/model/model_root.py | 4 ++-- watcher/decision_engine/model/notification/nova.py | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/watcher/common/exception.py b/watcher/common/exception.py index f962b3bbe..dcb489ec9 100644 --- a/watcher/common/exception.py +++ b/watcher/common/exception.py @@ -447,6 +447,11 @@ class InstanceNotFound(ComputeResourceNotFound): 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): msg_fmt = _("The compute node %(name)s could not be found") diff --git a/watcher/decision_engine/model/model_root.py b/watcher/decision_engine/model/model_root.py index ad85bdd9c..1845638de 100644 --- a/watcher/decision_engine/model/model_root.py +++ b/watcher/decision_engine/model/model_root.py @@ -170,7 +170,7 @@ class ModelRoot(nx.DiGraph, base.Model): node = self._get_by_uuid(node_uuid) if isinstance(node, element.ComputeNode): return node - raise exception.ComputeNodeNotFound(name=instance_uuid) + raise exception.InstanceNotMapped(uuid=instance_uuid) @lockutils.synchronized("model_root") def get_all_instances(self): @@ -211,7 +211,7 @@ class ModelRoot(nx.DiGraph, base.Model): key=lambda inst: inst.uuid): try: self.get_node_by_instance_uuid(instance.uuid) - except (exception.InstanceNotFound, exception.ComputeNodeNotFound): + except exception.ComputeResourceNotFound: root.append(instance.as_xml_element()) return etree.tostring(root, pretty_print=True).decode('utf-8') diff --git a/watcher/decision_engine/model/notification/nova.py b/watcher/decision_engine/model/notification/nova.py index a2254275e..5c885bd14 100644 --- a/watcher/decision_engine/model/notification/nova.py +++ b/watcher/decision_engine/model/notification/nova.py @@ -160,7 +160,7 @@ class NovaNotification(base.NotificationEndpoint): current_node = ( self.cluster_data_model.get_node_by_instance_uuid( instance.uuid)) - except exception.ComputeNodeNotFound as exc: + except exception.ComputeResourceNotFound as exc: LOG.exception(exc) # If we can't create the node, # we consider the instance as unmapped