Add new json events to PRH CSIT 92/78392/21
authorMarcin Migdal <marcin.migdal@nokia.com>
Wed, 13 Feb 2019 14:43:12 +0000 (15:43 +0100)
committerMarcin Migdal <marcin.migdal@nokia.com>
Fri, 15 Feb 2019 16:24:10 +0000 (17:24 +0100)
Change-Id: Ide0ee411eb05fa3243a77cf399c6889e73f2d4b3
Issue-ID: INT-871
Signed-off-by: Marcin Migdal <marcin.migdal@nokia.com>
17 files changed:
tests/dcaegen2/prh-testcases/assets/json_events/event_with_IPV4.json
tests/dcaegen2/prh-testcases/assets/json_events/event_with_IPV6.json
tests/dcaegen2/prh-testcases/assets/json_events/event_with_all_fields.json
tests/dcaegen2/prh-testcases/assets/json_events/event_with_missing_IPV4_and_IPV6.json
tests/dcaegen2/prh-testcases/assets/json_events/event_with_missing_sourceName.json
tests/dcaegen2/prh-testcases/assets/json_events/event_with_missing_sourceName_IPV4_and_IPV6.json
tests/dcaegen2/prh-testcases/assets/json_events/event_with_missing_sourceName_and_IPV4.json
tests/dcaegen2/prh-testcases/assets/json_events/event_with_missing_sourceName_and_IPV6.json
tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_all_filled.json [new file with mode: 0644]
tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_empty.json [moved from tests/dcaegen2/prh-testcases/assets/json_events/event_with_empty_addtional_fields.json with 53% similarity]
tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_missing_all.json [moved from tests/dcaegen2/prh-testcases/assets/json_events/event_with_missing_additional_fields.json with 100% similarity]
tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_missing_partial.json [new file with mode: 0644]
tests/dcaegen2/prh-testcases/assets/json_events/event_without_IPV6_field.json
tests/dcaegen2/prh-testcases/assets/json_events/not_json_format.json
tests/dcaegen2/prh-testcases/prh_tests.robot
tests/dcaegen2/prh-testcases/resources/PrhLibrary.py
tests/dcaegen2/prh-testcases/resources/prh_library.robot

index cdcab67..ac7c309 100644 (file)
@@ -6,12 +6,10 @@
     "pnfRegistrationFields": {
       "oamV4IpAddress":"10.17.123.234",
       "oamV6IpAddress":"",
-      "serial-number":"NOkkaaa123",
-      "equip-vendor":"equipVendor",
-      "equip-model":"equipModel",
-      "equip-type":"equipType",
-      "nf-role":"nf-role",
-      "sw-version":"swVersion"
+      "serialNumber":"NOkkaaa123",
+      "vendorName":"equipVendor",
+      "modelNumber":"equipModel",
+      "unitType":"equipType"
     }
   }
 }
index f5ec23d..5a67dfe 100644 (file)
@@ -6,12 +6,10 @@
     "pnfRegistrationFields": {
       "oamV4IpAddress":"",
       "oamV6IpAddress":"2001:0db8:85a3:0000:0000:8b2e:0370:7334",
-      "serial-number":"NOkkaaa123",
-      "equip-vendor":"equipVendor",
-      "equip-model":"equipModel",
-      "equip-type":"equipType",
-      "nf-role":"nf-role",
-      "sw-version":"swVersion"
+      "serialNumber":"NOkkaaa123",
+      "vendorName":"equipVendor",
+      "modelNumber":"equipModel",
+      "unitType":"equipType"
     }
   }
 }
index bc9cb1d..f55b2f9 100644 (file)
@@ -1,17 +1,16 @@
 {
   "event": {
     "commonEventHeader": {
-      "sourceName":"NOK6061ZW1"
+      "sourceName":"NOK6061ZW1",
+      "nfNamingCode": "nfNamingCode"
     },
     "pnfRegistrationFields": {
       "oamV4IpAddress":"10.16.123.234",
       "oamV6IpAddress":"2001:0db8:85a3:0000:0000:8a2e:0370:7334",
-      "serial-number":"NOkkaaa123",
-      "equip-vendor":"equipVendor",
-      "equip-model":"equipModel",
-      "equip-type":"equipType",
-      "nf-role":"nf-role",
-      "sw-version":"swVersion"
+      "serialNumber":"serialNumber",
+      "vendorName":"vendorName",
+      "modelNumber":"modelNumber",
+      "unitType":"unitType"
     }
   }
 }
