tests and fixtures for emulator autorequire

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2011-11-02 23:57:13 +01:00
parent 6e7ebf6de1
commit 0d05e61b85
9 changed files with 56 additions and 1 deletions

View file

@ -22,6 +22,7 @@
import os
import shutil
import cdist
from cdist import test
from cdist.exec import local
from cdist import emulator
@ -29,7 +30,6 @@ from cdist import core
local_base_path = test.cdist_base_path
class EmulatorTestCase(test.CdistTestCase):
def setUp(self):
@ -73,3 +73,32 @@ class EmulatorTestCase(test.CdistTestCase):
os.environ['require'] = '__file/bad/id/with/.cdist/inside'
emu = emulator.Emulator(argv)
self.assertRaises(core.IllegalObjectIdError, emu.run)
import os.path as op
my_dir = op.abspath(op.dirname(__file__))
fixtures = op.join(my_dir, 'fixtures')
class AutoRequireEmulatorTestCase(test.CdistTestCase):
def setUp(self):
self.temp_dir = self.mkdtemp()
self.target_host = 'localhost'
out_path = self.temp_dir
_local_base_path = fixtures
self.local = local.Local(self.target_host, _local_base_path, out_path)
self.local.create_directories()
self.local.link_emulator(cdist.test.cdist_exec_path)
self.manifest = core.Manifest(self.target_host, self.local)
def tearDown(self):
shutil.rmtree(self.temp_dir)
def test_autorequire(self):
initial_manifest = os.path.join(self.local.manifest_path, "init")
self.manifest.run_initial_manifest(initial_manifest)
cdist_type = core.Type(self.local.type_path, '__saturn')
cdist_object = core.Object(cdist_type, self.local.object_path, 'singleton')
self.manifest.run_type_manifest(cdist_object)
expected = ['__planet/Saturn', '__moon/Prometheus']
self.assertEqual(sorted(cdist_object.requirements), sorted(expected))

View file

@ -0,0 +1,3 @@
#!/bin/sh
__saturn

View file

@ -0,0 +1,8 @@
#!/bin/sh
if [ -f "$__object/parameter/name" ]; then
name="(cat "$__object/parameter/name")"
else
name="$__object_id"
echo "$name" > "$__object/parameter/name"
fi

View file

@ -0,0 +1 @@
planet

View file

@ -0,0 +1,8 @@
#!/bin/sh
if [ -f "$__object/parameter/name" ]; then
name="(cat "$__object/parameter/name")"
else
name="$__object_id"
echo "$name" > "$__object/parameter/name"
fi

View file

@ -0,0 +1,4 @@
#!/bin/sh
__planet Saturn
require="__planet/Saturn" __moon Prometheus --planet Saturn