|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +source "$(dirname "$0")/helper.sh" |
| 4 | +enable_strict_mode |
| 5 | + |
| 6 | +############################# |
| 7 | +## amoc REST API functions ## |
| 8 | +############################# |
| 9 | + |
| 10 | +function node_list() { |
| 11 | + local nodes=( "$@" ) nodes_json="" node= |
| 12 | + if [ "${#nodes[@]}" -gt "0" ]; then |
| 13 | + nodes_json+='"nodes": ["'"${nodes[0]}"'"' |
| 14 | + for node in "${nodes[@]:1}"; do |
| 15 | + nodes_json+=', "'"$node"'"' |
| 16 | + done |
| 17 | + nodes_json+='], ' |
| 18 | + fi |
| 19 | + echo -n "$nodes_json" |
| 20 | +} |
| 21 | + |
| 22 | +function add_users() { |
| 23 | + local port="$(amoc_container_port "$1")" # $1 - where to send request |
| 24 | + local n="$2" # $2 - number of users to add |
| 25 | + shift 2 |
| 26 | + local nodes="$(node_list "$@")" |
| 27 | + local json_body="{ ${nodes} \"users\": $n}" |
| 28 | + curl -X PATCH --header 'Content-Type: application/json' --header 'Accept: application/json' \ |
| 29 | + -s -w " %{http_code}" -d "$json_body" "http://localhost:${port}/execution/add_users" |
| 30 | +} |
| 31 | + |
| 32 | +function remove_users() { |
| 33 | + local port="$(amoc_container_port "$1")" # $1 - where to send request |
| 34 | + local n="$2" # $2 - number of users to add |
| 35 | + shift 2 |
| 36 | + local nodes="$(node_list "$@")" |
| 37 | + local json_body="{ ${nodes} \"users\": $n}" |
| 38 | + curl -X PATCH --header 'Content-Type: application/json' --header 'Accept: application/json' \ |
| 39 | + -s -w " %{http_code}" -d "$json_body" "http://localhost:${port}/execution/remove_users" |
| 40 | +} |
| 41 | + |
| 42 | + |
| 43 | +echo "adding users to nodes" |
| 44 | +add_users amoc-master 6 "amoc_arsenal@amoc-worker-3" | contains 200 |
| 45 | +add_users amoc-master 2 "amoc_arsenal@"{"amoc-worker-1","amoc-worker-2"} | contains 200 |
| 46 | +add_users amoc-master 15 | contains 200 ## add 5 users on each node |
| 47 | +add_users amoc-worker-3 15 | contains 500 '"error":"not_a_master"' |
| 48 | + |
| 49 | +echo "checking status of the nodes" |
| 50 | +sleep 1 ## 1 second is enough to start 11 |
| 51 | +get_status amoc-master | contains '"amoc_status":"up"' \ |
| 52 | + '"status":"disabled"' |
| 53 | +worker_status=( '"amoc_status":"up"' |
| 54 | + '"status":"running"' |
| 55 | + '"scenario":"dummy_scenario"' |
| 56 | + '"test":"<<\\"test_value\\">>"' |
| 57 | + '"interarrival":"50"' ) |
| 58 | +get_status amoc-worker-1 | contains "${worker_status[@]}" '"number_of_users":11' |
| 59 | +get_status amoc-worker-2 | contains "${worker_status[@]}" '"number_of_users":11' |
| 60 | +get_status amoc-worker-3 | contains "${worker_status[@]}" '"number_of_users":11' |
| 61 | + |
| 62 | +echo "removing users from nodes" |
| 63 | + ## remove all the users from amoc-worker-3 |
| 64 | +remove_users amoc-master 11 "amoc_arsenal@amoc-worker-3" | contains 200 |
| 65 | +remove_users amoc-master 2 "amoc_arsenal@"{"amoc-worker-1","amoc-worker-2"} | contains 200 |
| 66 | +sleep 3 ## two seconds is a shutdown period for a forced users removal. |
| 67 | + ## so we must wait before removing the next chunk of users, |
| 68 | + ## otherwise the same users can be selected for removal twice. |
| 69 | +remove_users amoc-master 15 | contains 200 ## remove 5 users from each node |
| 70 | +remove_users amoc-worker-3 15 | contains 500 '"error":"not_a_master"' |
| 71 | + |
| 72 | +echo "checking status of the nodes" |
| 73 | +sleep 3 ## 2 seconds is a shutdown period for a forced users removal. |
| 74 | +get_status amoc-master | contains '"amoc_status":"up"' \ |
| 75 | + '"status":"disabled"' |
| 76 | +get_status amoc-worker-1 | contains "${worker_status[@]}" '"number_of_users":5' |
| 77 | +get_status amoc-worker-2 | contains "${worker_status[@]}" '"number_of_users":5' |
| 78 | +get_status amoc-worker-3 | contains "${worker_status[@]}" '"number_of_users":0' |
0 commit comments