index 4942a3d..6a14bfd 100644 (file)
@@ -6,12 +6,10 @@
     "pnfRegistrationFields": {
       "oamV4IpAddress":"",
       "oamV6IpAddress":"",
-      "serial-number":"NOkkaaa123",
-      "equip-vendor":"equipVendor",
-      "equip-model":"equipModel",
-      "equip-type":"equipType",
-      "nf-role":"nf-role",
-      "sw-version":"swVersion"
+      "serialNumber":"",
+      "vendorName":"",
+      "modelNumber":"",
+      "unitType":""
     }
   }
 }
index 5e2a612..74425ec 100644 (file)
@@ -6,12 +6,10 @@
     "pnfRegistrationFields": {
       "oamV4IpAddress":"10.18.123.234",
       "oamV6IpAddress":"2001:0db8:85a3:0000:0000:8a2a:0370:7334",
-      "serial-number":"NOkkaaa123",
-      "equip-vendor":"equipVendor",
-      "equip-model":"equipModel",
-      "equip-type":"equipType",
-      "nf-role":"nf-role",
-      "sw-version":"swVersion"
+      "serialNumber":"",
+      "vendorName":"",
+      "modelNumber":"",
+      "unitType":""
     }
   }
 }
index a6a6f36..de1f576 100644 (file)
@@ -5,13 +5,7 @@
     },
     "pnfRegistrationFields": {
       "oamV4IpAddress":"",
-      "oamV6IpAddress":"",
-      "serial-number":"NOkkaaa123",
-      "equip-vendor":"equipVendor",
-      "equip-model":"equipModel",
-      "equip-type":"equipType",
-      "nf-role":"nf-role",
-      "sw-version":"swVersion"
+      "oamV6IpAddress":""
     }
   }
 }
index 6d9eadf..4838f1b 100644 (file)
@@ -5,13 +5,7 @@
     },
     "pnfRegistrationFields": {
       "oamV4IpAddress":"",
-      "oamV6IpAddress":"2001:0db8:85a3:0000:0000:8b2f:0370:7334",
-      "serial-number":"NOkkaaa123",
-      "equip-vendor":"equipVendor",
-      "equip-model":"equipModel",
-      "equip-type":"equipType",
-      "nf-role":"nf-role",
-      "sw-version":"swVersion"
+      "oamV6IpAddress":"2001:0db8:85a3:0000:0000:8b2f:0370:7334"
     }
   }
 }
index 9fac5b1..253869a 100644 (file)
@@ -5,13 +5,8 @@
     },
     "pnfRegistrationFields": {
       "oamV4IpAddress":"10.17.163.234",
-      "oamV6IpAddress":"",
-      "serial-number":"NOkkaaa123",
-      "equip-vendor":"equipVendor",
-      "equip-model":"equipModel",
-      "equip-type":"equipType",
-      "nf-role":"nf-role",
-      "sw-version":"swVersion"
+      "oamV6IpAddress":""
+
     }
   }
 }
diff --git a/tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_all_filled.json b/tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_all_filled.json
new file mode 100644 (file)
index 0000000..492d607
--- /dev/null
@@ -0,0 +1,17 @@
+{
+  "event": {
+    "commonEventHeader": {
+      "sourceName":"NOK6061ZW4",
+      "nfNamingCode": "nfNamingCode",
+      "nfcNamingCode": "nfcNamingCode"
+    },
+    "pnfRegistrationFields": {
+      "oamV4IpAddress":"ipv4",
+      "oamV6IpAddress":"",
+      "serialNumber":"sn1234",
+      "vendorName":"vendorName",
+      "modelNumber":"modelNumber",
+      "unitType":"unitType"
+    }
+  }
+}
@@ -1,17 +1,16 @@
 {
   "event": {
     "commonEventHeader": {
-      "sourceName":"NOK6061ZW1"
+      "sourceName":"NOK6061ZW1",
+      "nfNamingCode": ""
     },
     "pnfRegistrationFields": {
       "oamV4IpAddress":"10.16.123.234",
       "oamV6IpAddress":"2001:0db8:85a3:0000:0000:8a2e:0370:7334",
-      "serial-number":"",
-      "equip-vendor":"",
-      "equip-model":"",
-      "equip-type":"",
-      "nf-role":"",
-      "sw-version":""
+      "serialNumber":"",
+      "vendorName":"",
+      "modelNumber":"",
+      "unitType":""
     }
   }
 }
