diff options
author | sourabh_sourabh <sourabh.sourabh@est.tech> | 2023-03-20 15:53:44 +0000 |
---|---|---|
committer | sourabh_sourabh <sourabh.sourabh@est.tech> | 2023-03-20 15:55:40 +0000 |
commit | cb237058c5863253473671602806129dd6046ab5 (patch) | |
tree | e61e574ae95d0c9b3efe445c301456df06fe277a /test-tools/test-deregistration.sh | |
parent | 9c8b57d4ff1c8a70c65d04694cb1c164c5e770ad (diff) |
Script to fully automate CM-handle de-registration
Issue-ID: CPS-1552
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: Ie1ea0cf410f78f1a8675c30d2e278a407afc0d0a
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Diffstat (limited to 'test-tools/test-deregistration.sh')
-rwxr-xr-x | test-tools/test-deregistration.sh | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/test-tools/test-deregistration.sh b/test-tools/test-deregistration.sh new file mode 100755 index 0000000000..bf38e3b24c --- /dev/null +++ b/test-tools/test-deregistration.sh @@ -0,0 +1,162 @@ +#!/bin/bash +# +# Copyright 2023 Nordix Foundation. +# +# 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. +# + +set -o errexit # Exit on most errors +set -o nounset # Disallow expansion of unset variables +set -o pipefail # Use last non-zero exit code in a pipeline +#set -o xtrace # Uncomment for debugging + +GRAB_METRICS=true +DOCKER_COMPOSE_FILE=../docker-compose/docker-compose.yml +CREATE_REQUEST=/tmp/cmhandles-create-req.txt +REMOVE_REQUEST=/tmp/cmhandles-remove-req.txt +REPORT_FILE=metrics-reports/deregister-summary-$(date --iso-8601=seconds).tsv + +stop_docker() { + docker-compose -f $DOCKER_COMPOSE_FILE down >/dev/null + docker container prune -f >/dev/null + docker volume prune -f >/dev/null +} + +restart_docker() { + stop_docker + docker-compose -f $DOCKER_COMPOSE_FILE --profile dmi-stub --profile monitoring up -d >/dev/null +} + +wait_for_cps_to_start() { + docker logs cps-and-ncmp -f | grep -m 1 'Started Application' >/dev/null || true +} + +get_number_of_handles_ready() { + PGPASSWORD=cps psql -h localhost -p 5432 cpsdb cps -c \ + "SELECT count(*) FROM public.fragment where attributes @> '{\"cm-handle-state\": \"READY\"}';" \ + | sed '3!d' | sed 's/ *//' +} + +wait_for_handles_to_be_ready() { + local TOTAL_HANDLES=$1 + while + sleep 30 + HANDLES_READY=$(get_number_of_handles_ready) + echo "There are $HANDLES_READY CM handles in READY state." + [ $HANDLES_READY -ne $TOTAL_HANDLES ] + do true; done +} + +create_handles() { + curl --fail --silent --show-error \ + --location 'http://localhost:8883/ncmpInventory/v1/ch' \ + --header 'Authorization: Basic Y3BzdXNlcjpjcHNyMGNrcyE=' \ + --header 'Content-Type: application/json' \ + --data @$CREATE_REQUEST +} + +remove_handles_and_record_time() { + curl --fail --silent --show-error --output /dev/null --write-out '%{time_total}\n' \ + --location 'http://localhost:8883/ncmpInventory/v1/ch' \ + --header 'Authorization: Basic Y3BzdXNlcjpjcHNyMGNrcyE=' \ + --header 'Content-Type: application/json' \ + --header 'Cookie: JSESSIONID=node018g80wfn6qfk9yihx8pne7bc31.node0' \ + --data @$REMOVE_REQUEST >> $REPORT_FILE +} + +create_request_bodies() { + local CREATE_SIZE=$1 + local REMOVE_SIZE=$2 + echo -n '{"dmiPlugin": "http://ncmp-dmi-plugin-stub:8783","createdCmHandles":[' > $CREATE_REQUEST + echo -n '{"dmiPlugin": "http://ncmp-dmi-plugin-stub:8783","removedCmHandles":[' > $REMOVE_REQUEST + for i in $(seq 1 $CREATE_SIZE); do + local CMHANDLE=$(uuidgen | tr -d '-') + echo -n "{\"cmHandle\": \"$CMHANDLE\",\"cmHandleProperties\":{\"neType\":\"RadioNode\"}}" \ + >> $CREATE_REQUEST + if [ $i -lt $CREATE_SIZE ]; then + echo -n "," >> $CREATE_REQUEST + fi + if [ $i -le $REMOVE_SIZE ]; then + echo -n "\"$CMHANDLE\"" >> $REMOVE_REQUEST + fi + if [ $i -lt $REMOVE_SIZE ]; then + echo -n "," >> $REMOVE_REQUEST + fi + done + echo ']}' >> $CREATE_REQUEST + echo ']}' >> $REMOVE_REQUEST +} + +test_deregistration() { + local REMOVE_SIZE=$1 + local CREATE_SIZE=$2 + + echo "Testing deregistration of $REMOVE_SIZE out of $CREATE_SIZE CM handles" + + echo "Restarting docker" + restart_docker + echo "Waiting for CPS to start" + wait_for_cps_to_start + + echo "Creating request bodies" + create_request_bodies $CREATE_SIZE $REMOVE_SIZE + + echo "[$(date --iso-8601=seconds)] Creating CM handles" + create_handles + echo "Waiting for CM handles to be in READY state" + wait_for_handles_to_be_ready $CREATE_SIZE + + if [ "$GRAB_METRICS" = "true" ]; then + echo "Grabbing metrics before deregistration" + METRICS_BEFORE=$(./generate-metrics-report.sh) + fi + + echo "[$(date --iso-8601=seconds)] Removing CM handles" + echo -e -n "$REMOVE_SIZE\t$CREATE_SIZE\t" >> $REPORT_FILE + remove_handles_and_record_time + echo "There are $(get_number_of_handles_ready) CM handles still in READY state." + + if [ "$GRAB_METRICS" = "true" ]; then + echo "Grabbing metrics after deregistration" + METRICS_AFTER=$(./generate-metrics-report.sh) + echo "Generating metrics report" + ./subtract-metrics-reports.py -a $METRICS_AFTER -b $METRICS_BEFORE \ + -o metrics-reports/deregister-$(date --iso-8601=seconds)-$REMOVE_SIZE-$CREATE_SIZE.tsv + rm $METRICS_BEFORE $METRICS_AFTER + fi + + echo +} + +cleanup() { + rm -f "$CREATE_REQUEST" "$REMOVE_REQUEST" + stop_docker +} +trap cleanup EXIT + +mkdir -p $(dirname $REPORT_FILE) +echo -e "Removed\tTotal\tTime" > $REPORT_FILE + +# Delete N/N: 100/100, 200/200... 20000/20000 +for number_to_delete in 100 200 300 400 500 600 700 800 900 1000 2000 3000 4000 5000 10000 15000 20000; do + test_deregistration $number_to_delete $number_to_delete +done +# Delete N/C: 1000/5000, 2000/5000... 5000/5000 +for number_to_delete in 1000 2000 3000 4000 5000; do + test_deregistration $number_to_delete 5000 +done +# Delete C/N: 1000/1000, 1000/2000... 1000/5000 +for total in 1000 2000 3000 4000 5000; do + test_deregistration 1000 $total +done + |