This commit is contained in:
Darko Poljak 2016-07-05 20:44:24 +02:00
commit 64efa04599
29 changed files with 715 additions and 409 deletions

View file

@ -28,7 +28,9 @@ cdist_base_path = os.path.abspath(
cdist_exec_path = os.path.join(cdist_base_path, "scripts/cdist")
global_fixtures_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "fixtures"))
global_fixtures_dir = os.path.abspath(os.path.join(os.path.dirname(__file__),
"fixtures"))
class CdistTestCase(unittest.TestCase):

View file

@ -27,6 +27,7 @@ import unittest
import cdist
import cdist.banner
class Banner(unittest.TestCase):
def setUp(self):
self.banner = cdist.BANNER + "\n"
@ -38,5 +39,5 @@ class Banner(unittest.TestCase):
sys.stdout = output
cdist.banner.banner(None)
self.assertEqual(output.getvalue(), self.banner)

View file

@ -57,29 +57,37 @@ class ObjectClassTestCase(test.CdistTestCase):
self.expected_objects = []
for cdist_object_name in expected_object_names:
cdist_type, cdist_object_id = cdist_object_name.split("/", 1)
cdist_object = core.CdistObject(core.CdistType(type_base_path, cdist_type), self.object_base_path,
OBJECT_MARKER_NAME, cdist_object_id)
cdist_object = core.CdistObject(core.CdistType(type_base_path,
cdist_type),
self.object_base_path,
OBJECT_MARKER_NAME,
cdist_object_id)
cdist_object.create()
self.expected_objects.append(cdist_object)
def tearDown(self):
shutil.rmtree(self.tempdir)
def test_list_object_names(self):
found_object_names = sorted(list(core.CdistObject.list_object_names(self.object_base_path, OBJECT_MARKER_NAME)))
self.assertEqual(found_object_names, expected_object_names)
found_object_names = sorted(list(core.CdistObject.list_object_names(
self.object_base_path, OBJECT_MARKER_NAME)))
self.assertEqual(found_object_names, expected_object_names)
def test_list_type_names(self):
type_names = list(cdist.core.CdistObject.list_type_names(self.object_base_path))
self.assertEqual(sorted(type_names), ['__first', '__second', '__third'])
type_names = list(cdist.core.CdistObject.list_type_names(
self.object_base_path))
self.assertEqual(sorted(type_names),
['__first', '__second', '__third'])
def test_list_objects(self):
found_objects = sorted(list(core.CdistObject.list_objects(self.object_base_path, type_base_path, OBJECT_MARKER_NAME)))
found_objects = sorted(list(core.CdistObject.list_objects(
self.object_base_path, type_base_path, OBJECT_MARKER_NAME)))
self.assertEqual(found_objects, self.expected_objects)
def test_create_singleton(self):
"""Check whether creating an object without id (singleton) works"""
singleton = self.expected_objects[0].object_from_name("__test_singleton")
singleton = self.expected_objects[0].object_from_name(
"__test_singleton")
# came here - everything fine
def test_create_singleton_not_singleton_type(self):
@ -88,6 +96,7 @@ class ObjectClassTestCase(test.CdistTestCase):
with self.assertRaises(cdist.core.cdist_object.MissingObjectIdError):
self.expected_objects[0].object_from_name("__first")
class ObjectIdTestCase(test.CdistTestCase):
def setUp(self):
@ -97,11 +106,14 @@ class ObjectIdTestCase(test.CdistTestCase):
self.expected_objects = []
for cdist_object_name in expected_object_names:
cdist_type, cdist_object_id = cdist_object_name.split("/", 1)
cdist_object = core.CdistObject(core.CdistType(type_base_path, cdist_type), self.object_base_path,
OBJECT_MARKER_NAME, cdist_object_id)
cdist_object = core.CdistObject(core.CdistType(type_base_path,
cdist_type),
self.object_base_path,
OBJECT_MARKER_NAME,
cdist_object_id)
cdist_object.create()
self.expected_objects.append(cdist_object)
def tearDown(self):
shutil.rmtree(self.tempdir)
@ -109,31 +121,39 @@ class ObjectIdTestCase(test.CdistTestCase):
cdist_type = core.CdistType(type_base_path, '__third')
illegal_object_id = '/object_id//may/not/contain/double/slash'
with self.assertRaises(core.IllegalObjectIdError):
core.CdistObject(cdist_type, self.object_base_path, OBJECT_MARKER_NAME, illegal_object_id)
core.CdistObject(cdist_type, self.object_base_path,
OBJECT_MARKER_NAME, illegal_object_id)
def test_object_id_contains_object_marker(self):
cdist_type = core.CdistType(type_base_path, '__third')
illegal_object_id = 'object_id/may/not/contain/%s/anywhere' % OBJECT_MARKER_NAME
illegal_object_id = (
'object_id/may/not/contain/%s/anywhere' % OBJECT_MARKER_NAME)
with self.assertRaises(core.IllegalObjectIdError):
core.CdistObject(cdist_type, self.object_base_path, OBJECT_MARKER_NAME, illegal_object_id)
core.CdistObject(cdist_type, self.object_base_path,
OBJECT_MARKER_NAME, illegal_object_id)
def test_object_id_contains_object_marker_string(self):
cdist_type = core.CdistType(type_base_path, '__third')
illegal_object_id = 'object_id/may/contain_%s_in_filename' % OBJECT_MARKER_NAME
core.CdistObject(cdist_type, self.object_base_path, OBJECT_MARKER_NAME, illegal_object_id)
illegal_object_id = (
'object_id/may/contain_%s_in_filename' % OBJECT_MARKER_NAME)
core.CdistObject(cdist_type, self.object_base_path,
OBJECT_MARKER_NAME, illegal_object_id)
# if we get here, the test passed
def test_object_id_contains_only_dot(self):
cdist_type = core.CdistType(type_base_path, '__third')
illegal_object_id = '.'
with self.assertRaises(core.IllegalObjectIdError):
core.CdistObject(cdist_type, self.object_base_path, OBJECT_MARKER_NAME, illegal_object_id)
core.CdistObject(cdist_type, self.object_base_path,
OBJECT_MARKER_NAME, illegal_object_id)
def test_object_id_on_singleton_type(self):
cdist_type = core.CdistType(type_base_path, '__test_singleton')
illegal_object_id = 'object_id'
with self.assertRaises(core.IllegalObjectIdError):
core.CdistObject(cdist_type, self.object_base_path, OBJECT_MARKER_NAME, illegal_object_id)
core.CdistObject(cdist_type, self.object_base_path,
OBJECT_MARKER_NAME, illegal_object_id)
class ObjectTestCase(test.CdistTestCase):
@ -142,13 +162,14 @@ class ObjectTestCase(test.CdistTestCase):
self.object_base_path = self.tempdir
self.cdist_type = core.CdistType(type_base_path, '__third')
self.cdist_object = core.CdistObject(self.cdist_type, self.object_base_path, OBJECT_MARKER_NAME, 'moon')
self.cdist_object = core.CdistObject(self.cdist_type,
self.object_base_path,
OBJECT_MARKER_NAME, 'moon')
self.cdist_object.create()
self.cdist_object.parameters['planet'] = 'Saturn'
self.cdist_object.parameters['name'] = 'Prometheus'
def tearDown(self):
self.cdist_object.prepared = False
self.cdist_object.ran = False
@ -166,22 +187,29 @@ class ObjectTestCase(test.CdistTestCase):
self.assertEqual(self.cdist_object.object_id, 'moon')
def test_path(self):
self.assertEqual(self.cdist_object.path, "__third/moon/%s" % OBJECT_MARKER_NAME)
self.assertEqual(self.cdist_object.path,
"__third/moon/%s" % OBJECT_MARKER_NAME)
def test_absolute_path(self):
self.assertEqual(self.cdist_object.absolute_path, os.path.join(self.object_base_path, "__third/moon/%s" % OBJECT_MARKER_NAME))
self.assertEqual(self.cdist_object.absolute_path,
os.path.join(self.object_base_path,
"__third/moon/%s" % OBJECT_MARKER_NAME))
def test_code_local_path(self):
self.assertEqual(self.cdist_object.code_local_path, "__third/moon/%s/code-local" % OBJECT_MARKER_NAME)
self.assertEqual(self.cdist_object.code_local_path,
"__third/moon/%s/code-local" % OBJECT_MARKER_NAME)
def test_code_remote_path(self):
self.assertEqual(self.cdist_object.code_remote_path, "__third/moon/%s/code-remote" % OBJECT_MARKER_NAME)
self.assertEqual(self.cdist_object.code_remote_path,
"__third/moon/%s/code-remote" % OBJECT_MARKER_NAME)
def test_parameter_path(self):
self.assertEqual(self.cdist_object.parameter_path, "__third/moon/%s/parameter" % OBJECT_MARKER_NAME)
self.assertEqual(self.cdist_object.parameter_path,
"__third/moon/%s/parameter" % OBJECT_MARKER_NAME)
def test_explorer_path(self):
self.assertEqual(self.cdist_object.explorer_path, "__third/moon/%s/explorer" % OBJECT_MARKER_NAME)
self.assertEqual(self.cdist_object.explorer_path,
"__third/moon/%s/explorer" % OBJECT_MARKER_NAME)
def test_parameters(self):
expected_parameters = {'planet': 'Saturn', 'name': 'Prometheus'}
@ -190,32 +218,39 @@ class ObjectTestCase(test.CdistTestCase):
def test_explorers(self):
self.assertEqual(self.cdist_object.explorers, {})
# FIXME: actually testing fsproperty.DirectoryDictProperty here, move to their own test case
# FIXME: actually testing fsproperty.DirectoryDictProperty here,
# move to their own test case
def test_explorers_assign_dict(self):
expected = {'first': 'foo', 'second': 'bar'}
# when set, written to file
self.cdist_object.explorers = expected
object_explorer_path = os.path.join(self.cdist_object.base_path, self.cdist_object.explorer_path)
object_explorer_path = os.path.join(self.cdist_object.base_path,
self.cdist_object.explorer_path)
self.assertTrue(os.path.isdir(object_explorer_path))
# when accessed, read from file
self.assertEqual(self.cdist_object.explorers, expected)
# remove dynamically created folder
self.cdist_object.explorers = {}
os.rmdir(os.path.join(self.cdist_object.base_path, self.cdist_object.explorer_path))
os.rmdir(os.path.join(self.cdist_object.base_path,
self.cdist_object.explorer_path))
# FIXME: actually testing fsproperty.DirectoryDictProperty here, move to their own test case
# FIXME: actually testing fsproperty.DirectoryDictProperty here,
# move to their own test case
def test_explorers_assign_key_value(self):
expected = {'first': 'foo', 'second': 'bar'}
object_explorer_path = os.path.join(self.cdist_object.base_path, self.cdist_object.explorer_path)
for key,value in expected.items():
object_explorer_path = os.path.join(self.cdist_object.base_path,
self.cdist_object.explorer_path)
for key, value in expected.items():
# when set, written to file
self.cdist_object.explorers[key] = value
self.assertTrue(os.path.isfile(os.path.join(object_explorer_path, key)))
self.assertTrue(os.path.isfile(os.path.join(object_explorer_path,
key)))
# when accessed, read from file
self.assertEqual(self.cdist_object.explorers, expected)
# remove dynamically created folder
self.cdist_object.explorers = {}
os.rmdir(os.path.join(self.cdist_object.base_path, self.cdist_object.explorer_path))
os.rmdir(os.path.join(self.cdist_object.base_path,
self.cdist_object.explorer_path))
def test_requirements(self):
expected = []
@ -226,15 +261,18 @@ class ObjectTestCase(test.CdistTestCase):
def test_state_prepared(self):
self.cdist_object.state = core.CdistObject.STATE_PREPARED
self.assertEqual(self.cdist_object.state, core.CdistObject.STATE_PREPARED)
self.assertEqual(self.cdist_object.state,
core.CdistObject.STATE_PREPARED)
def test_state_running(self):
self.cdist_object.state = core.CdistObject.STATE_RUNNING
self.assertEqual(self.cdist_object.state, core.CdistObject.STATE_RUNNING)
self.assertEqual(self.cdist_object.state,
core.CdistObject.STATE_RUNNING)
def test_state_done(self):
self.cdist_object.state = core.CdistObject.STATE_DONE
self.assertEqual(self.cdist_object.state, core.CdistObject.STATE_DONE)
self.assertEqual(self.cdist_object.state,
core.CdistObject.STATE_DONE)
def test_source(self):
self.assertEqual(list(self.cdist_object.source), [])

