Exemplo n.º 1
0
    def __init__(self, tosca_parser_template, provider, cluster_name):

        self.provider = provider
        self.provider_config = ProviderConfiguration(self.provider)
        self.cluster_name = cluster_name
        ExceptionCollector.start()
        for sec in self.REQUIRED_CONFIG_PARAMS:
            if not self.provider_config.config[self.provider_config.MAIN_SECTION].get(sec):
                ExceptionCollector.appendException(ProviderConfigurationParameterError(
                    what=sec
                ))
        ExceptionCollector.stop()
        if ExceptionCollector.exceptionsCaught():
            raise ValidationError(
                message='\nTranslating to provider failed: '
                    .join(ExceptionCollector.getExceptionsReport())
            )

        # toscaparser.tosca_template:ToscaTemplate
        self.tosca_parser_template = tosca_parser_template
        # toscaparser.topology_template:TopologyTemplate
        self.tosca_topology_template = self.full_type_definitions(self.tosca_parser_template.topology_template)

        import_definition_file = ImportsLoader([self.definition_file()], None, list(SERVICE_TEMPLATE_KEYS),
                                               self.tosca_topology_template.tpl)
        self.full_provider_defs = copy.copy(self.tosca_topology_template.custom_defs)
        self.provider_defs = import_definition_file.get_custom_defs()
        self.full_provider_defs.update(self.provider_defs)

        self.artifacts = []
        self.used_conditions_set = set()
        self.extra_configuration_tool_params = dict()
        self.inputs = self.tosca_topology_template.inputs
        self.outputs = self.tosca_topology_template.outputs
        node_templates = self.resolve_get_property_functions(self.tosca_topology_template.nodetemplates)

        self.topology_template = self.translate_to_provider()

        self.node_templates = self.topology_template.nodetemplates
        self.relationship_templates = self.topology_template.relationship_templates

        self.template_dependencies = dict()  # list of lists
        # After this step self.node_templates has requirements with node_filter parameter
        self.resolve_in_template_dependencies()
        self.resolve_in_template_get_functions()

        self.configuration_content = None
        self.configuration_ready = None

        # Create the list of ProviderResource instances
        self.software_component_names = []
        for node in self.node_templates:
            if self._is_software_component(node):
                self.software_component_names.append(node.name)
        self.provider_nodes = self._provider_nodes()
        self.provider_nodes_by_name = self._provider_nodes_by_name()
        self.relationship_templates_by_name = self._relationship_templates_by_name()

        self.provider_node_names_by_priority = self._sort_nodes_by_priority()
        self.provider_nodes_queue = self.sort_nodes_by_dependency()
    def __init__(self,
                 path=None,
                 parsed_params=None,
                 a_file=True,
                 yaml_dict_tpl=None,
                 sub_mapped_node_template=None,
                 no_required_paras_check=False,
                 debug_mode=False):
        if sub_mapped_node_template is None:
            ExceptionCollector.start()
        self.a_file = a_file
        self.input_path = None
        self.path = None
        self.tpl = None
        self.sub_mapped_node_template = sub_mapped_node_template
        self.nested_tosca_tpls_with_topology = {}
        self.nested_tosca_templates_with_topology = []
        self.no_required_paras_check = no_required_paras_check
        self.debug_mode = debug_mode

        if path:
            self.input_path = path
            self.path = self._get_path(path)
            if self.path:
                self.tpl = YAML_LOADER(self.path, self.a_file)
            if yaml_dict_tpl:
                msg = (_('Both path and yaml_dict_tpl arguments were '
                         'provided. Using path and ignoring yaml_dict_tpl.'))
                log.info(msg)
                print(msg)
        else:
            if yaml_dict_tpl:
                self.tpl = yaml_dict_tpl
            else:
                ExceptionCollector.appendException(
                    ValueError(
                        _('No path or yaml_dict_tpl was provided. '
                          'There is nothing to parse.')))

        if self.tpl:
            self.parsed_params = parsed_params
            self._validate_field()
            self.version = self._tpl_version()
            self.relationship_types = self._tpl_relationship_types()
            self.description = self._tpl_description()
            self.topology_template = self._topology_template()
            self.repositories = self._tpl_repositories()
            if self.topology_template.tpl:
                self.inputs = self._inputs()
                self.relationship_templates = self._relationship_templates()
                self.nodetemplates = self._nodetemplates()
                self.outputs = self._outputs()
                self.policies = self._policies()
                self._handle_nested_tosca_templates_with_topology()
                self.graph = ToscaGraph(self.nodetemplates)

        if sub_mapped_node_template is None:
            ExceptionCollector.stop()
        self.verify_template()
