ecaiyanlinux | 426ce5f | 2020-05-30 15:17:59 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # ============LICENSE_START=============================================== |
ecaiyanlinux | 192aa4e | 2021-06-06 00:13:42 +0800 | [diff] [blame] | 4 | # Copyright (C) 2021 Nordix Foundation. All rights reserved. |
ecaiyanlinux | 426ce5f | 2020-05-30 15:17:59 +0200 | [diff] [blame] | 5 | # ======================================================================== |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # ============LICENSE_END================================================= |
| 18 | # |
| 19 | |
| 20 | # The scripts in data/ will generate some dummy data in the running system. |
| 21 | # It will create: |
| 22 | # one policy type in a1-sim-OSC |
| 23 | # one service in policy agent |
| 24 | # one policy in a1-sim-OSC |
| 25 | # one policy in a1-sim-STD |
| 26 | |
| 27 | # Run command: |
ecaiyanlinux | 192aa4e | 2021-06-06 00:13:42 +0800 | [diff] [blame] | 28 | # ./preparePmsData.sh [policy-agent port] [a1-sim-OSC port] [a1-sim-STD port] [http/https] |
ecaiyanlinux | 426ce5f | 2020-05-30 15:17:59 +0200 | [diff] [blame] | 29 | |
| 30 | policy_agent_port=${1:-8081} |
| 31 | a1_sim_OSC_port=${2:-30001} |
ecaiyanlinux | 192aa4e | 2021-06-06 00:13:42 +0800 | [diff] [blame] | 32 | a1_sim_STD_port=${3:-30005} |
| 33 | httpx=${4:-"http"} |
| 34 | SHELL_FOLDER=$(cd "$(dirname "$0")";pwd) |
ecaiyanlinux | 426ce5f | 2020-05-30 15:17:59 +0200 | [diff] [blame] | 35 | |
| 36 | echo "using policy_agent port: "$policy_agent_port |
| 37 | echo "using a1-sim-OSC port: "$a1_sim_OSC_port |
| 38 | echo "using a1-sim-STD port: "$a1_sim_STD_port |
| 39 | echo "using protocol: "$httpx |
| 40 | echo -e "\n" |
| 41 | |
ecaiyanlinux | 192aa4e | 2021-06-06 00:13:42 +0800 | [diff] [blame] | 42 | checkRes (){ |
| 43 | if [ "$res" != "$expect" ]; then |
| 44 | echo "$res is not expected! exit!" |
| 45 | exit 1; |
| 46 | fi |
| 47 | } |
| 48 | |
ecaiyanlinux | 426ce5f | 2020-05-30 15:17:59 +0200 | [diff] [blame] | 49 | echo "policy agent status:" |
ecaiyanlinux | 192aa4e | 2021-06-06 00:13:42 +0800 | [diff] [blame] | 50 | curlString="curl -skw %{http_code} $httpx://localhost:$policy_agent_port/status" |
| 51 | res=$($curlString) |
| 52 | echo "$res" |
| 53 | expect="hunky dory200" |
| 54 | checkRes |
ecaiyanlinux | 426ce5f | 2020-05-30 15:17:59 +0200 | [diff] [blame] | 55 | echo -e "\n" |
| 56 | |
| 57 | echo "ric1 version:" |
ecaiyanlinux | 192aa4e | 2021-06-06 00:13:42 +0800 | [diff] [blame] | 58 | curlString="curl -skw %{http_code} $httpx://localhost:$a1_sim_OSC_port/counter/interface" |
| 59 | res=$($curlString) |
| 60 | echo "$res" |
| 61 | expect="OSC_2.1.0200" |
| 62 | checkRes |
ecaiyanlinux | 426ce5f | 2020-05-30 15:17:59 +0200 | [diff] [blame] | 63 | echo -e "\n" |
| 64 | |
| 65 | echo "ric2 version:" |
ecaiyanlinux | 192aa4e | 2021-06-06 00:13:42 +0800 | [diff] [blame] | 66 | curlString="curl -skw %{http_code} $httpx://localhost:$a1_sim_STD_port/counter/interface" |
| 67 | res=$($curlString) |
| 68 | echo "$res" |
| 69 | expect="STD_2.0.0200" |
| 70 | checkRes |
ecaiyanlinux | 426ce5f | 2020-05-30 15:17:59 +0200 | [diff] [blame] | 71 | echo -e "\n" |
| 72 | |
| 73 | echo "create policy type 1 to ric1:" |
ecaiyanlinux | 192aa4e | 2021-06-06 00:13:42 +0800 | [diff] [blame] | 74 | curlString="curl -X PUT -skw %{http_code} $httpx://localhost:$a1_sim_OSC_port/policytype?id=1 -H Content-Type:application/json --data-binary @${SHELL_FOLDER}/testdata/OSC/policy_type.json" |
| 75 | res=$($curlString) |
| 76 | echo "$res" |
| 77 | expect="Policy type 1 is OK.201" |
| 78 | checkRes |
ecaiyanlinux | 30f931f | 2020-11-10 22:45:48 +0100 | [diff] [blame] | 79 | echo -e "\n" |
| 80 | |
ecaiyanlinux | 192aa4e | 2021-06-06 00:13:42 +0800 | [diff] [blame] | 81 | echo "create policy type 2 to ric2:" |
| 82 | curlString="curl -skw %{http_code} $httpx://localhost:$a1_sim_STD_port/policytype?id=2 -X PUT -H Accept:application/json -H Content-Type:application/json -H X-Requested-With:XMLHttpRequest --data-binary @${SHELL_FOLDER}/testdata/v2/policy_type.json" |
| 83 | res=$($curlString) |
| 84 | echo "$res" |
| 85 | expect="Policy type 2 is OK.201" |
| 86 | checkRes |
ecaiyanlinux | 426ce5f | 2020-05-30 15:17:59 +0200 | [diff] [blame] | 87 | echo -e "\n" |
| 88 | |
ecaiyanlinux | 192aa4e | 2021-06-06 00:13:42 +0800 | [diff] [blame] | 89 | for i in {1..60}; do |
ecaiyanlinux | 426ce5f | 2020-05-30 15:17:59 +0200 | [diff] [blame] | 90 | echo "policy types from policy agent:" |
ecaiyanlinux | 30f931f | 2020-11-10 22:45:48 +0100 | [diff] [blame] | 91 | curlString="curl -skw %{http_code} $httpx://localhost:$policy_agent_port/a1-policy/v2/policy-types" |
ecaiyanlinux | 426ce5f | 2020-05-30 15:17:59 +0200 | [diff] [blame] | 92 | res=$($curlString) |
| 93 | echo "$res" |
ecaiyanlinux | 30f931f | 2020-11-10 22:45:48 +0100 | [diff] [blame] | 94 | expect="{\"policytype_ids\":[\"\",\"1\",\"2\"]}200" |
ecaiyanlinux | 426ce5f | 2020-05-30 15:17:59 +0200 | [diff] [blame] | 95 | if [ "$res" == "$expect" ]; then |
| 96 | echo -e "\n" |
| 97 | break; |
| 98 | else |
| 99 | sleep $i |
| 100 | fi |
| 101 | done |
| 102 | |
ecaiyanlinux | 30f931f | 2020-11-10 22:45:48 +0100 | [diff] [blame] | 103 | echo "create service ric-registration to policy agent:" |
ecaiyanlinux | 192aa4e | 2021-06-06 00:13:42 +0800 | [diff] [blame] | 104 | curlString="curl -k -X PUT -sw %{http_code} -H accept:application/json -H Content-Type:application/json "$httpx://localhost:$policy_agent_port/a1-policy/v2/services" --data-binary @${SHELL_FOLDER}/testdata/v2/service.json" |
| 105 | res=$($curlString) |
| 106 | echo "$res" |
| 107 | expect="201" |
| 108 | checkRes |
ecaiyanlinux | 426ce5f | 2020-05-30 15:17:59 +0200 | [diff] [blame] | 109 | echo -e "\n" |
| 110 | |
ecaiyanlinux | 30f931f | 2020-11-10 22:45:48 +0100 | [diff] [blame] | 111 | echo "create policy aa8feaa88d944d919ef0e83f2172a5000 to ric1 with type 1 and service controlpanel via policy agent:" |
ecaiyanlinux | 192aa4e | 2021-06-06 00:13:42 +0800 | [diff] [blame] | 112 | curlString="curl -k -X PUT -sw %{http_code} -H accept:application/json -H Content-Type:application/json "$httpx://localhost:$policy_agent_port/a1-policy/v2/policies" --data-binary @${SHELL_FOLDER}/testdata/v2/policy_osc.json" |
| 113 | res=$($curlString) |
| 114 | echo "$res" |
| 115 | expect="201" |
| 116 | checkRes |
ecaiyanlinux | 426ce5f | 2020-05-30 15:17:59 +0200 | [diff] [blame] | 117 | echo -e "\n" |
| 118 | |
| 119 | echo "policy numbers from ric1:" |
ecaiyanlinux | 192aa4e | 2021-06-06 00:13:42 +0800 | [diff] [blame] | 120 | curlString="curl -skw %{http_code} $httpx://localhost:$a1_sim_OSC_port/counter/num_instances" |
| 121 | res=$($curlString) |
| 122 | echo "$res" |
| 123 | expect="1200" |
| 124 | checkRes |
ecaiyanlinux | 426ce5f | 2020-05-30 15:17:59 +0200 | [diff] [blame] | 125 | echo -e "\n" |
| 126 | |
ecaiyanlinux | 30f931f | 2020-11-10 22:45:48 +0100 | [diff] [blame] | 127 | echo "create policy aa8feaa88d944d919ef0e83f2172a5100 to ric2 with type 2 and service controlpanel via policy agent:" |
ecaiyanlinux | 192aa4e | 2021-06-06 00:13:42 +0800 | [diff] [blame] | 128 | curlString="curl -k -X PUT -sw %{http_code} -H accept:application/json -H Content-Type:application/json "$httpx://localhost:$policy_agent_port/a1-policy/v2/policies" --data-binary @${SHELL_FOLDER}/testdata/v2/policy_std_v2.json" |
| 129 | res=$($curlString) |
| 130 | echo "$res" |
| 131 | expect="201" |
| 132 | checkRes |
ecaiyanlinux | 426ce5f | 2020-05-30 15:17:59 +0200 | [diff] [blame] | 133 | echo -e "\n" |
| 134 | |
ecaiyanlinux | 192aa4e | 2021-06-06 00:13:42 +0800 | [diff] [blame] | 135 | echo "policy numbers from ric2:" |
| 136 | curlString="curl -skw %{http_code} $httpx://localhost:$a1_sim_STD_port/counter/num_instances" |
| 137 | res=$($curlString) |
| 138 | echo "$res" |
| 139 | expect="1200" |
| 140 | checkRes |
ecaiyanlinux | 426ce5f | 2020-05-30 15:17:59 +0200 | [diff] [blame] | 141 | echo -e "\n" |
| 142 | |
ecaiyanlinux | 30f931f | 2020-11-10 22:45:48 +0100 | [diff] [blame] | 143 | echo "policy id aa8feaa88d944d919ef0e83f2172a5000 from policy agent:" |
ecaiyanlinux | 192aa4e | 2021-06-06 00:13:42 +0800 | [diff] [blame] | 144 | curlString="curl -s -o /dev/null -I -w %{http_code} $httpx://localhost:$policy_agent_port/a1-policy/v2/policies/aa8feaa88d944d919ef0e83f2172a5000" |
| 145 | res=$($curlString) |
| 146 | echo "$res" |
| 147 | expect="200" |
| 148 | checkRes |
ecaiyanlinux | 426ce5f | 2020-05-30 15:17:59 +0200 | [diff] [blame] | 149 | echo -e "\n" |
| 150 | |
ecaiyanlinux | 30f931f | 2020-11-10 22:45:48 +0100 | [diff] [blame] | 151 | echo "policy id aa8feaa88d944d919ef0e83f2172a5100 from policy agent:" |
ecaiyanlinux | 192aa4e | 2021-06-06 00:13:42 +0800 | [diff] [blame] | 152 | curlString="curl -s -o /dev/null -I -w %{http_code} $httpx://localhost:$policy_agent_port/a1-policy/v2/policies/aa8feaa88d944d919ef0e83f2172a5100" |
| 153 | res=$($curlString) |
| 154 | echo "$res" |
| 155 | expect="200" |
| 156 | checkRes |
| 157 | echo -e "\n" |