Merge remote-tracking branch 'telmich/master'

This commit is contained in:
Steven Armstrong 2011-10-14 23:18:17 +02:00
commit e766f5048b
6 changed files with 30 additions and 69 deletions

View file

@ -170,7 +170,7 @@ __debug::
If this variable is setup, cdist runs in debug mode. If this variable is setup, cdist runs in debug mode.
You can use this information, to only output stuff in debug You can use this information, to only output stuff in debug
mode as well. mode as well.
Available for: initial manifest, type manifest Available for: initial manifest, type manifest, gencode, code
__explorer:: __explorer::
Directory that contains all global explorers. Directory that contains all global explorers.
Available for: explorer Available for: explorer

View file

@ -92,6 +92,9 @@ class Code(object):
'__global': self.local.out_path, '__global': self.local.out_path,
} }
if log.getEffectiveLevel() == logging.DEBUG:
self.env.update({'__debug': "yes" })
def _run_gencode(self, cdist_object, which): def _run_gencode(self, cdist_object, which):
cdist_type = cdist_object.type cdist_type = cdist_object.type
script = os.path.join(self.local.type_path, getattr(cdist_type, 'gencode_%s_path' % which)) script = os.path.join(self.local.type_path, getattr(cdist_type, 'gencode_%s_path' % which))

View file

@ -73,6 +73,8 @@ class Explorer(object):
'__target_host': self.target_host, '__target_host': self.target_host,
'__explorer': self.remote.global_explorer_path, '__explorer': self.remote.global_explorer_path,
} }
if log.getEffectiveLevel() == logging.DEBUG:
self.env.update({'__debug': "yes" })
### global ### global

View file

@ -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 <http://www.gnu.org/licenses/>.
#
#
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)

View file

@ -24,6 +24,7 @@ import tempfile
import unittest import unittest
import shutil import shutil
import getpass import getpass
import logging
import cdist import cdist
from cdist import core from cdist import core
@ -46,25 +47,27 @@ class CodeTestCase(unittest.TestCase):
return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs) return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs)
def setUp(self): def setUp(self):
target_host = 'localhost' self.target_host = 'localhost'
self.local_base_path = local_base_path self.local_base_path = local_base_path
self.out_path = self.mkdtemp() 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.local.create_directories()
self.remote_base_path = self.mkdtemp() self.remote_base_path = self.mkdtemp()
self.user = getpass.getuser() self.user = getpass.getuser()
remote_exec = "ssh -o User=%s -q" % self.user remote_exec = "ssh -o User=%s -q" % self.user
remote_copy = "scp -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_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 = core.Object(self.cdist_type, self.local.object_path, 'whatever')
self.cdist_object.create() self.cdist_object.create()
self.log = logging.getLogger("cdist")
def tearDown(self): def tearDown(self):
shutil.rmtree(self.out_path) shutil.rmtree(self.out_path)
shutil.rmtree(self.remote_base_path) shutil.rmtree(self.remote_base_path)
@ -113,3 +116,8 @@ class CodeTestCase(unittest.TestCase):
self.cdist_object.code_remote = self.code.run_gencode_remote(self.cdist_object) self.cdist_object.code_remote = self.code.run_gencode_remote(self.cdist_object)
self.code.transfer_code_remote(self.cdist_object) self.code.transfer_code_remote(self.cdist_object)
self.code.run_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)

View file

@ -24,6 +24,7 @@ import tempfile
import unittest import unittest
import shutil import shutil
import getpass import getpass
import logging
import cdist import cdist
from cdist import core from cdist import core
@ -46,20 +47,22 @@ class ExplorerClassTestCase(unittest.TestCase):
return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs) return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs)
def setUp(self): def setUp(self):
target_host = 'localhost' self.target_host = 'localhost'
self.local_base_path = local_base_path self.local_base_path = local_base_path
self.out_path = self.mkdtemp() 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.local.create_directories()
self.remote_base_path = self.mkdtemp() self.remote_base_path = self.mkdtemp()
self.user = getpass.getuser() self.user = getpass.getuser()
remote_exec = "ssh -o User=%s -q" % self.user remote_exec = "ssh -o User=%s -q" % self.user
remote_copy = "scp -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): def tearDown(self):
shutil.rmtree(self.out_path) shutil.rmtree(self.out_path)
@ -109,3 +112,7 @@ class ExplorerClassTestCase(unittest.TestCase):
output = self.explorer.run_type_explorer('world', cdist_object) output = self.explorer.run_type_explorer('world', cdist_object)
self.assertEqual(output, 'hello\n') 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)