Merge lp:~jaypipes/glance/bug742190 into lp:~glance-coresec/glance/cactus-trunk

Proposed by Jay Pipes
Status: Merged
Approved by: Rick Harris
Approved revision: 103
Merged at revision: 105
Proposed branch: lp:~jaypipes/glance/bug742190
Merge into: lp:~glance-coresec/glance/cactus-trunk
Diff against target: 384 lines (+228/-23)
6 files modified
bin/glance-manage (+9/-2)
doc/source/configuring.rst (+164/-5)
etc/glance.conf.sample (+1/-3)
glance/common/config.py (+48/-9)
glance/registry/db/__init__.py (+1/-1)
tests/unit/test_config.py (+5/-3)
To merge this branch: bzr merge lp:~jaypipes/glance/bug742190
Reviewer Review Type Date Requested Status
Rick Harris (community) Approve
Devin Carlen (community) Approve
Review via email: mp+56220@code.launchpad.net

Description of the change

Adds --config-file option to common options processing.

Updates glance-manage to use configuration files as well
as command line options.

Completes documentation on configuring Glance's servers
and CLI tools.

To post a comment you must log in.
Revision history for this message
Rick Harris (rconradharris) wrote :

Overall looks good, but looks like test needs to be updated for new code.

Failed test: http://paste.openstack.org/show/1115/

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

ah, cheers. I'll fix that up. not sure how that slipped past me ...

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

ok, should be fixed. pls re-review.

Revision history for this message
Devin Carlen (devcamcar) wrote :

excellent, lgtm!

review: Approve
Revision history for this message
Rick Harris (rconradharris) wrote :

Looks great, thanks Jay.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/glance-manage'
2--- bin/glance-manage 2011-03-17 14:39:50 +0000
3+++ bin/glance-manage 2011-04-07 18:56:35 +0000
4@@ -52,9 +52,9 @@
5
6 :param parser: The option parser
7 """
8- glance.registry.db.add_options(parser)
9 config.add_common_options(parser)
10 config.add_log_options(parser)
11+ glance.registry.db.add_options(parser)
12
13
14 def do_db_version(options, args):
15@@ -119,7 +119,11 @@
16 (options, args) = config.parse_options(oparser)
17
18 try:
19- config.setup_logging(options, {})
20+ # We load the glance-registry config section because
21+ # sql_connection is only part of the glance registry.
22+ conf_file, conf = config.load_paste_config('glance-registry',
23+ options, args)
24+ config.setup_logging(options, conf)
25 except RuntimeError, e:
26 sys.exit("ERROR: %s" % e)
27
28@@ -127,6 +131,9 @@
29 oparser.print_usage()
30 sys.exit(1)
31
32+ if conf.get('sql_connection') and not options['sql_connection']:
33+ options['sql_connection'] = conf.get('sql_connection')
34+
35 dispatch_cmd(options, args)
36
37
38
39=== modified file 'doc/source/configuring.rst'
40--- doc/source/configuring.rst 2011-03-08 21:52:38 +0000
41+++ doc/source/configuring.rst 2011-04-07 18:56:35 +0000
42@@ -17,14 +17,57 @@
43 Configuring Glance
44 ==================
45
46-.. todo:: Complete details of configuration with paste.deploy config files
47+In addition to this documentation page, you can check the
48+``etc/glance.conf.sample`` sample configuration file distributed with Glance
49+for an example configuration file with detailed comments on what each options
50+does.
51+
52+Common Configuration Options in Glance
53+--------------------------------------
54+
55+Glance has a few command-line options that are common to all Glance programs:
56+
57+* ``--verbose``
58+
59+Optional. Default: ``False``
60+
61+Can be specified on the command line and in configuration files.
62+
63+Turns on the INFO level in logging and prints more verbose command-line
64+interface printouts.
65+
66+* ``--debug``
67+
68+Optional. Default: ``False``
69+
70+Can be specified on the command line and in configuration files.
71+
72+Turns on the DEBUG level in logging.
73+
74+* ``--config-file=PATH``
75+
76+Optional. Default: ``None``
77+
78+Specified on the command line only.
79+
80+Takes a path to a configuration file to use when running the program. If this
81+CLI option is not specified, then we check to see if the first argument is a
82+file. If it is, then we try to use that as the configuration file. If there is
83+no file or there were no arguments, we search for a configuration file in the
84+following order:
85+
86+ - ./glance.conf
87+ - ~/glance.conf
88+ - ~/.glance/glance.conf
89+ - /etc/glance/glance.conf
90+ - /etc/glance.conf
91
92 Configuring Logging in Glance
93 -----------------------------
94
95 There are a number of configuration options in Glance that control how Glance
96-servers log messages. The configuration options are specified in the
97-``glance.conf`` config file.
98+servers log messages. The configuration options can be specified both on the
99+command line and in the ``glance.conf`` config file.
100
101 * ``--log-config=PATH``
102
103@@ -36,8 +79,8 @@
104
105 * ``--log-format``
106
107-*Because of a bug in the PasteDeploy package, this option is only available
108-on the command line.*
109+`Because of a bug in the PasteDeploy package, this option is only available
110+on the command line.`
111
112 Optional. Default: ``%(asctime)s %(levelname)8s [%(name)s] %(message)s``
113
114@@ -64,3 +107,119 @@
115 Defaults to ``%Y-%m-%d %H:%M:%S``. See the
116 `logging module <http://docs.python.org/library/logging.html>`_ documentation for
117 more information on setting this format string.
118+
119+Configuring Glance Storage Backends
120+-----------------------------------
121+
122+There are a number of configuration options in Glance that control how Glance
123+stores disk images. These configuration options are specified in the
124+``glance.conf`` config file `in the section [app:glance-api]`.
125+
126+* ``default_store=STORE``
127+
128+Optional. Default: ``file``
129+
130+Can only be specified in configuration files.
131+
132+Sets the storage backend to use by default when storing images in Glance.
133+Available options for this option are (``file``, ``swift``, or ``s3``).
134+
135+* ``filesystem_store_datadir=PATH``
136+
137+Optional. Default: ``/var/lib/glance/images/``
138+
139+Can only be specified in configuration files.
140+
141+`This option is specific to the filesystem storage backend.`
142+
143+Sets the path where the filesystem storage backend write disk images. Note that
144+the filesystem storage backend will attempt to create this directory if it does
145+not exist. Ensure that the user that ``glance-api`` runs under has write
146+permissions to this directory.
147+
148+* ``swift_store_auth_address=URL``
149+
150+Required when using the Swift storage backend.
151+
152+Can only be specified in configuration files.
153+
154+`This option is specific to the Swift storage backend.`
155+
156+Sets the authentication URL supplied to Swift when making calls to its storage
157+system. For more information about the Swift authentication system, please
158+see the `Swift auth <http://swift.openstack.org/overview_auth.html>`_
159+documentation and the
160+`overview of Swift authentication <http://docs.openstack.org/openstack-object-storage/admin/content/ch02s02.html>`_.
161+
162+* ``swift_store_user=USER``
163+
164+Required when using the Swift storage backend.
165+
166+Can only be specified in configuration files.
167+
168+`This option is specific to the Swift storage backend.`
169+
170+Sets the user to authenticate against the ``swift_store_auth_address`` with.
171+
172+* ``swift_store_key=KEY``
173+
174+Required when using the Swift storage backend.
175+
176+Can only be specified in configuration files.
177+
178+`This option is specific to the Swift storage backend.`
179+
180+Sets the authentication key to authenticate against the
181+``swift_store_auth_address`` with for the user ``swift_store_user``.
182+
183+* ``swift_store_container=CONTAINER``
184+
185+Optional. Default: ``glance``
186+
187+Can only be specified in configuration files.
188+
189+`This option is specific to the Swift storage backend.`
190+
191+Sets the name of the container to use for Glance images in Swift.
192+
193+* ``swift_store_create_container_on_put``
194+
195+Optional. Default: ``False``
196+
197+Can only be specified in configuration files.
198+
199+`This option is specific to the Swift storage backend.`
200+
201+If true, Glance will attempt to create the container ``swift_store_container``
202+if it does not exist.
203+
204+Configuring the Glance Registry
205+-------------------------------
206+
207+Glance ships with a default, reference implementation registry server. There
208+are a number of configuration options in Glance that control how this registry
209+server operates. These configuration options are specified in the
210+``glance.conf`` config file `in the section [app:glance-registry]`.
211+
212+* ``sql_connection=CONNECTION_STRING`` (``--sql-connection`` when specified
213+ on command line)
214+
215+Optional. Default: ``None``
216+
217+Can be specified in configuration files. Can also be specified on the
218+command-line for the ``glance-manage`` program.
219+
220+Sets the SQLAlchemy connection string to use when connecting to the registry
221+database. Please see the documentation for
222+`SQLAlchemy connection strings <http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/connections.html>`_
223+online.
224+
225+* ``sql_timeout=SECONDS``
226+ on command line)
227+
228+Optional. Default: ``3600``
229+
230+Can only be specified in configuration files.
231+
232+Sets the number of seconds after which SQLAlchemy should reconnect to the
233+datastore if no activity has been made on the connection.
234
235=== modified file 'etc/glance.conf.sample'
236--- etc/glance.conf.sample 2011-03-05 00:02:26 +0000
237+++ etc/glance.conf.sample 2011-04-07 18:56:35 +0000
238@@ -34,9 +34,7 @@
239 # ============ Swift Store Options =============================
240
241 # Address where the Swift authentication service lives
242-# The auth address should be in the form:
243-# <DOMAIN>[:<PORT>]/<VERSION>/<ACCOUNT>
244-swift_store_auth_address = 127.0.0.1:8080/v1.0/glance-account
245+swift_store_auth_address = 127.0.0.1:8080/v1.0/
246
247 # User to authenticate against the Swift authentication service
248 swift_store_user = jdoe
249
250=== modified file 'glance/common/config.py'
251--- glance/common/config.py 2011-03-08 21:52:38 +0000
252+++ glance/common/config.py 2011-04-07 18:56:35 +0000
253@@ -77,6 +77,12 @@
254 group.add_option('-d', '--debug', default=False, dest="debug",
255 action="store_true",
256 help="Print debugging output")
257+ group.add_option('--config-file', default=None, metavar="PATH",
258+ help="Path to the config file to use. When not specified "
259+ "(the default), we generally look at the first "
260+ "argument specified to be a config file, and if "
261+ "that is also missing, we search standard "
262+ "directories for a config file.")
263 parser.add_option_group(group)
264
265
266@@ -183,9 +189,9 @@
267 """
268
269 fix_path = lambda p: os.path.abspath(os.path.expanduser(p))
270- if getattr(options, 'config', None):
271- if os.path.exists(options.config_file):
272- return fix_path(getattr(options, 'config'))
273+ if options.get('config_file'):
274+ if os.path.exists(options['config_file']):
275+ return fix_path(options['config_file'])
276 elif args:
277 if os.path.exists(args[0]):
278 return fix_path(args[0])
279@@ -203,6 +209,43 @@
280 return cfg_file
281
282
283+def load_paste_config(app_name, options, args):
284+ """
285+ Looks for a config file to use for an app and returns the
286+ config file path and a configuration mapping from a paste config file.
287+
288+ We search for the paste config file in the following order:
289+ * If --config-file option is used, use that
290+ * If args[0] is a file, use that
291+ * Search for glance.conf in standard directories:
292+ * .
293+ * ~.glance/
294+ * ~
295+ * /etc/glance
296+ * /etc
297+
298+ :param app_name: Name of the application to load config for, or None.
299+ None signifies to only load the [DEFAULT] section of
300+ the config file.
301+ :param options: Set of typed options returned from parse_options()
302+ :param args: Command line arguments from argv[1:]
303+ :retval Tuple of (conf_file, conf)
304+
305+ :raises RuntimeError when config file cannot be located or there was a
306+ problem loading the configuration file.
307+ """
308+ conf_file = find_config_file(options, args)
309+ if not conf_file:
310+ raise RuntimeError("Unable to locate any configuration file. "
311+ "Cannot load application %s" % app_name)
312+ try:
313+ conf = deploy.appconfig("config:%s" % conf_file, name=app_name)
314+ return conf_file, conf
315+ except Exception, e:
316+ raise RuntimeError("Error trying to load config %s: %s"
317+ % (conf_file, e))
318+
319+
320 def load_paste_app(app_name, options, args):
321 """
322 Builds and returns a WSGI app from a paste config file.
323@@ -224,13 +267,9 @@
324 :raises RuntimeError when config file cannot be located or application
325 cannot be loaded from config file
326 """
327- conf_file = find_config_file(options, args)
328- if not conf_file:
329- raise RuntimeError("Unable to locate any configuration file. "
330- "Cannot load application %s" % app_name)
331+ conf_file, conf = load_paste_config(app_name, options, args)
332+
333 try:
334- conf = deploy.appconfig("config:%s" % conf_file, name=app_name)
335-
336 # Setup logging early, supplying both the CLI options and the
337 # configuration mapping from the config file
338 setup_logging(options, conf)
339
340=== modified file 'glance/registry/db/__init__.py'
341--- glance/registry/db/__init__.py 2011-02-02 16:55:07 +0000
342+++ glance/registry/db/__init__.py 2011-04-07 18:56:35 +0000
343@@ -33,7 +33,7 @@
344 group = optparse.OptionGroup(parser, "Registry Database Options",
345 help_text)
346 group.add_option('--sql-connection', metavar="CONNECTION",
347- default='sqlite:///glance.sqlite',
348+ default=None,
349 help="A valid SQLAlchemy connection string for the "
350 "registry database. Default: %default")
351 parser.add_option_group(group)
352
353=== modified file 'tests/unit/test_config.py'
354--- tests/unit/test_config.py 2011-02-09 23:57:05 +0000
355+++ tests/unit/test_config.py 2011-04-07 18:56:35 +0000
356@@ -30,7 +30,7 @@
357 config.add_common_options(parser)
358 self.assertEquals(1, len(parser.option_groups))
359
360- expected_options = ['--verbose', '--debug']
361+ expected_options = ['--verbose', '--debug', '--config-file']
362 for e in expected_options:
363 self.assertTrue(parser.option_groups[0].get_option(e),
364 "Missing required common option: %s" % e)
365@@ -42,7 +42,8 @@
366 config.add_common_options(parser)
367 parsed_options, args = config.parse_options(parser)
368
369- expected_options = {'verbose': False, 'debug': False}
370+ expected_options = {'verbose': False, 'debug': False,
371+ 'config_file': None}
372 self.assertEquals(expected_options, parsed_options)
373
374 # test non-empty args and that parse_options() returns a mapping
375@@ -51,7 +52,8 @@
376 config.add_common_options(parser)
377 parsed_options, args = config.parse_options(parser, ['--verbose'])
378
379- expected_options = {'verbose': True, 'debug': False}
380+ expected_options = {'verbose': True, 'debug': False,
381+ 'config_file': None}
382 self.assertEquals(expected_options, parsed_options)
383
384 # test non-empty args that contain unknown options raises

Subscribers

People subscribed via source and target branches