summaryrefslogtreecommitdiffstats
path: root/mock-ves
diff options
context:
space:
mode:
Diffstat (limited to 'mock-ves')
-rw-r--r--mock-ves/Dockerfile17
-rw-r--r--mock-ves/README.md26
-rw-r--r--mock-ves/app/app.py84
-rw-r--r--mock-ves/cleanup-dev.sh7
-rw-r--r--mock-ves/requirements.txt2
-rw-r--r--mock-ves/run-dev.sh8
6 files changed, 144 insertions, 0 deletions
diff --git a/mock-ves/Dockerfile b/mock-ves/Dockerfile
new file mode 100644
index 0000000..32c530a
--- /dev/null
+++ b/mock-ves/Dockerfile
@@ -0,0 +1,17 @@
+FROM python:3.8-alpine
+
+COPY . /app
+WORKDIR /app
+
+# GCC for Alpine Linux in Docker
+RUN apk add build-base
+
+
+# Dependencies
+RUN pip install -r requirements.txt
+
+EXPOSE 30417
+
+ENTRYPOINT ["python"]
+
+CMD ["app/app.py"] \ No newline at end of file
diff --git a/mock-ves/README.md b/mock-ves/README.md
new file mode 100644
index 0000000..b75ea97
--- /dev/null
+++ b/mock-ves/README.md
@@ -0,0 +1,26 @@
+# mock-ves
+This is a simple ves mock created for ONAP integration tests.
+
+Build image
+===========
+To build ves-mock image you can simply run command:
+
+ ```
+docker build . -t mock-ves
+```
+
+Run image
+=========
+
+To run ves-mock image use below command:
+```
+docker run -d --net=host --name mock-ves mock-ves
+```
+
+Stop container
+==============
+To stop the container use:
+```
+docker rm -f mock-ves
+```
+
diff --git a/mock-ves/app/app.py b/mock-ves/app/app.py
new file mode 100644
index 0000000..acf1caa
--- /dev/null
+++ b/mock-ves/app/app.py
@@ -0,0 +1,84 @@
+"""
+ Copyright 2023 Deutsche Telekom AG, Nokia, Orange
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+"""
+import json
+import requests
+import logging as sys_logging
+from flask import Flask, logging, request
+
+FAULT_TOPIC = "fault"
+dmaap_url = ""
+
+app = Flask(__name__)
+sys_logging.basicConfig(level=sys_logging.DEBUG)
+logger = logging.create_logger(app)
+
+
+@app.route("/set_dmaap_address", methods=['POST'])
+def set_dmaap_address():
+ logger.debug(request.json)
+ global dmaap_url
+ dmaap_url = get_dmaap_mock_url()
+ return {}, 202
+
+
+@app.route("/eventListener/<version>", methods=['POST'])
+def event_sec_fault_output(version):
+ logger.debug(request.json)
+ event = json.dumps(request.json["event"]) \
+ .replace('\n', ' ') \
+ .__add__("\n")
+ send_event_to_dmaap(dmaap_url, event, FAULT_TOPIC)
+ return handle_new_event(version)
+
+
+@app.route("/eventListener/<version>/eventBatch", methods=['POST'])
+def event_sec_fault_output_batch(version):
+ logger.debug(request.json)
+ dmaap_mock_url = dmaap_url
+ event = prepare_event_list_for_dmaap()
+ send_event_to_dmaap(dmaap_mock_url, event, FAULT_TOPIC)
+ return handle_new_event(version)
+
+
+def send_event_to_dmaap(dmaap_mock_url, event, topic):
+ byte_event = change_from_str_to_byte_array(event)
+ requests.post("{}/events/{}".format(dmaap_mock_url, topic), data=byte_event)
+
+
+def handle_new_event(version):
+ return {}, 202
+
+
+def change_from_str_to_byte_array(event):
+ b = bytearray()
+ b.extend(event.encode())
+ return b
+
+
+def prepare_event_list_for_dmaap():
+ event_list = []
+ for event in request.json["eventList"]:
+ event_list.append(json.dumps(event).replace('\n', ' '))
+ event = "\n".join(event_list).__add__("\n")
+ return event
+
+
+def get_dmaap_mock_url():
+ return request.json["DMAAP_MOCK"]
+
+
+if __name__ == "__main__":
+ app.run(host='0.0.0.0', port=30417, debug=True)
diff --git a/mock-ves/cleanup-dev.sh b/mock-ves/cleanup-dev.sh
new file mode 100644
index 0000000..0cf27b3
--- /dev/null
+++ b/mock-ves/cleanup-dev.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+export APP_NAME=mock-ves
+
+docker rm -f ${APP_NAME}
+docker rmi ${APP_NAME}
+
diff --git a/mock-ves/requirements.txt b/mock-ves/requirements.txt
new file mode 100644
index 0000000..07da031
--- /dev/null
+++ b/mock-ves/requirements.txt
@@ -0,0 +1,2 @@
+Flask-RESTful==0.3.8
+requests[socks]==2.24.0 \ No newline at end of file
diff --git a/mock-ves/run-dev.sh b/mock-ves/run-dev.sh
new file mode 100644
index 0000000..5b50d95
--- /dev/null
+++ b/mock-ves/run-dev.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+export APP_NAME=mock-ves
+export DOCKER_PORT=30417
+export APP_PORT=30417
+
+docker build . -t $APP_NAME
+docker run -p $DOCKER_PORT:$APP_PORT --name $APP_NAME $APP_NAME