~launchpad-pqm/launchpad/devel

6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
1
= Launchpad configs =
2
3
This directory defines the configurations used to run Launchpad
4
applications in specific environments.
5
6
7
== Environments ==
8
1831 by Canonical.com Patch Queue Manager
New config machinery, database helpers and oddsnsods required for staging
9
This directory stores configs. The config used is selected on startup
10
using the LPCONFIG environment variable.
11
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
12
Each config directory contains a launchpad-lazr.conf file, and optionally
1831 by Canonical.com Patch Queue Manager
New config machinery, database helpers and oddsnsods required for staging
13
a number of .zcml files. These .zcml files are processed as ZCML
14
overrides allowing you to change behavior not yet configurable in
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
15
launchpad-lazr.conf.
1831 by Canonical.com Patch Queue Manager
New config machinery, database helpers and oddsnsods required for staging
16
3691.239.2 by Stuart Bishop
Update to use Librarian as blob storage. Use Bytes types instead of String
17
If you want to create a temporary config, prefix the directory name with
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
18
'+' so that bzr ignores it and you won't accidentally commit it (this
3691.239.2 by Stuart Bishop
Update to use Librarian as blob storage. Use Bytes types instead of String
19
pattern is listed in the top level .bzrignore in this tree).
20
1831 by Canonical.com Patch Queue Manager
New config machinery, database helpers and oddsnsods required for staging
21
If you need to make changes to the production, staging or dogfood configs
22
make sure you inform the people in charge of those systems. You may wish
23
to do this if you are adding a new required config option to
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
24
launchpad-lazr.conf.
25
26
The old ZConfig-based launchpad.conf files are still used to define
27
servers and log files. These will be replaced when lazr.config is
28
bootstrapped into the Zope startup process.
29
30
14605.1.3 by Curtis Hovey
Renamed CanonicalConfig to LaunchpadConfig because that is what it is doing.
31
== LaunchpadConfig ==
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
32
14605.1.3 by Curtis Hovey
Renamed CanonicalConfig to LaunchpadConfig because that is what it is doing.
33
Launchpad uses a singleton LaunchpadConfig object to select the config
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
34
to load and manage its state.
35
36
37
=== Instance directories and process files ===
38
39
The directories in configs/ represent environment's config `instance`.
40
Environment and instance are synonymous in this case. The instance is
41
often set by the LPCONFIG environment variable, but an app may override
7659.4.1 by Danilo Šegan
Clean-up config options and add a new one for debian import failures.
42
this. The test.py calls:
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
43
44
    config.setInstance('testrunner')
45
46
to force the testrunner configuration to be loaded.
47
48
An instance directory may contain several lazr.config conf files.
14605.1.3 by Curtis Hovey
Renamed CanonicalConfig to LaunchpadConfig because that is what it is doing.
49
LaunchpadConfig loads the config file named for the process that is
50
running, eg. if the processes name is 'test', LaunchpadConfig looks for
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
51
test-lazr.conf. launchpad-lazr.conf is loaded if not a lazr config files
7024.1.6 by Jonathan Lange
More things I've missed.
52
named for the process.
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
53
54
All this information is available in the config object.
55
56
    >>> config.instance_name
57
    'testrunner'
58
    >>> config.process_name
59
    'test'
60
61
    >>> config.filename
62
    '.../configs/testrunner/launchpad-lazr.conf'
63
    >>> config.extends.filename
64
    '.../configs/development/launchpad-lazr.conf'
65
66
14605.1.3 by Curtis Hovey
Renamed CanonicalConfig to LaunchpadConfig because that is what it is doing.
67
=== Accessing the LaunchpadConfig in code ===
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
68
14605.1.3 by Curtis Hovey
Renamed CanonicalConfig to LaunchpadConfig because that is what it is doing.
69
The LaunchpadConfig singleton is exposed as config in its module.
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
70
14605.1.1 by Curtis Hovey
Moved canonical.config to lp.services.
71
    from lp.services.config import config
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
72
73
The config can be accessed as a dictionary...
74
75
    >>> 'launchpad' in config
