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
This commit is contained in:
Tobias Urdin 2022-11-28 15:16:55 +00:00 committed by Tobias Urdin
parent 604111b0ba
commit c253b38e21
5 changed files with 14 additions and 15 deletions

View File

@ -568,3 +568,7 @@ class InvalidTemplateVersions(HeatException):
class UnableToAutoAllocateNetwork(HeatException): class UnableToAutoAllocateNetwork(HeatException):
msg_fmt = _('Unable to automatically allocate a network: %(message)s') msg_fmt = _('Unable to automatically allocate a network: %(message)s')
class CircularDependencyException(HeatException):
msg_fmt = _("Circular Dependency Found: %(cycle)s")

View File

@ -15,11 +15,6 @@ import collections
import itertools import itertools
from heat.common import exception from heat.common import exception
from heat.common.i18n import _
class CircularDependencyException(exception.HeatException):
msg_fmt = _("Circular Dependency Found: %(cycle)s")
class Node(object): class Node(object):
@ -163,7 +158,7 @@ class Graph(collections.defaultdict):
else: else:
# There are nodes remaining, but none without # There are nodes remaining, but none without
# dependencies: a cycle # dependencies: a cycle
raise CircularDependencyException(cycle=str(graph)) raise exception.CircularDependencyException(cycle=str(graph))
class Dependencies(object): class Dependencies(object):

View File

@ -11,7 +11,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from heat.common import exception
from heat.engine import dependencies from heat.engine import dependencies
from heat.tests import common from heat.tests import common
@ -124,7 +124,7 @@ class dependenciesTest(common.HeatTestCase):
d = dependencies.Dependencies([('first', 'second'), d = dependencies.Dependencies([('first', 'second'),
('second', 'third'), ('second', 'third'),
('third', 'first')]) ('third', 'first')])
self.assertRaises(dependencies.CircularDependencyException, self.assertRaises(exception.CircularDependencyException,
list, list,
iter(d)) iter(d))
@ -132,13 +132,13 @@ class dependenciesTest(common.HeatTestCase):
d = dependencies.Dependencies([('first', 'second'), d = dependencies.Dependencies([('first', 'second'),
('second', 'third'), ('second', 'third'),
('third', 'first')]) ('third', 'first')])
self.assertRaises(dependencies.CircularDependencyException, self.assertRaises(exception.CircularDependencyException,
list, list,
reversed(d)) reversed(d))
def test_self_ref(self): def test_self_ref(self):
d = dependencies.Dependencies([('node', 'node')]) d = dependencies.Dependencies([('node', 'node')])
self.assertRaises(dependencies.CircularDependencyException, self.assertRaises(exception.CircularDependencyException,
list, list,
iter(d)) iter(d))
@ -147,7 +147,7 @@ class dependenciesTest(common.HeatTestCase):
('last', 'mid2'), ('mid1', 'e2'), ('last', 'mid2'), ('mid1', 'e2'),
('mid1', 'mid3'), ('mid2', 'mid3'), ('mid1', 'mid3'), ('mid2', 'mid3'),
('mid3', 'e3'), ('e3', 'mid1')]) ('mid3', 'e3'), ('e3', 'mid1')])
self.assertRaises(dependencies.CircularDependencyException, self.assertRaises(exception.CircularDependencyException,
list, list,
iter(d)) iter(d))
@ -156,7 +156,7 @@ class dependenciesTest(common.HeatTestCase):
('last', 'mid2'), ('mid1', 'e2'), ('last', 'mid2'), ('mid1', 'e2'),
('mid1', 'mid3'), ('mid2', 'mid3'), ('mid1', 'mid3'), ('mid2', 'mid3'),
('mid3', 'e3'), ('e3', 'mid1')]) ('mid3', 'e3'), ('e3', 'mid1')])
self.assertRaises(dependencies.CircularDependencyException, self.assertRaises(exception.CircularDependencyException,
list, list,
reversed(d)) reversed(d))

View File

@ -17,6 +17,7 @@ from unittest import mock
import eventlet import eventlet
from heat.common import exception
from heat.common import timeutils from heat.common import timeutils
from heat.engine import dependencies from heat.engine import dependencies
from heat.engine import scheduler from heat.engine import scheduler
@ -259,7 +260,7 @@ class DependencyTaskGroupTest(common.HeatTestCase):
d = dependencies.Dependencies([('first', 'second'), d = dependencies.Dependencies([('first', 'second'),
('second', 'third'), ('second', 'third'),
('third', 'first')]) ('third', 'first')])
self.assertRaises(dependencies.CircularDependencyException, self.assertRaises(exception.CircularDependencyException,
scheduler.DependencyTaskGroup, d) scheduler.DependencyTaskGroup, d)
def test_aggregate_exceptions_raises_all_at_the_end(self): def test_aggregate_exceptions_raises_all_at_the_end(self):

View File

@ -21,7 +21,6 @@ from heat.common.i18n import _
from heat.common import template_format from heat.common import template_format
from heat.common import urlfetch from heat.common import urlfetch
from heat.engine.clients.os import glance from heat.engine.clients.os import glance
from heat.engine import dependencies
from heat.engine import environment from heat.engine import environment
from heat.engine.hot import template as hot_tmpl from heat.engine.hot import template as hot_tmpl
from heat.engine import resources from heat.engine import resources
@ -2001,7 +2000,7 @@ parameter_groups:
exc = self.assertRaises(dispatcher.ExpectedException, exc = self.assertRaises(dispatcher.ExpectedException,
self.engine.validate_template, self.engine.validate_template,
self.ctx, t, {}) self.ctx, t, {})
self.assertEqual(dependencies.CircularDependencyException, self.assertEqual(exception.CircularDependencyException,
exc.exc_info[0]) exc.exc_info[0])
def test_validate_hot_parameter_tags_older(self): def test_validate_hot_parameter_tags_older(self):