From: Adurti Date: Tue, 7 May 2024 10:37:30 +0000 (+0000) Subject: Bug 2371 Fixed: Able to update sfc nsd descriptor even with invalid references X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=b6b33fb51bb08df3078977827ab3c8408c7acfd7;p=osm%2FNBI.git Bug 2371 Fixed: Able to update sfc nsd descriptor even with invalid references Change-Id: I2288ca9c2b5d4063bc5f6a47b909f617263659e1 Signed-off-by: Adurti Signed-off-by: garciadeblas --- diff --git a/osm_nbi/descriptor_topics.py b/osm_nbi/descriptor_topics.py index 3ba53c2..be37346 100644 --- a/osm_nbi/descriptor_topics.py +++ b/osm_nbi/descriptor_topics.py @@ -1652,6 +1652,53 @@ class NsdTopic(DescriptorTopic): ), http_code=HTTPStatus.UNPROCESSABLE_ENTITY, ) + vnf_ip_list = set() + for ma in get_iterable(position.get("match-attributes")): + ma_source_ip = ma.get("source-ip-address") + ma_dest_ip = ma.get("destination-ip-address") + ma_vp_id = "" + if ma_source_ip and ma_dest_ip: + if ma_source_ip == ma_dest_ip: + raise EngineException( + "Error at vnffgd match-attributes:source-ip-address and destination-ip-address should not match", + http_code=HTTPStatus.UNPROCESSABLE_ENTITY, + ) + if ma_source_ip: + for df in get_iterable(indata.get("df")): + for vp in get_iterable(df.get("vnf-profile")): + for vlc in get_iterable( + vp.get("virtual-link-connectivity") + ): + for cpd in get_iterable( + vlc.get("constituent-cpd-id") + ): + vnf_ip_list.add(cpd.get("ip-address")) + if ma_source_ip == cpd.get("ip-address"): + ma_vp_id = vp.get("id") + if ma_source_ip not in vnf_ip_list: + raise EngineException( + "Error at vnffgd match-attributes:source-ip-address='{}' " + "does not match any ip-address".format(ma_source_ip), + http_code=HTTPStatus.UNPROCESSABLE_ENTITY, + ) + if ma_dest_ip not in vnf_ip_list: + raise EngineException( + "Error at vnffgd match-attributes:destination-ip-address='{}' " + "does not match any ip-address".format(ma_dest_ip), + http_code=HTTPStatus.UNPROCESSABLE_ENTITY, + ) + constituent_base_element_id = ma.get("constituent-base-element-id") + if ( + constituent_base_element_id + and constituent_base_element_id not in ma_vp_id + ): + raise EngineException( + "Error at vnffgd match-attributes:vnfd-id='{}' " + "does not match source constituent-base-element-id".format( + constituent_base_element_id + ), + http_code=HTTPStatus.UNPROCESSABLE_ENTITY, + ) @staticmethod def validate_vnf_profiles_vnfd_id(indata): diff --git a/osm_nbi/tests/test_pkg_descriptors.py b/osm_nbi/tests/test_pkg_descriptors.py index 4dea8e4..09f0256 100644 --- a/osm_nbi/tests/test_pkg_descriptors.py +++ b/osm_nbi/tests/test_pkg_descriptors.py @@ -371,6 +371,7 @@ db_sfc_nsds_text = """ destination-ip-address: 20.20.3.5 source-port: 0 destination-port: 80 + constituent-base-element-id: '1' nfp-position-element-id: - test nfp-position-element: @@ -384,7 +385,16 @@ db_sfc_nsds_text = """ - constituent-cpd-id: - constituent-base-element-id: '1' constituent-cpd-id: eth0-ext + ip-address: 20.20.1.2 virtual-link-profile-id: osm-ext vnfd-id: cirros_vnffg-vnf + - id: '2' + virtual-link-connectivity: + - constituent-cpd-id: + - constituent-base-element-id: '2' + constituent-cpd-id: eth0-ext + ip-address: 20.20.3.5 + virtual-link-profile-id: osm-ext + vnfd-id: cirros_vnffg-vnf2 description: Simple NS example with vnffgd """