76
    True
77
78
    >>> config['launchpad']['default_batch_size']
79
    5
80
81
...though it is commonly accessed as an object.
82
83
    >>> config.librarian.download_host
84
    'localhost'
85
86
    >>> config.librarian.download_port
87
    58000
88
14605.1.1 by Curtis Hovey
Moved canonical.config to lp.services.
89
You can learn more about lp.services.config in the doctest located at
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
90
91
    lib/canonical/launchpad/doc/canonical-config.txt
92
93
14605.1.3 by Curtis Hovey
Renamed CanonicalConfig to LaunchpadConfig because that is what it is doing.
94
=== Testing with LaunchpadConfig ===
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
95
96
Configurations are meant to be immutable--applications should never
97
alter the config. Nor should tests. Older code and tests assumed
98
that because the keys looked like attributes of the config, they
99
could be set. This was *wrong*. The code was actually adding an
14605.1.3 by Curtis Hovey
Renamed CanonicalConfig to LaunchpadConfig because that is what it is doing.
100
attribute to the LaunchpadConfig instance rather that updating to
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
101
underlying config object. While the code intended to reset the key's
102
value to the original value, it would have to delete the new attribute
103
to really restore the config singleton.
104
14605.1.3 by Curtis Hovey
Renamed CanonicalConfig to LaunchpadConfig because that is what it is doing.
105
LaunchpadConfig supports testing by exposing lazr.config's push() and
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
106
pop() methods to add and remove configurations to the stack of
107
ConfigData. The configuration can be modified and safely restored.
108
109
Tests can call push() with the configuration name and data to update
110
the config singleton.
111
112
    >>> test_data = ("""
113
    ...     [answertracker]
114
    ...     email_domain: answers.launchpad.dev""")
115
    >>> config.push('test_data', test_data)
116
    >>> config.answertracker.email_domain
117
    'answers.launchpad.dev'
118
119
And tests can remove the data with pop() when they are done to restore
120
the config.
121
122
    >>> config.pop('test_data')
123
    (<canonical.lazr.config.ConfigData ...>,)
124
    >>> config.answertracker.email_domain
125
    'answers.launchpad.net'
126
127
128
== lazr.conf schema and confs ==
129
130
All Launchpad configs inherit from the Launchpad schema defined
14605.1.1 by Curtis Hovey
Moved canonical.config to lp.services.
131
in ../lib/lp/services/config/schema-lazr.conf (it is symlinked
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
132
as ./schema-lazr.conf for convenience).
133
134
lazr.config conf and schema files look like ini-based conf files, but
135
supports a number of features that make it easy for us to run multiple
136
versions of the application:
137
138
    1. The [meta] section's extends: key points to a file that defines
139
       the inherited sections, keys, and values.
140
    2. All config automatically inherit the default sections and
141
       key values from the schema. configs need only to define
142
       the keys that are unique to itself. Shared confs can be created
143
       to define a common set of key values for many configs.
144
    3. Except for optional sections ([<section>.optional]) which must
145
       be declared in a conf file for all the keys and values to be
146
       inherited.
147
    4. Schema's may define a template for a category of sections
148
       ([<category>.template]) to define a common set of keys and
149
       values.
150
    5. The schema and configs are validated. Configs cannot add
151
       sections or keys that are not defined in the schema. Sections
152
       and keys cannot be defined twice in a file.
153
    6. Launchpad uses implicit typing. The default value of a key is a
154
       str. If the vales looks like a int, it will be cast as an int.
155
       the tokens 'true', 'false', and 'none' (in any case) will map
156
       to Python types.
157
158
When adding sections and keys to the schema, include a comment that
159
documents their purpose.
160
161
The schema should define the default value for a key when the value is
162
safe for all environments. Values that enable a common feature, or set
163
the size of a list for example, should be in the schema. Values like
164
cause email to be sent, or development features should be disabled
165
in the schema--each environment that wants the enabled feature may do
166
so in its local conf file.
167
168
You can learn more about lazr.config in the doctest located at
169
170
    lib/canonical/lazr/doc/config.txt
171
172
6800.2.2 by Curtis Hovey
README revisions.
173
=== schema template and optional sections ===
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
174
175
The schema can contain [<category>.template] sections that define a
6800.2.2 by Curtis Hovey
README revisions.
176
common set of keys and default value for category of sections.
177
For example:
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
178
179
    [vhost.template]
180
    # Host name of this virtual host.
181
    # This is matched from the incoming Host header, and
182
    # also used to put together URLs if rooturl is not provided.
183
    # Example: launchpad.net
184
    # datatype: string
185
    hostname: none
186
187
    # Alternative host names to match, in addition to
188
    # the one given in hostname, comma separated.
189
    # Example: wwwww.launchpad.net, www.launchpad.net
190
    # datatype: string
191
    althostnames: none
192
193
    # Explicit root URL for this virtual host.
194
    # If this is not provided, the root URL is calculated
195
    # based on the host name.
196
    # Example: https://launchpad.net/
197
    # datatype: string
198
    rooturl: none
199
200
The [vhost.template] defines the keys and default values of a vhost.
6800.2.2 by Curtis Hovey
README revisions.
201
"vhost" is a category, any section whose name is prefixed "vhost" will
202
inherit the keys and default values of the [vhost.template].
203
204
[vhost.answers] is an empty section in the schema...
205
206
    [vhost.answers]
207
208
...and lpnet-lazr.conf defines this:
209
210
    [vhost.answers]
211
    hostname: answers.launchpad.net
212
213
./lpnet1/launchpad-lazr.conf does not define anything for
214
[vhost.answers], yet when it is loaded, it has the all the keys and
215
default values of [vhost.template] from the schema, with the hostname
216
change defined in lpnet-lazr.conf:
217
218
    [vhost.answers]
219
    althostnames: None
220
    hostname: answers.launchpad.net
221
    rooturl: None
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
222
223
The schema may contain [<section>.optional] to define a section
224
that may declared in a conf, but is not automatically
225
inherited. This allows the application to define process configuration
226
data without exposing that information in every environment.
227
For example:
228
229
    [vhost.xmlrpc_private.optional]
230
231
is defined in the schema. It has the default keys and values defined
232
in [vhost.template]. The [vhost.xmlrpc_private] is not visible in
233
most confs because they do not declare that they use the section.
6800.2.2 by Curtis Hovey
README revisions.
234
The production-xmlrpc-private/launchpad-lazr.conf file does though,
235
by including [vhost.xmlrpc_private] section:
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
236
6800.2.2 by Curtis Hovey
README revisions.
237
    [vhost.xmlrpc_private]
238
    hostname: xmlrpc.lp.internal
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
239
    rooturl: https://launchpad.net/
240
6800.2.2 by Curtis Hovey
README revisions.
241
Including just the section ([vhost.xmlrpc_private]) will suffice. In
242
this case, the two keys were redefined.
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
243
244
245
=== Implicit typing ===
246
247
lazr.config support implicit typing so that the application does not
248
need to coerce the config values:
249
250
    Integers: any value that is only made up of numbers, optionally
6800.2.2 by Curtis Hovey
README revisions.
251
        prefixed with +/- is cast as an int: 0, 2001, -55, +404, 100.
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
252
253
    True, False, or None: any value that matches the boolean and None
254
        keywords is treated as the prescribed type. The match is
6800.2.2 by Curtis Hovey
README revisions.
255
        case-insensitive: none, nOne, true, and False are all matched.
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
256
257
    Strings: any value that is not an int, bool, or None is treated as
258
        a str. Multi-line strings can be included by indenting the
259
        continuation lines to show that they are subordinate to the
260
        key:
261
262
            mykey: this line
263
                has a line break in it.
264
265
Implicit typing does not support lists, or compound types. Code must
266
split and unpack the value to make the desired object. For example,
267
the callsite must split the host:port compound object and coerce the
268
port to an int.
269
270
271
=== Config inheritance ===
272
273
The lazr configurations in this directory descend from the
274
Launchpad schema. This is a general outline of inheritance:
275
14605.1.1 by Curtis Hovey
Moved canonical.config to lp.services.
276
    ../lib/lp/services/config/schema-lazr.conf
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
277
        |
