1 From a0f1e680d81c7db66ae7a2a08c3d069901d0765a Mon Sep 17 00:00:00 2001
2 From: Jimmy.Ye <yexuerong@cmss.chinamobile.com>
3 Date: Thu, 30 Mar 2017 18:45:32 +0800
4 Subject: [PATCH] fix create vnffg instance not support param input
6 (1) update and add unit test yaml files
7 (2) update and add unit test fuctions
9 We are cherry picking this to ocata because we need it for OPNFV. There was a
10 conflict in exceptions.py and db/utils.py. I left the new version because I
11 think it should work. I will test it and check
13 Change-Id: I9c43eed0c16ac5a43130724f2eeebefce82c1277
17 diff --git a/tacker/common/exceptions.py b/tacker/common/exceptions.py
18 index 76afae6..321940b 100644
19 --- a/tacker/common/exceptions.py
20 +++ b/tacker/common/exceptions.py
22 message = _("%(resource)s with name %(name)s already exists")
25 -class InvalidParam(TackerException):
26 - message = _("Param values must be a dict type")
27 +class DuplicateEntity(TackerException):
28 + message = _("%(_type)s already exist with given %(entry)s")
29 diff --git a/tacker/db/nfvo/vnffg_db.py b/tacker/db/nfvo/vnffg_db.py
30 index 290d6d5..fd16f0f 100644
31 --- a/tacker/db/nfvo/vnffg_db.py
32 +++ b/tacker/db/nfvo/vnffg_db.py
36 from oslo_log import log as logging
37 +from six import iteritems
38 from sqlalchemy import orm
39 from sqlalchemy.orm import exc as orm_exc
40 from tacker._i18n import _
42 self._make_chain_dict,
43 filters=filters, fields=fields)
45 + def _update_template_params(self, original, paramvalues, param_matched):
46 + if 'get_input' not in str(original):
48 + if isinstance(original, dict):
49 + for key_, value in iteritems(original):
50 + if isinstance(value, dict) and 'get_input' in value:
51 + if value['get_input'] in paramvalues:
52 + original[key_] = paramvalues[value['get_input']]
53 + param_matched.setdefault(value['get_input'], 0)
54 + param_matched[value['get_input']] += 1
56 + raise nfvo.VnffgTemplateParamParsingException(
57 + get_input=value['get_input'])
59 + self._update_template_params(value,
60 + paramvalues, param_matched)
61 + elif isinstance(original, list):
62 + for element in original:
63 + self._update_template_params(element,
64 + paramvalues, param_matched)
66 + def _process_parameterized_template(self, dev_attrs, vnffgd_template):
67 + param_vattrs_dict = dev_attrs.pop('param_values', None)
69 + if isinstance(param_vattrs_dict, dict):
70 + self._update_template_params(vnffgd_template,
71 + param_vattrs_dict, param_matched)
73 + raise nfvo.VnffgParamValueFormatError(
74 + param_value=param_vattrs_dict)
75 + for param_key in param_vattrs_dict.keys():
76 + if param_matched.get(param_key) is None:
77 + raise nfvo.VnffgParamValueNotUsed(param_key=param_key)
79 # called internally, not by REST API
80 def _create_vnffg_pre(self, context, vnffg):
81 vnffg = vnffg['vnffg']
83 template_db = self._get_resource(context, VnffgTemplate,
85 LOG.debug(_('vnffg template %s'), template_db)
87 + if vnffg.get('attributes') and \
88 + vnffg['attributes'].get('param_values'):
89 + vnffg_param = vnffg['attributes']
90 + vnffgd_topology_template = \
91 + template_db.template['vnffgd']['topology_template']
92 + self._process_parameterized_template(vnffg_param,
93 + vnffgd_topology_template)
94 + template_db.template['vnffgd']['topology_template'] = \
95 + vnffgd_topology_template
97 vnf_members = self._get_vnffg_property(template_db,
99 LOG.debug(_('Constituent VNFs: %s'), vnf_members)
100 diff --git a/tacker/extensions/nfvo.py b/tacker/extensions/nfvo.py
101 index 449db95..cf15dff 100644
102 --- a/tacker/extensions/nfvo.py
103 +++ b/tacker/extensions/nfvo.py
105 "creating/updating VNFFG.")
108 -class VnffgVimMappingException(exceptions.TackerException):
109 - message = _("VNF Instance VNF %(vnf_id)s does not match VIM ID %(vim_id).")
110 +class VnffgParamValueFormatError(exceptions.TackerException):
111 + message = _("Param values %(param_value)s is not in dict format.")
114 +class VnffgTemplateParamParsingException(exceptions.TackerException):
115 + message = _("Failed to parse VNFFG Template due to "
116 + "missing input param %(get_input)s.")
119 +class VnffgParamValueNotUsed(exceptions.TackerException):
120 + message = _("Param input %(param_key)s not used.")
123 class VnffgPropertyNotFoundException(exceptions.NotFound):
124 diff --git a/tacker/nfvo/nfvo_plugin.py b/tacker/nfvo/nfvo_plugin.py
125 index 690ce90..6892842 100644
126 --- a/tacker/nfvo/nfvo_plugin.py
127 +++ b/tacker/nfvo/nfvo_plugin.py
131 def create_vnffg(self, context, vnffg):
132 - vnffg_attributes = vnffg['vnffg']['attributes']
133 - if vnffg_attributes.get('param_values'):
134 - param = vnffg_attributes['param_values']
135 - if isinstance(param, dict):
136 - vnffg_attributes['param_values'] = yaml.safe_dump(param)
138 - raise exceptions.InvalidParam()
139 vnffg_dict = super(NfvoPlugin, self)._create_vnffg_pre(context, vnffg)
140 nfp = super(NfvoPlugin, self).get_nfp(context,
141 vnffg_dict['forwarding_paths'])