verify manifest environment

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2011-10-18 14:23:06 +02:00
parent 91c1215566
commit a946b5cf59
3 changed files with 59 additions and 13 deletions

View file

@ -27,6 +27,8 @@ import shutil
import string import string
import random import random
import logging import logging
import io
import sys
import cdist import cdist
from cdist.exec import local from cdist.exec import local
@ -48,6 +50,8 @@ class ManifestTestCase(unittest.TestCase):
return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs) return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs)
def setUp(self): def setUp(self):
self.orig_environ = os.environ
os.environ = os.environ.copy()
self.temp_dir = self.mkdtemp() self.temp_dir = self.mkdtemp()
self.target_host = 'localhost' self.target_host = 'localhost'
out_path = self.temp_dir out_path = self.temp_dir
@ -58,17 +62,54 @@ class ManifestTestCase(unittest.TestCase):
self.log = logging.getLogger(self.target_host) self.log = logging.getLogger(self.target_host)
def tearDown(self): def tearDown(self):
os.environ = self.orig_environ
shutil.rmtree(self.temp_dir) shutil.rmtree(self.temp_dir)
def test_initial_manifest_environment(self): 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.environ['__cdist_test_out'] = output_file
self.manifest.run_initial_manifest(initial_manifest) self.manifest.run_initial_manifest(initial_manifest)
with open(output_file, 'r') as fd:
output_string = fd.read()
print("output_string: %s" % output_string)
output_dict = {}
for line in output_string.split('\n'):
if line:
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.out_path)
self.assertEqual(output_dict['__cdist_type_base_path'], self.local.type_path)
self.assertEqual(output_dict['__manifest'], self.local.manifest_path)
def test_type_manifest_environment(self): def test_type_manifest_environment(self):
cdist_type = core.Type(self.local.type_path, '__dump_environment') cdist_type = core.Type(self.local.type_path, '__dump_environment')
cdist_object = core.Object(cdist_type, self.local.object_path, 'whatever') cdist_object = core.Object(cdist_type, self.local.object_path, 'whatever')
handle, output_file = self.mkstemp(dir=self.temp_dir)
os.environ['__cdist_test_out'] = output_file
self.manifest.run_type_manifest(cdist_object) self.manifest.run_type_manifest(cdist_object)
with open(output_file, 'r') as fd:
output_string = fd.read()
print("output_string: %s" % output_string)
output_dict = {}
for line in output_string.split('\n'):
if line:
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.out_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['__self'], cdist_object.path)
self.assertEqual(output_dict['__object_id'], cdist_object.object_id)
self.assertEqual(output_dict['__object_fq'], cdist_object.path)
def test_debug_env_setup(self): def test_debug_env_setup(self):
self.log.setLevel(logging.DEBUG) self.log.setLevel(logging.DEBUG)
manifest = cdist.core.manifest.Manifest(self.target_host, self.local) manifest = cdist.core.manifest.Manifest(self.target_host, self.local)

View file

@ -1,7 +1,9 @@
#!/bin/sh #!/bin/sh
echo "PATH: $PATH" cat > $__cdist_test_out << DONE
echo "__target_host: $__target_host" PATH: $PATH
echo "__global: $__global" __target_host: $__target_host
echo "__cdist_type_base_path: $__cdist_type_base_path" __global: $__global
echo "__manifest: $__manifest" __cdist_type_base_path: $__cdist_type_base_path
__manifest: $__manifest
DONE

View file

@ -1,10 +1,13 @@
#!/bin/sh #!/bin/sh
echo "PATH: $PATH" cat > $__cdist_test_out << DONE
echo "__target_host: $__target_host" PATH: $PATH
echo "__global: $__global" __target_host: $__target_host
echo "__cdist_type_base_path: $__cdist_type_base_path" __global: $__global
echo "__type: $__type" __cdist_type_base_path: $__cdist_type_base_path
echo "__object: $__object" __type: $__type
echo "__object_id: $__object_id" __self: $__self
echo "__object_fq: $__object_fq" __object: $__object
__object_id: $__object_id
__object_fq: $__object_fq
DONE