forked from ungleich-public/cdist
__cdist_log_level=<log level int value>; __cdist_log_level_name=<log level name> (#574)
This commit is contained in:
parent
1ae5b1732e
commit
f0dc21ec0c
20 changed files with 192 additions and 40 deletions
|
|
@ -101,7 +101,9 @@ class CodeTestCase(test.CdistTestCase):
|
|||
self.assertEqual(output_dict['__files'], self.local.files_path)
|
||||
self.assertEqual(output_dict['__target_host_tags'],
|
||||
self.local.target_host_tags)
|
||||
self.assertEqual(output_dict['__cdist_log_level'], 'WARNING')
|
||||
self.assertEqual(output_dict['__cdist_log_level'],
|
||||
str(logging.WARNING))
|
||||
self.assertEqual(output_dict['__cdist_log_level_name'], 'WARNING')
|
||||
|
||||
def test_run_gencode_remote_environment(self):
|
||||
output_string = self.code.run_gencode_remote(self.cdist_object)
|
||||
|
|
@ -127,7 +129,9 @@ class CodeTestCase(test.CdistTestCase):
|
|||
self.assertEqual(output_dict['__files'], self.local.files_path)
|
||||
self.assertEqual(output_dict['__target_host_tags'],
|
||||
self.local.target_host_tags)
|
||||
self.assertEqual(output_dict['__cdist_log_level'], 'WARNING')
|
||||
self.assertEqual(output_dict['__cdist_log_level'],
|
||||
str(logging.WARNING))
|
||||
self.assertEqual(output_dict['__cdist_log_level_name'], 'WARNING')
|
||||
|
||||
def test_transfer_code_remote(self):
|
||||
self.cdist_object.code_remote = self.code.run_gencode_remote(
|
||||
|
|
|
|||
|
|
@ -11,3 +11,4 @@ echo "echo __object_name: $__object_name"
|
|||
echo "echo __files: $__files"
|
||||
echo "echo __target_host_tags: $__target_host_tags"
|
||||
echo "echo __cdist_log_level: $__cdist_log_level"
|
||||
echo "echo __cdist_log_level_name: $__cdist_log_level_name"
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import os.path as op
|
|||
import argparse
|
||||
from cdist import test
|
||||
import cdist.argparse as cap
|
||||
|
||||
import logging
|
||||
|
||||
my_dir = op.abspath(op.dirname(__file__))
|
||||
fixtures = op.join(my_dir, 'fixtures')
|
||||
|
|
@ -124,6 +124,18 @@ class ConfigurationOptionsTestCase(test.CdistTestCase):
|
|||
self.assertEqual(converter(value), ['spam', 'eggs', 'ham', ])
|
||||
self.assertIsNone(converter(''))
|
||||
|
||||
def test_LogLevelOption(self):
|
||||
option = cc.LogLevelOption()
|
||||
converter = option.converter()
|
||||
value = str(logging.DEBUG)
|
||||
conv_val = converter(value)
|
||||
self.assertEqual(conv_val, cap.VERBOSE_DEBUG)
|
||||
value = str(logging.INFO)
|
||||
conv_val = converter(value)
|
||||
self.assertEqual(conv_val, cap.VERBOSE_INFO)
|
||||
for value in ('11', '80', 'a'):
|
||||
self.assertRaises(ValueError, converter, value)
|
||||
|
||||
|
||||
class ConfigurationTestCase(test.CdistTestCase):
|
||||
|
||||
|
|
@ -234,17 +246,17 @@ class ConfigurationTestCase(test.CdistTestCase):
|
|||
os.remove(custom_config_file)
|
||||
|
||||
def test_singleton(self):
|
||||
x = cc.Configuration(None)
|
||||
x = cc.Configuration(None, env={}, config_files=())
|
||||
args = argparse.Namespace()
|
||||
args.a = 'a'
|
||||
y = cc.Configuration(args)
|
||||
y = cc.Configuration(args, env={}, config_files=())
|
||||
self.assertIs(x, y)
|
||||
|
||||
def test_non_singleton(self):
|
||||
x = cc.Configuration(None, singleton=False)
|
||||
x = cc.Configuration(None, env={}, config_files=(), singleton=False)
|
||||
args = argparse.Namespace()
|
||||
args.a = 'a'
|
||||
y = cc.Configuration(args, singleton=False)
|
||||
y = cc.Configuration(args, env={}, config_files=(), singleton=False)
|
||||
self.assertIsNot(x, y)
|
||||
|
||||
def test_read_config_file(self):
|
||||
|
|
@ -1122,6 +1134,39 @@ class ConfigurationTestCase(test.CdistTestCase):
|
|||
config_files=config_files)
|
||||
self.assertEqual(configuration.config, expected_config_dict)
|
||||
|
||||
def test_configuration_cdist_log_level_env_var(self):
|
||||
env = {
|
||||
'__cdist_log_level': str(logging.DEBUG),
|
||||
}
|
||||
args = argparse.Namespace()
|
||||
|
||||
expected_config_dict = {
|
||||
'GLOBAL': {
|
||||
'verbosity': cap.VERBOSE_DEBUG,
|
||||
},
|
||||
}
|
||||
|
||||
# bypass singleton so we can test further
|
||||
cc.Configuration.instance = None
|
||||
|
||||
configuration = cc.Configuration(args, env=env,
|
||||
config_files=())
|
||||
self.assertEqual(configuration.config, expected_config_dict)
|
||||
|
||||
# bypass singleton so we can test further
|
||||
cc.Configuration.instance = None
|
||||
env['__cdist_log_level'] = '80'
|
||||
with self.assertRaises(ValueError):
|
||||
configuration = cc.Configuration(args, env=env,
|
||||
config_files=())
|
||||
|
||||
# bypass singleton so we can test further
|
||||
cc.Configuration.instance = None
|
||||
env['__cdist_log_level'] = 'x'
|
||||
with self.assertRaises(ValueError):
|
||||
configuration = cc.Configuration(args, env=env,
|
||||
config_files=())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import unittest
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ class EmulatorTestCase(test.CdistTestCase):
|
|||
emu = emulator.Emulator(argv, env=self.env)
|
||||
emu_loglevel = emu.log.getEffectiveLevel()
|
||||
self.assertEqual(emu_loglevel, logging.WARNING)
|
||||
self.env['__cdist_log_level'] = logging.getLevelName(logging.DEBUG)
|
||||
self.env['__cdist_log_level'] = str(logging.DEBUG)
|
||||
emu = emulator.Emulator(argv, env=self.env)
|
||||
emu_loglevel = emu.log.getEffectiveLevel()
|
||||
self.assertEqual(emu_loglevel, logging.DEBUG)
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ from cdist import test
|
|||
from cdist.exec import local
|
||||
from cdist.exec import remote
|
||||
from cdist.core import explorer
|
||||
import logging
|
||||
|
||||
import os.path as op
|
||||
my_dir = op.abspath(op.dirname(__file__))
|
||||
|
|
@ -233,7 +234,9 @@ class ExplorerClassTestCase(test.CdistTestCase):
|
|||
self.remote.global_explorer_path)
|
||||
self.assertEqual(output_dict['__target_host_tags'],
|
||||
self.local.target_host_tags)
|
||||
self.assertEqual(output_dict['__cdist_log_level'], 'WARNING')
|
||||
self.assertEqual(output_dict['__cdist_log_level'],
|
||||
str(logging.WARNING))
|
||||
self.assertEqual(output_dict['__cdist_log_level_name'], 'WARNING')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -6,3 +6,4 @@ echo "__target_fqdn: $__target_fqdn"
|
|||
echo "__explorer: $__explorer"
|
||||
echo "__target_host_tags: $__target_host_tags"
|
||||
echo "__cdist_log_level: $__cdist_log_level"
|
||||
echo "__cdist_log_level_name: $__cdist_log_level_name"
|
||||
|
|
|
|||
|
|
@ -99,7 +99,9 @@ class ManifestTestCase(test.CdistTestCase):
|
|||
self.assertEqual(output_dict['__files'], self.local.files_path)
|
||||
self.assertEqual(output_dict['__target_host_tags'],
|
||||
self.local.target_host_tags)
|
||||
self.assertEqual(output_dict['__cdist_log_level'], 'VERBOSE')
|
||||
self.assertEqual(output_dict['__cdist_log_level'],
|
||||
str(logging.VERBOSE))
|
||||
self.assertEqual(output_dict['__cdist_log_level_name'], 'VERBOSE')
|
||||
self.log.setLevel(old_loglevel)
|
||||
|
||||
def test_type_manifest_environment(self):
|
||||
|
|
@ -139,7 +141,9 @@ class ManifestTestCase(test.CdistTestCase):
|
|||
self.assertEqual(output_dict['__files'], self.local.files_path)
|
||||
self.assertEqual(output_dict['__target_host_tags'],
|
||||
self.local.target_host_tags)
|
||||
self.assertEqual(output_dict['__cdist_log_level'], 'VERBOSE')
|
||||
self.assertEqual(output_dict['__cdist_log_level'],
|
||||
str(logging.VERBOSE))
|
||||
self.assertEqual(output_dict['__cdist_log_level_name'], 'VERBOSE')
|
||||
self.log.setLevel(old_loglevel)
|
||||
|
||||
def test_loglevel_env_setup(self):
|
||||
|
|
@ -147,7 +151,10 @@ class ManifestTestCase(test.CdistTestCase):
|
|||
self.log.setLevel(logging.DEBUG)
|
||||
manifest = cdist.core.manifest.Manifest(self.target_host, self.local)
|
||||
self.assertTrue("__cdist_log_level" in manifest.env)
|
||||
self.assertEqual(manifest.env["__cdist_log_level"], 'DEBUG')
|
||||
self.assertTrue("__cdist_log_level_name" in manifest.env)
|
||||
self.assertEqual(manifest.env["__cdist_log_level"],
|
||||
str(logging.DEBUG))
|
||||
self.assertEqual(manifest.env["__cdist_log_level_name"], 'DEBUG')
|
||||
self.log.setLevel(current_level)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -11,4 +11,5 @@ __manifest: $__manifest
|
|||
__files: $__files
|
||||
__target_host_tags: $__target_host_tags
|
||||
__cdist_log_level: $__cdist_log_level
|
||||
__cdist_log_level_name: $__cdist_log_level_name
|
||||
DONE
|
||||
|
|
|
|||
|
|
@ -15,4 +15,5 @@ __object_name: $__object_name
|
|||
__files: $__files
|
||||
__target_host_tags: $__target_host_tags
|
||||
__cdist_log_level: $__cdist_log_level
|
||||
__cdist_log_level_name: $__cdist_log_level_name
|
||||
DONE
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue