tests for ssl connection for PRH, AAI and DmaaP
Change-Id: I503a0749f22336b35b2633d372a3ef59d6bf71c8
Issue-ID: DCAEGEN2-880
Signed-off-by: piotr.karas <piotr.karas@nokia.com>
diff --git a/tests/dcaegen2/prh-testcases/prh_tests.robot b/tests/dcaegen2/prh-testcases/prh_tests.robot
index d81efe6..634f37f 100644
--- a/tests/dcaegen2/prh-testcases/prh_tests.robot
+++ b/tests/dcaegen2/prh-testcases/prh_tests.robot
@@ -1,14 +1,15 @@
*** Settings ***
Documentation Integration tests for PRH.
... PRH receive events from DMaaP and produce or not PNF_READY notification depends on required fields in received event.
-Suite Setup Run keywords Create header Create sessions
-Test Setup Run keywords Reset Simulators
+Suite Setup Run keywords Create header AND Create sessions AND Ensure Container Is Running prh AND Ensure Container Is Exited ssl_prh
+Suite Teardown Ensure Container Is Running ssl_prh
+Test Teardown Reset Simulators
Library resources/PrhLibrary.py
Resource resources/prh_library.robot
Resource ../../common.robot
*** Variables ***
-${DMAAP_SIMULATOR_URL} http://${DMAAP_SIMULATOR}
+${DMAAP_SIMULATOR_SETUP_URL} http://${DMAAP_SIMULATOR_SETUP}
${AAI_SIMULATOR_SETUP_URL} http://${AAI_SIMULATOR_SETUP}
${EVENT_WITH_ALL_VALID_REQUIRED_FIELDS} %{WORKSPACE}/tests/dcaegen2/prh-testcases/assets/json_events/event_with_all_fields.json
${EVENT_WITH_IPV4} %{WORKSPACE}/tests/dcaegen2/prh-testcases/assets/json_events/event_with_IPV4.json
@@ -62,6 +63,7 @@
[Tags] PRH AAI
[Timeout] 180s
${data}= Get Data From File ${EVENT_WITH_ALL_VALID_REQUIRED_FIELDS}
- Stop AAI
+ Ensure Container Is Exited aai_simulator
Set event in DMaaP ${data}
Wait Until Keyword Succeeds 100x 300ms Check PRH log java.net.UnknownHostException: aai
+ Ensure Container Is Running aai_simulator
diff --git a/tests/dcaegen2/prh-testcases/resources/PrhLibrary.py b/tests/dcaegen2/prh-testcases/resources/PrhLibrary.py
index 656f6fc..dc58936 100644
--- a/tests/dcaegen2/prh-testcases/resources/PrhLibrary.py
+++ b/tests/dcaegen2/prh-testcases/resources/PrhLibrary.py
@@ -1,6 +1,7 @@
import json
import docker
+import time
class PrhLibrary(object):
@@ -35,10 +36,45 @@
return correlation_id
@staticmethod
- def stop_aai():
+ def ensure_container_is_running(name):
client = docker.from_env()
- container = client.containers.get('aai_simulator')
- container.stop()
+
+ if not PrhLibrary.is_in_status(client, name, "running"):
+ print ("starting container", name)
+ container = client.containers.get(name)
+ container.start()
+ PrhLibrary.wait_for_status(client, name, "running")
+
+ PrhLibrary.print_status(client)
+
+ @staticmethod
+ def ensure_container_is_exited(name):
+ client = docker.from_env()
+
+ if not PrhLibrary.is_in_status(client, name, "exited"):
+ print ("stopping container", name)
+ container = client.containers.get(name)
+ container.stop()
+ PrhLibrary.wait_for_status(client, name, "exited")
+
+ PrhLibrary.print_status(client)
+
+ @staticmethod
+ def print_status(client):
+ print("containers status")
+ for c in client.containers.list(all=True):
+ print(c.name, " ", c.status)
+
+ @staticmethod
+ def wait_for_status(client, name, status):
+ while not PrhLibrary.is_in_status(client, name, status):
+ print ("waiting for container: ", name, "to be in status: ", status)
+ time.sleep(3)
+
+ @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):
return self.create_pnf_ready_notification(json_file).replace("\":", "\": ")\
diff --git a/tests/dcaegen2/prh-testcases/resources/docker-compose.yml b/tests/dcaegen2/prh-testcases/resources/docker-compose.yml
index 04d5763..6d64680 100644
--- a/tests/dcaegen2/prh-testcases/resources/docker-compose.yml
+++ b/tests/dcaegen2/prh-testcases/resources/docker-compose.yml
@@ -31,9 +31,9 @@
--dmaap.dmaapConsumerConfiguration.dmaapPortNumber=2222
--dmaap.dmaapProducerConfiguration.dmaapHostName=dmaap
--dmaap.dmaapProducerConfiguration.dmaapPortNumber=2222
- --aai.aaiClientConfiguration.aaiHostPortNumber=3334
+ --aai.aaiClientConfiguration.aaiHostPortNumber=3333
--aai.aaiClientConfiguration.aaiHost=aai
- --aai.aaiClientConfiguration.aaiProtocol=https
+ --aai.aaiClientConfiguration.aaiProtocol=http
entrypoint:
- java
- -Dspring.profiles.active=dev
@@ -54,6 +54,8 @@
dockerfile: DMaaP_simulator
ports:
- "2222:2222"
+ - "2223:2223"
+ - "2224:2224"
container_name: dmaap_simulator
aai:
diff --git a/tests/dcaegen2/prh-testcases/resources/prh_library.robot b/tests/dcaegen2/prh-testcases/resources/prh_library.robot
index b765367..7175387 100644
--- a/tests/dcaegen2/prh-testcases/resources/prh_library.robot
+++ b/tests/dcaegen2/prh-testcases/resources/prh_library.robot
@@ -10,13 +10,14 @@
Set Suite Variable ${suite_headers} ${headers}
Create sessions
- Create Session dmaap_session ${DMAAP_SIMULATOR_URL}
- Set Suite Variable ${suite_dmaap_session} dmaap_session
+ Create Session dmaap_setup_session ${DMAAP_SIMULATOR_SETUP_URL}
+ Set Suite Variable ${dmaap_setup_session} dmaap_setup_session
Create Session aai_setup_session ${AAI_SIMULATOR_SETUP_URL}
Set Suite Variable ${aai_setup_session} aai_setup_session
Reset Simulators
Reset AAI simulator
+ Reset DMaaP simulator
Invalid event processing
[Arguments] ${input_invalid_event_in_dmaap}
@@ -44,7 +45,7 @@
Check PNF_READY notification
[Arguments] ${posted_event_to_dmaap}
- ${resp}= Get Request ${suite_dmaap_session} /events/pnfReady headers=${suite_headers}
+ ${resp}= Get Request ${dmaap_setup_session} /events/pnfReady headers=${suite_headers}
Should Be Equal ${resp.text} ${posted_event_to_dmaap}
Set PNF name in AAI
@@ -55,9 +56,13 @@
Set event in DMaaP
[Arguments] ${event_in_dmaap}
- ${resp}= Put Request ${suite_dmaap_session} /set_get_event headers=${suite_headers} data=${event_in_dmaap}
+ ${resp}= Put Request ${dmaap_setup_session} /set_get_event headers=${suite_headers} data=${event_in_dmaap}
Should Be Equal As Strings ${resp.status_code} 200
Reset AAI simulator
${resp}= Post Request ${aai_setup_session} /reset
Should Be Equal As Strings ${resp.status_code} 200
+
+Reset DMaaP simulator
+ ${resp}= Post Request ${dmaap_setup_session} /reset
+ Should Be Equal As Strings ${resp.status_code} 200
\ No newline at end of file
diff --git a/tests/dcaegen2/prh-testcases/resources/simulator/AAI.py b/tests/dcaegen2/prh-testcases/resources/simulator/AAI.py
index b6c9c0f..76823b0 100644
--- a/tests/dcaegen2/prh-testcases/resources/simulator/AAI.py
+++ b/tests/dcaegen2/prh-testcases/resources/simulator/AAI.py
@@ -1,6 +1,9 @@
+import _thread
+import re
+import ssl
+import time
from http.server import BaseHTTPRequestHandler
from http.server import HTTPServer
-import _thread, ssl, time, re
pnfs = 'Empty'
diff --git a/tests/dcaegen2/prh-testcases/resources/simulator/AAI_simulator b/tests/dcaegen2/prh-testcases/resources/simulator/AAI_simulator
index b44add6..7364769 100644
--- a/tests/dcaegen2/prh-testcases/resources/simulator/AAI_simulator
+++ b/tests/dcaegen2/prh-testcases/resources/simulator/AAI_simulator
@@ -1,12 +1,4 @@
-FROM alpine:3.8
-
-RUN apk add --no-cache python3 && \
- python3 -m ensurepip && \
- rm -r /usr/lib/python*/ensurepip && \
- pip3 install --upgrade pip setuptools && \
- if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
- if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \
- rm -r /root/.cache
+FROM python:3-alpine
ADD AAI.py /
COPY certs/* /certs/
diff --git a/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py b/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py
index 85c3610..3ff951e 100644
--- a/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py
+++ b/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py
@@ -1,13 +1,15 @@
+import _thread
+import re
+import ssl
+import time
from http.server import BaseHTTPRequestHandler
from http.server import HTTPServer
-import re
-import sys
posted_event_from_prh = b'Empty'
received_event_to_get_method = b'Empty'
-class DMaaPHandler(BaseHTTPRequestHandler):
+class DmaapSetup(BaseHTTPRequestHandler):
def do_PUT(self):
if re.search('/set_get_event', self.path):
@@ -15,25 +17,42 @@
content_length = int(self.headers['Content-Length'])
received_event_to_get_method = self.rfile.read(content_length)
_header_200_and_json(self)
-
+
return
+ def do_GET(self):
+ if re.search('/events/pnfReady', self.path):
+ _header_200_and_json(self)
+ self.wfile.write(posted_event_from_prh)
+
+ return
+
+ def do_POST(self):
+ if re.search('/reset', self.path):
+ global posted_event_from_prh
+ global received_event_to_get_method
+ posted_event_from_prh = b'Empty'
+ received_event_to_get_method = b'Empty'
+ _header_200_and_json(self)
+
+ return
+
+
+class DMaaPHandler(BaseHTTPRequestHandler):
+
def do_POST(self):
if re.search('/events/unauthenticated.PNF_READY', self.path):
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)
-
+
return
def do_GET(self):
if re.search('/events/unauthenticated.VES_PNFREG_OUTPUT/OpenDcae-c12/c12', self.path):
_header_200_and_json(self)
self.wfile.write(received_event_to_get_method)
- elif re.search('/events/pnfReady', self.path):
- _header_200_and_json(self)
- self.wfile.write(posted_event_from_prh)
return
@@ -44,21 +63,30 @@
self.end_headers()
-def _main_(handler_class=DMaaPHandler, server_class=HTTPServer, protocol="HTTP/1.0"):
-
- if sys.argv[1:]:
- port = int(sys.argv[1])
- else:
- port = 2222
-
- server_address = ('', port)
-
+def _main_(handler_class=DMaaPHandler, protocol="HTTP/1.0"):
handler_class.protocol_version = protocol
- httpd = server_class(server_address, handler_class)
+ _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))
+ while 1:
+ time.sleep(10)
- sa = httpd.socket.getsockname()
- print("Serving HTTP on", sa[0], "port", sa[1], "...")
- httpd.serve_forever()
+
+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__':
diff --git a/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP_simulator b/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP_simulator
index 9cf21dc..40e1af0 100644
--- a/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP_simulator
+++ b/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP_simulator
@@ -1,15 +1,6 @@
-FROM alpine:3.8
-
-RUN apk add --no-cache python3 && \
- python3 -m ensurepip && \
- rm -r /usr/lib/python*/ensurepip && \
- pip3 install --upgrade pip setuptools && \
- if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
- if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \
- rm -r /root/.cache
+FROM python:3-alpine
ADD DMaaP.py /
-
-EXPOSE 2222
+COPY certs/* /certs/
CMD [ "python", "./DMaaP.py" ]
diff --git a/tests/dcaegen2/prh-testcases/ssl_prh_tests.robot b/tests/dcaegen2/prh-testcases/ssl_prh_tests.robot
index 3fd0faf..49d2c45 100644
--- a/tests/dcaegen2/prh-testcases/ssl_prh_tests.robot
+++ b/tests/dcaegen2/prh-testcases/ssl_prh_tests.robot
@@ -1,31 +1,27 @@
*** Settings ***
Documentation Integration tests for PRH.
-... PRH receive events from DMaaP and produce or not PNF_READY notification depends on required fields in received event.
-Suite Setup Run keywords Create header Create sessions
+... PRH receive events from DMaaP and produce or not PNF_READY notification depends on required fields in received event. PRH comunicates with AAI and DMaaP through SSL
+Suite Setup Run keywords Create header AND Create sessions AND Ensure Container Is Running ssl_prh AND Ensure Container Is Exited prh
+Suite Teardown Ensure Container Is Running prh
+Test Teardown Reset Simulators
Library resources/PrhLibrary.py
Resource resources/prh_library.robot
Resource ../../common.robot
*** Variables ***
-${DMAAP_SIMULATOR_URL} http://${DMAAP_SIMULATOR}
+${DMAAP_SIMULATOR_SETUP_URL} http://${DMAAP_SIMULATOR_SETUP}
${AAI_SIMULATOR_SETUP_URL} http://${AAI_SIMULATOR_SETUP}
${EVENT_WITH_ALL_VALID_REQUIRED_FIELDS} %{WORKSPACE}/tests/dcaegen2/prh-testcases/assets/json_events/event_with_all_fields.json
${EVENT_WITH_IPV4} %{WORKSPACE}/tests/dcaegen2/prh-testcases/assets/json_events/event_with_IPV4.json
${EVENT_WITH_IPV6} %{WORKSPACE}/tests/dcaegen2/prh-testcases/assets/json_events/event_with_IPV6.json
-${EVENT_WITH_MISSING_IPV4_AND_IPV6} %{WORKSPACE}/tests/dcaegen2/prh-testcases/assets/json_events/event_with_missing_IPV4_and_IPV6.json
-${EVENT_WITH_MISSING_SOURCENAME} %{WORKSPACE}/tests/dcaegen2/prh-testcases/assets/json_events/event_with_missing_sourceName.json
-${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_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
*** Test Cases ***
-#Valid DMaaP event can be converted to PNF_READY notification with ssl connection to AAI
-# [Documentation] PRH get valid event from DMaaP with required fields - PRH produce PNF_READY notification
-# [Tags] PRH Valid event
-# [Template] Valid event processing
-# ${EVENT_WITH_ALL_VALID_REQUIRED_FIELDS}
-# ${EVENT_WITH_IPV4}
-# ${EVENT_WITH_IPV6}
-# ${EVENT_WITHOUT_IPV6_FILED}
+Valid DMaaP event can be converted to PNF_READY notification with ssl connection to AAI
+ [Documentation] PRH get valid event from DMaaP with required fields - PRH produce PNF_READY notification
+ [Tags] PRH Valid event
+ [Template] Valid event processing
+ ${EVENT_WITH_ALL_VALID_REQUIRED_FIELDS}
+ ${EVENT_WITH_IPV4}
+ ${EVENT_WITH_IPV6}
+ ${EVENT_WITHOUT_IPV6_FILED}