diff options
author | Mariusz Wagner <mariusz.wagner@nokia.com> | 2018-05-24 14:14:39 +0200 |
---|---|---|
committer | Mariusz Wagner <mariusz.wagner@nokia.com> | 2018-05-24 14:14:39 +0200 |
commit | a50b911ad18155bc6d77d7260e83d5178b456957 (patch) | |
tree | fc46994b0921a01157e1c3cf08a9328b3ee80cee /test/csit/tests/dcaegen2/prh_testcases/resources | |
parent | 8053f360cab41003739bb3023b63027aa4cb60be (diff) |
Initial commit with robotframework
Robotframework python files to be used in tests.
At this moment it tests nothing
Issue-ID: INT-510
Change-Id: Icbd6a6ffcbdb28755b26cad3a2b8c6d163f77c38
Signed-off-by: Mariusz Wagner <mariusz.wagner@nokia.com>
Diffstat (limited to 'test/csit/tests/dcaegen2/prh_testcases/resources')
4 files changed, 265 insertions, 0 deletions
diff --git a/test/csit/tests/dcaegen2/prh_testcases/resources/PrhLibrary.py b/test/csit/tests/dcaegen2/prh_testcases/resources/PrhLibrary.py new file mode 100644 index 000000000..893ed9460 --- /dev/null +++ b/test/csit/tests/dcaegen2/prh_testcases/resources/PrhLibrary.py @@ -0,0 +1,95 @@ +''' +Created on Apr 27, 2018 + +@author: mwagner9 +''' + +import threading +import time + +from robot.api import logger + +import PrhVariables +import Simulator + +st = '{"event":{"correlationID":"NOKQTFCOC540002E", "pnfOamIpv4Address":"10.16.123.234", "pnfOamIpv6Address":"2001:0db8:85a3:0000:0000:8a2e:0370:7334"}}' + +class PrhLibrary(object): + def __init__(self): + pass + + def setup_dmaap_server(self): + return _setup(PrhVariables.DMaaPHttpServerThread, 'DMaaP', PrhVariables.DMaaPIsRobotRun, Simulator, 3904) + + def setup_aai_server(self): + return _setup(PrhVariables.AAIHttpServerThread, 'AAI', PrhVariables.AAIIsRobotRun, Simulator, 3905) + + def shutdown_dmaap_server(self): + return _shutdown(PrhVariables.DMaaPHTTPD, 'DMaaP') + + def shutdown_aai_server(self): + return _shutdown(PrhVariables.AAIHTTPD, 'AAI') + + def is_json_empty(self, response): + logger.info("Enter is_json_empty: response.text: " + response.text) + if response.text is None or len(response.text) < 2: + return 'True' + return 'False' + + def dmaap_collectorTimeStamp_receive(self, search, response): + return _find_element(search, response) + + def AAI_Ipv4_receive(self, search, response): + return _find_element(search, response) + + def AAI_Ipv6_receive(self, search, response): + return _find_element(search, response) + + def check_pnf_ready(self): + if st in Simulator.prh_ready: + return 'true' + return 'false' + +def _setup(serverthread, servername, isrobotrun, module, portNum): + if serverthread is not None: + logger.console('{} Mockup Sever started'.format(servername)) + return "true" + + isrobotrun = True + + module_handler = module.AAIHandler if servername is 'AAI' else module.DMaaPHandler + + module.run_server(module_handler, portNum) + try: + serverthread = threading.Thread(name='{}_HTTPServer'.format(servername), target=module.Httpd.serve_forever) + serverthread.start() + logger.console('{} Mockup Sever started'.format(servername)) + time.sleep(2) + return "true" + except Exception as e: + print (str(e)) + return "false" + +def _shutdown(server, name): + if server is not None: + server.shutdown() + logger.console("{} Server shut down".format(name)) + time.sleep(3) + return "true" + else: + return "false" + +def _find_element(search, response): + while response is not None: + json_data = str(response) + if search in json_data: + return 'true' + return 'false' + +if __name__ == '__main__': + lib = PrhLibrary() + ret = lib.setup_dmaap_server() + print ret + ret = lib.setup_aai_server() + print ret + time.sleep(10) diff --git a/test/csit/tests/dcaegen2/prh_testcases/resources/PrhVariables.py b/test/csit/tests/dcaegen2/prh_testcases/resources/PrhVariables.py new file mode 100644 index 000000000..882a4b9ce --- /dev/null +++ b/test/csit/tests/dcaegen2/prh_testcases/resources/PrhVariables.py @@ -0,0 +1,18 @@ +''' +Created on Apr 27, 2018 + +@author: mwagner9 +''' + +import os + +def GetEnvironmentVariable(envVarstr): + return os.environ.get(envVarstr) + +DMaaPHttpServerThread = None +DMaaPHTTPD = None +DMaaPIsRobotRun = False + +AAIHttpServerThread = None +AAIHTTPD = None +AAIIsRobotRun = False diff --git a/test/csit/tests/dcaegen2/prh_testcases/resources/Simulator.py b/test/csit/tests/dcaegen2/prh_testcases/resources/Simulator.py new file mode 100644 index 000000000..e746d5a48 --- /dev/null +++ b/test/csit/tests/dcaegen2/prh_testcases/resources/Simulator.py @@ -0,0 +1,91 @@ +''' +Created on May 10, 2018 + +@author: mwagner9 +''' + +import BaseHTTPServer +import re +import sys + +from robot.api import logger + +import PrhVariables + +Httpd = None +prh_ready = '' + +class BaseHandler(BaseHTTPServer.BaseHTTPRequestHandler, object): + def do_GET(self, param1, param2): + """Serve a GET request.""" + #prepare GET response + logger.console(self.raw_requestlinel) + json_string = param1 + if re.search(param2, self.path) is not None: + self.send_response(200) + self.send_header("Content-type", "application/json") + self.end_headers() + self.wfile.write(json_string) + +class AAIHandler(BaseHandler): + def do_PATCH(self): + #prepare PATCH response + logger.console('========') + logger.console(self.raw_requestline) + logger.console('========') + if re.search('/aai/v12/network/pnfs/pnf/NOKQTFCOC540002E', self.path)is not None: + st = '{"ipaddress-v6-oam": "2001:0db8:85a3:0000:0000:8a2e:0370:7334","ipaddress-v4-oam": "11.22.33.156"}' + logger.console('========') + logger.console(self.raw_requestline) + logger.console('========') + self.send_response(200) + + def do_GET(self): + param1 = '{"pnf-name":"NOKQTFCOC540002E", "pnf-id":"NOKQTFCOC540002E","ipaddress-v4-oam":"10.16.123.234","ipaddress-v6-oam":"2001:0db8:85a3:0000:0000:8a2e:0370:7334"}' + param2 = '/aai/v12/network/pnfs/pnf/NOKQTFCOC540002E' + super(self.__class__, self).do_GET(param1, param2) + +class DMaaPHandler(BaseHandler): + def do_GET(self): + param1 = '{"event": {"commonEventHeader": {"sourceId":"QTFCOC540002E", "startEpochMicrosec":1519837825682, "eventId":"QTFCOC540002E-reg", "nfcNamingCode":"5DU", "internalHeaderFields":{"collectorTimeStamp":"Fri, 04 27 2018 09:01:10 GMT"}, "eventType":"pnfRegistration", "priority":"Normal", "version":3, "reportingEntityName":"5GRAN_DU", "sequence":0, "domain":"other", "lastEpochMicrosec":1519837825682, "eventName":"pnfRegistration_5GDU", "sourceName":"5GRAN_DU", "nfNamingCode":"5GRAN"}, "otherFields": {"pnfLastServiceDate":1517206400, "pnfOamIpv6Address":"2001:0db8:85a3:0000:0000:8a2e:0370:7334", "pnfVendorName":"Nokia", "pnfModelNumber":"AJ02", "pnfFamily":"BBU", "pnfType":"AirScale", "otherFieldsVersion":1, "pnfOamIpv4Address":"10.16.123.234", "pnfSoftwareVersion":"v4.5.0.1", "pnfSerialNumber":"QTFCOC540002E", "pnfManufactureDate":1516406400}}}' + param2 = '/events/unauthenticated.SEC_OTHER_OUTPUT/OpenDCAE-c12/c12' + super(self.__class__, self).do_GET(param1, param2) + + def do_POST(self): + #Prepare POST response + logger.console('========') + logger.console(self.raw_requestline) + logger.console('========') + if re.search('/events/unauthenticated.PNF_READY', self.path) is not None: + global prh_ready + prh_ready = '{"event":{"correlationID":"NOKQTFCOC540002E", "pnfOamIpv4Address":"10.16.123.234", "pnfOamIpv6Address":"2001:0db8:85a3:0000:0000:8a2e:0370:7334"}}' + self.send_response(200) + +def run_server(HandlerClass, port, ServerClass = BaseHTTPServer.HTTPServer, protocol="HTTP/1.0"): + server_address = ('', port) + + HandlerClass.protocol_version = protocol + httpd = ServerClass(server_address, HandlerClass) + + global Httpd + Httpd = httpd + if HandlerClass is DMaaPHandler: + PrhVariables.DMaaPHTTPD = httpd + else: + PrhVariables.AAIHTTPD = httpd + + sa = httpd.socket.getsockname() + print "Serving HTTP on", sa[0], "port", sa[1], "..." + +def _main_ (HandlerClass, port, ServerClass = BaseHTTPServer.HTTPServer, protocol="HTTP/1.0"): + server_address = ('', port) + + HandlerClass.protocol_version = protocol + httpd = ServerClass(server_address, HandlerClass) + + sa = httpd.socket.getsockname() + print "Serving HTTP on", sa[0], "port", sa[1], "..." + httpd.serve_forever() + +if __name__ == '__main__': + _main_(DMaaPHandler, 3904) diff --git a/test/csit/tests/dcaegen2/prh_testcases/resources/prh_keywords.robot b/test/csit/tests/dcaegen2/prh_testcases/resources/prh_keywords.robot new file mode 100644 index 000000000..1595cd4a4 --- /dev/null +++ b/test/csit/tests/dcaegen2/prh_testcases/resources/prh_keywords.robot @@ -0,0 +1,61 @@ +*** Settings *** +Documentation The main interface for interacting with PRH. It handles low level stuff like managing the http request library +Library PrhLibrary.py +Library RequestsLibrary + +*** Variables *** + +*** Keywords *** +PRH Suite Setup + [Documentation] Start DMaaP and AAI Mockup Server + ${ret}= Setup DMaaP Server + Should Be Equal As Strings ${ret} true + ${ret}= Setup AAI Server + Should Be Equal As Strings ${ret} true + +PRH Suite Shutdown + [Documentation] Shutdown DMaaP and AAI Mockup Server + ${ret}= Shutdown DMaap Server + Should Be Equal As Strings ${ret} true + ${ret}= Shutdown AAI Server + Should Be Equal As Strings ${ret} true + +Get event from DMaaP + [Arguments] ${ip} ${endpoint} + [Documentation] Get an event from DMaaP + ${url}= Catenate SEPARATOR= ${ip} ${endpoint} + Log Creating session ${url} + Create Session prh-d1 ${url} + ${resp}= Get Request prh-d1 ${url} + Log Received response from dcae ${resp.json()} + [Return] ${resp} + +Send patch from AAI + [Arguments] ${ip} ${endpoint} + [Documentation] Get patch from AAI + ${url}= Catenate SEPARATOR= ${ip} ${endpoint} + Log Creating session ${url} + Create Session prh-d1 ${url} + ${resp}= Patch Request prh-d1 ${url} + Log ${resp} + [Return] ${resp} + +Get json from AAI + [Arguments] ${ip} ${endpoint} + [Documentation] Get json from AAI + ${url}= Catenate SEPARATOR= ${ip} ${endpoint} + Log Creating session ${url} + Create Session prh-d1 ${url} + ${resp}= Get Request prh-d1 ${url} + Log Received response from dcae ${resp.json()} + [Return] ${resp} + +Post json to DMaaP + [Arguments] ${ip} ${endpoint} ${PNF_READY} + [Documentation] Get json from AAI + ${url}= Catenate SEPARATOR= ${ip} ${endpoint} + Log Creating session ${url} + Create Session prh-d1 ${url} + ${resp}= Post Request prh-d1 ${url} data=${PNF_READY} + Log ${resp} + [Return] ${resp} |