summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2013-01-21 14:13:59 +0000
committerMark McLoughlin <markmc@redhat.com>2013-01-21 14:13:59 +0000
commitc5984ba9c4f3cb7b682d47a06018aacbf82f074d (patch)
tree7f2fe876a1620b6aaba827c9a848a3ec4542b1b8 /tests
parent82c8fb786a67b6e636095cb6bb8ebcb3ebc47463 (diff)
downloadoslo-c5984ba9c4f3cb7b682d47a06018aacbf82f074d.tar.gz
oslo-c5984ba9c4f3cb7b682d47a06018aacbf82f074d.tar.xz
oslo-c5984ba9c4f3cb7b682d47a06018aacbf82f074d.zip
Move logging config options into the log module
We learned a lesson in Nova - it's best to declare and use config options within a single module if possible. Globally declared and use config options grow like weeds and it becomes harder to find out if, where and how individual options are used. Strangely, in cfg itself, we randomly declare a bunch of logging options which are only used within the openstack.common.log module - let's move the options there and remove the CommonConfigOpts class before they become part of the API we commit to when oslo-config is released. A minor detail in the patch - the logfile and logdir options are already deprecated in favour of log_file and log_dir, but we never got around to removing all other traces of the deprecated options. Change-Id: I3913ea54465658d93dc56e014dfe5d911b0541d6
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_cfg.py56
-rw-r--r--tests/unit/test_log.py61
2 files changed, 56 insertions, 61 deletions
diff --git a/tests/unit/test_cfg.py b/tests/unit/test_cfg.py
index b2c14ec..8eaaf67 100644
--- a/tests/unit/test_cfg.py
+++ b/tests/unit/test_cfg.py
@@ -1573,62 +1573,6 @@ class OptDumpingTestCase(BaseTestCase):
])
-class CommonOptsTestCase(BaseTestCase):
-
- def setUp(self):
- super(CommonOptsTestCase, self).setUp()
- self.conf = CommonConfigOpts()
-
- def test_print_help(self):
- f = StringIO.StringIO()
- self.conf([])
- self.conf.print_help(file=f)
- self.assertTrue('debug' in f.getvalue())
- self.assertTrue('verbose' in f.getvalue())
- self.assertTrue('log-config' in f.getvalue())
- self.assertTrue('log-format' in f.getvalue())
-
- def test_debug_verbose(self):
- self.conf(['--debug', '--verbose'])
-
- self.assertEquals(self.conf.debug, True)
- self.assertEquals(self.conf.verbose, True)
-
- def test_logging_opts(self):
- self.conf([])
-
- self.assertTrue(self.conf.log_config is None)
- self.assertTrue(self.conf.log_file is None)
- self.assertTrue(self.conf.log_dir is None)
-
- self.assertEquals(self.conf.log_format,
- CommonConfigOpts.DEFAULT_LOG_FORMAT)
- self.assertEquals(self.conf.log_date_format,
- CommonConfigOpts.DEFAULT_LOG_DATE_FORMAT)
-
- self.assertEquals(self.conf.use_syslog, False)
-
- def test_log_file(self):
- log_file = '/some/path/foo-bar.log'
- self.conf(['--log-file', log_file])
- self.assertEquals(self.conf.log_file, log_file)
-
- def test_logfile_deprecated(self):
- logfile = '/some/other/path/foo-bar.log'
- self.conf(['--logfile', logfile])
- self.assertEquals(self.conf.log_file, logfile)
-
- def test_log_dir(self):
- log_dir = '/some/path/'
- self.conf(['--log-dir', log_dir])
- self.assertEquals(self.conf.log_dir, log_dir)
-
- def test_logdir_deprecated(self):
- logdir = '/some/other/path/'
- self.conf(['--logdir', logdir])
- self.assertEquals(self.conf.log_dir, logdir)
-
-
class ConfigParserTestCase(unittest.TestCase):
def test_no_section(self):
with tempfile.NamedTemporaryFile() as tmpfile:
diff --git a/tests/unit/test_log.py b/tests/unit/test_log.py
index a2ba31a..451fb4f 100644
--- a/tests/unit/test_log.py
+++ b/tests/unit/test_log.py
@@ -1,6 +1,7 @@
import cStringIO
import exceptions
import logging
+import StringIO
import subprocess
import sys
import textwrap
@@ -74,22 +75,22 @@ class LoggerTestCase(test_utils.BaseTestCase):
class LogHandlerTestCase(test_utils.BaseTestCase):
def test_log_path_logdir(self):
- self.config(logdir='/some/path', logfile=None)
+ self.config(log_dir='/some/path', log_file=None)
self.assertEquals(log._get_log_file_path(binary='foo-bar'),
'/some/path/foo-bar.log')
def test_log_path_logfile(self):
- self.config(logfile='/some/path/foo-bar.log')
+ self.config(log_file='/some/path/foo-bar.log')
self.assertEquals(log._get_log_file_path(binary='foo-bar'),
'/some/path/foo-bar.log')
def test_log_path_none(self):
- self.config(logdir=None, logfile=None)
+ self.config(log_dir=None, log_file=None)
self.assertTrue(log._get_log_file_path(binary='foo-bar') is None)
def test_log_path_logfile_overrides_logdir(self):
- self.config(logdir='/some/other/path',
- logfile='/some/path/foo-bar.log')
+ self.config(log_dir='/some/other/path',
+ log_file='/some/path/foo-bar.log')
self.assertEquals(log._get_log_file_path(binary='foo-bar'),
'/some/path/foo-bar.log')
@@ -328,3 +329,53 @@ class SetDefaultsTestCase(test_utils.BaseTestCase):
log.set_defaults(logging_context_format_string=my_default)
self.conf([])
self.assertEquals(self.conf.logging_context_format_string, my_default)
+
+
+class LogConfigOptsTestCase(test_utils.BaseTestCase):
+
+ def test_print_help(self):
+ f = StringIO.StringIO()
+ CONF([])
+ CONF.print_help(file=f)
+ self.assertTrue('debug' in f.getvalue())
+ self.assertTrue('verbose' in f.getvalue())
+ self.assertTrue('log-config' in f.getvalue())
+ self.assertTrue('log-format' in f.getvalue())
+
+ def test_debug_verbose(self):
+ CONF(['--debug', '--verbose'])
+
+ self.assertEquals(CONF.debug, True)
+ self.assertEquals(CONF.verbose, True)
+
+ def test_logging_opts(self):
+ CONF([])
+
+ self.assertTrue(CONF.log_config is None)
+ self.assertTrue(CONF.log_file is None)
+ self.assertTrue(CONF.log_dir is None)
+
+ self.assertEquals(CONF.log_format, log._DEFAULT_LOG_FORMAT)
+ self.assertEquals(CONF.log_date_format, log._DEFAULT_LOG_DATE_FORMAT)
+
+ self.assertEquals(CONF.use_syslog, False)
+
+ def test_log_file(self):
+ log_file = '/some/path/foo-bar.log'
+ CONF(['--log-file', log_file])
+ self.assertEquals(CONF.log_file, log_file)
+
+ def test_logfile_deprecated(self):
+ logfile = '/some/other/path/foo-bar.log'
+ CONF(['--logfile', logfile])
+ self.assertEquals(CONF.log_file, logfile)
+
+ def test_log_dir(self):
+ log_dir = '/some/path/'
+ CONF(['--log-dir', log_dir])
+ self.assertEquals(CONF.log_dir, log_dir)
+
+ def test_logdir_deprecated(self):
+ logdir = '/some/other/path/'
+ CONF(['--logdir', logdir])
+ self.assertEquals(CONF.log_dir, logdir)