Make sure we use get_option() when dealing with boolean values

read from configuration files...otherwise "False" is True :(
This commit is contained in:
jaypipes@gmail.com 2011-04-19 11:43:36 -04:00
parent 0dba121f03
commit cd4a41b44f
3 changed files with 53 additions and 46 deletions

View File

@ -135,8 +135,10 @@ def setup_logging(options, conf):
# If either the CLI option or the conf value # If either the CLI option or the conf value
# is True, we set to True # is True, we set to True
debug = options.get('debug') or conf.get('debug', False) debug = options.get('debug') or \
verbose = options.get('verbose') or conf.get('verbose', False) get_option(conf, 'debug', type='bool', default=False)
verbose = options.get('verbose') or \
get_option(conf, 'verbose', type='bool', default=False)
root_logger = logging.root root_logger = logging.root
if debug: if debug:
root_logger.setLevel(logging.DEBUG) root_logger.setLevel(logging.DEBUG)
@ -278,8 +280,10 @@ def load_paste_app(app_name, options, args):
# We only update the conf dict for the verbose and debug # We only update the conf dict for the verbose and debug
# flags. Everything else must be set up in the conf file... # flags. Everything else must be set up in the conf file...
debug = options.get('debug') or conf.get('debug', False) debug = options.get('debug') or \
verbose = options.get('verbose') or conf.get('verbose', False) get_option(conf, 'debug', type='bool', default=False)
verbose = options.get('verbose') or \
get_option(conf, 'verbose', type='bool', default=False)
conf['debug'] = debug conf['debug'] = debug
conf['verbose'] = verbose conf['verbose'] = verbose

View File

@ -46,6 +46,8 @@ class FunctionalTest(unittest.TestCase):
def setUp(self): def setUp(self):
self.verbose = True
self.debug = True
self.test_id = random.randint(0, 100000) self.test_id = random.randint(0, 100000)
self.test_dir = os.path.join("/", "tmp", "test.%d" % self.test_id) self.test_dir = os.path.join("/", "tmp", "test.%d" % self.test_id)
@ -144,8 +146,8 @@ class FunctionalTest(unittest.TestCase):
conf_file = tempfile.NamedTemporaryFile() conf_file = tempfile.NamedTemporaryFile()
conf_contents = """[DEFAULT] conf_contents = """[DEFAULT]
verbose = True verbose = %(verbose)s
debug = True debug = %(debug)s
[app:glance-api] [app:glance-api]
paste.app_factory = glance.server:app_factory paste.app_factory = glance.server:app_factory

View File

@ -15,6 +15,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
"""Functional test case that tests logging output"""
import os import os
import unittest import unittest
@ -24,56 +26,55 @@ from tests.utils import execute
class TestLogging(functional.FunctionalTest): class TestLogging(functional.FunctionalTest):
"""Tests that logging can be configured correctly""" """Functional tests for Glance's logging output"""
def test_logfile(self): def test_verbose_debug(self):
""" """
A test that logging can be configured properly from the Test logging output proper when verbose and debug
glance.conf file with the log_file option. is on.
We start both servers daemonized with a temporary config
file that has some logging options in it.
We then use curl to issue a few requests and verify that each server's
logging statements were logged to the one log file
""" """
self.cleanup() self.cleanup()
api_port, reg_port, conf_file = self.start_servers() api_port, reg_port, conf_file = self.start_servers()
cmd = "curl -X POST -H 'Content-Type: application/octet-stream' "\ # The default functional test case has both verbose
"-H 'X-Image-Meta-Name: ImageName' "\ # and debug on. Let's verify that debug statements
"-H 'X-Image-Meta-Disk-Format: Invalid' "\ # appear in both the API and registry logs.
"http://0.0.0.0:%d/images" % api_port
ignored, out, err = execute(cmd)
self.assertTrue('Invalid disk format' in out, self.assertTrue(os.path.exists(self.api_log_file))
"Could not find 'Invalid disk format' "
"in output: %s" % out)
self.assertTrue(os.path.exists(self.api_log_file), api_log_out = open(self.api_log_file, 'r').read()
"API Logfile %s does not exist!"
% self.api_log_file)
self.assertTrue(os.path.exists(self.registry_log_file),
"Registry Logfile %s does not exist!"
% self.registry_log_file)
api_logfile_contents = open(self.api_log_file, 'rb').read() self.assertTrue('DEBUG [glance-api]' in api_log_out)
registry_logfile_contents = open(self.registry_log_file, 'rb').read()
# Check that BOTH the glance API and registry server self.assertTrue(os.path.exists(self.registry_log_file))
# modules are logged to their respective logfiles.
self.assertTrue('[glance.server]'
in api_logfile_contents,
"Could not find '[glance.server]' "
"in API logfile: %s" % api_logfile_contents)
self.assertTrue('[glance.registry.server]'
in registry_logfile_contents,
"Could not find '[glance.registry.server]' "
"in Registry logfile: %s" % registry_logfile_contents)
# Test that the error we caused above is in the log registry_log_out = open(self.registry_log_file, 'r').read()
self.assertTrue('Invalid disk format' in api_logfile_contents,
"Could not find 'Invalid disk format' " self.assertTrue('DEBUG [glance-registry]' in registry_log_out)
"in API logfile: %s" % api_logfile_contents)
self.stop_servers()
def test_no_verbose_no_debug(self):
"""
Test logging output proper when verbose and debug
is off.
"""
self.cleanup()
api_port, reg_port, conf_file = self.start_servers(debug=False,
verbose=False)
self.assertTrue(os.path.exists(self.api_log_file))
api_log_out = open(self.api_log_file, 'r').read()
self.assertFalse('DEBUG [glance-api]' in api_log_out)
self.assertTrue(os.path.exists(self.registry_log_file))
registry_log_out = open(self.registry_log_file, 'r').read()
self.assertFalse('DEBUG [glance-registry]' in registry_log_out)
self.stop_servers() self.stop_servers()