From 2f5cd0bd1293012fe1003e7d8aed920ed6a7b924 Mon Sep 17 00:00:00 2001 From: Ratnadeep Debnath Date: Fri, 4 Dec 2015 15:09:52 +0530 Subject: [PATCH 1/4] Initial work on refactoring Nulecule params. Fixes #423. Date: Fri Dec 04 15:30:39 2015 +0530 --- atomicapp/nulecule/base.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/atomicapp/nulecule/base.py b/atomicapp/nulecule/base.py index a008abd8..40c0d1b3 100644 --- a/atomicapp/nulecule/base.py +++ b/atomicapp/nulecule/base.py @@ -178,8 +178,7 @@ def load_config(self, config=None, ask=False, skip_asking=False): # A component should not get access to all the variables, # but only to variables it needs. component.load_config(config=copy.deepcopy(self.config), - ask=ask, skip_asking=skip_asking) - self.merge_config(self.config, component.config) + ask=False, skip_asking=True) def load_components(self, nodeps=False, dryrun=False): """ @@ -280,12 +279,14 @@ def load_config(self, config=None, ask=False, skip_asking=False): """ Load config for the Nulecule component. """ - super(NuleculeComponent, self).load_config( - config, ask=ask, skip_asking=skip_asking) + for key, value in self.params.items(): + if value.startswith('$') and value[1:] in config.get( + GLOBAL_CONF, {}): + config[GLOBAL_CONF][key] = config[GLOBAL_CONF][value[1:]] if isinstance(self._app, Nulecule): - self._app.load_config(config=copy.deepcopy(self.config), + self._app.load_config(config=copy.deepcopy(config), ask=ask, skip_asking=skip_asking) - self.merge_config(self.config, self._app.config) + self.config = config def load_external_application(self, dryrun=False, update=False): """ From e4786882e24f10a08860c0f5a4d97036ca1d4ac3 Mon Sep 17 00:00:00 2001 From: Ratnadeep Debnath Date: Thu, 24 Dec 2015 18:12:47 +0530 Subject: [PATCH 2/4] Pass config params external apps ask for. - bugfix for not updating values for params in config with static value. --- atomicapp/nulecule/base.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/atomicapp/nulecule/base.py b/atomicapp/nulecule/base.py index 40c0d1b3..b60647ba 100644 --- a/atomicapp/nulecule/base.py +++ b/atomicapp/nulecule/base.py @@ -279,12 +279,15 @@ def load_config(self, config=None, ask=False, skip_asking=False): """ Load config for the Nulecule component. """ + _config = {GLOBAL_CONF: {}} if self.source else config for key, value in self.params.items(): if value.startswith('$') and value[1:] in config.get( GLOBAL_CONF, {}): - config[GLOBAL_CONF][key] = config[GLOBAL_CONF][value[1:]] + _config[GLOBAL_CONF][key] = config[GLOBAL_CONF][value[1:]] + else: + _config[GLOBAL_CONF][key] = value if isinstance(self._app, Nulecule): - self._app.load_config(config=copy.deepcopy(config), + self._app.load_config(config=copy.deepcopy(_config), ask=ask, skip_asking=skip_asking) self.config = config From 6d0b41177b3140c9234adb75524120029b32ab38 Mon Sep 17 00:00:00 2001 From: Ratnadeep Debnath Date: Thu, 31 Dec 2015 17:00:53 +0530 Subject: [PATCH 3/4] Fix namespace conflicts in answers.conf. Fixes #478 --- atomicapp/nulecule/base.py | 10 ++++++++-- atomicapp/nulecule/lib.py | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/atomicapp/nulecule/base.py b/atomicapp/nulecule/base.py index b60647ba..caef15fa 100644 --- a/atomicapp/nulecule/base.py +++ b/atomicapp/nulecule/base.py @@ -199,8 +199,8 @@ def load_components(self, nodeps=False, dryrun=False): node_name = node[NAME_KEY] source = Utils.getSourceImage(node) component = NuleculeComponent( - node_name, self.basepath, source, - node.get(PARAMS_KEY), node.get(ARTIFACTS_KEY)) + self._get_component_namespace(node_name), self.basepath, + source, node.get(PARAMS_KEY), node.get(ARTIFACTS_KEY)) component.load(nodeps, dryrun) components.append(component) self.components = components @@ -222,6 +222,12 @@ def render(self, provider_key=None, dryrun=False): for component in self.components: component.render(provider_key=provider_key, dryrun=dryrun) + def _get_component_namespace(self, component_name): + current_namespace = '' if self.namespace == GLOBAL_CONF else self.namespace + return ( + '%s:%s' % (current_namespace, component_name) + if current_namespace else component_name) + class NuleculeComponent(NuleculeBase): """ diff --git a/atomicapp/nulecule/lib.py b/atomicapp/nulecule/lib.py index 141a12d2..b4ef565e 100644 --- a/atomicapp/nulecule/lib.py +++ b/atomicapp/nulecule/lib.py @@ -39,8 +39,10 @@ def load_config(self, config, ask=False, skip_asking=False): Returns: None """ + parent_namespace = self._get_parent_namespace() for param in self.params: value = config.get(self.namespace, {}).get(param[NAME_KEY]) or \ + config.get(parent_namespace, {}).get(param[NAME_KEY]) or \ config.get(GLOBAL_CONF, {}).get(param[NAME_KEY]) if value is None and (ask or ( not skip_asking and param.get(DEFAULTNAME_KEY) is None)): @@ -109,3 +111,7 @@ def install(self): def uninstall(self): raise NotImplementedError + + def _get_parent_namespace(self): + tokens = self.namespace.split(':') + return ':'.join(tokens[:-1]) if len(tokens) > 1 else GLOBAL_CONF From e26d57f4650a7ca51baeb8256e269fa9f39f3718 Mon Sep 17 00:00:00 2001 From: Ratnadeep Debnath Date: Thu, 31 Dec 2015 18:44:59 +0530 Subject: [PATCH 4/4] Added backward compatibility for old style params. --- atomicapp/nulecule/base.py | 41 ++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/atomicapp/nulecule/base.py b/atomicapp/nulecule/base.py index caef15fa..01caca61 100644 --- a/atomicapp/nulecule/base.py +++ b/atomicapp/nulecule/base.py @@ -177,8 +177,14 @@ def load_config(self, config=None, ask=False, skip_asking=False): # FIXME: Find a better way to expose config data to components. # A component should not get access to all the variables, # but only to variables it needs. - component.load_config(config=copy.deepcopy(self.config), - ask=False, skip_asking=True) + if isinstance(component.params, dict): + component.load_config(config=copy.deepcopy(self.config), + ask=False, skip_asking=True) + else: + # FIXME: support old style component params list + component.load_config(config=copy.deepcopy(self.config), + ask=ask, skip_asking=skip_asking) + self.merge_config(self.config, component.config) def load_components(self, nodeps=False, dryrun=False): """ @@ -285,17 +291,26 @@ def load_config(self, config=None, ask=False, skip_asking=False): """ Load config for the Nulecule component. """ - _config = {GLOBAL_CONF: {}} if self.source else config - for key, value in self.params.items(): - if value.startswith('$') and value[1:] in config.get( - GLOBAL_CONF, {}): - _config[GLOBAL_CONF][key] = config[GLOBAL_CONF][value[1:]] - else: - _config[GLOBAL_CONF][key] = value - if isinstance(self._app, Nulecule): - self._app.load_config(config=copy.deepcopy(_config), - ask=ask, skip_asking=skip_asking) - self.config = config + if isinstance(self.params, dict): + _config = {GLOBAL_CONF: {}} if self.source else config + for key, value in self.params.items(): + if value.startswith('$') and value[1:] in config.get( + GLOBAL_CONF, {}): + _config[GLOBAL_CONF][key] = config[GLOBAL_CONF][value[1:]] + else: + _config[GLOBAL_CONF][key] = value + if isinstance(self._app, Nulecule): + self._app.load_config(config=copy.deepcopy(_config), + ask=ask, skip_asking=skip_asking) + self.config = config + else: + # FIXME: Support old style component params list + super(NuleculeComponent, self).load_config( + config, ask=ask, skip_asking=skip_asking) + if isinstance(self._app, Nulecule): + self._app.load_config(config=copy.deepcopy(self.config), + ask=ask, skip_asking=skip_asking) + self.merge_config(self.config, self._app.config) def load_external_application(self, dryrun=False, update=False): """