From: David Garcia Date: Thu, 11 Nov 2021 15:35:26 +0000 (+0100) Subject: Fix bug 1761: support entities in relations for backwards compatibility X-Git-Tag: v12.0.0rc1~36 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=444bf96bc9b940a9c9f887d717e0d3c9b4bd8a6d;p=osm%2FLCM.git Fix bug 1761: support entities in relations for backwards compatibility Change-Id: Ic257ca354c881b059c38283263049f8de52a79a1 Signed-off-by: David Garcia --- diff --git a/osm_lcm/ns.py b/osm_lcm/ns.py index d6184fd..2184ce6 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 @@ -2735,15 +2735,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) @@ -2759,7 +2781,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"] @@ -2767,11 +2789,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)