Exemplo n.º 3
0
    def __init__(self,
                 path=None,
                 parsed_params=None,
                 a_file=True,
                 yaml_dict_tpl=None,
                 import_resolver=None,
                 verify=True):

        ExceptionCollector.start()
        self.a_file = a_file
        self.input_path = None
        self.path = None
        self.tpl = None
        self.import_resolver = import_resolver
        self.nested_tosca_tpls = {}
        self.nested_topologies = {}
        if path:
            self.input_path = path
            # don't validate or load if yaml_dict_tpl was set
            if yaml_dict_tpl:
                self.path = path
            else:
                self.path = self._get_path(path)
                self.tpl = YAML_LOADER(self.path, self.a_file)

        if yaml_dict_tpl:
            self.tpl = yaml_dict_tpl

        if not path and not yaml_dict_tpl:
            ExceptionCollector.appendException(
                ValueError(
                    _('No path or yaml_dict_tpl was provided. '
                      'There is nothing to parse.')))

        if self.tpl:
            self.parsed_params = parsed_params
            self._validate_field()
            self.version = self._tpl_version()
            # XXX causes imports to be loaded twice
            self.description = self._tpl_description()
            self.topology_template = self._topology_template()
            self.repositories = self._tpl_repositories()
            if self.topology_template.tpl:
                self.inputs = self._inputs()
                self.relationship_templates = self._relationship_templates()
                self.outputs = self._outputs()
                self.policies = self._policies()
                self._handle_nested_tosca_templates_with_topology()

        ExceptionCollector.stop()
        if verify:
            self.verify_template()
Exemplo n.º 4
0
    def __init__(self, path=None, parsed_params=None, a_file=True,
                 yaml_dict_tpl=None):

        ExceptionCollector.start()
        self.a_file = a_file
        self.input_path = None
        self.path = None
        self.tpl = None
        self.nested_tosca_tpls_with_topology = {}
        self.nested_tosca_templates_with_topology = []
        if path:
            self.input_path = path
            self.path = self._get_path(path)
            if self.path:
                self.tpl = YAML_LOADER(self.path, self.a_file)
            if yaml_dict_tpl:
                msg = (_('Both path and yaml_dict_tpl arguments were '
                         'provided. Using path and ignoring yaml_dict_tpl.'))
                log.info(msg)
                print(msg)
        else:
            if yaml_dict_tpl:
                self.tpl = yaml_dict_tpl
            else:
                ExceptionCollector.appendException(
                    ValueError(_('No path or yaml_dict_tpl was provided. '
                                 'There is nothing to parse.')))

        if self.tpl:
            self.parsed_params = parsed_params
            self._validate_field()
            self.version = self._tpl_version()
            self.relationship_types = self._tpl_relationship_types()
            self.description = self._tpl_description()
            self.topology_template = self._topology_template()
            self.repositories = self._tpl_repositories()
            if self.topology_template.tpl:
                self.inputs = self._inputs()
                self.relationship_templates = self._relationship_templates()
                self.nodetemplates = self._nodetemplates()
                self.outputs = self._outputs()
                self._handle_nested_tosca_templates_with_topology()
                self.graph = ToscaGraph(self.nodetemplates)

        ExceptionCollector.stop()
        self.verify_template()
Exemplo n.º 5
0
    def __init__(self,
                 path=None,
                 parsed_params=None,
                 a_file=True,
                 yaml_dict_tpl=None):
        ExceptionCollector.start()
        self.a_file = a_file
        self.input_path = None
        self.path = None
        self.tpl = None
        if path:
            self.input_path = path
            self.path = self._get_path(path)
            if self.path:
                self.tpl = YAML_LOADER(self.path, self.a_file)
            if yaml_dict_tpl:
                msg = (_('Both path and yaml_dict_tpl arguments were '
                         'provided. Using path and ignoring yaml_dict_tpl.'))
                log.info(msg)
                print(msg)
        else:
            if yaml_dict_tpl:
                self.tpl = yaml_dict_tpl
            else:
                ExceptionCollector.appendException(
                    ValueError(
                        _('No path or yaml_dict_tpl was provided. '
                          'There is nothing to parse.')))

        if self.tpl:
            self.parsed_params = parsed_params
            self._validate_field()
            self.version = self._tpl_version()
            self.relationship_types = self._tpl_relationship_types()
            self.description = self._tpl_description()
            self.topology_template = self._topology_template()
            self.repositories = self._tpl_repositories()
            if self.topology_template.tpl:
                self.inputs = self._inputs()
                self.relationship_templates = self._relationship_templates()
                self.nodetemplates = self._nodetemplates()
                self.outputs = self._outputs()
                self.graph = ToscaGraph(self.nodetemplates)

        ExceptionCollector.stop()
        self.verify_template()
