From 6f82aef7048fa33c25130970147af312de55caff Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 20 Oct 2011 10:55:11 +0200 Subject: [PATCH 1/5] add test for Explorer run_global_explorers Signed-off-by: Steven Armstrong --- lib/cdist/test/explorer/__init__.py | 8 +++++++- lib/cdist/test/explorer/fixtures/conf/explorer/foobar | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100755 lib/cdist/test/explorer/fixtures/conf/explorer/foobar diff --git a/lib/cdist/test/explorer/__init__.py b/lib/cdist/test/explorer/__init__.py index 18815f07..6743ee26 100644 --- a/lib/cdist/test/explorer/__init__.py +++ b/lib/cdist/test/explorer/__init__.py @@ -62,7 +62,7 @@ class ExplorerClassTestCase(test.CdistTestCase): shutil.rmtree(self.remote_base_path) def test_list_global_explorer_names(self): - expected = ['global'] + expected = ['foobar', 'global'] self.assertEqual(self.explorer.list_global_explorer_names(), expected) def test_transfer_global_explorers(self): @@ -76,6 +76,12 @@ class ExplorerClassTestCase(test.CdistTestCase): output = self.explorer.run_global_explorer('global') self.assertEqual(output, 'global\n') + def test_run_global_explorers(self): + out_path = self.mkdtemp() + self.explorer.run_global_explorers(out_path) + self.assertEqual(os.listdir(out_path), ['foobar', 'global']) + shutil.rmtree(out_path) + def test_list_type_explorer_names(self): cdist_type = core.Type(self.local.type_path, '__test_type') expected = cdist_type.explorers diff --git a/lib/cdist/test/explorer/fixtures/conf/explorer/foobar b/lib/cdist/test/explorer/fixtures/conf/explorer/foobar new file mode 100755 index 00000000..33533edd --- /dev/null +++ b/lib/cdist/test/explorer/fixtures/conf/explorer/foobar @@ -0,0 +1,2 @@ +#!/bin/sh +echo foobar From 40971208f24fe0377ce353c1acc8131b80c0decb Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 20 Oct 2011 11:04:41 +0200 Subject: [PATCH 2/5] add test for Explorer run_type_explorers Signed-off-by: Steven Armstrong --- lib/cdist/test/explorer/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/cdist/test/explorer/__init__.py b/lib/cdist/test/explorer/__init__.py index 6743ee26..1f7a2e35 100644 --- a/lib/cdist/test/explorer/__init__.py +++ b/lib/cdist/test/explorer/__init__.py @@ -124,3 +124,10 @@ class ExplorerClassTestCase(test.CdistTestCase): 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.Type(self.local.type_path, '__test_type') + cdist_object = core.Object(cdist_type, self.local.object_path, 'whatever') + cdist_object.create() + self.explorer.run_type_explorers(cdist_object) + self.assertEqual(cdist_object.explorers, {'world': 'hello'}) From 60c4e21981390676deec431b3884332a7c7e39b9 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 20 Oct 2011 11:05:50 +0200 Subject: [PATCH 3/5] implement Explorer run_global_explorers and run_type_explorers Signed-off-by: Steven Armstrong --- lib/cdist/core/explorer.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/cdist/core/explorer.py b/lib/cdist/core/explorer.py index 2e13cc78..0a8c6986 100644 --- a/lib/cdist/core/explorer.py +++ b/lib/cdist/core/explorer.py @@ -83,6 +83,19 @@ class Explorer(object): """Return a list of global explorer names.""" return os.listdir(self.local.global_explorer_path) + def run_global_explorers(self, out_path): + """Run global explorers and save output to files in the given + out_path directory. + + """ + self.log.info("Running global explorers") + self.transfer_global_explorers() + for explorer in self.list_global_explorer_names(): + output = self.run_global_explorer(explorer) + path = os.path.join(out_path, explorer) + with open(path, 'w') as fd: + fd.write(output) + def transfer_global_explorers(self): """Transfer the global explorers to the remote side.""" self.remote.mkdir(self.remote.global_explorer_path) @@ -103,6 +116,20 @@ class Explorer(object): except EnvironmentError: return [] + def run_type_explorers(self, cdist_object): + """Run the type explorers for the given object and save their output + in the object. + + """ + self.log.debug("Transfering type explorers for type: %s", cdist_object.type) + self.transfer_type_explorers(cdist_object.type) + self.log.debug("Transfering object parameters for object: %s", cdist_object.name) + self.transfer_object_parameters(cdist_object) + for explorer in self.list_type_explorer_names(cdist_object.type): + output = self.run_type_explorer(explorer, cdist_object) + self.log.debug("Running type explorer '%s' for object '%s'", explorer, cdist_object.name) + cdist_object.explorers[explorer] = output + def transfer_type_explorers(self, cdist_type): """Transfer the type explorers for the given type to the remote side.""" if cdist_type.explorers: From 81e4c0a418c1e9cee3f30d14133c013bc919847c Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 20 Oct 2011 11:10:30 +0200 Subject: [PATCH 4/5] move run_*_explorers from config_install to core.explorer Signed-off-by: Steven Armstrong --- lib/cdist/config_install.py | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/lib/cdist/config_install.py b/lib/cdist/config_install.py index 8bc8adf5..75b07e78 100644 --- a/lib/cdist/config_install.py +++ b/lib/cdist/config_install.py @@ -77,7 +77,7 @@ class ConfigInstall(object): def stage_prepare(self): """Do everything for a deploy, minus the actual code stage""" self.local.link_emulator(self.context.exec_path) - self.run_global_explorers() + self.explorer.run_global_explorers(self.local.global_explorer_out_path) self.manifest.run_initial_manifest(self.context.initial_manifest) self.log.info("Running object manifests and type explorers") @@ -95,32 +95,10 @@ class ConfigInstall(object): self.object_prepare(cdist_object) new_objects_created = True - def run_global_explorers(self): - """Run global explorers and save output""" - # FIXME: move to explorer, pass global_explorer_out_path as argument - self.log.info("Running global explorers") - self.explorer.transfer_global_explorers() - for explorer in self.explorer.list_global_explorer_names(): - output = self.explorer.run_global_explorer(explorer) - path = os.path.join(self.local.global_explorer_out_path, explorer) - with open(path, 'w') as fd: - fd.write(output) - - def run_type_explorers(self, cdist_object): - """Run type explorers and save output in object.""" - self.log.debug("Transfering type explorers for type: %s", cdist_object.type) - self.explorer.transfer_type_explorers(cdist_object.type) - self.log.debug("Transfering object parameters for object: %s", cdist_object.name) - self.explorer.transfer_object_parameters(cdist_object) - for explorer in self.explorer.list_type_explorer_names(cdist_object.type): - output = self.explorer.run_type_explorer(explorer, cdist_object) - self.log.debug("Running type explorer '%s' for object '%s'", explorer, cdist_object.name) - cdist_object.explorers[explorer] = output - def object_prepare(self, cdist_object): """Prepare object: Run type explorer + manifest""" self.log.info("Running manifest and explorers for " + cdist_object.name) - self.run_type_explorers(cdist_object) + self.explorer.run_type_explorers(cdist_object) self.manifest.run_type_manifest(cdist_object) cdist_object.state = core.Object.STATE_PREPARED From a2cda1ccce87d62fc93cff291a61427134ee242b Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 20 Oct 2011 11:16:38 +0200 Subject: [PATCH 5/5] --todo Signed-off-by: Steven Armstrong --- doc/dev/todo/steven | 7 ------- 1 file changed, 7 deletions(-) diff --git a/doc/dev/todo/steven b/doc/dev/todo/steven index b6e07eac..f8e13a45 100644 --- a/doc/dev/todo/steven +++ b/doc/dev/todo/steven @@ -45,13 +45,6 @@ logging: [2] http://blog.ooz.ie/2011/03/python-logging-extending-standard.html -config_install: - - move code for running global and type explorer run to cdist.core.explorer - -tests: - - aufraeumen - - test suite - tests: