From 0d05e61b85cb6a82ea9f15a068b4deb4d763e70a Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 2 Nov 2011 23:57:13 +0100 Subject: [PATCH] tests and fixtures for emulator autorequire Signed-off-by: Steven Armstrong --- lib/cdist/test/emulator/__init__.py | 31 ++++++++++++++++++- .../test/emulator/fixtures/conf/manifest/init | 3 ++ .../fixtures/conf/type/__moon/manifest | 8 +++++ .../conf/type/__moon/parameter/optional | 1 + .../conf/type/__moon/parameter/required | 1 + .../fixtures/conf/type/__planet/manifest | 8 +++++ .../conf/type/__planet/parameter/optional | 1 + .../fixtures/conf/type/__saturn/manifest | 4 +++ .../fixtures/conf/type/__saturn/singleton | 0 9 files changed, 56 insertions(+), 1 deletion(-) create mode 100755 lib/cdist/test/emulator/fixtures/conf/manifest/init create mode 100755 lib/cdist/test/emulator/fixtures/conf/type/__moon/manifest create mode 100644 lib/cdist/test/emulator/fixtures/conf/type/__moon/parameter/optional create mode 100644 lib/cdist/test/emulator/fixtures/conf/type/__moon/parameter/required create mode 100755 lib/cdist/test/emulator/fixtures/conf/type/__planet/manifest create mode 100644 lib/cdist/test/emulator/fixtures/conf/type/__planet/parameter/optional create mode 100755 lib/cdist/test/emulator/fixtures/conf/type/__saturn/manifest create mode 100644 lib/cdist/test/emulator/fixtures/conf/type/__saturn/singleton diff --git a/lib/cdist/test/emulator/__init__.py b/lib/cdist/test/emulator/__init__.py index 91150334..7b30fba1 100644 --- a/lib/cdist/test/emulator/__init__.py +++ b/lib/cdist/test/emulator/__init__.py @@ -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)) diff --git a/lib/cdist/test/emulator/fixtures/conf/manifest/init b/lib/cdist/test/emulator/fixtures/conf/manifest/init new file mode 100755 index 00000000..9fa1aa53 --- /dev/null +++ b/lib/cdist/test/emulator/fixtures/conf/manifest/init @@ -0,0 +1,3 @@ +#!/bin/sh + +__saturn diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__moon/manifest b/lib/cdist/test/emulator/fixtures/conf/type/__moon/manifest new file mode 100755 index 00000000..362be5a1 --- /dev/null +++ b/lib/cdist/test/emulator/fixtures/conf/type/__moon/manifest @@ -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 diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__moon/parameter/optional b/lib/cdist/test/emulator/fixtures/conf/type/__moon/parameter/optional new file mode 100644 index 00000000..f121bdbf --- /dev/null +++ b/lib/cdist/test/emulator/fixtures/conf/type/__moon/parameter/optional @@ -0,0 +1 @@ +name diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__moon/parameter/required b/lib/cdist/test/emulator/fixtures/conf/type/__moon/parameter/required new file mode 100644 index 00000000..729a5167 --- /dev/null +++ b/lib/cdist/test/emulator/fixtures/conf/type/__moon/parameter/required @@ -0,0 +1 @@ +planet diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__planet/manifest b/lib/cdist/test/emulator/fixtures/conf/type/__planet/manifest new file mode 100755 index 00000000..362be5a1 --- /dev/null +++ b/lib/cdist/test/emulator/fixtures/conf/type/__planet/manifest @@ -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 diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__planet/parameter/optional b/lib/cdist/test/emulator/fixtures/conf/type/__planet/parameter/optional new file mode 100644 index 00000000..f121bdbf --- /dev/null +++ b/lib/cdist/test/emulator/fixtures/conf/type/__planet/parameter/optional @@ -0,0 +1 @@ +name diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__saturn/manifest b/lib/cdist/test/emulator/fixtures/conf/type/__saturn/manifest new file mode 100755 index 00000000..38b8cbf3 --- /dev/null +++ b/lib/cdist/test/emulator/fixtures/conf/type/__saturn/manifest @@ -0,0 +1,4 @@ +#!/bin/sh + +__planet Saturn +require="__planet/Saturn" __moon Prometheus --planet Saturn diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__saturn/singleton b/lib/cdist/test/emulator/fixtures/conf/type/__saturn/singleton new file mode 100644 index 00000000..e69de29b