Exemplo n.º 6
0
def translate_node_from_tosca(restructured_mapping, tpl_name, self):
    """
    Translator from TOSCA definitions in provider definitions using rules from element_map_to_provider
    :param restructured_mapping: list of dicts(parameter, map, value)
    :param tpl_name: str
    :return: entity_tpl as dict
    """
    resulted_structure = {}

    for item in restructured_mapping:
        ExceptionCollector.start()
        self[PARAMETER] = item[PARAMETER]
        self[VALUE] = item[VALUE]
        mapped_param = restructure_value(mapping_value=item[MAP_KEY],
                                         self=self)
        ExceptionCollector.stop()
        if ExceptionCollector.exceptionsCaught():
            raise ValidationError(
                message='\nTranslating to provider failed: '.join(
                    ExceptionCollector.getExceptionsReport()))
        structures, keyname = get_structure_of_mapped_param(
            mapped_param, item[VALUE])

        for structure in structures:
            r = retrieve_node_templates(structure)
            for node_type, tpl in r.items():
                if not keyname:
                    (_, _, type_name) = tosca_type.parse(node_type)
                    if not type_name:
                        ExceptionCollector.appendException()
                    keyname = self[KEYNAME] + "_" + snake_case.convert(
                        type_name)
                node_tpl_with_name = {keyname: {node_type: tpl}}
                resulted_structure = deep_update_dict(resulted_structure,
                                                      node_tpl_with_name)

    for keyname, node in resulted_structure.items():
        for node_type, tpl in node.items():
            if tpl.get(REQUIREMENTS):
                reqs = []
                for req_name, req in tpl[REQUIREMENTS].items():
                    reqs.append({req_name: req})
                resulted_structure[keyname][node_type][REQUIREMENTS] = reqs
    return resulted_structure
Exemplo n.º 7
0
 def __init__(self, path, parsed_params=None, a_file=True):
     ExceptionCollector.start()
     self.a_file = a_file
     self.input_path = path
     self.path = self._get_path(path)
     if self.path:
         self.tpl = YAML_LOADER(self.path, self.a_file)
         self.parsed_params = parsed_params
         self._validate_field()
         self.version = self._tpl_version()
         self.relationship_types = self._tpl_relationship_types()
         self.description = self._tpl_description()
         self.topology_template = self._topology_template()
         if self.topology_template.tpl:
             self.inputs = self._inputs()
             self.relationship_templates = self._relationship_templates()
             self.nodetemplates = self._nodetemplates()
             self.outputs = self._outputs()
             self.graph = ToscaGraph(self.nodetemplates)
     ExceptionCollector.stop()
     self.verify_template()
Exemplo n.º 8
0
 def __init__(self, path, parsed_params=None, a_file=True):
     ExceptionCollector.start()
     self.a_file = a_file
     self.input_path = path
     self.path = self._get_path(path)
     if self.path:
         self.tpl = YAML_LOADER(self.path, self.a_file)
         self.parsed_params = parsed_params
         self._validate_field()
         self.version = self._tpl_version()
         self.relationship_types = self._tpl_relationship_types()
         self.description = self._tpl_description()
         self.topology_template = self._topology_template()
         if self.topology_template.tpl:
             self.inputs = self._inputs()
             self.relationship_templates = self._relationship_templates()
             self.nodetemplates = self._nodetemplates()
             self.outputs = self._outputs()
             self.graph = ToscaGraph(self.nodetemplates)
     ExceptionCollector.stop()
     self.verify_template()
Exemplo n.º 9
0
 def setUp(self):
     TestCase.setUp(self)
     ExceptionCollector.stop(
     )  # Added as sometimes negative testcases fails.
Exemplo n.º 10
0
 def setUp(self):
     super(CSARPrereqTest, self).setUp()
     ExceptionCollector.clear()
     ExceptionCollector.stop()