From c253b38e210a82f3c1f0e4f0e07ac135ff0071e2 Mon Sep 17 00:00:00 2001 From: Tobias Urdin Date: Mon, 28 Nov 2022 15:16:55 +0000 Subject: Move CircularDependencyException to common Moves the exception from inside the engine code to the common code so that we can use it in the API fault middleware. Change-Id: I017b95153c358829501f6a5740918cdb005fb32f --- heat/common/exception.py | 4 ++++ heat/engine/dependencies.py | 7 +------ heat/tests/engine/test_dependencies.py | 12 ++++++------ heat/tests/engine/test_scheduler.py | 3 ++- heat/tests/test_validate.py | 3 +-- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/heat/common/exception.py b/heat/common/exception.py index ecb809eb5..c4184a69b 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -568,3 +568,7 @@ class InvalidTemplateVersions(HeatException): class UnableToAutoAllocateNetwork(HeatException): msg_fmt = _('Unable to automatically allocate a network: %(message)s') + + +class CircularDependencyException(HeatException): + msg_fmt = _("Circular Dependency Found: %(cycle)s") diff --git a/heat/engine/dependencies.py b/heat/engine/dependencies.py index b61dd578c..f4d085f93 100644 --- a/heat/engine/dependencies.py +++ b/heat/engine/dependencies.py @@ -15,11 +15,6 @@ import collections import itertools from heat.common import exception -from heat.common.i18n import _ - - -class CircularDependencyException(exception.HeatException): - msg_fmt = _("Circular Dependency Found: %(cycle)s") class Node(object): @@ -163,7 +158,7 @@ class Graph(collections.defaultdict): else: # There are nodes remaining, but none without # dependencies: a cycle - raise CircularDependencyException(cycle=str(graph)) + raise exception.CircularDependencyException(cycle=str(graph)) class Dependencies(object): diff --git a/heat/tests/engine/test_dependencies.py b/heat/tests/engine/test_dependencies.py index 7643232d4..588cc96e8 100644 --- a/heat/tests/engine/test_dependencies.py +++ b/heat/tests/engine/test_dependencies.py @@ -11,7 +11,7 @@ # License for the specific language governing permissions and limitations # under the License. - +from heat.common import exception from heat.engine import dependencies from heat.tests import common @@ -124,7 +124,7 @@ class dependenciesTest(common.HeatTestCase): d = dependencies.Dependencies([('first', 'second'), ('second', 'third'), ('third', 'first')]) - self.assertRaises(dependencies.CircularDependencyException, + self.assertRaises(exception.CircularDependencyException, list, iter(d)) @@ -132,13 +132,13 @@ class dependenciesTest(common.HeatTestCase): d = dependencies.Dependencies([('first', 'second'), ('second', 'third'), ('third', 'first')]) - self.assertRaises(dependencies.CircularDependencyException, + self.assertRaises(exception.CircularDependencyException, list, reversed(d)) def test_self_ref(self): d = dependencies.Dependencies([('node', 'node')]) - self.assertRaises(dependencies.CircularDependencyException, + self.assertRaises(exception.CircularDependencyException, list, iter(d)) @@ -147,7 +147,7 @@ class dependenciesTest(common.HeatTestCase): ('last', 'mid2'), ('mid1', 'e2'), ('mid1', 'mid3'), ('mid2', 'mid3'), ('mid3', 'e3'), ('e3', 'mid1')]) - self.assertRaises(dependencies.CircularDependencyException, + self.assertRaises(exception.CircularDependencyException, list, iter(d)) @@ -156,7 +156,7 @@ class dependenciesTest(common.HeatTestCase): ('last', 'mid2'), ('mid1', 'e2'), ('mid1', 'mid3'), ('mid2', 'mid3'), ('mid3', 'e3'), ('e3', 'mid1')]) - self.assertRaises(dependencies.CircularDependencyException, + self.assertRaises(exception.CircularDependencyException, list, reversed(d)) diff --git a/heat/tests/engine/test_scheduler.py b/heat/tests/engine/test_scheduler.py index 112d810a1..894c43263 100644 --- a/heat/tests/engine/test_scheduler.py +++ b/heat/tests/engine/test_scheduler.py @@ -17,6 +17,7 @@ from unittest import mock import eventlet +from heat.common import exception from heat.common import timeutils from heat.engine import dependencies from heat.engine import scheduler @@ -259,7 +260,7 @@ class DependencyTaskGroupTest(common.HeatTestCase): d = dependencies.Dependencies([('first', 'second'), ('second', 'third'), ('third', 'first')]) - self.assertRaises(dependencies.CircularDependencyException, + self.assertRaises(exception.CircularDependencyException, scheduler.DependencyTaskGroup, d) def test_aggregate_exceptions_raises_all_at_the_end(self): diff --git a/heat/tests/test_validate.py b/heat/tests/test_validate.py index a5521e435..f7a429cce 100644 --- a/heat/tests/test_validate.py +++ b/heat/tests/test_validate.py @@ -21,7 +21,6 @@ from heat.common.i18n import _ from heat.common import template_format from heat.common import urlfetch from heat.engine.clients.os import glance -from heat.engine import dependencies from heat.engine import environment from heat.engine.hot import template as hot_tmpl from heat.engine import resources @@ -2001,7 +2000,7 @@ parameter_groups: exc = self.assertRaises(dispatcher.ExpectedException, self.engine.validate_template, self.ctx, t, {}) - self.assertEqual(dependencies.CircularDependencyException, + self.assertEqual(exception.CircularDependencyException, exc.exc_info[0]) def test_validate_hot_parameter_tags_older(self): -- cgit v1.2.1