~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/config/doc/canonical-config.txt

  • Committer: Curtis Hovey
  • Date: 2011-12-24 17:49:30 UTC
  • mto: This revision was merged to the branch mainline in revision 14602.
  • Revision ID: curtis.hovey@canonical.com-20111224174930-xk1d5cvhyxq46ctf
Moved webapp to lp.services.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
Canonical Config
2
2
================
3
3
 
4
 
`lp.services.config` provides singleton access to the Launchpad
 
4
`canonical.config` provides singleton access to the Launchpad
5
5
configuration, accessed via the `config` module global. It is
6
6
responsible for loading the Launchpad schema and the environment's
7
7
correct config.
8
8
 
9
9
 
10
 
LaunchpadConfig AKA config
 
10
CanonicalConfig AKA config
11
11
--------------------------
12
12
 
13
 
LaunchpadConfig is a singleton that manages access to the config. Cached
 
13
CanonicalConfig is a singleton that manages access to the config. Cached
14
14
copies are kept in thread locals ensuring the configuration is thread
15
15
safe (not that this will be a problem if we stick with simple
16
16
configuration).
17
17
 
18
 
    >>> from lp.services.config import config
19
 
    >>> from lp.testing.layers import DatabaseLayer
 
18
    >>> from canonical.config import config
 
19
    >>> from canonical.testing.layers import DatabaseLayer
20
20
    >>> expected = (
21
21
    ...     'dbname=%s host=localhost' % DatabaseLayer._db_fixture.dbname)
22
22
    >>> expected == config.database.rw_main_master
38
38
    ...     canonical.__file__)
39
39
    True
40
40
 
41
 
LaunchpadConfig loads the conf file from the directory that matches its
 
41
CanonicalConfig loads the conf file from the directory that matches its
42
42
instance_name. The instance name is often the same as the LPCONFIG
43
43
environment variable (scripts can override this using setInstance()). It
44
44
will choose the conf file that matches its process_name if it exists,
46
46
configs/<instance_name>/<process_name>.conf. The testrunner sets the
47
47
instance_name to 'testrunner' and additionally uses unique temporary
48
48
configs to permit changing the config during tests (but not if we are
49
 
using persistent helpers - see lp.testing.layers).
 
49
using persistent helpers - see canonical.testing.layers).
50
50
 
51
51
    >>> (config.instance_name == 'testrunner' or
52
52
    ...     config.instance_name == os.environ['LPCONFIG'])
61
61
    >>> config.extends.filename
62
62
    '.../launchpad-lazr.conf'
63
63
 
64
 
LaunchpadConfig provides __contains__ and __getitem__ to check and
 
64
CanonicalConfig provides __contains__ and __getitem__ to check and
65
65
access lazr.config sections and keys.
66
66
 
67
67
    >>> 'launchpad' in config
72
72
 
73
73
The application root directory is assigned to the root attribute.
74
74
 
75
 
    >>> import lp.services.config
76
 
    >>> example_path = lp.services.config.__file__
 
75
    >>> import canonical.config
 
76
    >>> example_path = canonical.config.__file__
77
77
    >>> config.root in example_path
78
78
    True
79
79
 
80
80
    >>> example_path[len(config.root):]
81
 
    '/lib/lp/services/...'
 
81
    '/lib/canonical/...'
82
82
 
83
83
The config instance has additional attributes that come from the
84
84
ZConfig.
127
127
Setting just the instance_name will change the directory from which the
128
128
conf file is loaded.
129
129
 
130
 
    >>> from lp.services.config import LaunchpadConfig
131
 
    >>> test_config = LaunchpadConfig('testrunner', 'test')
 
130
    >>> from canonical.config import CanonicalConfig
 
131
    >>> test_config = CanonicalConfig('testrunner', 'test')
132
132
    >>> test_config.setInstance('development')
133
133
    >>> test_config.instance_name
134
134
    'development'
190
190
The initial instance_name is set via the LPCONFIG environment variable.
191
191
Because Config is designed to failover to the default development
192
192
environment, and the testrunner overrides the environment and config, we
193
 
need to reconfigure the environment and reload the lp.services.config
194
 
module to test LaunchpadConfig's behaviour.
 
193
need to reconfigure the environment and reload the canonical.config
 
194
module to test CanonicalConfig's behaviour.
195
195
 
196
196
Alternatively, the instance name and process name can be specified as
197
197
argument to the constructor.
198
198
 
199
 
    >>> dev_config = LaunchpadConfig('development', 'authserver')
 
199
    >>> dev_config = CanonicalConfig('development', 'authserver')
200
200
    >>> dev_config.instance_name
201
201
    'development'
202
202
 
210
210
# config can be restored when this test is torn down.
211
211
#    >>> true_config = config
212
212
#    >>> import os
213
 
#    >>> from lp.services.config import LPCONFIG, DEFAULT_SECTION
 
213
#    >>> from canonical.config import LPCONFIG, DEFAULT_SECTION
214
214
#    >>> os.environ[LPCONFIG] = 'mailman-itests'
215
215
#    >>> os.environ[DEFAULT_SECTION] = 'default'
216
216
 
217
 
#    # reload the LaunchpadConfig class object.
218
 
#    >>> config_module = reload(lp.services.config)
219
 
#    >>> from lp.services.config import config
 
217
#    # reload the CanonicalConfig class object.
 
218
#    >>> config_module = reload(canonical.config)
 
219
#    >>> from canonical.config import config
220
220
#    >>> config.filename
221
221
#    '.../configs/mailman-itests/launchpad-lazr.conf'
222
222
#    >>> config.extends.filename
238
238
#We need to reset the config for the testrunner.
239
239
 
240
240
#    >>> config = true_config
241
 
#    >>> lp.services.config.config = config
 
241
#    >>> canonical.config.config = config
242
242
#    >>> config.filename
243
243
#    '.../configs/testrunner/launchpad-lazr.conf'
244
244
#    >>> config.dbname == DatabaseLayer._db_fixture.dbname