diff options
author | Joanna Jeremicz <joanna.jeremicz@nokia.com> | 2019-03-14 10:58:32 +0100 |
---|---|---|
committer | Joanna Jeremicz <joanna.jeremicz@nokia.com> | 2019-03-18 12:10:20 +0100 |
commit | 0a39148c4af6c663035d04f8c0e99afd22fd67b4 (patch) | |
tree | 60edbd75d5ee33a62822170181e0662e46140e0a | |
parent | abeb9748bbf4c68b20381e84aeeee1e52b9ff623 (diff) |
Fix PRH CSITs with additionalFields
Change-Id: I51796ed76ce9bd1d74777411fcb172cae205ef8a
Issue-ID: INT-961
Signed-off-by: Joanna Jeremicz <joanna.jeremicz@nokia.com>
8 files changed, 68 insertions, 61 deletions
diff --git a/tests/dcaegen2/prh-testcases/assets/json_events/event_with_IPV6.json b/tests/dcaegen2/prh-testcases/assets/json_events/event_with_IPV6.json index 5a67dfe1..7fdef4fc 100644 --- a/tests/dcaegen2/prh-testcases/assets/json_events/event_with_IPV6.json +++ b/tests/dcaegen2/prh-testcases/assets/json_events/event_with_IPV6.json @@ -9,7 +9,8 @@ "serialNumber":"NOkkaaa123", "vendorName":"equipVendor", "modelNumber":"equipModel", - "unitType":"equipType" + "unitType":"equipType", + "additionalFields": {} } } } diff --git a/tests/dcaegen2/prh-testcases/assets/json_events/event_with_all_fields.json b/tests/dcaegen2/prh-testcases/assets/json_events/event_with_all_fields.json index f55b2f9c..eb4dfaf9 100644 --- a/tests/dcaegen2/prh-testcases/assets/json_events/event_with_all_fields.json +++ b/tests/dcaegen2/prh-testcases/assets/json_events/event_with_all_fields.json @@ -10,7 +10,12 @@ "serialNumber":"serialNumber", "vendorName":"vendorName", "modelNumber":"modelNumber", - "unitType":"unitType" + "unitType":"unitType", + "additionalFields": { + "attachmentPoint": "bla-bla-30-3", + "svlan": "1005", + "cvlan": "678" + } } } } diff --git a/tests/dcaegen2/prh-testcases/assets/json_events/event_with_missing_sourceName.json b/tests/dcaegen2/prh-testcases/assets/json_events/event_with_missing_sourceName.json index 74425ec2..2bae7e64 100644 --- a/tests/dcaegen2/prh-testcases/assets/json_events/event_with_missing_sourceName.json +++ b/tests/dcaegen2/prh-testcases/assets/json_events/event_with_missing_sourceName.json @@ -9,7 +9,8 @@ "serialNumber":"", "vendorName":"", "modelNumber":"", - "unitType":"" + "unitType":"", + "additionalFields": {} } } } 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 index 492d6071..39fadb8a 100644 --- 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 @@ -11,7 +11,12 @@ "serialNumber":"sn1234", "vendorName":"vendorName", "modelNumber":"modelNumber", - "unitType":"unitType" + "unitType":"unitType", + "additionalFields": { + "attachmentPoint": "bla-bla-30-3", + "svlan": "1005", + "cvlan": "678" + } } } } diff --git a/tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_empty.json b/tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_empty.json index 48363a47..986b992d 100644 --- a/tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_empty.json +++ b/tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_empty.json @@ -1,7 +1,7 @@ { "event": { "commonEventHeader": { - "sourceName":"NOK6061ZW1", + "sourceName":"NOK6061ZW3", "nfNamingCode": "" }, "pnfRegistrationFields": { @@ -10,7 +10,8 @@ "serialNumber":"", "vendorName":"", "modelNumber":"", - "unitType":"" + "unitType":"", + "additionalFields": {} } } } diff --git a/tests/dcaegen2/prh-testcases/prh_tests.robot b/tests/dcaegen2/prh-testcases/prh_tests.robot index 77278d47..429f365e 100644 --- a/tests/dcaegen2/prh-testcases/prh_tests.robot +++ b/tests/dcaegen2/prh-testcases/prh_tests.robot @@ -35,6 +35,9 @@ Valid DMaaP event can be converted to PNF_READY notification ${EVENT_WITH_IPV4} ${EVENT_WITH_IPV6} ${EVENT_WITHOUT_IPV6_FILED} + ${EVENT_WITH_OPTIONAL_REGISTRATION_FIELDS_ALL_FILLED} + ${EVENT_WITH_OPTIONAL_REGISTRATION_FIELDS_EMPTY} + ${EVENT_WITH_OPTIONAL_REGISTRATION_FIELDS_MISSING_ALL} Invalid DMaaP event cannot be converted to PNF_READY notification [Documentation] PRH get invalid event from DMaaP with missing required fields - PRH does not produce PNF_READY notification diff --git a/tests/dcaegen2/prh-testcases/resources/PrhLibrary.py b/tests/dcaegen2/prh-testcases/resources/PrhLibrary.py index 1a3875b9..ee89be68 100644 --- a/tests/dcaegen2/prh-testcases/resources/PrhLibrary.py +++ b/tests/dcaegen2/prh-testcases/resources/PrhLibrary.py @@ -13,73 +13,72 @@ 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 ) + print ("Check for log searches for pattern: ", search_for ) for line in container.logs(stream=True): - #print ("Check for log analysis line: ", line ) + print ("Check for log analysis line: ", line ) if search_for in line.strip(): return True else: return False @staticmethod - def create_pnf_ready_notification_from_ves(json_file): + def create_invalid_notification(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) - - 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] + correlation_id = PrhLibrary.extract_correlation_id_value(json_to_python, "correlationId") + ipv4 = PrhLibrary.extract_value_from_pnfRegistrationFields(json_to_python, "oamV4IpAddress", "oamV4IpAddress") + ipv6 = PrhLibrary.extract_value_from_pnfRegistrationFields(json_to_python, "oamV6IpAddress", "oamV6IpAddress") + serial_number = PrhLibrary.extract_value_from_pnfRegistrationFields(json_to_python, "serialNumber", "serialNumber") + vendor_name = PrhLibrary.extract_value_from_pnfRegistrationFields(json_to_python, "vendorName", "vendorName") + model_number = PrhLibrary.extract_value_from_pnfRegistrationFields(json_to_python, "modelNumber", "modelNumber") + unit_type = PrhLibrary.extract_value_from_pnfRegistrationFields(json_to_python, "unitType", "unitType") + additional_fields = PrhLibrary.extract_additional_fields(json_to_python, "additionalFields") + + str_json = '{' + correlation_id + ipv4 + ipv6 + serial_number + vendor_name + model_number + unit_type + '"nfNamingCode":""' + "," + '"softwareVersion":"",' + additional_fields + return json.dumps(str_json).replace("\\", "")[1:-1].replace("\":", "\": ").rstrip(',') + '\\n}' @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) + correlation_id = PrhLibrary.extract_correlation_id_value(json_to_python, "correlationId") + serial_number = PrhLibrary.extract_value_from_pnfRegistrationFields(json_to_python, "serial-number", "serialNumber") + vendor_name = PrhLibrary.extract_value_from_pnfRegistrationFields(json_to_python, "equip-vendor", "vendorName") + model_number = PrhLibrary.extract_value_from_pnfRegistrationFields(json_to_python, "equip-model", "modelNumber") + unit_type = PrhLibrary.extract_value_from_pnfRegistrationFields(json_to_python, "equip-type", "unitType") + additional_fields = PrhLibrary.extract_additional_fields_value(json_to_python, "additionalFields") 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 "" + str_json = '{' + correlation_id + serial_number + vendor_name + model_number + unit_type + '"nf-role":"' + nf_role + '","sw-version":"",' + additional_fields - @staticmethod - def extract_correlation_id(content): - return content.get("event").get("commonEventHeader").get("sourceName") if "sourceName" in content["event"]["commonEventHeader"] else "" + return json.dumps(str_json.rstrip(',') + '}').replace("\\", "")[1:-1] @staticmethod - def extract_serial_number(content): - return content.get("event").get("pnfRegistrationFields").get("serialNumber") if "serialNumber" in content["event"]["pnfRegistrationFields"] else "" + def extract_additional_fields(content, name): + fields = content.get("event").get("pnfRegistrationFields").get(name) if name in content["event"]["pnfRegistrationFields"] else [] + if fields == []: + return '"additionalFields":' + 'null' + res = '"' + name + '":{' + for f in fields: + res += '"' + f + '"' + ':' + '"' + fields.get(f) + '",' + return res.rstrip(',') + '},' @staticmethod - def extract_vendor_name(content): - return content.get("event").get("pnfRegistrationFields").get("vendorName") if "vendorName" in content["event"]["pnfRegistrationFields"] else "" + def extract_additional_fields_value(content, name): + fields = content.get("event").get("pnfRegistrationFields").get(name) if name in content["event"]["pnfRegistrationFields"] else [] + if fields == [] or len(fields) == 0: + return "" + res = '"' + name + '":{' + for f in fields: + res += '"' + f + '"' + ':' + '"' + fields.get(f) + '",' + return res.rstrip(',') + '},' @staticmethod - def extract_model_number(content): - return content.get("event").get("pnfRegistrationFields").get("modelNumber") if "modelNumber" in content["event"]["pnfRegistrationFields"] else "" + def extract_value_from_pnfRegistrationFields(content, name, key): + return '"' + name + '":"' + (content.get("event").get("pnfRegistrationFields").get(key) + '",' if key 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 "" + def extract_correlation_id_value(content, name): + return '"' + name + '":"' + (content.get("event").get("commonEventHeader").get("sourceName") + '",' if "sourceName" in content["event"]["commonEventHeader"] else '",') @staticmethod def create_pnf_name(json_file): @@ -126,10 +125,3 @@ class PrhLibrary(object): @staticmethod def is_in_status(client, name, status): return len(client.containers.list(all=True, filters={"name": "^/"+name+"$", "status": status})) == 1 - - - def create_invalid_notification(self, json_file): - 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 diff --git a/tests/dcaegen2/prh-testcases/resources/prh_library.robot b/tests/dcaegen2/prh-testcases/resources/prh_library.robot index 105365c3..4f64694d 100644 --- a/tests/dcaegen2/prh-testcases/resources/prh_library.robot +++ b/tests/dcaegen2/prh-testcases/resources/prh_library.robot @@ -29,10 +29,9 @@ Invalid event processing Wait Until Keyword Succeeds 100x 100ms Check PRH log ${notification} Valid event processing - [Arguments] ${input_valid_event_in_dmaap} + [Arguments] ${input_valid__ves_event_in_dmaap} [Timeout] 30s - ${data}= Get Data From File ${input_valid_event_in_dmaap} - ${posted_event_to_dmaap}= create pnf ready notification from ves ${data} + ${data}= Get Data From File ${input_valid__ves_event_in_dmaap} ${pnf_name}= Create PNF name ${data} Set PNF name in AAI ${pnf_name} Set event in DMaaP ${data} @@ -45,9 +44,9 @@ Check PRH log Should Be Equal As Strings ${status} True Check PNF_READY notification - [Arguments] ${posted_event_to_dmaap} + [Arguments] ${expected_event_pnf_ready_in_dpaap} ${resp}= Get Request ${dmaap_setup_session} /events/pnfReady headers=${suite_headers} - Should Be Equal ${resp.text} ${posted_event_to_dmaap} + Should Be Equal ${resp.text} ${expected_event_pnf_ready_in_dpaap} Set PNF name in AAI [Arguments] ${pnfs_name} |