slapos/recipe/slapconfiguration: Propagate SR defaults to configuration dict
Currently in slapos / slapconfiguration-recipe we have 2 ways to access instance parameters:
configuration dict,
and
configuration.<key>
for every valid key in configuration dict.
An SR could also provide default value for a key, e.g. like helloworld
SR does for name
parameter:
https://lab.nexedi.com/nexedi/slapos/blob/3c552c05/software/helloworld/instance.cfg.in#L38
and if such parameter is not provided in instance parameters, the default will be used...
... Though currently it only works for configuration. way of access: if a default value was provided by SR with
configuration.key = ...
it will be available via configuration.key
, but configuration
dict
will not have key
entry at all.
This looks non-consistent to me, so imho in addition to propagating
configuration {} -> configuration.<key>
on parameters receive, we should also propagate
configuration.<key> -> configuration {} defaults
so that at any time two pictures (configuration {} and set of configuration.) agree between each other.
NOTE The fix also works for slapconfiguration.serialised case, where we obtain parameters as { _ -> json } and json-decode them to python dict after receive.
The reason it works is that we apply defaults after parameters
decode, so e.g. the following
# in SR
configuration.name = John Doe
# instance parameters
_ = { "aaa": "bbb" }
will result in the following `configuration` dict:
{ 'aaa': 'bbb', 'name': 'John Doe' }