aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plans/dcaegen2/prh-testsuites/setup.sh17
-rw-r--r--tests/dcaegen2/prh-testcases/prh_tests.robot10
-rw-r--r--tests/dcaegen2/prh-testcases/resources/PrhLibrary.py42
-rw-r--r--tests/dcaegen2/prh-testcases/resources/docker-compose.yml6
-rw-r--r--tests/dcaegen2/prh-testcases/resources/prh_library.robot13
-rw-r--r--tests/dcaegen2/prh-testcases/resources/simulator/AAI.py5
-rw-r--r--tests/dcaegen2/prh-testcases/resources/simulator/AAI_simulator10
-rw-r--r--tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py72
-rw-r--r--tests/dcaegen2/prh-testcases/resources/simulator/DMaaP_simulator13
-rw-r--r--tests/dcaegen2/prh-testcases/ssl_prh_tests.robot30
10 files changed, 131 insertions, 87 deletions
diff --git a/plans/dcaegen2/prh-testsuites/setup.sh b/plans/dcaegen2/prh-testsuites/setup.sh
index 096c695b..9040ae60 100644
--- a/plans/dcaegen2/prh-testsuites/setup.sh
+++ b/plans/dcaegen2/prh-testsuites/setup.sh
@@ -2,17 +2,6 @@
source ${SCRIPTS}/common_functions.sh
-function check_heartbeat ()
-{
- local port=$1
-
- for i in {1..10}; do
- curl -sS -m 1 localhost:$port/heartbeat && break
- echo sleep ${i}
- sleep ${i}
- done
-}
-
export PRH_SERVICE="prh"
export SSL_PRH_SERVICE="ssl_prh"
export DMAAP_SIMULATOR="dmaap_simulator"
@@ -41,9 +30,9 @@ echo DMAAP_SIMULATOR_IP=${DMAAP_SIMULATOR_IP}
echo AAI_SIMULATOR_IP=${AAI_SIMULATOR_IP}
# Wait for initialization of PRH services
-check_heartbeat 8100
-check_heartbeat 8200
+wait_for_service_init localhost:8100/heartbeat
+wait_for_service_init localhost:8200/heartbeat
# #Pass any variables required by Robot test suites in ROBOT_VARIABLES
-ROBOT_VARIABLES="-v DMAAP_SIMULATOR:${DMAAP_SIMULATOR_IP}:2222 -v AAI_SIMULATOR:${AAI_SIMULATOR_IP}:3333 -v SSL_AAI_SIMULATOR:${AAI_SIMULATOR_IP}:3334 -v AAI_SIMULATOR_SETUP:${AAI_SIMULATOR_IP}:3335"
+ROBOT_VARIABLES="-v DMAAP_SIMULATOR_SETUP:${DMAAP_SIMULATOR_IP}:2224 -v AAI_SIMULATOR_SETUP:${AAI_SIMULATOR_IP}:3335"
diff --git a/tests/dcaegen2/prh-testcases/prh_tests.robot b/tests/dcaegen2/prh-testcases/prh_tests.robot
index d81efe6e..634f37f8 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 @@ Get valid event from DMaaP and AAI is not responding
[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 656f6fc3..dc589369 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 @@ class PrhLibrary(object):
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 04d5763f..6d646801 100644
--- a/tests/dcaegen2/prh-testcases/resources/docker-compose.yml
+++ b/tests/dcaegen2/prh-testcases/resources/docker-compose.yml
@@ -31,9 +31,9 @@ services:
--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 @@ services:
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 b7653671..71753875 100644
--- a/tests/dcaegen2/prh-testcases/resources/prh_library.robot
+++ b/tests/dcaegen2/prh-testcases/resources/prh_library.robot
@@ -10,13 +10,14 @@ Create header
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 PRH log
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 PNF name in AAI
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 b6c9c0f9..76823b0d 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 b44add60..7364769f 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 85c36109..3ff951e8 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 @@ class DMaaPHandler(BaseHTTPRequestHandler):
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 @@ def _header_200_and_json(self):
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)
-
- sa = httpd.socket.getsockname()
- print("Serving HTTP on", sa[0], "port", sa[1], "...")
- httpd.serve_forever()
+ _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)
+
+
+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 9cf21dc9..40e1af09 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 3fd0faf1..49d2c45a 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}