View file

@ -34,7 +34,8 @@ class TypeTestCase(test.CdistTestCase):
def test_list_type_names(self):
base_path = op.join(fixtures, 'list_types')
type_names = core.CdistType.list_type_names(base_path)
self.assertEqual(sorted(type_names), ['__first', '__second', '__third'])
self.assertEqual(sorted(type_names),
['__first', '__second', '__third'])
def test_list_types(self):
base_path = op.join(fixtures, 'list_types')
@ -54,7 +55,8 @@ class TypeTestCase(test.CdistTestCase):
def test_nonexistent_type(self):
base_path = fixtures
self.assertRaises(core.NoSuchTypeError, core.CdistType, base_path, '__i-dont-exist')
self.assertRaises(core.NoSuchTypeError, core.CdistType, base_path,
'__i-dont-exist')
def test_name(self):
base_path = fixtures
@ -74,27 +76,32 @@ class TypeTestCase(test.CdistTestCase):
def test_absolute_path(self):
base_path = fixtures
cdist_type = core.CdistType(base_path, '__name_path')
self.assertEqual(cdist_type.absolute_path, os.path.join(base_path, '__name_path'))
self.assertEqual(cdist_type.absolute_path,
os.path.join(base_path, '__name_path'))
def test_manifest_path(self):
base_path = fixtures
cdist_type = core.CdistType(base_path, '__name_path')
self.assertEqual(cdist_type.manifest_path, os.path.join('__name_path', 'manifest'))
self.assertEqual(cdist_type.manifest_path,
os.path.join('__name_path', 'manifest'))
def test_explorer_path(self):
base_path = fixtures
cdist_type = core.CdistType(base_path, '__name_path')
self.assertEqual(cdist_type.explorer_path, os.path.join('__name_path', 'explorer'))
self.assertEqual(cdist_type.explorer_path,
os.path.join('__name_path', 'explorer'))
def test_gencode_local_path(self):
base_path = fixtures
cdist_type = core.CdistType(base_path, '__name_path')
self.assertEqual(cdist_type.gencode_local_path, os.path.join('__name_path', 'gencode-local'))
self.assertEqual(cdist_type.gencode_local_path,
os.path.join('__name_path', 'gencode-local'))
def test_gencode_remote_path(self):
base_path = fixtures
cdist_type = core.CdistType(base_path, '__name_path')
self.assertEqual(cdist_type.gencode_remote_path, os.path.join('__name_path', 'gencode-remote'))
self.assertEqual(cdist_type.gencode_remote_path,
os.path.join('__name_path', 'gencode-remote'))
def test_singleton_is_singleton(self):
base_path = fixtures
@ -119,17 +126,20 @@ class TypeTestCase(test.CdistTestCase):
def test_with_required_parameters(self):
base_path = fixtures
cdist_type = core.CdistType(base_path, '__with_required_parameters')
self.assertEqual(cdist_type.required_parameters, ['required1', 'required2'])
self.assertEqual(cdist_type.required_parameters,
['required1', 'required2'])
def test_without_required_parameters(self):
base_path = fixtures
cdist_type = core.CdistType(base_path, '__without_required_parameters')
cdist_type = core.CdistType(base_path,
'__without_required_parameters')
self.assertEqual(cdist_type.required_parameters, [])
def test_with_optional_parameters(self):
base_path = fixtures
cdist_type = core.CdistType(base_path, '__with_optional_parameters')
self.assertEqual(cdist_type.optional_parameters, ['optional1', 'optional2'])
self.assertEqual(cdist_type.optional_parameters,
['optional1', 'optional2'])
def test_without_optional_parameters(self):
base_path = fixtures
@ -139,7 +149,8 @@ class TypeTestCase(test.CdistTestCase):
def test_with_boolean_parameters(self):
base_path = fixtures
cdist_type = core.CdistType(base_path, '__with_boolean_parameters')
self.assertEqual(cdist_type.boolean_parameters, ['boolean1', 'boolean2'])
self.assertEqual(cdist_type.boolean_parameters,
['boolean1', 'boolean2'])
def test_without_boolean_parameters(self):
base_path = fixtures
@ -158,5 +169,4 @@ class TypeTestCase(test.CdistTestCase):
cdist_type = core.CdistType(base_path, '__directory_in_default')
self.assertEqual(
list(sorted(cdist_type.parameter_defaults.keys())),
['bar', 'foo']
)
['bar', 'foo'])

View file

@ -36,15 +36,16 @@ my_dir = op.abspath(op.dirname(__file__))
fixtures = op.join(my_dir, 'fixtures')
conf_dir = op.join(fixtures, 'conf')
class CodeTestCase(test.CdistTestCase):
def setUp(self):
self.local_dir = self.mkdtemp()
self.local = local.Local(
target_host=self.target_host,
base_path = self.local_dir,
exec_path = cdist.test.cdist_exec_path,
target_host=self.target_host,
base_path=self.local_dir,
exec_path=cdist.test.cdist_exec_path,
add_conf_dirs=[conf_dir])
self.local.create_files_dirs()
@ -52,16 +53,19 @@ class CodeTestCase(test.CdistTestCase):
remote_exec = self.remote_exec
remote_copy = self.remote_copy
self.remote = remote.Remote(
target_host=self.target_host,
remote_exec=remote_exec,
target_host=self.target_host,
remote_exec=remote_exec,
remote_copy=remote_copy,
base_path=self.remote_dir)
self.remote.create_files_dirs()
self.code = code.Code(self.target_host, self.local, self.remote)
self.cdist_type = core.CdistType(self.local.type_path, '__dump_environment')
self.cdist_object = core.CdistObject(self.cdist_type, self.local.object_path, 'whatever', self.local.object_marker_name)
self.cdist_type = core.CdistType(self.local.type_path,
'__dump_environment')
self.cdist_object = core.CdistObject(
self.cdist_type, self.local.object_path, 'whatever',
self.local.object_marker_name)
self.cdist_object.create()
def tearDown(self):
@ -73,14 +77,16 @@ class CodeTestCase(test.CdistTestCase):
output_dict = {}
for line in output_string.split('\n'):
if line:
junk,value = line.split(': ')
junk, value = line.split(': ')
key = junk.split(' ')[1]
output_dict[key] = value
self.assertEqual(output_dict['__target_host'], self.local.target_host)
self.assertEqual(output_dict['__global'], self.local.base_path)
self.assertEqual(output_dict['__type'], self.cdist_type.absolute_path)
self.assertEqual(output_dict['__object'], self.cdist_object.absolute_path)
self.assertEqual(output_dict['__object_id'], self.cdist_object.object_id)
self.assertEqual(output_dict['__object'],
self.cdist_object.absolute_path)
self.assertEqual(output_dict['__object_id'],
self.cdist_object.object_id)
self.assertEqual(output_dict['__object_name'], self.cdist_object.name)
self.assertEqual(output_dict['__files'], self.local.files_path)
@ -89,29 +95,35 @@ class CodeTestCase(test.CdistTestCase):
output_dict = {}
for line in output_string.split('\n'):
if line:
junk,value = line.split(': ')
junk, value = line.split(': ')
key = junk.split(' ')[1]
output_dict[key] = value
self.assertEqual(output_dict['__target_host'], self.local.target_host)
self.assertEqual(output_dict['__global'], self.local.base_path)
self.assertEqual(output_dict['__type'], self.cdist_type.absolute_path)
self.assertEqual(output_dict['__object'], self.cdist_object.absolute_path)
self.assertEqual(output_dict['__object_id'], self.cdist_object.object_id)
self.assertEqual(output_dict['__object'],
self.cdist_object.absolute_path)
self.assertEqual(output_dict['__object_id'],
self.cdist_object.object_id)
self.assertEqual(output_dict['__object_name'], self.cdist_object.name)
self.assertEqual(output_dict['__files'], self.local.files_path)
def test_transfer_code_remote(self):
self.cdist_object.code_remote = self.code.run_gencode_remote(self.cdist_object)
self.cdist_object.code_remote = self.code.run_gencode_remote(
self.cdist_object)
self.code.transfer_code_remote(self.cdist_object)
destination = os.path.join(self.remote.object_path, self.cdist_object.code_remote_path)
destination = os.path.join(self.remote.object_path,
self.cdist_object.code_remote_path)
self.assertTrue(os.path.isfile(destination))
def test_run_code_local(self):
self.cdist_object.code_local = self.code.run_gencode_local(self.cdist_object)
self.cdist_object.code_local = self.code.run_gencode_local(
self.cdist_object)
self.code.run_code_local(self.cdist_object)
def test_run_code_remote_environment(self):
self.cdist_object.code_remote = self.code.run_gencode_remote(self.cdist_object)
self.cdist_object.code_remote = self.code.run_gencode_remote(
self.cdist_object)
self.code.transfer_code_remote(self.cdist_object)
self.code.run_code_remote(self.cdist_object)

View file

@ -44,6 +44,7 @@ expected_object_names = sorted([
'__second/on-the',
'__third/moon'])
class ConfigRunTestCase(test.CdistTestCase):
def setUp(self):
@ -65,8 +66,11 @@ class ConfigRunTestCase(test.CdistTestCase):
self.objects = []
for cdist_object_name in expected_object_names:
cdist_type, cdist_object_id = cdist_object_name.split("/", 1)
cdist_object = core.CdistObject(core.CdistType(type_base_path, cdist_type), self.object_base_path,
self.local.object_marker_name, cdist_object_id)
cdist_object = core.CdistObject(core.CdistType(type_base_path,
cdist_type),
self.object_base_path,
self.local.object_marker_name,
cdist_object_id)
cdist_object.create()
self.objects.append(cdist_object)
@ -81,8 +85,8 @@ class ConfigRunTestCase(test.CdistTestCase):
remote_exec=self.remote_exec,
base_path=self.remote_dir)
self.local.object_path = self.object_base_path
self.local.type_path = type_base_path
self.local.object_path = self.object_base_path
self.local.type_path = type_base_path
self.config = cdist.config.Config(self.local, self.remote)
@ -95,14 +99,14 @@ class ConfigRunTestCase(test.CdistTestCase):
shutil.rmtree(self.temp_dir)
def test_dependency_resolution(self):
first = self.object_index['__first/man']
second = self.object_index['__second/on-the']
third = self.object_index['__third/moon']
first = self.object_index['__first/man']
second = self.object_index['__second/on-the']
third = self.object_index['__third/moon']
first.requirements = [second.name]
second.requirements = [third.name]
# First run:
# First run:
# solves first and maybe second (depending on the order in the set)
self.config.iterate_once()
self.assertTrue(third.state == third.STATE_DONE)
@ -110,11 +114,11 @@ class ConfigRunTestCase(test.CdistTestCase):
self.config.iterate_once()
self.assertTrue(second.state == second.STATE_DONE)
try:
self.config.iterate_once()
except cdist.Error:
# Allow failing, because the third run may or may not be unecessary already,
# Allow failing, because the third run may or may not be
# unecessary already,
# depending on the order of the objects
pass
self.assertTrue(first.state == first.STATE_DONE)
@ -123,8 +127,8 @@ class ConfigRunTestCase(test.CdistTestCase):
"""Ensure an exception is thrown for unresolvable depedencies"""
# Create to objects depending on each other - no solution possible
first = self.object_index['__first/man']
second = self.object_index['__second/on-the']
first = self.object_index['__first/man']
second = self.object_index['__second/on-the']
first.requirements = [second.name]
second.requirements = [first.name]
@ -153,21 +157,22 @@ class ConfigRunTestCase(test.CdistTestCase):
with self.assertRaises(cdist.core.cdist_object.MissingObjectIdError):
self.config.iterate_until_finished()
def test_dryrun(self):
"""Test if the dryrun option is working like expected"""
drylocal = cdist.exec.local.Local(
target_host=self.target_host,
base_path=self.local_dir,
#exec_path can not derivated from sys.argv in case of unittest ...
exec_path=os.path.abspath(os.path.join(my_dir,'../../../scripts/cdist')),
initial_manifest=os.path.join(fixtures, 'manifest/dryrun_manifest'),
add_conf_dirs=[ fixtures ] )
# exec_path can not derivated from sys.argv in case of unittest
exec_path=os.path.abspath(os.path.join(
my_dir, '../../../scripts/cdist')),
initial_manifest=os.path.join(fixtures,
'manifest/dryrun_manifest'),
add_conf_dirs=[fixtures])
dryrun = cdist.config.Config(drylocal, self.remote, dry_run=True)
dryrun.run()
# if we are here, dryrun works like expected
# 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

View file

@ -40,6 +40,7 @@ my_dir = op.abspath(op.dirname(__file__))
fixtures = op.join(my_dir, 'fixtures')
conf_dir = op.join(fixtures, 'conf')
class EmulatorTestCase(test.CdistTestCase):
def setUp(self):
@ -68,7 +69,8 @@ class EmulatorTestCase(test.CdistTestCase):
def test_nonexistent_type_exec(self):
argv = ['__does-not-exist']
self.assertRaises(core.cdist_type.NoSuchTypeError, emulator.Emulator, argv, env=self.env)
self.assertRaises(core.cdist_type.NoSuchTypeError, emulator.Emulator,
argv, env=self.env)
def test_nonexistent_type_requirement(self):
argv = ['__file', '/tmp/foobar']
@ -78,7 +80,8 @@ class EmulatorTestCase(test.CdistTestCase):
def test_illegal_object_id_requirement(self):
argv = ['__file', '/tmp/foobar']
self.env['require'] = "__file/bad/id/with/%s/inside" % self.local.object_marker_name
self.env['require'] = (
"__file/bad/id/with/%s/inside") % self.local.object_marker_name
emu = emulator.Emulator(argv, env=self.env)
self.assertRaises(core.IllegalObjectIdError, emu.run)
@ -123,16 +126,21 @@ class EmulatorTestCase(test.CdistTestCase):
emu.run()
# now load the objects and verify the require parameter of the objects
cdist_type = core.CdistType(self.local.type_path, '__planet')
erde_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, 'erde')
mars_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, 'mars')
erde_object = core.CdistObject(cdist_type, self.local.object_path,
self.local.object_marker_name, 'erde')
mars_object = core.CdistObject(cdist_type, self.local.object_path,
self.local.object_marker_name, 'mars')
cdist_type = core.CdistType(self.local.type_path, '__file')
file_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, '/tmp/cdisttest')
file_object = core.CdistObject(cdist_type, self.local.object_path,
self.local.object_marker_name,
'/tmp/cdisttest')
# now test the recorded requirements
self.assertTrue(len(erde_object.requirements) == 0)
self.assertEqual(list(mars_object.requirements), ['__planet/erde'])
self.assertEqual(list(file_object.requirements), ['__planet/mars'])
# if we get here all is fine
class EmulatorConflictingRequirementsTestCase(test.CdistTestCase):
def setUp(self):
@ -170,7 +178,8 @@ class EmulatorConflictingRequirementsTestCase(test.CdistTestCase):
emu.run()
cdist_type = core.CdistType(self.local.type_path, '__file')
cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, 'eggs')
cdist_object = core.CdistObject(cdist_type, self.local.object_path,
self.local.object_marker_name, 'eggs')
reqs = set(('__directory/spam',))
self.assertEqual(reqs, set(cdist_object.requirements))
@ -189,7 +198,8 @@ class EmulatorConflictingRequirementsTestCase(test.CdistTestCase):
emu.run()
cdist_type = core.CdistType(self.local.type_path, '__file')
cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, 'eggs')
cdist_object = core.CdistObject(cdist_type, self.local.object_path,
self.local.object_marker_name, 'eggs')
reqs = set(('__directory/spam',))
self.assertEqual(reqs, set(cdist_object.requirements))
@ -214,7 +224,8 @@ class EmulatorConflictingRequirementsTestCase(test.CdistTestCase):
emu.run()
cdist_type = core.CdistType(self.local.type_path, '__file')
cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, 'eggs')
cdist_object = core.CdistObject(cdist_type, self.local.object_path,
self.local.object_marker_name, 'eggs')
reqs = set(('__directory/spam', '__directory/spameggs',))
self.assertEqual(reqs, set(cdist_object.requirements))
@ -240,11 +251,13 @@ class AutoRequireEmulatorTestCase(test.CdistTestCase):
initial_manifest = os.path.join(self.local.manifest_path, "init")
self.manifest.run_initial_manifest(initial_manifest)
cdist_type = core.CdistType(self.local.type_path, '__saturn')
cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, '')
cdist_object = core.CdistObject(cdist_type, self.local.object_path,
self.local.object_marker_name, '')
self.manifest.run_type_manifest(cdist_object)
expected = ['__planet/Saturn', '__moon/Prometheus']
self.assertEqual(sorted(cdist_object.autorequire), sorted(expected))
class OverrideTestCase(test.CdistTestCase):
def setUp(self):
@ -271,7 +284,7 @@ class OverrideTestCase(test.CdistTestCase):
argv = ['__file', '/tmp/foobar']
emu = emulator.Emulator(argv, env=self.env)
emu.run()
argv = ['__file', '/tmp/foobar','--mode','404']
argv = ['__file', '/tmp/foobar', '--mode', '404']
emu = emulator.Emulator(argv, env=self.env)
self.assertRaises(cdist.Error, emu.run)
@ -279,7 +292,7 @@ class OverrideTestCase(test.CdistTestCase):
argv = ['__file', '/tmp/foobar']
emu = emulator.Emulator(argv, env=self.env)
emu.run()
argv = ['__file', '/tmp/foobar','--mode','404']
argv = ['__file', '/tmp/foobar', '--mode', '404']
self.env['CDIST_OVERRIDE'] = 'on'
emu = emulator.Emulator(argv, env=self.env)
emu.run()
@ -308,13 +321,17 @@ class ArgumentsTestCase(test.CdistTestCase):
shutil.rmtree(self.temp_dir)
def test_arguments_with_dashes(self):
argv = ['__arguments_with_dashes', 'some-id', '--with-dash', 'some value']
argv = ['__arguments_with_dashes', 'some-id', '--with-dash',
'some value']
os.environ.update(self.env)
emu = emulator.Emulator(argv)
emu.run()
cdist_type = core.CdistType(self.local.type_path, '__arguments_with_dashes')
cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, 'some-id')
cdist_type = core.CdistType(self.local.type_path,
'__arguments_with_dashes')
cdist_object = core.CdistObject(cdist_type, self.local.object_path,
self.local.object_marker_name,
'some-id')
self.assertTrue('with-dash' in cdist_object.parameters)
def test_boolean(self):
@ -326,7 +343,9 @@ class ArgumentsTestCase(test.CdistTestCase):
emu.run()
cdist_type = core.CdistType(self.local.type_path, type_name)
cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, object_id)
cdist_object = core.CdistObject(cdist_type, self.local.object_path,
self.local.object_marker_name,
object_id)
self.assertTrue('boolean1' in cdist_object.parameters)
self.assertFalse('boolean2' in cdist_object.parameters)
# empty file -> True
@ -338,13 +357,16 @@ class ArgumentsTestCase(test.CdistTestCase):
type_name = '__arguments_required'
object_id = 'some-id'
value = 'some value'
argv = [type_name, object_id, '--required1', value, '--required2', value]
argv = [type_name, object_id, '--required1', value,
'--required2', value]
os.environ.update(self.env)
emu = emulator.Emulator(argv)
emu.run()
cdist_type = core.CdistType(self.local.type_path, type_name)
cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, object_id)
cdist_object = core.CdistObject(cdist_type, self.local.object_path,
self.local.object_marker_name,
object_id)
self.assertTrue('required1' in cdist_object.parameters)
self.assertTrue('required2' in cdist_object.parameters)
self.assertEqual(cdist_object.parameters['required1'], value)
@ -370,7 +392,9 @@ class ArgumentsTestCase(test.CdistTestCase):
emu.run()
cdist_type = core.CdistType(self.local.type_path, type_name)
cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, object_id)
cdist_object = core.CdistObject(cdist_type, self.local.object_path,
self.local.object_marker_name,
object_id)
self.assertTrue('optional1' in cdist_object.parameters)
self.assertFalse('optional2' in cdist_object.parameters)
self.assertEqual(cdist_object.parameters['optional1'], value)
@ -385,7 +409,9 @@ class ArgumentsTestCase(test.CdistTestCase):
emu.run()
cdist_type = core.CdistType(self.local.type_path, type_name)
cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, object_id)
cdist_object = core.CdistObject(cdist_type, self.local.object_path,
self.local.object_marker_name,
object_id)
self.assertTrue('optional1' in cdist_object.parameters)
self.assertFalse('optional2' in cdist_object.parameters)
self.assertEqual(cdist_object.parameters['optional1'], value)
@ -437,7 +463,9 @@ class StdinTestCase(test.CdistTestCase):
######################################################################
# Create path where stdin should reside at
cdist_type = core.CdistType(self.local.type_path, type_name)
cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, object_id)
cdist_object = core.CdistObject(cdist_type, self.local.object_path,
self.local.object_marker_name,
object_id)
stdin_out_path = os.path.join(cdist_object.absolute_path, 'stdin')
######################################################################

View file

@ -39,6 +39,7 @@ conf_dir = op.join(fixtures, "conf")
bin_true = "true"
bin_false = "false"
class LocalTestCase(test.CdistTestCase):
def setUp(self):
@ -59,43 +60,52 @@ class LocalTestCase(test.CdistTestCase):
def tearDown(self):
shutil.rmtree(self.temp_dir)
### test api
# test api
def test_cache_path(self):
self.assertEqual(self.local.cache_path, os.path.join(self.home_dir, "cache"))
self.assertEqual(self.local.cache_path,
os.path.join(self.home_dir, "cache"))
def test_conf_path(self):
self.assertEqual(self.local.conf_path, os.path.join(self.out_path, "conf"))
self.assertEqual(self.local.conf_path,
os.path.join(self.out_path, "conf"))
def test_out_path(self):
self.assertEqual(self.local.base_path, self.out_path)
def test_bin_path(self):
self.assertEqual(self.local.bin_path, os.path.join(self.out_path, "bin"))
self.assertEqual(self.local.bin_path,
os.path.join(self.out_path, "bin"))
def test_global_explorer_out_path(self):
self.assertEqual(self.local.global_explorer_out_path, os.path.join(self.out_path, "explorer"))
self.assertEqual(self.local.global_explorer_out_path,
os.path.join(self.out_path, "explorer"))
def test_object_path(self):
self.assertEqual(self.local.object_path, os.path.join(self.out_path, "object"))
self.assertEqual(self.local.object_path,
os.path.join(self.out_path, "object"))
### /test api
# /test api
### test internal implementation
# test internal implementation
def test_global_explorer_path(self):
self.assertEqual(self.local.global_explorer_path, os.path.join(self.out_path, "conf", "explorer"))
self.assertEqual(self.local.global_explorer_path,
os.path.join(self.out_path, "conf", "explorer"))
def test_manifest_path(self):
self.assertEqual(self.local.manifest_path, os.path.join(self.out_path, "conf", "manifest"))
self.assertEqual(self.local.manifest_path,
os.path.join(self.out_path, "conf", "manifest"))
def test_type_path(self):
self.assertEqual(self.local.type_path, os.path.join(self.out_path, "conf", "type"))
self.assertEqual(self.local.type_path,
os.path.join(self.out_path, "conf", "type"))
def test_dist_conf_dir_linking(self):
"""Ensure that links are correctly created for types included in distribution"""
"""Ensure that links are correctly created for types included
in distribution"""
test_type="__file"
test_type = "__file"
link_test_local = local.Local(
target_host='localhost',
@ -110,9 +120,10 @@ class LocalTestCase(test.CdistTestCase):
self.assertTrue(os.path.isdir(our_type_dir))
def test_added_conf_dir_linking(self):
"""Ensure that links are correctly created for types in added conf directories"""
"""Ensure that links are correctly created for types in added conf
directories"""
test_type="__cdist_test_type"
test_type = "__cdist_test_type"
link_test_local = local.Local(
target_host='localhost',
@ -128,9 +139,10 @@ class LocalTestCase(test.CdistTestCase):
self.assertTrue(os.path.isdir(our_type_dir))
def test_conf_dir_from_path_linking(self):
"""Ensure that links are correctly created for types in conf directories which are defined in CDIST_PATH"""
"""Ensure that links are correctly created for types in conf
directories which are defined in CDIST_PATH"""
test_type="__cdist_test_type"
test_type = "__cdist_test_type"
os.environ['CDIST_PATH'] = conf_dir
@ -146,7 +158,7 @@ class LocalTestCase(test.CdistTestCase):
self.assertTrue(os.path.isdir(our_type_dir))
### other tests
# other tests
def test_run_success(self):
self.local.run([bin_true])
@ -170,7 +182,8 @@ class LocalTestCase(test.CdistTestCase):
handle, script = self.mkstemp(dir=self.temp_dir)
with os.fdopen(handle, "w") as fd:
fd.writelines(["#!/bin/sh\n", "echo foobar"])
self.assertEqual(self.local.run_script(script, return_output=True), "foobar\n")
self.assertEqual(self.local.run_script(script, return_output=True),
"foobar\n")
def test_mkdir(self):
temp_dir = self.mkdtemp(dir=self.temp_dir)

View file

@ -39,26 +39,32 @@ class RemoteTestCase(test.CdistTestCase):
user = getpass.getuser()
remote_exec = "ssh -o User=%s -q" % user
remote_copy = "scp -o User=%s -q" % user
self.remote = remote.Remote(self.target_host, base_path=self.base_path, remote_exec=remote_exec, remote_copy=remote_copy)
self.remote = remote.Remote(self.target_host, base_path=self.base_path,
remote_exec=remote_exec,
remote_copy=remote_copy)
def tearDown(self):
shutil.rmtree(self.temp_dir)
### test api
# test api
def test_conf_path(self):
self.assertEqual(self.remote.conf_path, os.path.join(self.base_path, "conf"))
self.assertEqual(self.remote.conf_path,
os.path.join(self.base_path, "conf"))
def test_object_path(self):
self.assertEqual(self.remote.object_path, os.path.join(self.base_path, "object"))
self.assertEqual(self.remote.object_path,
os.path.join(self.base_path, "object"))
def test_type_path(self):
self.assertEqual(self.remote.type_path, os.path.join(self.base_path, "conf", "type"))
self.assertEqual(self.remote.type_path,
os.path.join(self.base_path, "conf", "type"))
def test_global_explorer_path(self):
self.assertEqual(self.remote.global_explorer_path, os.path.join(self.base_path, "conf", "explorer"))
self.assertEqual(self.remote.global_explorer_path,
os.path.join(self.base_path, "conf", "explorer"))
### /test api
# /test api
def test_run_success(self):
self.remote.run(['/bin/true'])
@ -76,13 +82,15 @@ class RemoteTestCase(test.CdistTestCase):
handle, script = self.mkstemp(dir=self.temp_dir)
with os.fdopen(handle, "w") as fd:
fd.writelines(["#!/bin/sh\n", "/bin/false"])
self.assertRaises(remote.RemoteScriptError, self.remote.run_script, script)
self.assertRaises(remote.RemoteScriptError, self.remote.run_script,
script)
def test_run_script_get_output(self):
handle, script = self.mkstemp(dir=self.temp_dir)
with os.fdopen(handle, "w") as fd:
fd.writelines(["#!/bin/sh\n", "echo foobar"])
self.assertEqual(self.remote.run_script(script, return_output=True), "foobar\n")
self.assertEqual(self.remote.run_script(script, return_output=True),
"foobar\n")
def test_mkdir(self):
temp_dir = self.mkdtemp(dir=self.temp_dir)
@ -125,8 +133,10 @@ class RemoteTestCase(test.CdistTestCase):
os.chmod(remote_exec_path, 0o755)
remote_exec = remote_exec_path
remote_copy = "echo"
r = remote.Remote(self.target_host, base_path=self.base_path, remote_exec=remote_exec, remote_copy=remote_copy)
self.assertEqual(r.run('/bin/true', return_output=True), "%s\n" % self.target_host)
r = remote.Remote(self.target_host, base_path=self.base_path,
remote_exec=remote_exec, remote_copy=remote_copy)
self.assertEqual(r.run('/bin/true', return_output=True),
"%s\n" % self.target_host)
def test_run_script_target_host_in_env(self):
handle, remote_exec_path = self.mkstemp(dir=self.temp_dir)
@ -135,16 +145,21 @@ class RemoteTestCase(test.CdistTestCase):
os.chmod(remote_exec_path, 0o755)
remote_exec = remote_exec_path
remote_copy = "echo"
r = remote.Remote(self.target_host, base_path=self.base_path, remote_exec=remote_exec, remote_copy=remote_copy)
r = remote.Remote(self.target_host, base_path=self.base_path,
remote_exec=remote_exec, remote_copy=remote_copy)
handle, script = self.mkstemp(dir=self.temp_dir)
with os.fdopen(handle, "w") as fd:
fd.writelines(["#!/bin/sh\n", "/bin/true"])
self.assertEqual(r.run_script(script, return_output=True), "%s\n" % self.target_host)
self.assertEqual(r.run_script(script, return_output=True),
"%s\n" % self.target_host)
def test_run_script_with_env_target_host_in_env(self):
handle, script = self.mkstemp(dir=self.temp_dir)
with os.fdopen(handle, "w") as fd:
fd.writelines(["#!/bin/sh\n", 'if [ "$__object" ]; then echo $__object; else echo no_env; fi\n'])
fd.writelines([
"#!/bin/sh\n",
('if [ "$__object" ]; then echo $__object; '
'else echo no_env; fi\n')])
os.chmod(script, 0o755)
handle, remote_exec_path = self.mkstemp(dir=self.temp_dir)
with os.fdopen(handle, 'w') as fd:
@ -152,7 +167,8 @@ class RemoteTestCase(test.CdistTestCase):
os.chmod(remote_exec_path, 0o755)
remote_exec = remote_exec_path
remote_copy = "echo"
r = remote.Remote(self.target_host, base_path=self.base_path, remote_exec=remote_exec, remote_copy=remote_copy)
r = remote.Remote(self.target_host, base_path=self.base_path,
remote_exec=remote_exec, remote_copy=remote_copy)
output = r.run_script(script, return_output=True)
self.assertEqual(output, "no_env\n")
@ -164,7 +180,8 @@ class RemoteTestCase(test.CdistTestCase):
env = {
'__object': 'test_object',
}
r = remote.Remote(self.target_host, base_path=self.base_path, remote_exec=remote_exec, remote_copy=remote_copy)
r = remote.Remote(self.target_host, base_path=self.base_path,
remote_exec=remote_exec, remote_copy=remote_copy)
output = r.run_script(script, env=env, return_output=True)
self.assertEqual(output, "test_object\n")

View file

@ -36,12 +36,13 @@ my_dir = op.abspath(op.dirname(__file__))
fixtures = op.join(my_dir, 'fixtures')
conf_dir = op.join(fixtures, "conf")
class ExplorerClassTestCase(test.CdistTestCase):
def setUp(self):
self.temp_dir = self.mkdtemp()
self.local_path = os.path.join(self.temp_dir, "local")
self.remote_base_path = os.path.join(self.temp_dir, "remote")
self.temp_dir = self.mkdtemp()
self.local_path = os.path.join(self.temp_dir, "local")
self.remote_base_path = os.path.join(self.temp_dir, "remote")
os.makedirs(self.remote_base_path)
self.local = local.Local(
@ -54,15 +55,15 @@ class ExplorerClassTestCase(test.CdistTestCase):
self.local.create_files_dirs()
self.remote = remote.Remote(
target_host=self.target_host,
target_host=self.target_host,
remote_exec=self.remote_exec,
remote_copy=self.remote_copy,
base_path=self.remote_base_path)
self.remote.create_files_dirs()
self.explorer = explorer.Explorer(
self.target_host,
self.local,
self.target_host,
self.local,
self.remote)
def tearDown(self):
@ -79,7 +80,8 @@ class ExplorerClassTestCase(test.CdistTestCase):
self.explorer.transfer_global_explorers()
source = self.local.global_explorer_path
destination = self.remote.global_explorer_path
self.assertEqual(sorted(os.listdir(source)), sorted(os.listdir(destination)))
self.assertEqual(sorted(os.listdir(source)),
sorted(os.listdir(destination)))
def test_run_global_explorer(self):
"""Checkt that running ONE global explorer works"""
@ -101,14 +103,16 @@ class ExplorerClassTestCase(test.CdistTestCase):
def test_list_type_explorer_names(self):
cdist_type = core.CdistType(self.local.type_path, '__test_type')
expected = cdist_type.explorers
self.assertEqual(self.explorer.list_type_explorer_names(cdist_type), expected)
self.assertEqual(self.explorer.list_type_explorer_names(cdist_type),
expected)
def test_transfer_type_explorers(self):
"""Test if transferring type explorers works"""
cdist_type = core.CdistType(self.local.type_path, '__test_type')
self.explorer.transfer_type_explorers(cdist_type)
source = os.path.join(self.local.type_path, cdist_type.explorer_path)
destination = os.path.join(self.remote.type_path, cdist_type.explorer_path)
destination = os.path.join(self.remote.type_path,
cdist_type.explorer_path)
self.assertEqual(os.listdir(source), os.listdir(destination))
def test_transfer_type_explorers_only_once(self):
@ -116,7 +120,8 @@ class ExplorerClassTestCase(test.CdistTestCase):
# first transfer
self.explorer.transfer_type_explorers(cdist_type)
source = os.path.join(self.local.type_path, cdist_type.explorer_path)
destination = os.path.join(self.remote.type_path, cdist_type.explorer_path)
destination = os.path.join(self.remote.type_path,
cdist_type.explorer_path)
self.assertEqual(os.listdir(source), os.listdir(destination))
# nuke destination folder content, but recreate directory
shutil.rmtree(destination)
@ -127,24 +132,36 @@ class ExplorerClassTestCase(test.CdistTestCase):
def test_transfer_object_parameters(self):
cdist_type = core.CdistType(self.local.type_path, '__test_type')
cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, 'whatever')
cdist_object = core.CdistObject(cdist_type, self.local.object_path,
self.local.object_marker_name,
'whatever')
cdist_object.create()
cdist_object.parameters = {'first': 'first value', 'second': 'second value'}
cdist_object.parameters = {
'first': 'first value',
'second': 'second value'
}
self.explorer.transfer_object_parameters(cdist_object)
source = os.path.join(self.local.object_path, cdist_object.parameter_path)
destination = os.path.join(self.remote.object_path, cdist_object.parameter_path)
self.assertEqual(sorted(os.listdir(source)), sorted(os.listdir(destination)))
source = os.path.join(self.local.object_path,
cdist_object.parameter_path)
destination = os.path.join(self.remote.object_path,
cdist_object.parameter_path)
self.assertEqual(sorted(os.listdir(source)),
sorted(os.listdir(destination)))
def test_run_type_explorer(self):
cdist_type = core.CdistType(self.local.type_path, '__test_type')
cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, 'whatever')
cdist_object = core.CdistObject(cdist_type, self.local.object_path,
self.local.object_marker_name,
'whatever')
self.explorer.transfer_type_explorers(cdist_type)
output = self.explorer.run_type_explorer('world', cdist_object)
self.assertEqual(output, 'hello\n')
def test_run_type_explorers(self):
cdist_type = core.CdistType(self.local.type_path, '__test_type')
cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, 'whatever')
cdist_object = core.CdistObject(cdist_type, self.local.object_path,
self.local.object_marker_name,
'whatever')
cdist_object.create()
self.explorer.run_type_explorers(cdist_object)
self.assertEqual(cdist_object.explorers, {'world': 'hello'})

