From dd05a9b0d75196f5b7154a46a2ea6f23febded8d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 14 Oct 2011 23:02:47 +0200 Subject: [PATCH 1/5] add test to verify code setups debug env Signed-off-by: Nico Schottelius --- lib/cdist/test/code/__init__.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/cdist/test/code/__init__.py b/lib/cdist/test/code/__init__.py index f661ad24..c9761a4b 100644 --- a/lib/cdist/test/code/__init__.py +++ b/lib/cdist/test/code/__init__.py @@ -24,6 +24,7 @@ import tempfile import unittest import shutil import getpass +import logging import cdist from cdist import core @@ -46,25 +47,27 @@ class CodeTestCase(unittest.TestCase): return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs) def setUp(self): - target_host = 'localhost' + self.target_host = 'localhost' self.local_base_path = local_base_path self.out_path = self.mkdtemp() - self.local = local.Local(target_host, self.local_base_path, self.out_path) + self.local = local.Local(self.target_host, self.local_base_path, self.out_path) self.local.create_directories() self.remote_base_path = self.mkdtemp() self.user = getpass.getuser() remote_exec = "ssh -o User=%s -q" % self.user remote_copy = "scp -o User=%s -q" % self.user - self.remote = remote.Remote(target_host, self.remote_base_path, remote_exec, remote_copy) + self.remote = remote.Remote(self.target_host, self.remote_base_path, remote_exec, remote_copy) - self.code = code.Code(target_host, self.local, self.remote) + self.code = code.Code(self.target_host, self.local, self.remote) self.cdist_type = core.Type(self.local.type_path, '__dump_environment') self.cdist_object = core.Object(self.cdist_type, self.local.object_path, 'whatever') self.cdist_object.create() + self.log = logging.getLogger("cdist") + def tearDown(self): shutil.rmtree(self.out_path) shutil.rmtree(self.remote_base_path) @@ -108,8 +111,13 @@ class CodeTestCase(unittest.TestCase): def test_run_code_local(self): self.cdist_object.code_local = self.code.run_gencode_local(self.cdist_object) 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) self.code.run_code_remote(self.cdist_object) + + def test_debug_env_setup(self): + self.log.setLevel(logging.DEBUG) + code = cdist.core.code.Code(self.target_host, self.local, self.remote) + self.assertTrue("__debug" in code.env) From bc85237eaab020ee71e44b31822693b5312e0871 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 14 Oct 2011 23:04:19 +0200 Subject: [PATCH 2/5] make code setup debug env Signed-off-by: Nico Schottelius --- doc/man/cdist-reference.text.sh | 2 +- lib/cdist/core/code.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/man/cdist-reference.text.sh b/doc/man/cdist-reference.text.sh index 7196c3b3..57dbde4a 100755 --- a/doc/man/cdist-reference.text.sh +++ b/doc/man/cdist-reference.text.sh @@ -170,7 +170,7 @@ __debug:: If this variable is setup, cdist runs in debug mode. You can use this information, to only output stuff in debug mode as well. - Available for: initial manifest, type manifest + Available for: initial manifest, type manifest, gencode, code __explorer:: Directory that contains all global explorers. Available for: explorer diff --git a/lib/cdist/core/code.py b/lib/cdist/core/code.py index e81f7954..0f2591b3 100644 --- a/lib/cdist/core/code.py +++ b/lib/cdist/core/code.py @@ -92,6 +92,9 @@ class Code(object): '__global': self.local.out_path, } + if log.getEffectiveLevel() == logging.DEBUG: + self.env.update({'__debug': "yes" }) + def _run_gencode(self, cdist_object, which): cdist_type = cdist_object.type script = os.path.join(self.local.type_path, getattr(cdist_type, 'gencode_%s_path' % which)) From db04ec0473eab51115ee31cbac6a936b940633b1 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 14 Oct 2011 23:11:57 +0200 Subject: [PATCH 3/5] test whether debug is setup in explorer env Signed-off-by: Nico Schottelius --- lib/cdist/test/explorer/__init__.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/cdist/test/explorer/__init__.py b/lib/cdist/test/explorer/__init__.py index 3b3a7e98..a3a0c9f8 100644 --- a/lib/cdist/test/explorer/__init__.py +++ b/lib/cdist/test/explorer/__init__.py @@ -24,6 +24,7 @@ import tempfile import unittest import shutil import getpass +import logging import cdist from cdist import core @@ -46,20 +47,22 @@ class ExplorerClassTestCase(unittest.TestCase): return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs) def setUp(self): - target_host = 'localhost' + self.target_host = 'localhost' self.local_base_path = local_base_path self.out_path = self.mkdtemp() - self.local = local.Local(target_host, self.local_base_path, self.out_path) + self.local = local.Local(self.target_host, self.local_base_path, self.out_path) self.local.create_directories() self.remote_base_path = self.mkdtemp() self.user = getpass.getuser() remote_exec = "ssh -o User=%s -q" % self.user remote_copy = "scp -o User=%s -q" % self.user - self.remote = remote.Remote(target_host, self.remote_base_path, remote_exec, remote_copy) + self.remote = remote.Remote(self.target_host, self.remote_base_path, remote_exec, remote_copy) - self.explorer = explorer.Explorer(target_host, self.local, self.remote) + self.explorer = explorer.Explorer(self.target_host, self.local, self.remote) + + self.log = logging.getLogger("cdist") def tearDown(self): shutil.rmtree(self.out_path) @@ -109,3 +112,7 @@ class ExplorerClassTestCase(unittest.TestCase): output = self.explorer.run_type_explorer('world', cdist_object) self.assertEqual(output, 'hello\n') + def test_debug_env_setup(self): + self.log.setLevel(logging.DEBUG) + explorer = cdist.core.explorer.Explorer(self.target_host, self.local, self.remote) + self.assertTrue("__debug" in explorer.env) From 02934055e749ea2fe3406842b8ef6d76351a6ab4 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 14 Oct 2011 23:14:05 +0200 Subject: [PATCH 4/5] make debug test work for explorer Signed-off-by: Nico Schottelius --- lib/cdist/core/explorer.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/cdist/core/explorer.py b/lib/cdist/core/explorer.py index 46230bcd..9dd5d210 100644 --- a/lib/cdist/core/explorer.py +++ b/lib/cdist/core/explorer.py @@ -73,6 +73,8 @@ class Explorer(object): '__target_host': self.target_host, '__explorer': self.remote.global_explorer_path, } + if log.getEffectiveLevel() == logging.DEBUG: + self.env.update({'__debug': "yes" }) ### global From f80520090bad3968742974d0607e3a7c82ad1d98 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 14 Oct 2011 23:14:49 +0200 Subject: [PATCH 5/5] remove obsolete global_explorer Signed-off-by: Nico Schottelius --- lib/cdist/core/global_explorer.py | 59 ------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 lib/cdist/core/global_explorer.py diff --git a/lib/cdist/core/global_explorer.py b/lib/cdist/core/global_explorer.py deleted file mode 100644 index fe0ea018..00000000 --- a/lib/cdist/core/global_explorer.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org) -# -# This file is part of cdist. -# -# cdist is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# cdist is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with cdist. If not, see . -# -# - -import io -import logging -import os -#import stat -#import shutil -#import sys -#import tempfile -#import time -# -#import cdist.exec - -import cdist - -log = logging.getLogger(__name__) - -class GlobalExplorer(object): - def __init__(self, local_path, remote_path): - self.local_path = local_path - self.remote_path = remote_path - - def run(self): - """Run global explorers""" - log.info("Running global explorers") - - outputs = {} - for explorer in os.listdir(src_path): - outputs[explorer] = io.StringIO() - cmd = [] - cmd.append("__explorer=" + remote_dst_path) - cmd.append(os.path.join(remote_dst_path, explorer)) - cdist.exec.run_or_fail(cmd, stdout=outputs[explorer], remote_prefix=True) - - def transfer(self): - """Transfer the global explorers""" - self.remote_mkdir(self.remote_global_explorer_path) - self.transfer_path(self.global_explorer_path, - self.remote_global_explorer_path)