278
        + development/launchpad-lazr.conf
279
        |    |
280
        |    + testrunner/launchpad-lazr.conf
281
        |         |
282
        |         + authserver-lazr.conf
283
        |         |
11728.3.2 by Robert Collins
Create unique configs in the test runner.
284
        |         + testrunner_\d+/launchpad-lazr.conf
285
        |         |
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
286
        |         + testrunner-appserver/launchpad-lazr.conf
287
        |             |
288
        |             + authserver-lazr.conf
11728.3.2 by Robert Collins
Create unique configs in the test runner.
289
        |             |
290
        |             + testrunner-appserver_\d+/launchpad-lazr.conf
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
291
        |
292
        + staging-lazr.conf
293
        |    |
294
        |    + bazaar-staging/launchpad-lazr.conf
295
        |    |
296
        |    + staging/launchpad-lazr.conf
297
        |    |    |
298
        |    |    + authserver-lazr.conf
299
        |    |
300
        |    + staging-mailman/launchpad-lazr.conf
301
        |
302
        + lpnet-lazr.conf
303
        |    |
304
        |    + lpnet<1-8>/launchpad-lazr.conf
305
        |    |
8137.17.24 by Barry Warsaw
thread merge
306
        |    + wildcherry/launchpad-lazr.conf
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
307
        |    |
308
        |    + librarian/launchpad-lazr.conf
309
        |    |
310
        |    + librarian-restricted/launchpad-lazr.conf
311
        |    |
312
        |    + production/launchpad-lazr.conf
313
        |    |
314
        |    + production-mailman/launchpad-lazr.conf
315
        |    |
316
        |    + production-xmlrpc-private/launchpad-lazr.conf
317
        |
318
        + demo-lazr.conf
319
        |    |
320
        |    + demo<1-4>/launchpad-lazr.conf
321
        |
322
        + beta-lazr.conf
323
        |    |
324
        |    + beta<1-3>/launchpad-lazr.conf
325
        |
326
        + dogfood/launchpad-lazr.conf
327
        |
328
        + ...
329
330
There are other configuration in this directory that are not
331
listed here
332
333
334
=== Viewing a configuration with lsconf.py ===
335
336
You can view the complete configuration for an process using the
337
lsconf.py utility to assemble the configuration from the lazr
338
conf file. eg:
339
340
    ./utilities/lsconf.py ./configs/production/launchpad-lazr.conf
341
342
The output looks like a lazr.conf file that lists all the sections
343
and keys in the configuration. The heading lists the order the conf
344
files were processed from child to ancestor.
345
346
Two useful options are -v and -s. The verbose option (-v) will annotate
347
each key with a comment explaining which conf file set the value.
348
The section name option (-s) will limit the output to the named
349
section. eg:
350
351
    ./utilities/lsconf.py -v -s answertracker \
352
        ./configs/production/launchpad-lazr.conf
353
354
    # This configuration derives from:
355
    #     ./configs/production/launchpad-lazr.conf
356
    #     ./configs/lpnet-lazr.conf
14605.1.1 by Curtis Hovey
Moved canonical.config to lp.services.
357
    #     ./lib/lp/services/config/schema-lazr.conf
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
358
359
    [answertracker]
14605.1.1 by Curtis Hovey
Moved canonical.config to lp.services.
360
    # Defined in: lib/lp/services/config/schema-lazr.conf
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
361
    days_before_expiration: 15
362
14605.1.1 by Curtis Hovey
Moved canonical.config to lp.services.
363
    # Defined in: lib/lp/services/config/schema-lazr.conf
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
364
    dbuser: answertracker
365
14605.1.1 by Curtis Hovey
Moved canonical.config to lp.services.
366
    # Defined in: lib/lp/services/config/schema-lazr.conf
6800.2.1 by Curtis Hovey
Updated config/README with lazr.config and canonical.config information. Fixed
367
    email_domain: answers.launchpad.net
368