Make sure we use get_option() when dealing with boolean values
read from configuration files...otherwise "False" is True :(
This commit is contained in:
parent
0dba121f03
commit
cd4a41b44f
@ -135,8 +135,10 @@ def setup_logging(options, conf):
|
||||
|
||||
# If either the CLI option or the conf value
|
||||
# is True, we set to True
|
||||
debug = options.get('debug') or conf.get('debug', False)
|
||||
verbose = options.get('verbose') or conf.get('verbose', False)
|
||||
debug = options.get('debug') or \
|
||||
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
|
||||
if 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
|
||||
# flags. Everything else must be set up in the conf file...
|
||||
debug = options.get('debug') or conf.get('debug', False)
|
||||
verbose = options.get('verbose') or conf.get('verbose', False)
|
||||
debug = options.get('debug') or \
|
||||
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['verbose'] = verbose
|
||||
|
||||
|
@ -46,6 +46,8 @@ class FunctionalTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
||||
self.verbose = True
|
||||
self.debug = True
|
||||
self.test_id = random.randint(0, 100000)
|
||||
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_contents = """[DEFAULT]
|
||||
verbose = True
|
||||
debug = True
|
||||
verbose = %(verbose)s
|
||||
debug = %(debug)s
|
||||
|
||||
[app:glance-api]
|
||||
paste.app_factory = glance.server:app_factory
|
||||
|
@ -15,6 +15,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""Functional test case that tests logging output"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
@ -24,56 +26,55 @@ from tests.utils import execute
|
||||
|
||||
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
|
||||
glance.conf file with the log_file option.
|
||||
|
||||
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
|
||||
Test logging output proper when verbose and debug
|
||||
is on.
|
||||
"""
|
||||
|
||||
self.cleanup()
|
||||
api_port, reg_port, conf_file = self.start_servers()
|
||||
|
||||
cmd = "curl -X POST -H 'Content-Type: application/octet-stream' "\
|
||||
"-H 'X-Image-Meta-Name: ImageName' "\
|
||||
"-H 'X-Image-Meta-Disk-Format: Invalid' "\
|
||||
"http://0.0.0.0:%d/images" % api_port
|
||||
ignored, out, err = execute(cmd)
|
||||
# The default functional test case has both verbose
|
||||
# and debug on. Let's verify that debug statements
|
||||
# appear in both the API and registry logs.
|
||||
|
||||
self.assertTrue('Invalid disk format' in out,
|
||||
"Could not find 'Invalid disk format' "
|
||||
"in output: %s" % out)
|
||||
self.assertTrue(os.path.exists(self.api_log_file))
|
||||
|
||||
self.assertTrue(os.path.exists(self.api_log_file),
|
||||
"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_log_out = open(self.api_log_file, 'r').read()
|
||||
|
||||
api_logfile_contents = open(self.api_log_file, 'rb').read()
|
||||
registry_logfile_contents = open(self.registry_log_file, 'rb').read()
|
||||
self.assertTrue('DEBUG [glance-api]' in api_log_out)
|
||||
|
||||
# Check that BOTH the glance API and registry server
|
||||
# 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)
|
||||
self.assertTrue(os.path.exists(self.registry_log_file))
|
||||
|
||||
# Test that the error we caused above is in the log
|
||||
self.assertTrue('Invalid disk format' in api_logfile_contents,
|
||||
"Could not find 'Invalid disk format' "
|
||||
"in API logfile: %s" % api_logfile_contents)
|
||||
registry_log_out = open(self.registry_log_file, 'r').read()
|
||||
|
||||
self.assertTrue('DEBUG [glance-registry]' in registry_log_out)
|
||||
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user