Detect dependency cycle as soon as possible
This commit is contained in:
parent
2505023387
commit
edfaa65d2b
2 changed files with 123 additions and 4 deletions
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
from cdist import test
|
||||
from cdist import core
|
||||
|
|
@ -212,7 +211,7 @@ class ConfigRunTestCase(test.CdistTestCase):
|
|||
dryrun.run()
|
||||
# if we are here, dryrun works like expected
|
||||
|
||||
def test_desp_resolver(self):
|
||||
def test_deps_resolver(self):
|
||||
"""Test to show dependency resolver warning message."""
|
||||
local = cdist.exec.local.Local(
|
||||
target_host=self.target_host,
|
||||
|
|
@ -229,6 +228,71 @@ class ConfigRunTestCase(test.CdistTestCase):
|
|||
config = cdist.config.Config(local, self.remote, dry_run=True)
|
||||
config.run()
|
||||
|
||||
def test_graph_check_cycle_empty(self):
|
||||
graph = {}
|
||||
has_cycle, path = cdist.config.graph_check_cycle(graph)
|
||||
self.assertFalse(has_cycle)
|
||||
|
||||
def test_graph_check_cycle_1(self):
|
||||
#
|
||||
# a -> b -> c
|
||||
# |
|
||||
# +--> d -> e
|
||||
graph = {
|
||||
'a': ['b', ],
|
||||
'b': ['c', 'd', ],
|
||||
'd': ['e', ],
|
||||
}
|
||||
has_cycle, path = cdist.config.graph_check_cycle(graph)
|
||||
self.assertFalse(has_cycle)
|
||||
|
||||
def test_graph_check_cycle_2(self):
|
||||
#
|
||||
# a -> b -> c
|
||||
# /\ |
|
||||
# \ |
|
||||
# +-------+
|
||||
graph = {
|
||||
'a': ['b', ],
|
||||
'b': ['c', ],
|
||||
'c': ['a', ],
|
||||
}
|
||||
has_cycle, path = cdist.config.graph_check_cycle(graph)
|
||||
self.assertTrue(has_cycle)
|
||||
self.assertGreater(path.count(path[-1]), 1)
|
||||
|
||||
def test_graph_check_cycle_3(self):
|
||||
#
|
||||
# a -> b -> c
|
||||
# \ \
|
||||
# \ +--> g
|
||||
# \ /\
|
||||
# \ /|
|
||||
# +-> d -> e |
|
||||
# \ |
|
||||
# + --> f
|
||||
#
|
||||
# h -> i --> j
|
||||
# | /\ |
|
||||
# \/ | \/
|
||||
# n m <- k
|
||||
graph = {
|
||||
'a': ['b', 'd', ],
|
||||
'b': ['c', ],
|
||||
'c': ['g', ],
|
||||
'd': ['e', 'f', ],
|
||||
'e': ['g', ],
|
||||
'f': ['g', ],
|
||||
'h': ['i', 'n', ],
|
||||
'i': ['j', ],
|
||||
'j': ['k', ],
|
||||
'k': ['m', ],
|
||||
'm': ['i', ],
|
||||
}
|
||||
has_cycle, path = cdist.config.graph_check_cycle(graph)
|
||||
self.assertTrue(has_cycle)
|
||||
self.assertGreater(path.count(path[-1]), 1)
|
||||
|
||||
|
||||
# Currently the resolving code will simply detect that this object does
|
||||
# not exist. It should probably check if the type is a singleton as well
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue