Skip to content

Commit 71a82c6

Browse files
committed
Lay groundwork for splitting runtime and static configuration data.
This change paves the way adding further runtime specific data to configuration objects. An instance of a configuration already contains such data, such as the mig_server_id property when in use by daemons and a reference to the logger. With needs arising for further runtime data, make a clear separation between runtime attributes and the static configuration data clear. Opt to do this by making an object which internally keeps a reference to an underlying configuration object, proxies attribute access to it and can then be used as a drop-in substitute in ay call stack of logic. Name this RuntimeConfiguration. Stop short of moving existing runtime properties as of this commit.
1 parent 473e4ce commit 71a82c6

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

mig/shared/conf.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,45 @@
3232
import os
3333
import sys
3434

35+
from mig.shared.configuration import Configuration
3536
from mig.shared.defaults import MIG_ENV
3637
from mig.shared.fileio import unpickle
3738

3839

40+
class RuntimeConfiguration:
41+
"""A proxy object to be passed in-place of a Configuration which can be
42+
extended with information relevant only at runtime.
43+
44+
Given Configuration objects are threaded into and through almost all
45+
the necessary codepaths to make this information available, they are an
46+
attractive place to put this - but a Configuration is currently loaded
47+
from static per-site data.
48+
49+
Resolve this dichotomy with this class - a Configuration instance will
50+
continue to represent the static data while an object that proxies its
51+
attributes and thus is entirely drop-in compatible with it can be handed
52+
to callers without being mixed in with the statuc data.
53+
"""
54+
55+
def __init__(self, configuration):
56+
object.__setattr__(self, '_configuration', configuration)
57+
58+
def __delattr__(self, attr):
59+
return setattr(self._configuration, attr)
60+
61+
def __getattr__(self, attr):
62+
return getattr(self._configuration, attr)
63+
64+
def __setattr__(self, attr, value):
65+
return setattr(self._configuration, attr, value)
66+
67+
3968
def get_configuration_object(config_file=None, skip_log=False,
4069
disable_auth_log=False):
4170
"""Simple helper to call the general configuration init. Optional skip_log
4271
and disable_auth_log arguments are passed on to allow skipping the default
4372
log initialization and disabling auth log for unit tests.
4473
"""
45-
from mig.shared.configuration import Configuration
4674
if config_file:
4775
_config_file = config_file
4876
elif os.environ.get('MIG_CONF', None):
@@ -65,7 +93,7 @@ def get_configuration_object(config_file=None, skip_log=False,
6593

6694
configuration = Configuration(_config_file, False, skip_log,
6795
disable_auth_log)
68-
return configuration
96+
return RuntimeConfiguration(configuration)
6997

7098

7199
def get_resource_configuration(resource_home, unique_resource_name,

tests/test_support.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
from tests.support import MigTestCase, PY2, testmain, temppath, \
3636
AssertOver, FakeConfiguration
3737

38-
from mig.shared.conf import get_configuration_object
39-
from mig.shared.configuration import Configuration
38+
from mig.shared.conf import get_configuration_object, RuntimeConfiguration
4039

4140

4241
class InstrumentedAssertOver(AssertOver):
@@ -165,7 +164,7 @@ def test_provides_the_test_configuration(self):
165164
configuration = self.configuration
166165

167166
# check we have a real config object
168-
self.assertIsInstance(configuration, Configuration)
167+
self.assertIsInstance(configuration, RuntimeConfiguration)
169168
# check for having loaded a config file from a test config dir
170169
config_file_path_parts = configuration.config_file.split(os.path.sep)
171170
config_file_path_parts.pop() # discard file part

0 commit comments

Comments
 (0)