From 77813efdf369152d2616439c0cc320b072124931 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 10:30:56 +0200 Subject: [PATCH 01/23] +todo Signed-off-by: Steven Armstrong --- doc/dev/todo/steven | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/dev/todo/steven b/doc/dev/todo/steven index 6364c4d4..a602b753 100644 --- a/doc/dev/todo/steven +++ b/doc/dev/todo/steven @@ -10,6 +10,10 @@ logging: ... then one could filter e.g. on explorer.* +exec local & remote: + - don't capture output by default + - add new mechanism to capture output explicitly + tests: From 96d5d9b8e8a22256212ecd9fa9d924d5bca67ab8 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 10:32:25 +0200 Subject: [PATCH 02/23] +todo Signed-off-by: Steven Armstrong --- doc/dev/todo/steven | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/dev/todo/steven b/doc/dev/todo/steven index a602b753..c7e93423 100644 --- a/doc/dev/todo/steven +++ b/doc/dev/todo/steven @@ -15,6 +15,10 @@ exec local & remote: - add new mechanism to capture output explicitly +config_install: + - move code for running global and type explorer run to cdist.core.explorer + + tests: __init__(): From 6067646ffa4855f357cc3f3902a96e3425934ad7 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 10:40:10 +0200 Subject: [PATCH 03/23] +todo Signed-off-by: Steven Armstrong --- doc/dev/todo/steven | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/dev/todo/steven b/doc/dev/todo/steven index c7e93423..90040ad6 100644 --- a/doc/dev/todo/steven +++ b/doc/dev/todo/steven @@ -10,6 +10,10 @@ logging: ... then one could filter e.g. on explorer.* + - more granular debug output, + [2] http://blog.ooz.ie/2011/03/python-logging-extending-standard.html + + exec local & remote: - don't capture output by default - add new mechanism to capture output explicitly @@ -18,6 +22,10 @@ exec local & remote: config_install: - move code for running global and type explorer run to cdist.core.explorer +tests: + - aufraeumen + - test suite + tests: From 9640c3a0981ce165ac4e552cf97de7062232b25f Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 11:21:12 +0200 Subject: [PATCH 04/23] test for illegal object_id Signed-off-by: Steven Armstrong --- lib/cdist/test/object/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/cdist/test/object/__init__.py b/lib/cdist/test/object/__init__.py index 9ba3ed61..9a13f524 100644 --- a/lib/cdist/test/object/__init__.py +++ b/lib/cdist/test/object/__init__.py @@ -52,6 +52,14 @@ class ObjectClassTestCase(unittest.TestCase): self.assertEqual(objects, objects_expected) +class ObjectIdTestCase(unittest.TestCase): + def test_illegal_object_id(self): + cdist_type = core.Type(type_base_path, '__third') + illegal_object_id = '/object_id/may/not/start/with/slash' + with self.assertRaises(core.IllegalObjectIdError): + core.Object(cdist_type, object_base_path, illegal_object_id) + + class ObjectTestCase(unittest.TestCase): def setUp(self): From 3e3919d15f00c62c670b3ab901d7274e43a2b770 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 11:25:39 +0200 Subject: [PATCH 05/23] implement fail if object_id starts with / Signed-off-by: Steven Armstrong --- lib/cdist/core/__init__.py | 1 + lib/cdist/core/object.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/cdist/core/__init__.py b/lib/cdist/core/__init__.py index 1dec9e8f..507082a3 100644 --- a/lib/cdist/core/__init__.py +++ b/lib/cdist/core/__init__.py @@ -21,6 +21,7 @@ from cdist.core.type import Type from cdist.core.object import Object +from cdist.core.object import IllegalObjectIdError from cdist.core.explorer import Explorer from cdist.core.manifest import Manifest from cdist.core.code import Code diff --git a/lib/cdist/core/object.py b/lib/cdist/core/object.py index 282e8be5..c447f243 100644 --- a/lib/cdist/core/object.py +++ b/lib/cdist/core/object.py @@ -33,6 +33,14 @@ log = logging.getLogger(__name__) DOT_CDIST = '.cdist' +class IllegalObjectIdError(cdist.Error): + def __init__(self, object_id): + self.object_id = object_id + + def __str__(self): + return 'Illegal object id: %s' % self.object_id + + class Object(object): """Represents a cdist object. @@ -79,6 +87,8 @@ class Object(object): return self.__class__(self.type.__class__(type_path, type_name), object_path, object_id=object_id) def __init__(self, cdist_type, base_path, object_id=None): + if object_id and object_id.startswith('/'): + raise IllegalObjectIdError(object_id) self.type = cdist_type # instance of Type self.base_path = base_path self.object_id = object_id From d346364544b0eea9f2687477103884caf3720c50 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 11:39:03 +0200 Subject: [PATCH 06/23] better error message Signed-off-by: Steven Armstrong --- lib/cdist/core/object.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/cdist/core/object.py b/lib/cdist/core/object.py index c447f243..eeb5799b 100644 --- a/lib/cdist/core/object.py +++ b/lib/cdist/core/object.py @@ -34,11 +34,12 @@ DOT_CDIST = '.cdist' class IllegalObjectIdError(cdist.Error): - def __init__(self, object_id): + def __init__(self, object_id, message=None): self.object_id = object_id + self.message = message or 'Illegal object id' def __str__(self): - return 'Illegal object id: %s' % self.object_id + return '%s: %s' % (self.message, self.object_id) class Object(object): @@ -88,7 +89,7 @@ class Object(object): def __init__(self, cdist_type, base_path, object_id=None): if object_id and object_id.startswith('/'): - raise IllegalObjectIdError(object_id) + raise IllegalObjectIdError(object_id, 'object_id may not start with /') self.type = cdist_type # instance of Type self.base_path = base_path self.object_id = object_id From f285d9e64ee1e3e3111eab7ccba0099097fac43e Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 11:39:55 +0200 Subject: [PATCH 07/23] emulator: fail if object_id of requirement starts with slash Signed-off-by: Steven Armstrong --- lib/cdist/emulator.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/cdist/emulator.py b/lib/cdist/emulator.py index 4445f0f7..ca65e731 100644 --- a/lib/cdist/emulator.py +++ b/lib/cdist/emulator.py @@ -106,8 +106,19 @@ def run(argv): # Record requirements if "require" in os.environ: requirements = os.environ['require'] - log.debug("%s:Writing requirements: %s" % (cdist_object.path, requirements)) - cdist_object.requirements.extend(requirements.split(" ")) + for requirement in requirements.split(" "): + requirement_parts = requirement.split(os.sep, 1) + requirement_parts.reverse() + requirement_type_name = requirement_parts.pop() + try: + requirement_object_id = requirement_parts.pop() + except IndexError: + # no object id, must be singleton + requirement_object_id = 'singleton' + if requirement_object_id.startswith('/'): + raise core.IllegalObjectIdError(requirement_object_id, 'object_id may not start with /') + log.debug("Recording requirement: %s -> %s" % (cdist_object.path, requirement)) + cdist_object.requirements.append(rement_object_id) # Record / Append source cdist_object.source.append(object_source) From 1c84e423d11b9535a940ed9f76f8e69a3b2ff40e Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 11:49:37 +0200 Subject: [PATCH 08/23] include type name in error message Signed-off-by: Steven Armstrong --- lib/cdist/core/object.py | 7 ++++--- lib/cdist/emulator.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/cdist/core/object.py b/lib/cdist/core/object.py index eeb5799b..60ae59f4 100644 --- a/lib/cdist/core/object.py +++ b/lib/cdist/core/object.py @@ -34,12 +34,13 @@ DOT_CDIST = '.cdist' class IllegalObjectIdError(cdist.Error): - def __init__(self, object_id, message=None): + def __init__(self, object_id, type_name, message=None): self.object_id = object_id + self.type_name = type_name self.message = message or 'Illegal object id' def __str__(self): - return '%s: %s' % (self.message, self.object_id) + return '%s: %s' % (self.message, os.path.join(self.type_name. self.object_id)) class Object(object): @@ -89,7 +90,7 @@ class Object(object): def __init__(self, cdist_type, base_path, object_id=None): if object_id and object_id.startswith('/'): - raise IllegalObjectIdError(object_id, 'object_id may not start with /') + raise IllegalObjectIdError(object_id, cdist_type.name, 'object_id may not start with /') self.type = cdist_type # instance of Type self.base_path = base_path self.object_id = object_id diff --git a/lib/cdist/emulator.py b/lib/cdist/emulator.py index ca65e731..f37c3169 100644 --- a/lib/cdist/emulator.py +++ b/lib/cdist/emulator.py @@ -116,9 +116,9 @@ def run(argv): # no object id, must be singleton requirement_object_id = 'singleton' if requirement_object_id.startswith('/'): - raise core.IllegalObjectIdError(requirement_object_id, 'object_id may not start with /') + raise core.IllegalObjectIdError(requirement_object_id, requirement_type_name, 'object_id may not start with /') log.debug("Recording requirement: %s -> %s" % (cdist_object.path, requirement)) - cdist_object.requirements.append(rement_object_id) + cdist_object.requirements.append(requirement) # Record / Append source cdist_object.source.append(object_source) From f76a5abf6f1e97483bd974a905df26d1f6037c49 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 11:50:40 +0200 Subject: [PATCH 09/23] /./,/ Signed-off-by: Steven Armstrong --- lib/cdist/core/object.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cdist/core/object.py b/lib/cdist/core/object.py index 60ae59f4..a802a457 100644 --- a/lib/cdist/core/object.py +++ b/lib/cdist/core/object.py @@ -40,7 +40,7 @@ class IllegalObjectIdError(cdist.Error): self.message = message or 'Illegal object id' def __str__(self): - return '%s: %s' % (self.message, os.path.join(self.type_name. self.object_id)) + return '%s: %s' % (self.message, os.path.join(self.type_name, self.object_id)) class Object(object): From 93db0b58d64210f14539a3c79766e810c368423a Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 12:05:30 +0200 Subject: [PATCH 10/23] append type to error message Signed-off-by: Steven Armstrong --- lib/cdist/core/object.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cdist/core/object.py b/lib/cdist/core/object.py index a802a457..339591ad 100644 --- a/lib/cdist/core/object.py +++ b/lib/cdist/core/object.py @@ -40,7 +40,7 @@ class IllegalObjectIdError(cdist.Error): self.message = message or 'Illegal object id' def __str__(self): - return '%s: %s' % (self.message, os.path.join(self.type_name, self.object_id)) + return '%s: type: %s, object_id: %s' % (self.message, self.type_name, self.object_id) class Object(object): From fb705adc5d8af9d708dcfd11f7ac37c2ca803342 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 14:04:56 +0200 Subject: [PATCH 11/23] simplify object_id error handling Signed-off-by: Steven Armstrong --- lib/cdist/core/object.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/cdist/core/object.py b/lib/cdist/core/object.py index 339591ad..eeb5799b 100644 --- a/lib/cdist/core/object.py +++ b/lib/cdist/core/object.py @@ -34,13 +34,12 @@ DOT_CDIST = '.cdist' class IllegalObjectIdError(cdist.Error): - def __init__(self, object_id, type_name, message=None): + def __init__(self, object_id, message=None): self.object_id = object_id - self.type_name = type_name self.message = message or 'Illegal object id' def __str__(self): - return '%s: type: %s, object_id: %s' % (self.message, self.type_name, self.object_id) + return '%s: %s' % (self.message, self.object_id) class Object(object): @@ -90,7 +89,7 @@ class Object(object): def __init__(self, cdist_type, base_path, object_id=None): if object_id and object_id.startswith('/'): - raise IllegalObjectIdError(object_id, cdist_type.name, 'object_id may not start with /') + raise IllegalObjectIdError(object_id, 'object_id may not start with /') self.type = cdist_type # instance of Type self.base_path = base_path self.object_id = object_id From e715dbb8017de2401a85c105abe2a701cc00eaa6 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 15:50:10 +0200 Subject: [PATCH 12/23] update test: dont return command output by default Signed-off-by: Steven Armstrong --- lib/cdist/test/exec/local.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cdist/test/exec/local.py b/lib/cdist/test/exec/local.py index 8585f87a..f19bf55c 100644 --- a/lib/cdist/test/exec/local.py +++ b/lib/cdist/test/exec/local.py @@ -114,7 +114,7 @@ class LocalTestCase(unittest.TestCase): fd = open(script, "w") fd.writelines(["#!/bin/sh\n", "echo foobar"]) fd.close() - self.assertEqual(self.local.run_script(script), "foobar\n") + self.assertEqual(self.local.run_script(script, return_output=True), "foobar\n") def test_mkdir(self): temp_dir = self.mkdtemp(dir=self.temp_dir) From ab1d3d16f16c94e42174ccdcedd791c69bb970c8 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 15:51:00 +0200 Subject: [PATCH 13/23] implement: dont return command output by default Signed-off-by: Steven Armstrong --- lib/cdist/exec/local.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/cdist/exec/local.py b/lib/cdist/exec/local.py index bef44e21..56c29cb7 100644 --- a/lib/cdist/exec/local.py +++ b/lib/cdist/exec/local.py @@ -87,7 +87,7 @@ class Local(object): # FIXME: dont set mode here, fix unittest mkdtemp instead os.makedirs(path, mode=0o700, exist_ok=True) - def run(self, command, env=None): + def run(self, command, env=None, return_output=False): """Run the given command with the given environment. Return the output as a string. @@ -95,13 +95,16 @@ class Local(object): assert isinstance(command, (list, tuple)), "list or tuple argument expected, got: %s" % command self.log.debug("Local run: %s", command) try: - return subprocess.check_output(command, env=env).decode() + if return_output: + return subprocess.check_output(command, env=env).decode() + else: + subprocess.check_call(command, env=env) except subprocess.CalledProcessError: raise cdist.Error("Command failed: " + " ".join(command)) except OSError as error: raise cdist.Error(" ".join(*args) + ": " + error.args[1]) - def run_script(self, script, env=None): + def run_script(self, script, env=None, return_output=False): """Run the given script with the given environment. Return the output as a string. @@ -114,7 +117,10 @@ class Local(object): self.log.debug("Local run script env: %s", env) try: - return subprocess.check_output(command, env=env).decode() + if return_output: + return subprocess.check_output(command, env=env).decode() + else: + subprocess.check_call(command, env=env) except subprocess.CalledProcessError as error: script_content = self.run(["cat", script]) self.log.error("Code that raised the error:\n%s", script_content) From 86cb65cd9ce81ba24ccfc420c7e80d6a3a6aefec Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 15:51:40 +0200 Subject: [PATCH 14/23] update test: dont return command output by default Signed-off-by: Steven Armstrong --- lib/cdist/test/exec/remote.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cdist/test/exec/remote.py b/lib/cdist/test/exec/remote.py index ea9a17aa..f5151156 100644 --- a/lib/cdist/test/exec/remote.py +++ b/lib/cdist/test/exec/remote.py @@ -92,7 +92,7 @@ class RemoteTestCase(unittest.TestCase): fd = open(script, "w") fd.writelines(["#!/bin/sh\n", "echo foobar"]) fd.close() - self.assertEqual(self.remote.run_script(script), "foobar\n") + self.assertEqual(self.remote.run_script(script, return_output=True), "foobar\n") def test_mkdir(self): temp_dir = self.mkdtemp(dir=self.temp_dir) From 829b0b2d0b3faa10366d2c8fcd95b01f01093b74 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 15:52:16 +0200 Subject: [PATCH 15/23] implement: dont return command output by default Signed-off-by: Steven Armstrong --- lib/cdist/exec/remote.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/cdist/exec/remote.py b/lib/cdist/exec/remote.py index 2ffc73fd..2de16426 100644 --- a/lib/cdist/exec/remote.py +++ b/lib/cdist/exec/remote.py @@ -85,7 +85,7 @@ class Remote(object): command.extend(["-r", source, self.target_host + ":" + destination]) self.run_command(command) - def run(self, command, env=None): + def run(self, command, env=None, return_output=False): """Run the given command with the given environment on the remote side. Return the output as a string. @@ -94,9 +94,9 @@ class Remote(object): cmd = self._exec.split() cmd.append(self.target_host) cmd.extend(command) - return self.run_command(cmd, env=env) + return self.run_command(cmd, env=env, return_output=return_output) - def run_command(self, command, env=None): + def run_command(self, command, env=None, return_output=False): """Run the given command with the given environment. Return the output as a string. @@ -113,13 +113,16 @@ class Remote(object): self.log.debug("Remote run: %s", command) try: - return subprocess.check_output(cmd).decode() + if return_output: + return subprocess.check_output(command, env=env).decode() + else: + subprocess.check_call(command, env=env) except subprocess.CalledProcessError: raise cdist.Error("Command failed: " + " ".join(command)) except OSError as error: raise cdist.Error(" ".join(*args) + ": " + error.args[1]) - def run_script(self, script, env=None): + def run_script(self, script, env=None, return_output=False): """Run the given script with the given environment on the remote side. Return the output as a string. @@ -140,7 +143,10 @@ class Remote(object): self.log.debug("Remote run script env: %s", env) try: - return subprocess.check_output(command).decode() + if return_output: + return subprocess.check_output(command, env=env).decode() + else: + subprocess.check_call(command, env=env) except subprocess.CalledProcessError as error: script_content = self.run(["cat", script]) self.log.error("Code that raised the error:\n%s", script_content) From 1e622f91280c57174db8eabfc00cbf0d61737404 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 15:52:53 +0200 Subject: [PATCH 16/23] raise IllegalRequirementError if requirements object_id starts with a / Signed-off-by: Steven Armstrong --- lib/cdist/emulator.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/cdist/emulator.py b/lib/cdist/emulator.py index f37c3169..0b303b23 100644 --- a/lib/cdist/emulator.py +++ b/lib/cdist/emulator.py @@ -28,6 +28,16 @@ from cdist import core log = logging.getLogger(__name__) + +class IllegalRequirementError(cdist.Error): + def __init__(self, requirement, message=None): + self.requirement = requirement + self.message = message or 'Illegal requirement' + + def __str__(self): + return '%s: %s' % (self.message, self.requirement) + + def run(argv): """Emulate type commands (i.e. __file and co)""" global_path = os.environ['__global'] @@ -116,7 +126,7 @@ def run(argv): # no object id, must be singleton requirement_object_id = 'singleton' if requirement_object_id.startswith('/'): - raise core.IllegalObjectIdError(requirement_object_id, requirement_type_name, 'object_id may not start with /') + raise IllegalRequirementError(requirement, 'requirements object_id may not start with /') log.debug("Recording requirement: %s -> %s" % (cdist_object.path, requirement)) cdist_object.requirements.append(requirement) From 63ad8825127cfa75f0ae74c25cf5538b596aab93 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 15:58:42 +0200 Subject: [PATCH 17/23] update test: run_code* should no longer return output Signed-off-by: Steven Armstrong --- lib/cdist/test/code/__init__.py | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/lib/cdist/test/code/__init__.py b/lib/cdist/test/code/__init__.py index 0d7aec75..f661ad24 100644 --- a/lib/cdist/test/code/__init__.py +++ b/lib/cdist/test/code/__init__.py @@ -105,33 +105,11 @@ class CodeTestCase(unittest.TestCase): destination = os.path.join(self.remote.object_path, self.cdist_object.code_remote_path) self.assertTrue(os.path.isfile(destination)) - def test_run_code_local_environment(self): + def test_run_code_local(self): self.cdist_object.code_local = self.code.run_gencode_local(self.cdist_object) - output_string = self.code.run_code_local(self.cdist_object) - output_dict = {} - for line in output_string.split('\n'): - if line: - key,value = line.split(': ') - output_dict[key] = value - self.assertEqual(output_dict['__target_host'], self.local.target_host) - self.assertEqual(output_dict['__global'], self.local.out_path) - self.assertEqual(output_dict['__type'], self.cdist_type.absolute_path) - self.assertEqual(output_dict['__object'], self.cdist_object.absolute_path) - self.assertEqual(output_dict['__object_id'], self.cdist_object.object_id) - self.assertEqual(output_dict['__object_fq'], self.cdist_object.path) + self.code.run_code_local(self.cdist_object) def test_run_code_remote_environment(self): self.cdist_object.code_remote = self.code.run_gencode_remote(self.cdist_object) self.code.transfer_code_remote(self.cdist_object) - output_string = self.code.run_code_remote(self.cdist_object) - output_dict = {} - for line in output_string.split('\n'): - if line: - key,value = line.split(': ') - output_dict[key] = value - self.assertEqual(output_dict['__target_host'], self.local.target_host) - self.assertEqual(output_dict['__global'], self.local.out_path) - self.assertEqual(output_dict['__type'], self.cdist_type.absolute_path) - self.assertEqual(output_dict['__object'], self.cdist_object.absolute_path) - self.assertEqual(output_dict['__object_id'], self.cdist_object.object_id) - self.assertEqual(output_dict['__object_fq'], self.cdist_object.path) + self.code.run_code_remote(self.cdist_object) From c9bb10551820c4b2f8017ea290791d500d34716a Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 15:59:58 +0200 Subject: [PATCH 18/23] run_code* no longer returns output Signed-off-by: Steven Armstrong --- lib/cdist/core/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cdist/core/code.py b/lib/cdist/core/code.py index af756263..e81f7954 100644 --- a/lib/cdist/core/code.py +++ b/lib/cdist/core/code.py @@ -104,7 +104,7 @@ class Code(object): '__object_id': cdist_object.object_id, '__object_fq': cdist_object.path, }) - return self.local.run_script(script, env=env) + return self.local.run_script(script, env=env, return_output=True) def run_gencode_local(self, cdist_object): """Run the gencode-local script for the given cdist object.""" From bbef928a6d02a43efb11a855b0951fd4db3d6381 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 16:04:55 +0200 Subject: [PATCH 19/23] --copy paste error Signed-off-by: Steven Armstrong --- lib/cdist/exec/remote.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cdist/exec/remote.py b/lib/cdist/exec/remote.py index 2de16426..e1d9f920 100644 --- a/lib/cdist/exec/remote.py +++ b/lib/cdist/exec/remote.py @@ -114,9 +114,9 @@ class Remote(object): self.log.debug("Remote run: %s", command) try: if return_output: - return subprocess.check_output(command, env=env).decode() + return subprocess.check_output(command).decode() else: - subprocess.check_call(command, env=env) + subprocess.check_call(command) except subprocess.CalledProcessError: raise cdist.Error("Command failed: " + " ".join(command)) except OSError as error: @@ -144,9 +144,9 @@ class Remote(object): try: if return_output: - return subprocess.check_output(command, env=env).decode() + return subprocess.check_output(command).decode() else: - subprocess.check_call(command, env=env) + subprocess.check_call(command) except subprocess.CalledProcessError as error: script_content = self.run(["cat", script]) self.log.error("Code that raised the error:\n%s", script_content) From c30e112e4a2773bee50bc440e1a740fbc2465fff Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 16:07:50 +0200 Subject: [PATCH 20/23] explorer: make tests pass again Signed-off-by: Steven Armstrong --- lib/cdist/core/explorer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cdist/core/explorer.py b/lib/cdist/core/explorer.py index ee1008fe..46230bcd 100644 --- a/lib/cdist/core/explorer.py +++ b/lib/cdist/core/explorer.py @@ -88,7 +88,7 @@ class Explorer(object): def run_global_explorer(self, explorer): """Run the given global explorer and return it's output.""" script = os.path.join(self.remote.global_explorer_path, explorer) - return self.remote.run_script(script, env=self.env) + return self.remote.run_script(script, env=self.env, return_output=True) ### type @@ -126,4 +126,4 @@ class Explorer(object): '__type_explorer': os.path.join(self.remote.type_path, cdist_type.explorer_path) }) script = os.path.join(self.remote.type_path, cdist_type.explorer_path, explorer) - return self.remote.run_script(script, env=env) + return self.remote.run_script(script, env=env, return_output=True) From d1930e983cb3d0f32d08c10813974e886680d364 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 16:14:04 +0200 Subject: [PATCH 21/23] update test: run_*_manifest should no longer return output Signed-off-by: Steven Armstrong --- lib/cdist/test/manifest/__init__.py | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/lib/cdist/test/manifest/__init__.py b/lib/cdist/test/manifest/__init__.py index 341f4893..879c4c1a 100644 --- a/lib/cdist/test/manifest/__init__.py +++ b/lib/cdist/test/manifest/__init__.py @@ -63,33 +63,9 @@ class ManifestTestCase(unittest.TestCase): def test_initial_manifest_environment(self): initial_manifest = os.path.join(self.local.manifest_path, "dump_environment") - output_string = self.manifest.run_initial_manifest(initial_manifest) - 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) + self.manifest.run_initial_manifest(initial_manifest) def test_type_manifest_environment(self): cdist_type = core.Type(self.local.type_path, '__dump_environment') cdist_object = core.Object(cdist_type, self.local.object_path, 'whatever') - - output_string = self.manifest.run_type_manifest(cdist_object) - 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['__object_id'], cdist_object.object_id) - self.assertEqual(output_dict['__object_fq'], cdist_object.path) + self.manifest.run_type_manifest(cdist_object) From f723bede109b3352f099179d0a4bc61df5090c99 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 16:14:39 +0200 Subject: [PATCH 22/23] no longer return output from run_*_manifest Signed-off-by: Steven Armstrong --- lib/cdist/core/manifest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cdist/core/manifest.py b/lib/cdist/core/manifest.py index 93eb6f2d..3eca166c 100644 --- a/lib/cdist/core/manifest.py +++ b/lib/cdist/core/manifest.py @@ -80,7 +80,7 @@ class Manifest(object): env.update(self.env) env['__manifest'] = self.local.manifest_path env['__cdist_manifest'] = script - return self.local.run_script(script, env=env) + self.local.run_script(script, env=env) def run_type_manifest(self, cdist_object): script = os.path.join(self.local.type_path, cdist_object.type.manifest_path) @@ -94,4 +94,4 @@ class Manifest(object): '__type': cdist_object.type.absolute_path, '__cdist_manifest': script, }) - return self.local.run_script(script, env=env) + self.local.run_script(script, env=env) From eac3cc31c46d26a0a0d3e5f786ba266a29268c17 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 16:33:56 +0200 Subject: [PATCH 23/23] export __debug in environment Signed-off-by: Steven Armstrong --- lib/cdist/context.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/cdist/context.py b/lib/cdist/context.py index cf314409..ed1fd31d 100644 --- a/lib/cdist/context.py +++ b/lib/cdist/context.py @@ -41,6 +41,8 @@ class Context(object): debug=False): self.debug = debug + if self.debug: + os.environ['__debug'] = 'yes' self.target_host = target_host