def _policies(self): policies = [] for policy in self._tpl_policies(): for policy_name, policy_tpl in policy.items(): target_list = policy_tpl.get('targets') target_objects = [] targets_type = "groups" if target_list and len(target_list) >= 1: target_objects = self._get_policy_groups(target_list) if not target_objects: targets_type = "node_templates" target_objects = self._get_group_members(target_list) policyObj = Policy(policy_name, policy_tpl, target_objects, targets_type, self.custom_defs) # If the policyObj.type is defined in TOSCA_definition_1_0.yaml # or is defined as a custom definition, validate the properties # before adding it to the policies list. if (policyObj.type_definition and (policyObj.type in policyObj.type_definition.TOSCA_DEF or (policyObj.type not in policyObj.type_definition.TOSCA_DEF and bool(policyObj.custom_def)))): policyObj.validate() policies.append(policyObj) return policies
def _tosca_scaling_test(self, tpl_snippet, expectedprops, hot_template_parameters=None): nodetemplates = (toscaparser.utils.yamlparser. simple_parse(tpl_snippet)['node_templates']) policies = (toscaparser.utils.yamlparser. simple_parse(tpl_snippet)['policies']) name = list(nodetemplates.keys())[0] policy_name = list(policies[0].keys())[0] for policy in policies: tpl = policy[policy_name] targets = tpl["targets"] properties = tpl["properties"] try: nodetemplate = NodeTemplate(name, nodetemplates) toscacompute = ToscaCompute(nodetemplate) toscacompute.handle_properties() policy = Policy(policy_name, tpl, targets, properties, "node_templates") toscascaling = ToscaAutoscaling( policy, hot_template_parameters=hot_template_parameters) parameters = toscascaling.handle_properties([toscacompute]) if hot_template_parameters: substack_template = toscascaling.extract_substack_templates( "output.yaml", HOT_TEMPLATE_VERSION) actual_nested_resource = yaml.load( substack_template['SP1_res.yaml']) self.assertEqual(expectedprops, actual_nested_resource) else: self.assertEqual(parameters[0].properties, expectedprops) except Exception: raise
def _tosca_policy_test(self, tpl_snippet, expectedprops): nodetemplates = (toscaparser.utils.yamlparser. simple_parse(tpl_snippet)['node_templates']) policies = (toscaparser.utils.yamlparser. simple_parse(tpl_snippet)['policies']) name = list(nodetemplates.keys())[0] policy_name = list(policies[0].keys())[0] for policy in policies: tpl = policy[policy_name] targets = tpl["targets"] try: nodetemplate = NodeTemplate(name, nodetemplates) toscacompute = ToscaCompute(nodetemplate) toscacompute.handle_properties() # adding a property to test that # ToscaPolicies.handle_properties does not overwrite this. toscacompute.properties['scheduler_hints'] = { 'target_cell': 'cell0'} policy = Policy(policy_name, tpl, targets, "node_templates") toscapolicy = ToscaPolicies(policy) nodetemplate = [toscacompute] toscapolicy.handle_properties(nodetemplate) self.assertEqual(toscacompute.properties, expectedprops) except Exception: raise
def _policies(self): policies = [] for policy in self._tpl_policies(): for policy_name, policy_tpl in policy.items(): target_list = policy_tpl.get('targets') target_objects = [] targets_type = "groups" if target_list and len(target_list) >= 1: target_objects = self._get_policy_groups(target_list) if not target_objects: targets_type = "node_templates" target_objects = self._get_group_members(target_list) policyObj = Policy(policy_name, policy_tpl, target_objects, targets_type, self.custom_defs) policies.append(policyObj) return policies
def _policies(self): policies = [] for policy in self._tpl_policies(): log.debug("Policy: {}".format(policy)) for policy_name, policy_tpl in policy.items(): exception.TOSCAException.set_context("policy", policy_name) target_list = policy_tpl.get('targets') target_objects = [] targets_type = "groups" if target_list and len(target_list) >= 1: target_objects = self._get_policy_groups(target_list) if not target_objects: targets_type = "node_templates" target_objects = self._get_group_members(target_list) policyObj = Policy(policy_name, policy_tpl, target_objects, targets_type, self.custom_defs) policies.append(policyObj) exception.TOSCAException.reset_context() return policies
def _tosca_scaling_test(self, tpl_snippet, expectedprops): nodetemplates = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet) ['node_templates']) policies = ( toscaparser.utils.yamlparser.simple_parse(tpl_snippet)['policies']) name = list(nodetemplates.keys())[0] policy_name = list(policies[0].keys())[0] for policy in policies: tpl = policy[policy_name] targets = tpl["targets"] properties = tpl["properties"] try: nodetemplate = NodeTemplate(name, nodetemplates) toscacompute = ToscaCompute(nodetemplate) toscacompute.handle_properties() policy = Policy(policy_name, tpl, targets, properties, "node_templates") toscascaling = ToscaAutoscaling(policy) parameters = toscascaling.handle_properties([toscacompute]) self.assertEqual(parameters[0].properties, expectedprops) except Exception: raise