mere tests of autorequire and resolver into execution_order
Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
parent
782d84870d
commit
ae8040536f
30 changed files with 91 additions and 91 deletions
179
cdist/test/execution_order/__init__.py
Normal file
179
cdist/test/execution_order/__init__.py
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
# cdist is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# cdist is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
import cdist
|
||||
from cdist import test
|
||||
from cdist import core
|
||||
from cdist import resolver
|
||||
|
||||
import os.path as op
|
||||
my_dir = op.abspath(op.dirname(__file__))
|
||||
fixtures = op.join(my_dir, 'fixtures')
|
||||
object_base_path = op.join(fixtures, 'object')
|
||||
type_base_path = op.join(fixtures, 'type')
|
||||
|
||||
|
||||
class ResolverTestCase(test.CdistTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.objects = list(core.CdistObject.list_objects(object_base_path, type_base_path))
|
||||
self.object_index = dict((o.name, o) for o in self.objects)
|
||||
self.dependency_resolver = resolver.DependencyResolver(self.objects)
|
||||
|
||||
def tearDown(self):
|
||||
for o in self.objects:
|
||||
o.requirements = []
|
||||
|
||||
def test_find_requirements_by_name_string(self):
|
||||
requirements = ['__first/man', '__second/on-the', '__third/moon']
|
||||
required_objects = [self.object_index[name] for name in requirements]
|
||||
self.assertEqual(sorted(list(self.dependency_resolver.find_requirements_by_name(requirements))),
|
||||
sorted(required_objects))
|
||||
|
||||
def test_find_requirements_by_name_pattern(self):
|
||||
requirements = ['__first/*', '__second/*-the', '__third/moon']
|
||||
requirements_expanded = [
|
||||
'__first/child', '__first/dog', '__first/man', '__first/woman',
|
||||
'__second/on-the', '__second/under-the',
|
||||
'__third/moon'
|
||||
]
|
||||
required_objects = [self.object_index[name] for name in requirements_expanded]
|
||||
self.assertEqual(sorted(list(self.dependency_resolver.find_requirements_by_name(requirements))),
|
||||
sorted(required_objects))
|
||||
|
||||
def test_dependency_resolution(self):
|
||||
first_man = self.object_index['__first/man']
|
||||
second_on_the = self.object_index['__second/on-the']
|
||||
third_moon = self.object_index['__third/moon']
|
||||
first_man.requirements = [second_on_the.name]
|
||||
second_on_the.requirements = [third_moon.name]
|
||||
self.assertEqual(
|
||||
self.dependency_resolver.dependencies['__first/man'],
|
||||
[third_moon, second_on_the, first_man]
|
||||
)
|
||||
|
||||
def test_circular_reference(self):
|
||||
first_man = self.object_index['__first/man']
|
||||
first_woman = self.object_index['__first/woman']
|
||||
first_man.requirements = [first_woman.name]
|
||||
first_woman.requirements = [first_man.name]
|
||||
with self.assertRaises(resolver.CircularReferenceError):
|
||||
self.dependency_resolver.dependencies
|
||||
|
||||
def test_requirement_not_found(self):
|
||||
first_man = self.object_index['__first/man']
|
||||
first_man.requirements = ['__does/not/exist']
|
||||
with self.assertRaises(cdist.Error):
|
||||
self.dependency_resolver.dependencies
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
# cdist is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# cdist is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
import cdist
|
||||
from cdist import test
|
||||
from cdist.exec import local
|
||||
from cdist import core
|
||||
from cdist.core import manifest
|
||||
from cdist import resolver
|
||||
from cdist import config
|
||||
import cdist.context
|
||||
|
||||
import os.path as op
|
||||
my_dir = op.abspath(op.dirname(__file__))
|
||||
fixtures = op.join(my_dir, 'fixtures')
|
||||
add_conf_dir = op.join(fixtures, 'conf')
|
||||
|
||||
class AutorequireTestCase(test.CdistTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.orig_environ = os.environ
|
||||
os.environ = os.environ.copy()
|
||||
self.temp_dir = self.mkdtemp()
|
||||
|
||||
self.out_dir = os.path.join(self.temp_dir, "out")
|
||||
self.remote_out_dir = os.path.join(self.temp_dir, "remote")
|
||||
|
||||
os.environ['__cdist_out_dir'] = self.out_dir
|
||||
os.environ['__cdist_remote_out_dir'] = self.remote_out_dir
|
||||
|
||||
self.context = cdist.context.Context(
|
||||
target_host=self.target_host,
|
||||
remote_copy=self.remote_copy,
|
||||
remote_exec=self.remote_exec,
|
||||
add_conf_dirs=[add_conf_dir],
|
||||
exec_path=test.cdist_exec_path,
|
||||
debug=False)
|
||||
|
||||
self.config = config.Config(self.context)
|
||||
|
||||
def tearDown(self):
|
||||
os.environ = self.orig_environ
|
||||
shutil.rmtree(self.temp_dir)
|
||||
|
||||
def test_implicit_dependencies(self):
|
||||
self.context.initial_manifest = os.path.join(self.context.local.manifest_path, 'implicit_dependencies')
|
||||
self.config.stage_prepare()
|
||||
|
||||
objects = core.CdistObject.list_objects(self.context.local.object_path, self.context.local.type_path)
|
||||
dependency_resolver = resolver.DependencyResolver(objects)
|
||||
expected_dependencies = [
|
||||
dependency_resolver.objects['__package_special/b'],
|
||||
dependency_resolver.objects['__package/b'],
|
||||
dependency_resolver.objects['__package_special/a']
|
||||
]
|
||||
resolved_dependencies = dependency_resolver.dependencies['__package_special/a']
|
||||
self.assertEqual(resolved_dependencies, expected_dependencies)
|
||||
|
||||
def test_circular_dependency(self):
|
||||
self.context.initial_manifest = os.path.join(self.context.local.manifest_path, 'circular_dependency')
|
||||
self.config.stage_prepare()
|
||||
# raises CircularDependecyError
|
||||
self.config.stage_run()
|
||||
|
||||
def test_recursive_type(self):
|
||||
self.context.initial_manifest = os.path.join(self.config.local.manifest_path, 'recursive_type')
|
||||
self.config.stage_prepare()
|
||||
# raises CircularDependecyError
|
||||
self.config.stage_run()
|
||||
0
cdist/test/execution_order/fixtures/conf/explorer/.keep
Normal file
0
cdist/test/execution_order/fixtures/conf/explorer/.keep
Normal file
2
cdist/test/execution_order/fixtures/conf/manifest/circular_dependency
Executable file
2
cdist/test/execution_order/fixtures/conf/manifest/circular_dependency
Executable file
|
|
@ -0,0 +1,2 @@
|
|||
# this has triggered CircularReferenceError
|
||||
__nfsroot_client test
|
||||
3
cdist/test/execution_order/fixtures/conf/manifest/implicit_dependencies
Executable file
3
cdist/test/execution_order/fixtures/conf/manifest/implicit_dependencies
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
# this creates implicit dependencies through autorequire.
|
||||
# this failed because autorequired dependencies where not aware of their anchestors dependencies
|
||||
__top test
|
||||
2
cdist/test/execution_order/fixtures/conf/manifest/recursive_type
Executable file
2
cdist/test/execution_order/fixtures/conf/manifest/recursive_type
Executable file
|
|
@ -0,0 +1,2 @@
|
|||
__git foo
|
||||
require="__git/foo" __git bar
|
||||
|
|
@ -0,0 +1 @@
|
|||
__package git
|
||||
3
cdist/test/execution_order/fixtures/conf/type/__nfsroot_client/manifest
Executable file
3
cdist/test/execution_order/fixtures/conf/type/__nfsroot_client/manifest
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
__user root
|
||||
__root_ssh_authorized_key john
|
||||
__root_ssh_authorized_key frank
|
||||
1
cdist/test/execution_order/fixtures/conf/type/__package/manifest
Executable file
1
cdist/test/execution_order/fixtures/conf/type/__package/manifest
Executable file
|
|
@ -0,0 +1 @@
|
|||
__package_special "$__object_id"
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
user="$__object_id"
|
||||
__directory /root/.ssh
|
||||
require="__directory/root/.ssh" \
|
||||
__addifnosuchline "ssh-root-$user"
|
||||
2
cdist/test/execution_order/fixtures/conf/type/__top/manifest
Executable file
2
cdist/test/execution_order/fixtures/conf/type/__top/manifest
Executable file
|
|
@ -0,0 +1,2 @@
|
|||
__package b
|
||||
require="__package/b" __package a
|
||||
0
cdist/test/execution_order/fixtures/object/__first/.keep
Normal file
0
cdist/test/execution_order/fixtures/object/__first/.keep
Normal file
0
cdist/test/execution_order/fixtures/object/__third/.keep
Normal file
0
cdist/test/execution_order/fixtures/object/__third/.keep
Normal file
|
|
@ -0,0 +1 @@
|
|||
Prometheus
|
||||
|
|
@ -0,0 +1 @@
|
|||
Saturn
|
||||
0
cdist/test/execution_order/fixtures/type/__first/.keep
Normal file
0
cdist/test/execution_order/fixtures/type/__first/.keep
Normal file
0
cdist/test/execution_order/fixtures/type/__second/.keep
Normal file
0
cdist/test/execution_order/fixtures/type/__second/.keep
Normal file
0
cdist/test/execution_order/fixtures/type/__third/.keep
Normal file
0
cdist/test/execution_order/fixtures/type/__third/.keep
Normal file
Loading…
Add table
Add a link
Reference in a new issue