From 982da4e03c39e679919c1cb36fc00e9b8bd5d450 Mon Sep 17 00:00:00 2001 From: tierno Date: Tue, 3 Sep 2019 11:51:55 +0000 Subject: [PATCH] bug 838 fix vnfd obtained from nsr reference Change-Id: I1b2934ea196d3db19717e68874de6fc59d2c9288 Signed-off-by: tierno --- osm_nbi/__init__.py | 2 +- osm_nbi/instance_topics.py | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/osm_nbi/__init__.py b/osm_nbi/__init__.py index 3c38124..8e72edf 100644 --- a/osm_nbi/__init__.py +++ b/osm_nbi/__init__.py @@ -12,5 +12,5 @@ # under the License. ## -version = '6.0.2.post4' +version = '6.0.2.post5' version_date = '2018-09-13' diff --git a/osm_nbi/instance_topics.py b/osm_nbi/instance_topics.py index e36a723..d3a3b41 100644 --- a/osm_nbi/instance_topics.py +++ b/osm_nbi/instance_topics.py @@ -426,22 +426,27 @@ class NsLcmOpTopic(BaseTopic): :param indata: descriptor with the parameters of the operation :return: None """ - vnfds = {} + vnf_member_index_to_vnfd = {} # map between vnf_member_index to vnf descriptor. vim_accounts = [] wim_accounts = [] nsd = nsr["nsd"] def check_valid_vnf_member_index(member_vnf_index): - # TODO change to vnfR - for vnf in nsd["constituent-vnfd"]: - if member_vnf_index == vnf["member-vnf-index"]: - vnfd_id = vnf["vnfd-id-ref"] - if vnfd_id not in vnfds: - vnfds[vnfd_id] = self.db.get_one("vnfds", {"id": vnfd_id}) - return vnfds[vnfd_id] - else: + # Obtain vnf descriptor. The vnfr is used to get the vnfd._id used for this member_vnf_index + if vnf_member_index_to_vnfd.get(member_vnf_index): + return vnf_member_index_to_vnfd[member_vnf_index] + vnfr = self.db.get_one("vnfrs", + {"nsr-id-ref": nsr["_id"], "member-vnf-index-ref": member_vnf_index}, + fail_on_empty=False) + if not vnfr: raise EngineException("Invalid parameter member_vnf_index='{}' is not one of the " "nsd:constituent-vnfd".format(member_vnf_index)) + vnfd = self.db.get_one("vnfds", {"_id": vnfr["vnfd-id"]}, fail_on_empty=False) + if not vnfd: + raise EngineException("vnfd id={} has been deleted!. Operation cannot be performed". + format(vnfr["vnfd-id"])) + vnf_member_index_to_vnfd[member_vnf_index] = vnfd # add to cache, avoiding a later look for + return vnfd def check_valid_vdu(vnfd, vdu_id): for vdud in get_iterable(vnfd.get("vdu")): -- 2.25.1