Commit dda79f36 authored by Kirill Smelkov's avatar Kirill Smelkov

slapos/recipe/slapconfiguration: Move post-expand-parameter-dict actions to __init__

The reason is: in the next patch we'll want to adjust fetched
parameter_dict with SR defaults, but since currently
_expandParameterDict(), besides expanding itself, also stores result to
options - we cannot do that after - options is not a plain dict - it is
buildout own dictionary-like class

    https://lab.nexedi.com/nexedi/slapos.buildout/blob/d5deb01f/src/zc/buildout/buildout.py#L1377

which on __setitem__ not stores a reference to value, but somehow copies value inside

    https://lab.nexedi.com/nexedi/slapos.buildout/blob/d5deb01f/src/zc/buildout/buildout.py#L1540

so e.g. after the following:

    parameter_dict = {'aaa': 'bbb'}
    options['configuration'] = parameter_dict
    parameter_dict['ccc'] = 'ddd'

parameter_dict is           {'aaa': 'bbb', 'ccc': 'ddd'} and
options['configuration'] is {'aaa': 'bbb' } # no 'ccc' key

~~~~

So let's rework the code so that _expandParameterDict() only expands the
dict and we do (future) postprocessing and options['configuration']
setting in the main driver code.

P.S. isn't it even more logical now?

/cc @vpelletier, @alain.takoudjou
parent 3c552c05
...@@ -111,12 +111,19 @@ class Recipe(object): ...@@ -111,12 +111,19 @@ class Recipe(object):
parameter_dict = self.fetch_parameter_dict(options, parameter_dict = self.fetch_parameter_dict(options,
buildout['buildout']['directory']) buildout['buildout']['directory'])
# parameter_dict is usually {}, but potentially could be of any type,
# e.g. after deserialising { _ -> non-dict json } in Serialised.
# If it is non-dict - we just store it as is;
# if it is dict - we process it further.
if isinstance(parameter_dict, dict):
match = self.OPTCRE_match match = self.OPTCRE_match
for key, value in parameter_dict.iteritems(): for key, value in parameter_dict.iteritems():
if match(key) is not None: if match(key) is not None:
continue continue
options['configuration.' + key] = value options['configuration.' + key] = value
options['configuration'] = parameter_dict
def fetch_parameter_dict(self, options, instance_root): def fetch_parameter_dict(self, options, instance_root):
slap = slapos.slap.slap() slap = slapos.slap.slap()
slap.initializeConnection( slap.initializeConnection(
...@@ -224,18 +231,13 @@ class Recipe(object): ...@@ -224,18 +231,13 @@ class Recipe(object):
return self._expandParameterDict(options, parameter_dict) return self._expandParameterDict(options, parameter_dict)
def _expandParameterDict(self, options, parameter_dict): def _expandParameterDict(self, options, parameter_dict):
options['configuration'] = parameter_dict
return parameter_dict return parameter_dict
install = update = lambda self: [] install = update = lambda self: []
class Serialised(Recipe): class Serialised(Recipe):
def _expandParameterDict(self, options, parameter_dict): def _expandParameterDict(self, options, parameter_dict):
options['configuration'] = parameter_dict = unwrap(parameter_dict) return unwrap(parameter_dict)
if isinstance(parameter_dict, dict):
return parameter_dict
else:
return {}
class JsonDump(Recipe): class JsonDump(Recipe):
def __init__(self, buildout, name, options): def __init__(self, buildout, name, options):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment