Save output streams.
This commit is contained in:
parent
13a13eee03
commit
00cd5fa91e
19 changed files with 450 additions and 110 deletions
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||
# 2010-2017 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||
# 2012-2015 Nico Schottelius (nico-cdist at schottelius.org)
|
||||
# 2014 Daniel Heule (hda at sfs.biz)
|
||||
#
|
||||
|
|
@ -45,6 +45,19 @@ expected_object_names = sorted([
|
|||
'__third/moon'])
|
||||
|
||||
|
||||
class CdistObjectErrorContext(object):
|
||||
def __init__(self, original_error):
|
||||
self.original_error = original_error
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, tb):
|
||||
if exc_type is not None:
|
||||
if exc_value.original_error:
|
||||
raise exc_value.original_error
|
||||
|
||||
|
||||
class ConfigRunTestCase(test.CdistTestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
@ -87,7 +100,9 @@ class ConfigRunTestCase(test.CdistTestCase):
|
|||
target_host=self.target_host,
|
||||
remote_copy=self.remote_copy,
|
||||
remote_exec=self.remote_exec,
|
||||
base_path=self.remote_dir)
|
||||
base_path=self.remote_dir,
|
||||
stdout_base_path=self.local.stdout_base_path,
|
||||
stderr_base_path=self.local.stderr_base_path)
|
||||
|
||||
self.local.object_path = self.object_base_path
|
||||
self.local.type_path = type_base_path
|
||||
|
|
@ -102,6 +117,20 @@ class ConfigRunTestCase(test.CdistTestCase):
|
|||
os.environ = self.orig_environ
|
||||
shutil.rmtree(self.temp_dir)
|
||||
|
||||
def assertRaisesCdistObjectError(self, original_error, callable_obj):
|
||||
"""
|
||||
Test if a raised CdistObjectError was caused by the given
|
||||
original_error.
|
||||
"""
|
||||
with self.assertRaises(original_error):
|
||||
try:
|
||||
callable_obj()
|
||||
except cdist.CdistObjectError as e:
|
||||
if e.original_error:
|
||||
raise e.original_error
|
||||
else:
|
||||
raise
|
||||
|
||||
def test_dependency_resolution(self):
|
||||
first = self.object_index['__first/man']
|
||||
second = self.object_index['__second/on-the']
|
||||
|
|
@ -137,29 +166,33 @@ class ConfigRunTestCase(test.CdistTestCase):
|
|||
first.requirements = [second.name]
|
||||
second.requirements = [first.name]
|
||||
|
||||
with self.assertRaises(cdist.UnresolvableRequirementsError):
|
||||
self.config.iterate_until_finished()
|
||||
self.assertRaisesCdistObjectError(
|
||||
cdist.UnresolvableRequirementsError,
|
||||
self.config.iterate_until_finished)
|
||||
|
||||
def test_missing_requirements(self):
|
||||
"""Throw an error if requiring something non-existing"""
|
||||
first = self.object_index['__first/man']
|
||||
first.requirements = ['__first/not/exist']
|
||||
with self.assertRaises(cdist.UnresolvableRequirementsError):
|
||||
self.config.iterate_until_finished()
|
||||
self.assertRaisesCdistObjectError(
|
||||
cdist.UnresolvableRequirementsError,
|
||||
self.config.iterate_until_finished)
|
||||
|
||||
def test_requirement_broken_type(self):
|
||||
"""Unknown type should be detected in the resolving process"""
|
||||
first = self.object_index['__first/man']
|
||||
first.requirements = ['__nosuchtype/not/exist']
|
||||
with self.assertRaises(cdist.core.cdist_type.InvalidTypeError):
|
||||
self.config.iterate_until_finished()
|
||||
self.assertRaisesCdistObjectError(
|
||||
cdist.core.cdist_type.NoSuchTypeError,
|
||||
self.config.iterate_until_finished)
|
||||
|
||||
def test_requirement_singleton_where_no_singleton(self):
|
||||
"""Missing object id should be detected in the resolving process"""
|
||||
first = self.object_index['__first/man']
|
||||
first.requirements = ['__first']
|
||||
with self.assertRaises(cdist.core.cdist_object.MissingObjectIdError):
|
||||
self.config.iterate_until_finished()
|
||||
self.assertRaisesCdistObjectError(
|
||||
cdist.core.cdist_object.MissingObjectIdError,
|
||||
self.config.iterate_until_finished)
|
||||
|
||||
def test_dryrun(self):
|
||||
"""Test if the dryrun option is working like expected"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue