fix most test cases broken by no-dot-cdist change

Signed-off-by: Nico Schottelius <nico@freiheit.schottelius.org>
This commit is contained in:
Nico Schottelius 2015-03-05 18:32:47 +01:00
parent fa6e389fdd
commit d08c29b581
19 changed files with 97 additions and 53 deletions

View File

@ -158,12 +158,13 @@ class CdistObject(object):
base_path = self.base_path
type_path = self.cdist_type.base_path
object_marker = self.object_marker
type_name, object_id = self.split_name(object_name)
cdist_type = self.cdist_type.__class__(type_path, type_name)
return self.__class__(cdist_type, base_path, object_id=object_id)
return self.__class__(cdist_type, base_path, object_marker, object_id=object_id)
def __repr__(self):
return '<CdistObject %s>' % self.name

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
# 2012-2015 Nico Schottelius (nico-cdist at schottelius.org)
# 2014 Daniel Heule (hda at sfs.biz)
#
# This file is part of cdist.
@ -23,6 +23,7 @@
import os
import shutil
import tempfile
from cdist import test
from cdist import core
@ -32,37 +33,48 @@ import cdist
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')
OBJECT_MARKER_NAME = '.cdist-pseudo-random'
expected_object_names = sorted([
'__first/child',
'__first/dog',
'__first/man',
'__first/woman',
'__second/on-the',
'__second/under-the',
'__third/moon'])
class ObjectClassTestCase(test.CdistTestCase):
def setUp(self):
self.expected_object_names = sorted([
'__first/child',
'__first/dog',
'__first/man',
'__first/woman',
'__second/on-the',
'__second/under-the',
'__third/moon'])
self.tempdir = tempfile.mkdtemp(prefix="cdist.test")
self.object_base_path = self.tempdir
self.expected_objects = []
for cdist_object_name in self.expected_object_names:
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), object_base_path, 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(object_base_path)))
self.assertEqual(found_object_names, self.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(object_base_path))
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(object_base_path, type_base_path)))
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):
@ -77,41 +89,65 @@ class ObjectClassTestCase(test.CdistTestCase):
self.expected_objects[0].object_from_name("__first")
class ObjectIdTestCase(test.CdistTestCase):
def setUp(self):
self.tempdir = tempfile.mkdtemp(prefix="cdist.test")
self.object_base_path = self.tempdir
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.create()
self.expected_objects.append(cdist_object)
def tearDown(self):
shutil.rmtree(self.tempdir)
def test_object_id_contains_double_slash(self):
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, object_base_path, 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' % core.OBJECT_MARKER
illegal_object_id = 'object_id/may/not/contain/%s/anywhere' % OBJECT_MARKER_NAME
with self.assertRaises(core.IllegalObjectIdError):
core.CdistObject(cdist_type, object_base_path, 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' % core.OBJECT_MARKER
core.CdistObject(cdist_type, object_base_path, 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, object_base_path, 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, object_base_path, illegal_object_id)
core.CdistObject(cdist_type, self.object_base_path, OBJECT_MARKER_NAME, illegal_object_id)
class ObjectTestCase(test.CdistTestCase):
def setUp(self):
self.tempdir = tempfile.mkdtemp(prefix="cdist.test")
self.object_base_path = self.tempdir
self.cdist_type = core.CdistType(type_base_path, '__third')
self.cdist_object = core.CdistObject(self.cdist_type, object_base_path, '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
@ -121,6 +157,8 @@ class ObjectTestCase(test.CdistTestCase):
self.cdist_object.code_remote = ''
self.cdist_object.state = ''
shutil.rmtree(self.tempdir)
def test_name(self):
self.assertEqual(self.cdist_object.name, '__third/moon')
@ -128,22 +166,22 @@ class ObjectTestCase(test.CdistTestCase):
self.assertEqual(self.cdist_object.object_id, 'moon')
def test_path(self):
self.assertEqual(self.cdist_object.path, '__third/moon/.cdist')
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(object_base_path, '__third/moon/.cdist'))
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/.cdist/code-local')
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/.cdist/code-remote')
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/.cdist/parameter')
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/.cdist/explorer')
self.assertEqual(self.cdist_object.explorer_path, "__third/moon/%s/explorer" % OBJECT_MARKER_NAME)
def test_parameters(self):
expected_parameters = {'planet': 'Saturn', 'name': 'Prometheus'}

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2012-2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2012-2015 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
@ -61,7 +61,7 @@ class CodeTestCase(test.CdistTestCase):
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.cdist_object = core.CdistObject(self.cdist_type, self.local.object_path, 'whatever', self.local.object_marker_name)
self.cdist_object.create()
def tearDown(self):

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2012-2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2012-2015 Nico Schottelius (nico-cdist at schottelius.org)
# 2014 Daniel Heule (hda at sfs.biz)
#
# This file is part of cdist.
@ -67,7 +67,7 @@ class ConfigRunTestCase(test.CdistTestCase):
self.config = cdist.config.Config(self.local, self.remote)
self.objects = list(core.CdistObject.list_objects(object_base_path, type_base_path))
self.objects = list(core.CdistObject.list_objects(object_base_path, type_base_path, self.local.object_marker_name))
self.object_index = dict((o.name, o) for o in self.objects)
self.object_names = [o.name for o in self.objects]

View File

@ -57,10 +57,15 @@ class EmulatorTestCase(test.CdistTestCase):
self.manifest = core.Manifest(self.target_host, self.local)
self.env = self.manifest.env_initial_manifest(self.script)
self.env['__cdist_object_marker'] = self.local.object_marker_name
def tearDown(self):
shutil.rmtree(self.temp_dir)
# def test_missing_object_marker_variable(self):
# del self.env['__cdist_object_marker']
# self.assertRaises(KeyError, emulator.Emulator, argv, env=self.env)
def test_nonexistent_type_exec(self):
argv = ['__does-not-exist']
self.assertRaises(core.cdist_type.NoSuchTypeError, emulator.Emulator, argv, env=self.env)
@ -73,7 +78,7 @@ class EmulatorTestCase(test.CdistTestCase):
def test_illegal_object_id_requirement(self):
argv = ['__file', '/tmp/foobar']
self.env['require'] = '__file/bad/id/with/.cdist/inside'
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)
@ -118,10 +123,10 @@ 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, 'erde')
mars_object = core.CdistObject(cdist_type, self.local.object_path, '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, '/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'])
@ -150,7 +155,7 @@ 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)
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))
@ -172,6 +177,7 @@ class OverrideTestCase(test.CdistTestCase):
self.manifest = core.Manifest(self.target_host, self.local)
self.env = self.manifest.env_initial_manifest(self.script)
self.env['__cdist_object_marker'] = self.local.object_marker_name
def tearDown(self):
shutil.rmtree(self.temp_dir)
@ -211,6 +217,7 @@ class ArgumentsTestCase(test.CdistTestCase):
self.manifest = core.Manifest(self.target_host, self.local)
self.env = self.manifest.env_initial_manifest(self.script)
self.env['__cdist_object_marker'] = self.local.object_marker_name
def tearDown(self):
shutil.rmtree(self.temp_dir)
@ -222,7 +229,7 @@ class ArgumentsTestCase(test.CdistTestCase):
emu.run()
cdist_type = core.CdistType(self.local.type_path, '__arguments_with_dashes')
cdist_object = core.CdistObject(cdist_type, self.local.object_path, 'some-id')
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):
@ -234,7 +241,7 @@ 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, 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
@ -242,17 +249,17 @@ class ArgumentsTestCase(test.CdistTestCase):
def test_required_arguments(self):
"""check whether assigning required parameter works"""
type_name = '__arguments_required'
object_id = 'some-id'
value = 'some value'
argv = [type_name, object_id, '--required1', value, '--required2', value]
# print(self.env)
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, 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)
@ -278,7 +285,7 @@ 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, 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)
@ -293,7 +300,7 @@ 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, 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)
@ -346,7 +353,7 @@ 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, 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

@ -127,7 +127,7 @@ 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, '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'}
self.explorer.transfer_object_parameters(cdist_object)
@ -137,14 +137,14 @@ class ExplorerClassTestCase(test.CdistTestCase):
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, '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, '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

@ -84,7 +84,7 @@ class ManifestTestCase(test.CdistTestCase):
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, '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