Bug 2371 Fixed: Able to update sfc nsd descriptor even with invalid references 45/14345/3
authorAdurti <adurti.v@tataelxsi.co.in>
Tue, 7 May 2024 10:37:30 +0000 (10:37 +0000)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Fri, 11 Apr 2025 17:15:46 +0000 (19:15 +0200)
Change-Id: I2288ca9c2b5d4063bc5f6a47b909f617263659e1
Signed-off-by: Adurti <adurti.v@tataelxsi.co.in>
osm_nbi/descriptor_topics.py
osm_nbi/tests/test_pkg_descriptors.py

index 3ba53c2..be37346 100644 (file)
@@ -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):
index 4dea8e4..09f0256 100644 (file)
@@ -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
 """