BulkPM Add Metadata Test Case 89/78489/2
authorLiamBurke <Liam.Burke@ericsson.com>
Thu, 14 Feb 2019 13:24:52 +0000 (13:24 +0000)
committerLiamBurke <liam.burke@ericsson.com>
Thu, 14 Feb 2019 14:35:26 +0000 (14:35 +0000)
Change-Id: Ieb5709f6b223579baca402322f7a9fec1daa1a73
Issue-ID: INT-832
Signed-off-by: LiamBurke <liam.burke@ericsson.com>
tests/usecases/5G-bulkpm/BulkpmE2E.robot
tests/usecases/5G-bulkpm/assets/metadata.schema.json [new file with mode: 0644]
tests/usecases/5G-bulkpm/resources/JsonValidatorLibrary.py [new file with mode: 0644]
tests/usecases/5G-bulkpm/resources/bulkpm_keywords.robot

index 28de4c2..4b85e6b 100644 (file)
@@ -19,6 +19,11 @@ ${TARGETURL_SUBSCR}                      http://${DMAAP_MR_IP}:3904/events/unaut
 ${CLI_EXEC_CLI}                          curl -k https://${DR_PROV_IP}:8443/internal/prov
 ${CLI_EXEC_CLI_FILECONSUMER}             docker exec fileconsumer-node /bin/sh -c "ls /opt/app/subscriber/delivery | grep .gz"
 
+${CLI_EXEC_CLI_FILECONSUMER_CP}          docker cp fileconsumer-node:/opt/app/subscriber/delivery/xNF.pm.xml.gz.M %{WORKSPACE}
+${CLI_EXEC_RENAME_METADATA}              mv %{WORKSPACE}/xNF.pm.xml.gz.M  %{WORKSPACE}/metadata.json
+${metadataSchemaPath}                    %{WORKSPACE}/tests/usecases/5G-bulkpm/assets/metadata.schema.json
+${metadataJsonPath}                      %{WORKSPACE}/metadata.json
+
 *** Test Cases ***
 
 Send VES File Ready Event to VES Collector
@@ -77,3 +82,15 @@ Verify Fileconsumer Receive PM file from Data Router
     Log                             ${cli_cmd_output.stdout}
     Should Be Equal As Strings      ${cli_cmd_output.rc}            0
     Should Contain                  ${cli_cmd_output.stdout}        xNF.pm.xml.gz
+
+Verify File Consumer Receive valid metadata from Data Router
+    [Tags]                          Bulk_PM_E2E_06
+    [Documentation]                 Check PM XML file is delivered to the FileConsumer Simulator with valid metadata
+    ${cli_cmd_output}=              Run Process                     ${CLI_EXEC_CLI_FILECONSUMER}        shell=yes
+    Log                             ${cli_cmd_output.stdout}
+    Should Be Equal As Strings      ${cli_cmd_output.rc}            0
+    Should Contain                  ${cli_cmd_output.stdout}        xNF.pm.xml.gz.M
+    ${cli_cmd_output}=              Run Process                     ${CLI_EXEC_CLI_FILECONSUMER_CP}     shell=yes
+    ${cli_cmd_output}=              Run Process                     ${CLI_EXEC_RENAME_METADATA}         shell=yes
+    ${validation_result}=           Validate                        ${metadataSchemaPath}    ${metadataJsonPath}
+    Should Be Equal As Strings      ${validation_result}            0
diff --git a/tests/usecases/5G-bulkpm/assets/metadata.schema.json b/tests/usecases/5G-bulkpm/assets/metadata.schema.json
new file mode 100644 (file)
index 0000000..a41b354
--- /dev/null
@@ -0,0 +1,74 @@
+{
+    "$schema":  "http://json-schema.org/draft-07/schema",
+    "$id": "metadata.schema.json",
+    "title": "DataRouter PM File Metadata",
+    "description": "Metadata for 3GPP PM files that are placed on the DMaaP Data Router by the Data File Collector (VES 7.1)",
+    "type": "object",
+
+    "properties": {
+        "productName": {
+            "description": "from the FileReady event eventName",
+            "type": "string"
+        },
+
+        "vendorName": {
+            "description": "from the FileReady event eventName",
+            "type": "string"
+        },
+
+        "lastEpochMicrosec": {
+            "description": "the latest unix epoch time associated with the FileReady event",
+            "type": "string"
+        },
+
+        "sourceName": {
+            "description": "the name of the entity experiencing the event",
+            "type": "string"
+        },
+
+        "startEpochMicrosec": {
+            "description": "the earliest unix epoch time associated with the FileReady event",
+            "type": "string"
+        },
+
+        "timeZoneOffset": {
+            "description": "the timezone offset from UTC",
+            "type": "string",
+            "pattern": "^(?:(?:[a-zA-Z]{3})[+-](?:[01][0-9]|2[0-3]).[0-5][0-9])$"
+        },
+
+        "location": {
+            "description": "follows the format <protocol>://<ip address>:<port>/<path>/<filename>, the IP address is the node ip address, the port of the protocol server",
+            "type": "string"
+        },
+
+        "compression": {
+            "description": "specifies if the file is compressed",
+            "type": "string",
+            "enum": [ "gzip" ]
+        },
+
+        "fileFormatType": {
+            "description": "the file format",
+            "type": "string"
+        },
+
+        "fileFormatVersion": {
+            "description": "the version of the file format",
+            "type": "string"
+        }
+    },
+
+    "required": [
+        "productName",
+        "vendorName",
+        "lastEpochMicrosec",
+        "sourceName",
+        "startEpochMicrosec",
+        "timeZoneOffset",
+        "location",
+        "compression",
+        "fileFormatType",
+        "fileFormatVersion"
+    ]
+}
diff --git a/tests/usecases/5G-bulkpm/resources/JsonValidatorLibrary.py b/tests/usecases/5G-bulkpm/resources/JsonValidatorLibrary.py
new file mode 100644 (file)
index 0000000..12d5d85
--- /dev/null
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+
+import sys
+import logging
+from simplejson import load
+from jsonschema import validate, ValidationError, SchemaError
+
+
+class JsonValidatorLibrary(object):
+
+    def __init__(self):
+        pass
+
+    def validate(self, schemaPath, jsonPath):
+        logging.info("Schema path: " + schemaPath)
+        logging.info("JSON path: " + jsonPath)
+        schema = None
+        data = None
+        try:
+            schema = load(open(schemaPath, 'r'))
+            data = load(open(jsonPath, 'r'))
+        except (IOError, ValueError, OSError) as e:
+            logging.error(e.message)
+            return 1
+
+        try:
+            validate(data, schema)
+        except (ValidationError, SchemaError) as e:
+            logging.error(e.message)
+            return 1
+
+        # logger.log("JSON validation successful")
+        print("JSON validation successful")
+        return 0
+
+if __name__ == '__main__':
+    lib = JsonValidatorLibrary()
+    # sys.exit(JsonValidatorLibrary().validate(sys.argv[1], sys.argv[2]))
index 6859ea0..9ef56c8 100644 (file)
@@ -2,6 +2,7 @@
 Documentation     The main interface for interacting with VES. It handles low level stuff like managing the http request library and VES required fields
 Library              RequestsLibrary
 Library                  ../resources/xNFLibrary.py
+Library           ../resources/JsonValidatorLibrary.py
 Library           OperatingSystem
 Library           Collections
 Library           requests