View file

@ -40,6 +40,7 @@ my_dir = op.abspath(op.dirname(__file__))
fixtures = op.join(my_dir, 'fixtures')
conf_dir = op.join(fixtures, 'conf')
class ManifestTestCase(test.CdistTestCase):
def setUp(self):
@ -51,7 +52,7 @@ class ManifestTestCase(test.CdistTestCase):
self.local = local.Local(
target_host=self.target_host,
base_path=out_path,
exec_path = cdist.test.cdist_exec_path,
exec_path=cdist.test.cdist_exec_path,
add_conf_dirs=[conf_dir])
self.local.create_files_dirs()
@ -63,7 +64,8 @@ class ManifestTestCase(test.CdistTestCase):
shutil.rmtree(self.temp_dir)
def test_initial_manifest_environment(self):
initial_manifest = os.path.join(self.local.manifest_path, "dump_environment")
initial_manifest = os.path.join(self.local.manifest_path,
"dump_environment")
handle, output_file = self.mkstemp(dir=self.temp_dir)
os.close(handle)
os.environ['__cdist_test_out'] = output_file
@ -74,18 +76,21 @@ class ManifestTestCase(test.CdistTestCase):
output_dict = {}
for line in output_string.split('\n'):
if line:
key,value = line.split(': ')
key, value = line.split(': ')
output_dict[key] = value
self.assertTrue(output_dict['PATH'].startswith(self.local.bin_path))
self.assertEqual(output_dict['__target_host'], self.local.target_host)
self.assertEqual(output_dict['__global'], self.local.base_path)
self.assertEqual(output_dict['__cdist_type_base_path'], self.local.type_path)
self.assertEqual(output_dict['__cdist_type_base_path'],
self.local.type_path)
self.assertEqual(output_dict['__manifest'], self.local.manifest_path)
self.assertEqual(output_dict['__files'], self.local.files_path)
def test_type_manifest_environment(self):
cdist_type = core.CdistType(self.local.type_path, '__dump_environment')
cdist_object = core.CdistObject(cdist_type, self.local.object_path, self.local.object_marker_name, 'whatever')
cdist_object = core.CdistObject(cdist_type, self.local.object_path,
self.local.object_marker_name,
'whatever')
handle, output_file = self.mkstemp(dir=self.temp_dir)
os.close(handle)
os.environ['__cdist_test_out'] = output_file
@ -96,12 +101,13 @@ class ManifestTestCase(test.CdistTestCase):
output_dict = {}
for line in output_string.split('\n'):
if line:
key,value = line.split(': ')
key, value = line.split(': ')
output_dict[key] = value
self.assertTrue(output_dict['PATH'].startswith(self.local.bin_path))
self.assertEqual(output_dict['__target_host'], self.local.target_host)
self.assertEqual(output_dict['__global'], self.local.base_path)
self.assertEqual(output_dict['__cdist_type_base_path'], self.local.type_path)
self.assertEqual(output_dict['__cdist_type_base_path'],
self.local.type_path)
self.assertEqual(output_dict['__type'], cdist_type.absolute_path)
self.assertEqual(output_dict['__object'], cdist_object.absolute_path)
self.assertEqual(output_dict['__object_id'], cdist_object.object_id)

View file

@ -25,14 +25,15 @@ import tempfile
from cdist import test
import cdist.message
class MessageTestCase(test.CdistTestCase):
def setUp(self):
self.prefix="cdist-test"
self.prefix = "cdist-test"
self.content = "A very short story"
self.tempfile = tempfile.mkstemp()[1]
self.message = cdist.message.Message(prefix=self.prefix,
messages=self.tempfile)
messages=self.tempfile)
def tearDown(self):
os.remove(self.tempfile)
@ -48,7 +49,6 @@ class MessageTestCase(test.CdistTestCase):
self.assertIn('__messages_in', env)
self.assertIn('__messages_out', env)
def test_copy_content(self):
"""
Ensure content copying is working