aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py
diff options
context:
space:
mode:
authorpkaras <piotr.karas@nokia.com>2018-10-23 09:06:37 +0200
committerpkaras <piotr.karas@nokia.com>2018-10-23 09:26:15 +0200
commite416584e6f4acdc0ea3351add5d4bc08a5476af3 (patch)
tree47cb6807d0a16b94268ec610f55377ba3479a93c /tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py
parentc7abba816ad7d702a9e01e9286e7661cb13fe11f (diff)
tests for ssl connection for PRH, AAI and DmaaP
Change-Id: If1e73dee9d517832852ae618d73e45da29052828 Issue-ID: DCAEGEN2-886 Signed-off-by: piotr.karas <piotr.karas@nokia.com>
Diffstat (limited to 'tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py')
-rw-r--r--tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py43
1 files changed, 9 insertions, 34 deletions
diff --git a/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py b/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py
index 3ff951e8..bb37ddd0 100644
--- a/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py
+++ b/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py
@@ -1,9 +1,7 @@
-import _thread
import re
-import ssl
import time
from http.server import BaseHTTPRequestHandler
-from http.server import HTTPServer
+import httpServerLib
posted_event_from_prh = b'Empty'
received_event_to_get_method = b'Empty'
@@ -16,13 +14,13 @@ class DmaapSetup(BaseHTTPRequestHandler):
global received_event_to_get_method
content_length = int(self.headers['Content-Length'])
received_event_to_get_method = self.rfile.read(content_length)
- _header_200_and_json(self)
+ httpServerLib.header_200_and_json(self)
return
def do_GET(self):
if re.search('/events/pnfReady', self.path):
- _header_200_and_json(self)
+ httpServerLib.header_200_and_json(self)
self.wfile.write(posted_event_from_prh)
return
@@ -33,7 +31,7 @@ class DmaapSetup(BaseHTTPRequestHandler):
global received_event_to_get_method
posted_event_from_prh = b'Empty'
received_event_to_get_method = b'Empty'
- _header_200_and_json(self)
+ httpServerLib.header_200_and_json(self)
return
@@ -45,49 +43,26 @@ class DMaaPHandler(BaseHTTPRequestHandler):
global posted_event_from_prh
content_length = int(self.headers['Content-Length'])
posted_event_from_prh = self.rfile.read(content_length)
- _header_200_and_json(self)
+ httpServerLib.header_200_and_json(self)
return
def do_GET(self):
if re.search('/events/unauthenticated.VES_PNFREG_OUTPUT/OpenDcae-c12/c12', self.path):
- _header_200_and_json(self)
+ httpServerLib.header_200_and_json(self)
self.wfile.write(received_event_to_get_method)
return
-def _header_200_and_json(self):
- self.send_response(200)
- self.send_header('Content-Type', 'application/json')
- self.end_headers()
-
-
def _main_(handler_class=DMaaPHandler, protocol="HTTP/1.0"):
handler_class.protocol_version = protocol
- _thread.start_new_thread(_init_http_endpoints, (2222, DMaaPHandler))
- _thread.start_new_thread(_init_https_endpoints, (2223, DMaaPHandler))
- _thread.start_new_thread(_init_http_endpoints, (2224, DmaapSetup))
+ httpServerLib.start_http_endpoint(2222, DMaaPHandler)
+ httpServerLib.start_https_endpoint(2223, DMaaPHandler)
+ httpServerLib.start_http_endpoint(2224, DmaapSetup)
while 1:
time.sleep(10)
-def _init_http_endpoints(port, handler_class, server_class=HTTPServer):
- server = server_class(('', port), handler_class)
- sa = server.socket.getsockname()
- print("Serving HTTP on", sa[0], "port", sa[1], "for", handler_class, "...")
- server.serve_forever()
-
-
-def _init_https_endpoints(port, handler_class, server_class=HTTPServer):
- server = server_class(('', port), handler_class)
- server.socket = ssl.wrap_socket(server.socket,
- keyfile="certs/server.key", certfile="certs/server.crt",
- ca_certs="certs/client.crt", server_side=True)
- sa = server.socket.getsockname()
- print("Serving HTTPS on", sa[0], "port", sa[1], "for", handler_class, "...")
- server.serve_forever()
-
-
if __name__ == '__main__':
_main_()