From 1f40aa9a0086a2355fed4db10ca8347b2cb771b3 Mon Sep 17 00:00:00 2001 From: David Garcia Date: Thu, 11 Nov 2021 16:35:26 +0100 Subject: [PATCH] Fix bug 1762: support entities in relations for backwards compatibility Change-Id: Ic257ca354c881b059c38283263049f8de52a79a1 Signed-off-by: David Garcia --- osm_lcm/ns.py | 60 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/osm_lcm/ns.py b/osm_lcm/ns.py index ab25be3..9e9c1f6 100644 --- a/osm_lcm/ns.py +++ b/osm_lcm/ns.py @@ -17,7 +17,7 @@ ## import asyncio -from typing import Any, Dict +from typing import Any, Dict, List import yaml import logging import logging.handlers @@ -2714,15 +2714,37 @@ class NsLcm(LcmBase): nsd: Dict[str, Any], vca: DeployedVCA, cached_vnfds: Dict[str, Any], - ): + ) -> List[Relation]: relations = [] db_ns_relations = get_ns_configuration_relation_list(nsd) for r in db_ns_relations: + provider_dict = None + requirer_dict = None + if all(key in r for key in ("provider", "requirer")): + provider_dict = r["provider"] + requirer_dict = r["requirer"] + elif "entities" in r: + provider_id = r["entities"][0]["id"] + provider_dict = { + "nsr-id": nsr_id, + "endpoint": r["entities"][0]["endpoint"], + } + if provider_id != nsd["id"]: + provider_dict["vnf-profile-id"] = provider_id + requirer_id = r["entities"][1]["id"] + requirer_dict = { + "nsr-id": nsr_id, + "endpoint": r["entities"][1]["endpoint"], + } + if requirer_id != nsd["id"]: + requirer_dict["vnf-profile-id"] = requirer_id + else: + raise Exception("provider/requirer or entities must be included in the relation.") relation_provider = self._update_ee_relation_data_with_implicit_data( - nsr_id, nsd, r["provider"], cached_vnfds + nsr_id, nsd, provider_dict, cached_vnfds ) relation_requirer = self._update_ee_relation_data_with_implicit_data( - nsr_id, nsd, r["requirer"], cached_vnfds + nsr_id, nsd, requirer_dict, cached_vnfds ) provider = EERelation(relation_provider) requirer = EERelation(relation_requirer) @@ -2738,7 +2760,7 @@ class NsLcm(LcmBase): nsd: Dict[str, Any], vca: DeployedVCA, cached_vnfds: Dict[str, Any], - ): + ) -> List[Relation]: relations = [] vnf_profile = get_vnf_profile(nsd, vca.vnf_profile_id) vnf_profile_id = vnf_profile["id"] @@ -2746,11 +2768,35 @@ class NsLcm(LcmBase): db_vnfd = self._get_vnfd(vnfd_id, cached_vnfds) db_vnf_relations = get_relation_list(db_vnfd, vnfd_id) for r in db_vnf_relations: + provider_dict = None + requirer_dict = None + if all(key in r for key in ("provider", "requirer")): + provider_dict = r["provider"] + requirer_dict = r["requirer"] + elif "entities" in r: + provider_id = r["entities"][0]["id"] + provider_dict = { + "nsr-id": nsr_id, + "vnf-profile-id": vnf_profile_id, + "endpoint": r["entities"][0]["endpoint"], + } + if provider_id != vnfd_id: + provider_dict["vdu-profile-id"] = provider_id + requirer_id = r["entities"][1]["id"] + requirer_dict = { + "nsr-id": nsr_id, + "vnf-profile-id": vnf_profile_id, + "endpoint": r["entities"][1]["endpoint"], + } + if requirer_id != vnfd_id: + requirer_dict["vdu-profile-id"] = requirer_id + else: + raise Exception("provider/requirer or entities must be included in the relation.") relation_provider = self._update_ee_relation_data_with_implicit_data( - nsr_id, nsd, r["provider"], cached_vnfds, vnf_profile_id=vnf_profile_id + nsr_id, nsd, provider_dict, cached_vnfds, vnf_profile_id=vnf_profile_id ) relation_requirer = self._update_ee_relation_data_with_implicit_data( - nsr_id, nsd, r["requirer"], cached_vnfds, vnf_profile_id=vnf_profile_id + nsr_id, nsd, requirer_dict, cached_vnfds, vnf_profile_id=vnf_profile_id ) provider = EERelation(relation_provider) requirer = EERelation(relation_requirer) -- 2.25.1