diff --git a/tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_missing_partial.json b/tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_missing_partial.json
new file mode 100644 (file)
index 0000000..ede956f
--- /dev/null
@@ -0,0 +1,14 @@
+{
+  "event": {
+    "commonEventHeader": {
+      "sourceName":"NOK6061ZW4"
+    },
+    "pnfRegistrationFields": {
+      "oamV4IpAddress":"",
+      "oamV6IpAddress":"",
+      "serialNumber":"123",
+      "modelNumber":"sn123243",
+      "unitType": "unitType"
+    }
+  }
+}
index a416bb7..02f0137 100644 (file)
@@ -5,12 +5,10 @@
     },
     "pnfRegistrationFields": {
       "oamV4IpAddress":"10.17.123.24",
-      "serial-number":"NOkkaaa123",
-      "equip-vendor":"equipVendor",
-      "equip-model":"equipModel",
-      "equip-type":"equipType",
-      "nf-role":"nf-role",
-      "sw-version":"swVersion"
+      "serialNumber":"NOkkaaa123",
+      "vendorName":"equipVendor",
+      "modelNumber":"equipModel",
+      "unitType":"equipType"
     }
   }
 }
index 08d9a49..f6afb1d 100644 (file)
@@ -6,12 +6,10 @@
     "pnfRegistrationFields": {
       "oamV4IpAddress":"10.16.123.234",
       "oamV6IpAddress":"2001:0db8:85a3:0000:0000:8a2e:0370:7334",
-      "serial-number":"NOkkaaa123",
-      "equip-vendor":"equipVendor",
-      "equip-model":"equipModel",
-      "equip-type":"equipType",
-      "nf-role":"nf-role",
-      "sw-version":"swVersion",
+      "serialNumber":"NOkkaaa123",
+      "vendorName":"equipVendor",
+      "modelNumber":"equipModel",
+      "unitType":"equipType",
     }
   }
 }
index 4ecc9c8..77278d4 100644 (file)
@@ -19,6 +19,10 @@ ${EVENT_WITH_MISSING_SOURCENAME}    %{WORKSPACE}/tests/dcaegen2/prh-testcases/as
 ${EVENT_WITH_MISSING_SOURCENAME_AND_IPV4}    %{WORKSPACE}/tests/dcaegen2/prh-testcases/assets/json_events/event_with_missing_sourceName_and_IPV4.json
 ${EVENT_WITH_MISSING_SOURCENAME_AND_IPV6}    %{WORKSPACE}/tests/dcaegen2/prh-testcases/assets/json_events/event_with_missing_sourceName_and_IPV6.json
 ${EVENT_WITH_MISSING_SOURCENAME_IPV4_AND_IPV6}    %{WORKSPACE}/tests/dcaegen2/prh-testcases/assets/json_events/event_with_missing_sourceName_IPV4_and_IPV6.json
+${EVENT_WITH_OPTIONAL_REGISTRATION_FIELDS_ALL_FILLED}    %{WORKSPACE}/tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_all_filled.json
+${EVENT_WITH_OPTIONAL_REGISTRATION_FIELDS_EMPTY}    %{WORKSPACE}/tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_empty.json
+${EVENT_WITH_OPTIONAL_REGISTRATION_FIELDS_MISSING_ALL}    %{WORKSPACE}/tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_missing_all.json
+${EVENT_WITH_OPTIONAL_REGISTRATION_FIELDS_MISSING_PARTIAL}    %{WORKSPACE}/tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_missing_partial.json
 ${EVENT_WITHOUT_IPV6_FILED}    %{WORKSPACE}/tests/dcaegen2/prh-testcases/assets/json_events/event_without_IPV6_field.json
 ${Not_json_format}    %{WORKSPACE}/tests/dcaegen2/prh-testcases/assets/json_events/not_json_format.json
 
