Merge remote-tracking branch 'steven/run-explorers-in-cdist.core.explorer'

This commit is contained in:
Nico Schottelius 2011-10-21 20:19:41 +02:00
commit 80cd35fc3d
5 changed files with 45 additions and 32 deletions

View file

@ -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:

View file

@ -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

View file

@ -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:

View file

@ -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
@ -118,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'})

View file

@ -0,0 +1,2 @@
#!/bin/sh
echo foobar