Merge lp:~jaypipes/glance/bug720816 into lp:~glance-coresec/glance/cactus-trunk
- bug720816
- Merge into cactus-trunk
Proposed by
Jay Pipes
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Jay Pipes | ||||
Approved revision: | 87 | ||||
Merged at revision: | 89 | ||||
Proposed branch: | lp:~jaypipes/glance/bug720816 | ||||
Merge into: | lp:~glance-coresec/glance/cactus-trunk | ||||
Diff against target: |
436 lines (+222/-72) 7 files modified
bin/glance-api (+1/-2) bin/glance-registry (+1/-2) doc/source/configuring.rst (+46/-0) glance/common/config.py (+20/-55) run_tests.py (+10/-11) tests/unit/test_migrations.py (+1/-2) tests/unit/test_misc.py (+143/-0) |
||||
To merge this branch: | bzr merge lp:~jaypipes/glance/bug720816 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jay Pipes (community) | Approve | ||
Rick Harris (community) | Approve | ||
Devin Carlen (community) | Approve | ||
Dan Prince | Pending | ||
Review via email: mp+52617@code.launchpad.net |
Commit message
Adds documentation on configuring logging and a unit test for checking simple log output
Description of the change
Adds documentation on configuring logging and a test that log_file works. It didn't, so this also inludes fixes for setting up log handling :)
To post a comment you must log in.
Revision history for this message
Rick Harris (rconradharris) wrote : | # |
Thanks Jay, this is a definite improvement.
review:
Approve
Revision history for this message
Cory Wright (corywright) wrote : | # |
You may want to merge trunk in once more. I just tried it and got a conflict.
Revision history for this message
Jay Pipes (jaypipes) wrote : | # |
Merged and fixed.
lp:~jaypipes/glance/bug720816
updated
Revision history for this message
Jay Pipes (jaypipes) wrote : | # |
pushing to trunk...
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'bin/glance-api' | |||
2 | --- bin/glance-api 2011-02-21 22:11:27 +0000 | |||
3 | +++ bin/glance-api 2011-03-16 16:32:09 +0000 | |||
4 | @@ -47,7 +47,7 @@ | |||
5 | 47 | :param parser: The option parser | 47 | :param parser: The option parser |
6 | 48 | """ | 48 | """ |
7 | 49 | config.add_common_options(parser) | 49 | config.add_common_options(parser) |
9 | 50 | config.add_log_options('glance-api', parser) | 50 | config.add_log_options(parser) |
10 | 51 | 51 | ||
11 | 52 | 52 | ||
12 | 53 | if __name__ == '__main__': | 53 | if __name__ == '__main__': |
13 | @@ -57,7 +57,6 @@ | |||
14 | 57 | (options, args) = config.parse_options(oparser) | 57 | (options, args) = config.parse_options(oparser) |
15 | 58 | 58 | ||
16 | 59 | try: | 59 | try: |
17 | 60 | config.setup_logging(options) | ||
18 | 61 | conf, app = config.load_paste_app('glance-api', options, args) | 60 | conf, app = config.load_paste_app('glance-api', options, args) |
19 | 62 | 61 | ||
20 | 63 | server = wsgi.Server() | 62 | server = wsgi.Server() |
21 | 64 | 63 | ||
22 | === modified file 'bin/glance-registry' | |||
23 | --- bin/glance-registry 2011-02-21 22:11:27 +0000 | |||
24 | +++ bin/glance-registry 2011-03-16 16:32:09 +0000 | |||
25 | @@ -47,7 +47,7 @@ | |||
26 | 47 | :param parser: The option parser | 47 | :param parser: The option parser |
27 | 48 | """ | 48 | """ |
28 | 49 | config.add_common_options(parser) | 49 | config.add_common_options(parser) |
30 | 50 | config.add_log_options('glance-registry', parser) | 50 | config.add_log_options(parser) |
31 | 51 | 51 | ||
32 | 52 | 52 | ||
33 | 53 | if __name__ == '__main__': | 53 | if __name__ == '__main__': |
34 | @@ -57,7 +57,6 @@ | |||
35 | 57 | (options, args) = config.parse_options(oparser) | 57 | (options, args) = config.parse_options(oparser) |
36 | 58 | 58 | ||
37 | 59 | try: | 59 | try: |
38 | 60 | config.setup_logging(options) | ||
39 | 61 | conf, app = config.load_paste_app('glance-registry', options, args) | 60 | conf, app = config.load_paste_app('glance-registry', options, args) |
40 | 62 | 61 | ||
41 | 63 | server = wsgi.Server() | 62 | server = wsgi.Server() |
42 | 64 | 63 | ||
43 | === modified file 'doc/source/configuring.rst' | |||
44 | --- doc/source/configuring.rst 2011-02-04 23:59:52 +0000 | |||
45 | +++ doc/source/configuring.rst 2011-03-16 16:32:09 +0000 | |||
46 | @@ -18,3 +18,49 @@ | |||
47 | 18 | ================== | 18 | ================== |
48 | 19 | 19 | ||
49 | 20 | .. todo:: Complete details of configuration with paste.deploy config files | 20 | .. todo:: Complete details of configuration with paste.deploy config files |
50 | 21 | |||
51 | 22 | Configuring Logging in Glance | ||
52 | 23 | ----------------------------- | ||
53 | 24 | |||
54 | 25 | There are a number of configuration options in Glance that control how Glance | ||
55 | 26 | servers log messages. The configuration options are specified in the | ||
56 | 27 | ``glance.conf`` config file. | ||
57 | 28 | |||
58 | 29 | * ``--log-config=PATH`` | ||
59 | 30 | |||
60 | 31 | Optional. Default: ``None`` | ||
61 | 32 | |||
62 | 33 | Specified on the command line only. | ||
63 | 34 | |||
64 | 35 | Takes a path to a configuration file to use for configuring logging. | ||
65 | 36 | |||
66 | 37 | * ``--log-format`` | ||
67 | 38 | |||
68 | 39 | *Because of a bug in the PasteDeploy package, this option is only available | ||
69 | 40 | on the command line.* | ||
70 | 41 | |||
71 | 42 | Optional. Default: ``%(asctime)s %(levelname)8s [%(name)s] %(message)s`` | ||
72 | 43 | |||
73 | 44 | The format of the log records. See the | ||
74 | 45 | `logging module <http://docs.python.org/library/logging.html>`_ documentation for | ||
75 | 46 | more information on setting this format string. | ||
76 | 47 | |||
77 | 48 | * ``log_file`` (``--log-file`` when specified on the command line) | ||
78 | 49 | |||
79 | 50 | The filepath of the file to use for logging messages from Glance's servers. If | ||
80 | 51 | missing, the default is to output messages to ``stdout``, so if you are running | ||
81 | 52 | Glance servers in a daemon mode (using ``glance-control``) you should make | ||
82 | 53 | sure that the ``log_file`` option is set appropriately. | ||
83 | 54 | |||
84 | 55 | * ``log_dir`` (``--log-dir`` when specified on the command line) | ||
85 | 56 | |||
86 | 57 | The filepath of the directory to use for log files. If not specified (the default) | ||
87 | 58 | the ``log_file`` is used as an absolute filepath. | ||
88 | 59 | |||
89 | 60 | * ``log_date_format`` (``--log-date-format`` when specified from the command line) | ||
90 | 61 | |||
91 | 62 | The format string for timestamps in the log output. | ||
92 | 63 | |||
93 | 64 | Defaults to ``%Y-%m-%d %H:%M:%S``. See the | ||
94 | 65 | `logging module <http://docs.python.org/library/logging.html>`_ documentation for | ||
95 | 66 | more information on setting this format string. | ||
96 | 21 | 67 | ||
97 | === modified file 'glance/common/config.py' | |||
98 | --- glance/common/config.py 2011-02-11 00:12:51 +0000 | |||
99 | +++ glance/common/config.py 2011-03-16 16:32:09 +0000 | |||
100 | @@ -35,8 +35,6 @@ | |||
101 | 35 | 35 | ||
102 | 36 | DEFAULT_LOG_FORMAT = "%(asctime)s %(levelname)8s [%(name)s] %(message)s" | 36 | DEFAULT_LOG_FORMAT = "%(asctime)s %(levelname)8s [%(name)s] %(message)s" |
103 | 37 | DEFAULT_LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S" | 37 | DEFAULT_LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S" |
104 | 38 | DEFAULT_LOG_HANDLER = 'stream' | ||
105 | 39 | LOGGING_HANDLER_CHOICES = ['syslog', 'file', 'stream'] | ||
106 | 40 | 38 | ||
107 | 41 | 39 | ||
108 | 42 | def parse_options(parser, cli_args=None): | 40 | def parse_options(parser, cli_args=None): |
109 | @@ -82,38 +80,7 @@ | |||
110 | 82 | parser.add_option_group(group) | 80 | parser.add_option_group(group) |
111 | 83 | 81 | ||
112 | 84 | 82 | ||
145 | 85 | def add_daemon_options(parser): | 83 | def add_log_options(parser): |
114 | 86 | """ | ||
115 | 87 | Given a supplied optparse.OptionParser, adds an OptionGroup that | ||
116 | 88 | represents all the configuration options around daemonization. | ||
117 | 89 | |||
118 | 90 | :param parser: optparse.OptionParser | ||
119 | 91 | """ | ||
120 | 92 | help_text = "The following configuration options are specific to "\ | ||
121 | 93 | "the daemonizing of this program." | ||
122 | 94 | |||
123 | 95 | group = optparse.OptionGroup(parser, "Daemon Options", help_text) | ||
124 | 96 | group.add_option('--config', default=None, | ||
125 | 97 | help="Configuration file to read when loading " | ||
126 | 98 | "application. If missing, the first argument is " | ||
127 | 99 | "used. If no arguments are found, then a set of " | ||
128 | 100 | "standard directories are searched for a config " | ||
129 | 101 | "file.") | ||
130 | 102 | group.add_option("--pid-file", default=None, metavar="PATH", | ||
131 | 103 | help="(Optional) Name of pid file for the server. " | ||
132 | 104 | "If not specified, the pid file will be named " | ||
133 | 105 | "/var/run/glance/<SERVER>.pid.") | ||
134 | 106 | group.add_option("--uid", type=int, default=os.getuid(), | ||
135 | 107 | help="uid under which to run. Default: %default") | ||
136 | 108 | group.add_option("--gid", type=int, default=os.getgid(), | ||
137 | 109 | help="gid under which to run. Default: %default") | ||
138 | 110 | group.add_option('--working-directory', '--working-dir', | ||
139 | 111 | default=os.path.abspath(os.getcwd()), | ||
140 | 112 | help="The working directory. Default: %default") | ||
141 | 113 | parser.add_option_group(group) | ||
142 | 114 | |||
143 | 115 | |||
144 | 116 | def add_log_options(prog_name, parser): | ||
146 | 117 | """ | 84 | """ |
147 | 118 | Given a supplied optparse.OptionParser, adds an OptionGroup that | 85 | Given a supplied optparse.OptionParser, adds an OptionGroup that |
148 | 119 | represents all the configuration options around logging. | 86 | represents all the configuration options around logging. |
149 | @@ -130,29 +97,25 @@ | |||
150 | 130 | "any other logging options specified. Please see " | 97 | "any other logging options specified. Please see " |
151 | 131 | "the Python logging module documentation for " | 98 | "the Python logging module documentation for " |
152 | 132 | "details on logging configuration files.") | 99 | "details on logging configuration files.") |
153 | 133 | group.add_option('--log-handler', default=DEFAULT_LOG_HANDLER, | ||
154 | 134 | metavar="HANDLER", | ||
155 | 135 | choices=LOGGING_HANDLER_CHOICES, | ||
156 | 136 | help="What logging handler to use? " | ||
157 | 137 | "Default: %default") | ||
158 | 138 | group.add_option('--log-date-format', metavar="FORMAT", | 100 | group.add_option('--log-date-format', metavar="FORMAT", |
159 | 139 | default=DEFAULT_LOG_DATE_FORMAT, | 101 | default=DEFAULT_LOG_DATE_FORMAT, |
160 | 140 | help="Format string for %(asctime)s in log records. " | 102 | help="Format string for %(asctime)s in log records. " |
161 | 141 | "Default: %default") | 103 | "Default: %default") |
165 | 142 | group.add_option('--log-file', default="%s.log" % prog_name, | 104 | group.add_option('--log-file', default=None, metavar="PATH", |
166 | 143 | metavar="PATH", | 105 | help="(Optional) Name of log file to output to. " |
167 | 144 | help="(Optional) Name of log file to output to.") | 106 | "If not set, logging will go to stdout.") |
168 | 145 | group.add_option("--log-dir", default=None, | 107 | group.add_option("--log-dir", default=None, |
169 | 146 | help="(Optional) The directory to keep log files in " | 108 | help="(Optional) The directory to keep log files in " |
170 | 147 | "(will be prepended to --logfile)") | 109 | "(will be prepended to --logfile)") |
171 | 148 | parser.add_option_group(group) | 110 | parser.add_option_group(group) |
172 | 149 | 111 | ||
173 | 150 | 112 | ||
175 | 151 | def setup_logging(options): | 113 | def setup_logging(options, conf): |
176 | 152 | """ | 114 | """ |
177 | 153 | Sets up the logging options for a log with supplied name | 115 | Sets up the logging options for a log with supplied name |
178 | 154 | 116 | ||
179 | 155 | :param options: Mapping of typed option key/values | 117 | :param options: Mapping of typed option key/values |
180 | 118 | :param conf: Mapping of untyped key/values from config file | ||
181 | 156 | """ | 119 | """ |
182 | 157 | 120 | ||
183 | 158 | if options.get('log_config', None): | 121 | if options.get('log_config', None): |
184 | @@ -182,27 +145,24 @@ | |||
185 | 182 | log_date_format = options.get('log_date_format', DEFAULT_LOG_DATE_FORMAT) | 145 | log_date_format = options.get('log_date_format', DEFAULT_LOG_DATE_FORMAT) |
186 | 183 | formatter = logging.Formatter(log_format, log_date_format) | 146 | formatter = logging.Formatter(log_format, log_date_format) |
187 | 184 | 147 | ||
196 | 185 | log_handler = options.get('log_handler', DEFAULT_LOG_HANDLER) | 148 | logfile = options.get('log_file') |
197 | 186 | if log_handler == 'syslog': | 149 | if not logfile: |
198 | 187 | syslog = logging.handlers.SysLogHandler(address='/dev/log') | 150 | logfile = conf.get('log_file') |
199 | 188 | syslog.setFormatter(formatter) | 151 | |
200 | 189 | root_logger.addHandler(syslog) | 152 | if logfile: |
201 | 190 | elif log_handler == 'file': | 153 | logdir = options.get('log_dir') |
202 | 191 | logfile = options['log_file'] | 154 | if not logdir: |
203 | 192 | logdir = options['log_dir'] | 155 | logdir = conf.get('log_dir') |
204 | 193 | if logdir: | 156 | if logdir: |
205 | 194 | logfile = os.path.join(logdir, logfile) | 157 | logfile = os.path.join(logdir, logfile) |
206 | 195 | logfile = logging.FileHandler(logfile) | 158 | logfile = logging.FileHandler(logfile) |
207 | 196 | logfile.setFormatter(formatter) | 159 | logfile.setFormatter(formatter) |
208 | 197 | logfile.setFormatter(formatter) | 160 | logfile.setFormatter(formatter) |
209 | 198 | root_logger.addHandler(logfile) | 161 | root_logger.addHandler(logfile) |
211 | 199 | elif log_handler == 'stream': | 162 | else: |
212 | 200 | handler = logging.StreamHandler(sys.stdout) | 163 | handler = logging.StreamHandler(sys.stdout) |
213 | 201 | handler.setFormatter(formatter) | 164 | handler.setFormatter(formatter) |
214 | 202 | root_logger.addHandler(handler) | 165 | root_logger.addHandler(handler) |
215 | 203 | else: | ||
216 | 204 | raise exception.BadInputError( | ||
217 | 205 | "unrecognized log handler '%(log_handler)s'" % locals()) | ||
218 | 206 | 166 | ||
219 | 207 | 167 | ||
220 | 208 | def find_config_file(options, args): | 168 | def find_config_file(options, args): |
221 | @@ -270,6 +230,11 @@ | |||
222 | 270 | "Cannot load application %s" % app_name) | 230 | "Cannot load application %s" % app_name) |
223 | 271 | try: | 231 | try: |
224 | 272 | conf = deploy.appconfig("config:%s" % conf_file, name=app_name) | 232 | conf = deploy.appconfig("config:%s" % conf_file, name=app_name) |
225 | 233 | |||
226 | 234 | # Setup logging early, supplying both the CLI options and the | ||
227 | 235 | # configuration mapping from the config file | ||
228 | 236 | setup_logging(options, conf) | ||
229 | 237 | |||
230 | 273 | # We only update the conf dict for the verbose and debug | 238 | # We only update the conf dict for the verbose and debug |
231 | 274 | # flags. Everything else must be set up in the conf file... | 239 | # flags. Everything else must be set up in the conf file... |
232 | 275 | conf['verbose'] = options['verbose'] | 240 | conf['verbose'] = options['verbose'] |
233 | 276 | 241 | ||
234 | === modified file 'run_tests.py' | |||
235 | --- run_tests.py 2011-03-16 06:43:16 +0000 | |||
236 | +++ run_tests.py 2011-03-16 16:32:09 +0000 | |||
237 | @@ -129,8 +129,7 @@ | |||
238 | 129 | 'yellow': red | green | bold, | 129 | 'yellow': red | green | bold, |
239 | 130 | 'magenta': red | blue | bold, | 130 | 'magenta': red | blue | bold, |
240 | 131 | 'cyan': green | blue | bold, | 131 | 'cyan': green | blue | bold, |
243 | 132 | 'white': red | green | blue | bold | 132 | 'white': red | green | blue | bold} |
242 | 133 | } | ||
244 | 134 | 133 | ||
245 | 135 | def supported(cls, stream=sys.stdout): | 134 | def supported(cls, stream=sys.stdout): |
246 | 136 | try: | 135 | try: |
247 | @@ -238,15 +237,15 @@ | |||
248 | 238 | elif self.dots: | 237 | elif self.dots: |
249 | 239 | stream.write(label[:1]) | 238 | stream.write(label[:1]) |
250 | 240 | return | 239 | return |
260 | 241 | self.errors.append((test, exc_info)) | 240 | self.errors.append((test, exc_info)) |
261 | 242 | test.passed = False | 241 | test.passed = False |
262 | 243 | if stream is not None: | 242 | if stream is not None: |
263 | 244 | if self.showAll: | 243 | if self.showAll: |
264 | 245 | self.colorizer.write("ERROR", 'red') | 244 | self.colorizer.write("ERROR", 'red') |
265 | 246 | self.stream.writeln() | 245 | self.stream.writeln() |
266 | 247 | elif self.dots: | 246 | elif self.dots: |
267 | 248 | stream.write('E') | 247 | stream.write('E') |
268 | 249 | 248 | ||
269 | 250 | def startTest(self, test): | 249 | def startTest(self, test): |
270 | 251 | unittest.TestResult.startTest(self, test) | 250 | unittest.TestResult.startTest(self, test) |
271 | 252 | current_case = test.test.__class__.__name__ | 251 | current_case = test.test.__class__.__name__ |
272 | 253 | 252 | ||
273 | === modified file 'tests/unit/test_migrations.py' | |||
274 | --- tests/unit/test_migrations.py 2011-03-08 17:53:25 +0000 | |||
275 | +++ tests/unit/test_migrations.py 2011-03-16 16:32:09 +0000 | |||
276 | @@ -33,8 +33,7 @@ | |||
277 | 33 | 33 | ||
278 | 34 | self.options = dict(sql_connection=sql_connection, | 34 | self.options = dict(sql_connection=sql_connection, |
279 | 35 | verbose=False) | 35 | verbose=False) |
282 | 36 | 36 | config.setup_logging(self.options, {}) | |
281 | 37 | config.setup_logging(self.options) | ||
283 | 38 | 37 | ||
284 | 39 | def tearDown(self): | 38 | def tearDown(self): |
285 | 40 | api.configure_db(self.options) | 39 | api.configure_db(self.options) |
286 | 41 | 40 | ||
287 | === modified file 'tests/unit/test_misc.py' | |||
288 | --- tests/unit/test_misc.py 2011-03-14 19:10:24 +0000 | |||
289 | +++ tests/unit/test_misc.py 2011-03-16 16:32:09 +0000 | |||
290 | @@ -207,3 +207,146 @@ | |||
291 | 207 | cmd = "./bin/glance-control registry stop "\ | 207 | cmd = "./bin/glance-control registry stop "\ |
292 | 208 | "%s --pid-file=glance-registry.pid" % conf_file_name | 208 | "%s --pid-file=glance-registry.pid" % conf_file_name |
293 | 209 | ignored, out, err = execute(cmd) | 209 | ignored, out, err = execute(cmd) |
294 | 210 | |||
295 | 211 | |||
296 | 212 | # TODO(jaypipes): Move this to separate test file once | ||
297 | 213 | # LP Bug#731304 moves execute() out to a common file, etc | ||
298 | 214 | class TestLogging(unittest.TestCase): | ||
299 | 215 | |||
300 | 216 | """Tests that logging can be configured correctly""" | ||
301 | 217 | |||
302 | 218 | def setUp(self): | ||
303 | 219 | self.logfiles = [] | ||
304 | 220 | |||
305 | 221 | def tearDown(self): | ||
306 | 222 | self._cleanup_test_servers() | ||
307 | 223 | self._cleanup_log_files() | ||
308 | 224 | |||
309 | 225 | def _cleanup_test_servers(self): | ||
310 | 226 | # Clean up any leftover test servers... | ||
311 | 227 | pid_files = ('glance-api.pid', 'glance-registry.pid') | ||
312 | 228 | for pid_file in pid_files: | ||
313 | 229 | if os.path.exists(pid_file): | ||
314 | 230 | pid = int(open(pid_file).read().strip()) | ||
315 | 231 | try: | ||
316 | 232 | os.killpg(pid, signal.SIGTERM) | ||
317 | 233 | except: | ||
318 | 234 | pass # Ignore if the process group is dead | ||
319 | 235 | os.unlink(pid_file) | ||
320 | 236 | |||
321 | 237 | def _cleanup_log_files(self): | ||
322 | 238 | for f in self.logfiles: | ||
323 | 239 | if os.path.exists(f): | ||
324 | 240 | os.unlink(f) | ||
325 | 241 | |||
326 | 242 | def test_logfile(self): | ||
327 | 243 | """ | ||
328 | 244 | A test that logging can be configured properly from the | ||
329 | 245 | glance.conf file with the log_file option. | ||
330 | 246 | |||
331 | 247 | We start both servers daemonized with a temporary config | ||
332 | 248 | file that has some logging options in it. | ||
333 | 249 | |||
334 | 250 | We then use curl to issue a few requests and verify that each server's | ||
335 | 251 | logging statements were logged to the one log file | ||
336 | 252 | """ | ||
337 | 253 | logfile = "/tmp/test_logfile.log" | ||
338 | 254 | self.logfiles.append(logfile) | ||
339 | 255 | |||
340 | 256 | if os.path.exists(logfile): | ||
341 | 257 | os.unlink(logfile) | ||
342 | 258 | |||
343 | 259 | self._cleanup_test_servers() | ||
344 | 260 | |||
345 | 261 | # Port numbers hopefully not used by anything... | ||
346 | 262 | api_port = 32001 | ||
347 | 263 | reg_port = 32000 | ||
348 | 264 | image_dir = "/tmp/test.images.%d" % api_port | ||
349 | 265 | if os.path.exists(image_dir): | ||
350 | 266 | shutil.rmtree(image_dir) | ||
351 | 267 | |||
352 | 268 | # A config file to use just for this test...we don't want | ||
353 | 269 | # to trample on currently-running Glance servers, now do we? | ||
354 | 270 | with tempfile.NamedTemporaryFile() as conf_file: | ||
355 | 271 | conf_contents = """[DEFAULT] | ||
356 | 272 | verbose = True | ||
357 | 273 | debug = True | ||
358 | 274 | log_file = %(logfile)s | ||
359 | 275 | |||
360 | 276 | [app:glance-api] | ||
361 | 277 | paste.app_factory = glance.server:app_factory | ||
362 | 278 | filesystem_store_datadir=%(image_dir)s | ||
363 | 279 | default_store = file | ||
364 | 280 | bind_host = 0.0.0.0 | ||
365 | 281 | bind_port = %(api_port)s | ||
366 | 282 | registry_host = 0.0.0.0 | ||
367 | 283 | registry_port = %(reg_port)s | ||
368 | 284 | |||
369 | 285 | [app:glance-registry] | ||
370 | 286 | paste.app_factory = glance.registry.server:app_factory | ||
371 | 287 | bind_host = 0.0.0.0 | ||
372 | 288 | bind_port = %(reg_port)s | ||
373 | 289 | sql_connection = sqlite:// | ||
374 | 290 | sql_idle_timeout = 3600 | ||
375 | 291 | """ % locals() | ||
376 | 292 | conf_file.write(conf_contents) | ||
377 | 293 | conf_file.flush() | ||
378 | 294 | conf_file_name = conf_file.name | ||
379 | 295 | |||
380 | 296 | venv = "" | ||
381 | 297 | if 'VIRTUAL_ENV' in os.environ: | ||
382 | 298 | venv = "tools/with_venv.sh " | ||
383 | 299 | |||
384 | 300 | # Start up the API and default registry server | ||
385 | 301 | cmd = venv + "./bin/glance-control api start "\ | ||
386 | 302 | "%s --pid-file=glance-api.pid" % conf_file_name | ||
387 | 303 | exitcode, out, err = execute(cmd) | ||
388 | 304 | |||
389 | 305 | self.assertEquals(0, exitcode) | ||
390 | 306 | self.assertTrue("Starting glance-api with" in out) | ||
391 | 307 | |||
392 | 308 | cmd = venv + "./bin/glance-control registry start "\ | ||
393 | 309 | "%s --pid-file=glance-registry.pid" % conf_file_name | ||
394 | 310 | exitcode, out, err = execute(cmd) | ||
395 | 311 | |||
396 | 312 | self.assertEquals(0, exitcode) | ||
397 | 313 | self.assertTrue("Starting glance-registry with" in out) | ||
398 | 314 | |||
399 | 315 | time.sleep(2) # Gotta give some time for spin up... | ||
400 | 316 | |||
401 | 317 | cmd = "curl -X POST -H 'Content-Type: application/octet-stream' "\ | ||
402 | 318 | "-H 'X-Image-Meta-Name: ImageName' "\ | ||
403 | 319 | "-H 'X-Image-Meta-Disk-Format: Invalid' "\ | ||
404 | 320 | "http://0.0.0.0:%d/images" % api_port | ||
405 | 321 | ignored, out, err = execute(cmd) | ||
406 | 322 | |||
407 | 323 | self.assertTrue('Invalid disk format' in out, | ||
408 | 324 | "Could not find 'Invalid disk format' " | ||
409 | 325 | "in output: %s" % out) | ||
410 | 326 | |||
411 | 327 | self.assertTrue(os.path.exists(logfile), | ||
412 | 328 | "Logfile %s does not exist!" % logfile) | ||
413 | 329 | |||
414 | 330 | logfile_contents = open(logfile, 'rb').read() | ||
415 | 331 | |||
416 | 332 | # Check that BOTH the glance API and registry server | ||
417 | 333 | # modules are logged to the file. | ||
418 | 334 | self.assertTrue('[glance.server]' in logfile_contents, | ||
419 | 335 | "Could not find '[glance.server]' " | ||
420 | 336 | "in logfile: %s" % logfile_contents) | ||
421 | 337 | self.assertTrue('[glance.registry.server]' in logfile_contents, | ||
422 | 338 | "Could not find '[glance.registry.server]' " | ||
423 | 339 | "in logfile: %s" % logfile_contents) | ||
424 | 340 | |||
425 | 341 | # Test that the error we caused above is in the log | ||
426 | 342 | self.assertTrue('Invalid disk format' in logfile_contents, | ||
427 | 343 | "Could not find 'Invalid disk format' " | ||
428 | 344 | "in logfile: %s" % logfile_contents) | ||
429 | 345 | |||
430 | 346 | # Spin down the API and default registry server | ||
431 | 347 | cmd = "./bin/glance-control api stop "\ | ||
432 | 348 | "%s --pid-file=glance-api.pid" % conf_file_name | ||
433 | 349 | ignored, out, err = execute(cmd) | ||
434 | 350 | cmd = "./bin/glance-control registry stop "\ | ||
435 | 351 | "%s --pid-file=glance-registry.pid" % conf_file_name | ||
436 | 352 | ignored, out, err = execute(cmd) |
good stuff!