index d413be5..1a3875b 100644 (file)
@@ -13,28 +13,74 @@ class PrhLibrary(object):
     def check_for_log(search_for):
         client = docker.from_env()
         container = client.containers.get('prh')
+        #print ("Check for log searches for pattern: ", search_for )
         for line in container.logs(stream=True):
+            #print ("Check for log analysis line: ", line )
             if search_for in line.strip():
                 return True
         else:
             return False
 
     @staticmethod
-    def create_pnf_ready_notification(json_file):
+    def create_pnf_ready_notification_from_ves(json_file):
         json_to_python = json.loads(json_file)
-        ipv4 = json_to_python.get("event").get("pnfRegistrationFields").get("oamV4IpAddress")
-        ipv6 = json_to_python.get("event").get("pnfRegistrationFields").get("oamV6IpAddress") if "oamV6IpAddress" in json_to_python["event"]["pnfRegistrationFields"] else ""
-        serial_number = json_to_python.get("event").get("pnfRegistrationFields").get("serial-number") if "serial-number" in json_to_python["event"]["pnfRegistrationFields"] else ""
-        equip_vendor = json_to_python.get("event").get("pnfRegistrationFields").get("equip-vendor") if "equip-vendor" in json_to_python["event"]["pnfRegistrationFields"] else ""
-        equip_model = json_to_python.get("event").get("pnfRegistrationFields").get("equip-model") if "equip-model" in json_to_python["event"]["pnfRegistrationFields"] else ""
-        equip_type = json_to_python.get("event").get("pnfRegistrationFields").get("equip-type") if "equip-type" in json_to_python["event"]["pnfRegistrationFields"] else ""
-        nf_role = json_to_python.get("event").get("pnfRegistrationFields").get("nf-role") if "nf-role" in json_to_python["event"]["pnfRegistrationFields"] else ""
-        sw_version = json_to_python.get("event").get("pnfRegistrationFields").get("sw-version") if "sw-version" in json_to_python["event"]["pnfRegistrationFields"] else ""
-        correlation_id = json_to_python.get("event").get("commonEventHeader").get("sourceName")
-        str_json = '{"correlationId":"' + correlation_id + '","ipaddress-v4-oam":"' + ipv4 + '","ipaddress-v6-oam":"' + ipv6 + '","serial-number":"' + serial_number + '","equip-vendor":"' + equip_vendor + '","equip-model":"' + equip_model + '","equip-type":"' + equip_type + '","nf-role":"' + nf_role + '","sw-version":"' + sw_version + '"}'
+        ipv4 =  PrhLibrary.extract_ip_v4(json_to_python)
+        ipv6 = PrhLibrary.extract_ip_v6(json_to_python)
+        correlation_id = PrhLibrary.extract_correlation_id(json_to_python)
+        serial_number = PrhLibrary.extract_serial_number(json_to_python)
+        vendor_name = PrhLibrary.extract_vendor_name(json_to_python)
+        model_number = PrhLibrary.extract_model_number(json_to_python)
+        unit_type = PrhLibrary.extract_unit_type(json_to_python)
+
+        str_json = '{"correlationId":"' + correlation_id + '","ipaddress-v4-oam":"' + ipv4 + '","ipaddress-v6-oam":"' + ipv6 + '","serialNumber":"' + serial_number + '","vendorName":"' + vendor_name  + '","modelNumber":"' + model_number + '","unitType":"' + unit_type + '"}'
         python_to_json = json.dumps(str_json)
         return python_to_json.replace("\\", "")[1:-1]
 
