def test_set(self): obj = {} DictUtils.set(obj, 'a.b.c', 1) self.assertEqual(1, DictUtils.get(obj, 'a.b.c')) obj = {} DictUtils.set(obj, 'a', 2) self.assertEqual(2, DictUtils.get(obj, 'a'))
def get_for_each(self) -> List[AppConfig]: """ Returns all instances of this app which should be created. :return: Instances, 1 by default :raise MissingVar: Gets raised if the data inside forEach is not complete """ instances = [] for instance_vars in self.data.get('forEach', []): assert isinstance(instance_vars, dict) dc_name = instance_vars.get('DC_NAME') if dc_name is None: raise MissingVar('DC_NAME not defined in forEach for app ' + self.get_dc_name()) config = AppConfig(self._config_root, None, instance_vars) # Inherit all parameters config.data.update(self.data) # Update the DC_NAME DictUtils.set(config.data, 'dc.name', dc_name) instances.append(config) if len(instances) == 0: # No forEach defined, just create one instance instances.append(self) return instances
def process(self, yml): kind = yml.get('kind') if kind == 'DeploymentConfig': yml['kind'] = 'Deployment' version = yml.get('apiVersion') if not version.startswith('apps/'): yml['apiVersion'] = 'apps/' + version name_selector = DictUtils.get(yml, 'spec.selector.name') if name_selector is not None: DictUtils.delete(yml, 'spec.selector.name') DictUtils.set(yml, 'spec.selector.matchLabels.app', name_selector) strategy_type = DictUtils.get(yml, 'spec.strategy.type') if strategy_type == 'Rolling': DictUtils.set(yml, 'spec.strategy.type', 'RollingUpdate') name = DictUtils.get(yml, 'spec.template.metadata.labels.name') if name is not None: DictUtils.delete(yml, 'spec.template.metadata.labels.name') DictUtils.set(yml, 'spec.template.metadata.labels.app', name) return