Merge lp:~jaypipes/glance/bug766052 into lp:~hudson-openstack/glance/trunk

Proposed by Jay Pipes
Status: Merged
Approved by: Jay Pipes
Approved revision: 117
Merged at revision: 118
Proposed branch: lp:~jaypipes/glance/bug766052
Merge into: lp:~hudson-openstack/glance/trunk
Diff against target: 170 lines (+61/-54)
3 files modified
glance/common/config.py (+8/-4)
tests/functional/__init__.py (+4/-2)
tests/functional/test_logging.py (+49/-48)
To merge this branch: bzr merge lp:~jaypipes/glance/bug766052
Reviewer Review Type Date Requested Status
Dan Prince (community) Approve
Brian Waldon (community) Approve
Review via email: mp+58336@code.launchpad.net

Description of the change

Make sure we use get_option() when dealing with boolean values
read from configuration files...otherwise "False" is True :(

To post a comment you must log in.
Revision history for this message
Brian Waldon (bcwaldon) wrote :

Great job.

review: Approve
Revision history for this message
Jay Pipes (jaypipes) wrote :

FYI, the other test case (test_logfile) was removed because other tests in test_curl_api and the new tests in test_logging covered the same code path.

Revision history for this message
Dan Prince (dan-prince) wrote :

Hey Jay. I think this looks good. Looks like you've coded it such that the config file settings will override the glance-api and glance-registry command line --debug and --verbose options. Now that we have upstart scripts I'm not sure anybody would even use those options but they may be handy for occasionally running in the foreground. Should we make it so those options override the config file?

review: Needs Information
Revision history for this message
Dan Prince (dan-prince) wrote :

Never mind. I was misreading it. Looks great. Approve.

review: Approve
Revision history for this message
Jay Pipes (jaypipes) wrote :

The CLI option overrides the config files value, AFAIK.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'glance/common/config.py'
2--- glance/common/config.py 2011-04-13 12:56:45 +0000
3+++ glance/common/config.py 2011-04-19 15:51:32 +0000
4@@ -135,8 +135,10 @@
5
6 # If either the CLI option or the conf value
7 # is True, we set to True
8- debug = options.get('debug') or conf.get('debug', False)
9- verbose = options.get('verbose') or conf.get('verbose', False)
10+ debug = options.get('debug') or \
11+ get_option(conf, 'debug', type='bool', default=False)
12+ verbose = options.get('verbose') or \
13+ get_option(conf, 'verbose', type='bool', default=False)
14 root_logger = logging.root
15 if debug:
16 root_logger.setLevel(logging.DEBUG)
17@@ -278,8 +280,10 @@
18
19 # We only update the conf dict for the verbose and debug
20 # flags. Everything else must be set up in the conf file...
21- debug = options.get('debug') or conf.get('debug', False)
22- verbose = options.get('verbose') or conf.get('verbose', False)
23+ debug = options.get('debug') or \
24+ get_option(conf, 'debug', type='bool', default=False)
25+ verbose = options.get('verbose') or \
26+ get_option(conf, 'verbose', type='bool', default=False)
27 conf['debug'] = debug
28 conf['verbose'] = verbose
29
30
31=== modified file 'tests/functional/__init__.py'
32--- tests/functional/__init__.py 2011-04-04 13:59:07 +0000
33+++ tests/functional/__init__.py 2011-04-19 15:51:32 +0000
34@@ -46,6 +46,8 @@
35
36 def setUp(self):
37
38+ self.verbose = True
39+ self.debug = True
40 self.test_id = random.randint(0, 100000)
41 self.test_dir = os.path.join("/", "tmp", "test.%d" % self.test_id)
42
43@@ -144,8 +146,8 @@
44
45 conf_file = tempfile.NamedTemporaryFile()
46 conf_contents = """[DEFAULT]
47-verbose = True
48-debug = True
49+verbose = %(verbose)s
50+debug = %(debug)s
51
52 [app:glance-api]
53 paste.app_factory = glance.server:app_factory
54
55=== modified file 'tests/functional/test_logging.py'
56--- tests/functional/test_logging.py 2011-03-17 21:43:26 +0000
57+++ tests/functional/test_logging.py 2011-04-19 15:51:32 +0000
58@@ -15,6 +15,8 @@
59 # License for the specific language governing permissions and limitations
60 # under the License.
61
62+"""Functional test case that tests logging output"""
63+
64 import os
65 import unittest
66
67@@ -24,56 +26,55 @@
68
69 class TestLogging(functional.FunctionalTest):
70
71- """Tests that logging can be configured correctly"""
72-
73- def test_logfile(self):
74- """
75- A test that logging can be configured properly from the
76- glance.conf file with the log_file option.
77-
78- We start both servers daemonized with a temporary config
79- file that has some logging options in it.
80-
81- We then use curl to issue a few requests and verify that each server's
82- logging statements were logged to the one log file
83- """
84+ """Functional tests for Glance's logging output"""
85+
86+ def test_verbose_debug(self):
87+ """
88+ Test logging output proper when verbose and debug
89+ is on.
90+ """
91+
92 self.cleanup()
93 api_port, reg_port, conf_file = self.start_servers()
94
95- cmd = "curl -X POST -H 'Content-Type: application/octet-stream' "\
96- "-H 'X-Image-Meta-Name: ImageName' "\
97- "-H 'X-Image-Meta-Disk-Format: Invalid' "\
98- "http://0.0.0.0:%d/images" % api_port
99- ignored, out, err = execute(cmd)
100-
101- self.assertTrue('Invalid disk format' in out,
102- "Could not find 'Invalid disk format' "
103- "in output: %s" % out)
104-
105- self.assertTrue(os.path.exists(self.api_log_file),
106- "API Logfile %s does not exist!"
107- % self.api_log_file)
108- self.assertTrue(os.path.exists(self.registry_log_file),
109- "Registry Logfile %s does not exist!"
110- % self.registry_log_file)
111-
112- api_logfile_contents = open(self.api_log_file, 'rb').read()
113- registry_logfile_contents = open(self.registry_log_file, 'rb').read()
114-
115- # Check that BOTH the glance API and registry server
116- # modules are logged to their respective logfiles.
117- self.assertTrue('[glance.server]'
118- in api_logfile_contents,
119- "Could not find '[glance.server]' "
120- "in API logfile: %s" % api_logfile_contents)
121- self.assertTrue('[glance.registry.server]'
122- in registry_logfile_contents,
123- "Could not find '[glance.registry.server]' "
124- "in Registry logfile: %s" % registry_logfile_contents)
125-
126- # Test that the error we caused above is in the log
127- self.assertTrue('Invalid disk format' in api_logfile_contents,
128- "Could not find 'Invalid disk format' "
129- "in API logfile: %s" % api_logfile_contents)
130+ # The default functional test case has both verbose
131+ # and debug on. Let's verify that debug statements
132+ # appear in both the API and registry logs.
133+
134+ self.assertTrue(os.path.exists(self.api_log_file))
135+
136+ api_log_out = open(self.api_log_file, 'r').read()
137+
138+ self.assertTrue('DEBUG [glance-api]' in api_log_out)
139+
140+ self.assertTrue(os.path.exists(self.registry_log_file))
141+
142+ registry_log_out = open(self.registry_log_file, 'r').read()
143+
144+ self.assertTrue('DEBUG [glance-registry]' in registry_log_out)
145+
146+ self.stop_servers()
147+
148+ def test_no_verbose_no_debug(self):
149+ """
150+ Test logging output proper when verbose and debug
151+ is off.
152+ """
153+
154+ self.cleanup()
155+ api_port, reg_port, conf_file = self.start_servers(debug=False,
156+ verbose=False)
157+
158+ self.assertTrue(os.path.exists(self.api_log_file))
159+
160+ api_log_out = open(self.api_log_file, 'r').read()
161+
162+ self.assertFalse('DEBUG [glance-api]' in api_log_out)
163+
164+ self.assertTrue(os.path.exists(self.registry_log_file))
165+
166+ registry_log_out = open(self.registry_log_file, 'r').read()
167+
168+ self.assertFalse('DEBUG [glance-registry]' in registry_log_out)
169
170 self.stop_servers()

Subscribers

People subscribed via source and target branches