aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/pnfsimulator/simulator.sh
diff options
context:
space:
mode:
authorPawel Kadlubanski <pawel.kadlubanski@nokia.com>2018-05-11 14:35:43 +0200
committerPawel Kadlubanski <pawel.kadlubanski@nokia.com>2018-05-11 15:39:54 +0200
commit8d0066e435caa66fdd271d14025788299809ab14 (patch)
tree75233ff2a3761eeb0fef4aa6aff05fbd591f2e57 /test/mocks/pnfsimulator/simulator.sh
parent5c314cf2ebadece91f9b3745bf1d4e80064bbd70 (diff)
Add pnf simulator
Issue-ID: INT-458 Change-Id: I6fd6b58e5d302d83e4b4e1d1dfd59247a6df9700 Signed-off-by: Pawel Kadlubanski <pawel.kadlubanski@nokia.com>
Diffstat (limited to 'test/mocks/pnfsimulator/simulator.sh')
-rwxr-xr-xtest/mocks/pnfsimulator/simulator.sh108
1 files changed, 108 insertions, 0 deletions
diff --git a/test/mocks/pnfsimulator/simulator.sh b/test/mocks/pnfsimulator/simulator.sh
new file mode 100755
index 000000000..27384dd04
--- /dev/null
+++ b/test/mocks/pnfsimulator/simulator.sh
@@ -0,0 +1,108 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+CONTAINER_NAME=pnf-simulator
+CONFIG_FILE_PATH=/config/body.json
+SIMULATOR_DOCKER_HUB=hub-name
+SIMULATOR_TAG=latest
+
+function main(){
+
+ COMMAND=${1:-"help"}
+
+ case $COMMAND in
+ "build")
+ build_image;;
+ "start")
+ start_simulator $2 $CONFIG_FILE_PATH $SIMULATOR_DOCKER_HUB/pnf-simulator:$SIMULATOR_TAG;;
+ "start-dev")
+ start_simulator $2 $CONFIG_FILE_PATH pnf-simulator:$SIMULATOR_TAG;;
+ "stop")
+ stop_simulator;;
+ "status")
+ print_status;;
+ "logs")
+ get_logs;;
+ "help")
+ print_help;;
+ *)
+ print_help;;
+ esac
+}
+
+function build_image(){
+ if [ -f pom.xml ]; then
+ mvn clean package
+ else
+ echo "pom.xml file not found"
+ exit 1
+ fi
+}
+
+function start_simulator(){
+
+ stop_and_remove_container || true
+
+ if [ $(docker run -d --name $CONTAINER_NAME -v $(pwd):/config -e VES_ADDRESS=$1 -e CONFIG_FILE_PATH=$2 $3) > /dev/null ]; then
+ echo "Simulator started"
+ else
+ echo "Failed to start simulator"
+ fi
+}
+
+function stop_and_remove_container(){
+ docker rm -f $CONTAINER_NAME 1> /dev/null
+}
+
+function stop_simulator(){
+ if [ $(docker kill $CONTAINER_NAME) > /dev/null ]; then
+ echo "Simulator stopped"
+ else
+ echo "Failed to stop simulator"
+ fi
+
+}
+
+function print_status(){
+cat << EndOfMessage
+
+Simulator container status:
+
+$(docker ps -a -f name=$CONTAINER_NAME)
+
+EndOfMessage
+}
+
+function print_help(){
+cat << EndOfMessage
+
+Available options:
+build - locally builds simulator image from existing code
+start <ves-url> - starts simulator using remote docker image and connects to given VES server
+start-dev <ves-url> - starts simulator using local docker image and connects to given VES server
+stop - stops simulator
+status - prints container status
+logs - prints logs
+help - prints this message
+
+Starting simulation:
+Use "./simulator.sh start". It will download required docker image from the internet and start simulator using body.json file
+
+To stop simulation use "./simulator.sh stop" command. To check simulator's status use "./simulator.sh status".
+If you want to change message parameters simply edit body.json file then run simulator again.
+
+FOR DEVELOPERS
+1. Build local simulator image using "./simulator.sh build"
+2. Run simulation with "./simulator.sh start-dev"
+
+If you change the source code you have to rebuild image with "./simulator.sh build" and run "./simulator.sh start-dev" again
+
+EndOfMessage
+}
+
+function get_logs(){
+ docker logs --tail all $CONTAINER_NAME
+}
+
+main $@ \ No newline at end of file