+    @staticmethod
+    def create_pnf_ready_notification_as_pnf_ready(json_file):
+        json_to_python = json.loads(json_file)
+        ipv4 =  PrhLibrary.extract_ip_v4(json_to_python)
+        ipv6 = PrhLibrary.extract_ip_v6(json_to_python)
+        correlation_id = PrhLibrary.extract_correlation_id(json_to_python)
+        serial_number = PrhLibrary.extract_serial_number(json_to_python)
+        vendor_name = PrhLibrary.extract_vendor_name(json_to_python)
+        model_number = PrhLibrary.extract_model_number(json_to_python)
+        unit_type = PrhLibrary.extract_unit_type(json_to_python)
+
+        nf_role  = json_to_python.get("event").get("commonEventHeader").get("nfNamingCode") if "nfNamingCode" in json_to_python["event"]["commonEventHeader"] else ""
+
+        str_json = '{"correlationId":"' + correlation_id + '","ipaddress-v4-oam":"' + ipv4 + '","ipaddress-v6-oam":"' + ipv6 + '","serial-number":"' + serial_number + '","equip-vendor":"' + vendor_name  + '","equip-model":"' + model_number + '","equip-type":"' + unit_type + '","nf-role":"' + nf_role + '","sw-version":""}'
+        python_to_json = json.dumps(str_json)
+        return python_to_json.replace("\\", "")[1:-1]
+
+    @staticmethod
+    def extract_ip_v4(content):
+        return content.get("event").get("pnfRegistrationFields").get("oamV4IpAddress") if "oamV4IpAddress" in content["event"]["pnfRegistrationFields"] else ""
+
+    @staticmethod
+    def extract_ip_v6(content):
+        return content.get("event").get("pnfRegistrationFields").get("oamV6IpAddress") if "oamV6IpAddress" in content["event"]["pnfRegistrationFields"] else ""
+
+    @staticmethod
+    def extract_correlation_id(content):
+        return content.get("event").get("commonEventHeader").get("sourceName") if "sourceName" in content["event"]["commonEventHeader"] else ""
+
+    @staticmethod
+    def extract_serial_number(content):
+        return content.get("event").get("pnfRegistrationFields").get("serialNumber") if "serialNumber" in content["event"]["pnfRegistrationFields"] else ""
+
+    @staticmethod
+    def extract_vendor_name(content):
+        return content.get("event").get("pnfRegistrationFields").get("vendorName") if "vendorName" in content["event"]["pnfRegistrationFields"] else ""
+
+    @staticmethod
+    def extract_model_number(content):
+        return content.get("event").get("pnfRegistrationFields").get("modelNumber") if "modelNumber" in content["event"]["pnfRegistrationFields"] else ""
+
+    @staticmethod
+    def extract_unit_type(content):
+        return content.get("event").get("pnfRegistrationFields").get("unitType") if "unitType" in content["event"]["pnfRegistrationFields"] else ""
+
     @staticmethod
     def create_pnf_name(json_file):
         json_to_python = json.loads(json_file)
@@ -83,6 +129,7 @@ class PrhLibrary(object):
 
 
     def create_invalid_notification(self, json_file):
-        return self.create_pnf_ready_notification(json_file).replace("\":", "\": ")\
-            .replace("ipaddress-v4-oam", "oamV4IpAddress").replace("ipaddress-v6-oam", "oamV6IpAddress")\
-            .replace("}", "\\n}")
+        invalidate_input = self.create_pnf_ready_notification_from_ves(json_file).replace("\":", "\": ") \
+            .replace("ipaddress-v4-oam", "oamV4IpAddress").replace("ipaddress-v6-oam","oamV6IpAddress").replace("}",'')
+        invalidate_input__and_add_additional_fields = invalidate_input + ',"nfNamingCode": ""' + "," + '"softwareVersion": ""' +"\\n"
+        return invalidate_input__and_add_additional_fields
index 7175387..105365c 100644 (file)
@@ -32,11 +32,12 @@ Valid event processing
     [Arguments]    ${input_valid_event_in_dmaap}
     [Timeout]    30s
     ${data}=    Get Data From File    ${input_valid_event_in_dmaap}
-    ${posted_event_to_dmaap}=    Create PNF_Ready notification    ${data}
+    ${posted_event_to_dmaap}=    create pnf ready notification from ves    ${data}
     ${pnf_name}=    Create PNF name    ${data}
     Set PNF name in AAI    ${pnf_name}
     Set event in DMaaP    ${data}
-    Wait Until Keyword Succeeds    100x    300ms    Check PNF_READY notification    ${posted_event_to_dmaap}
+    ${expected_event_pnf_ready_in_dpaap}=    create pnf ready_notification as pnf ready    ${data}
+    Wait Until Keyword Succeeds    100x    300ms    Check PNF_READY notification    ${expected_event_pnf_ready_in_dpaap}
 
 Check PRH log
     [Arguments]    ${searched_log}