blob: bc1ad97e613d3736bca33ccb524aa0c0c4c11984 [file] [log] [blame]
ecaiyanlinux426ce5f2020-05-30 15:17:59 +02001#!/bin/bash
2
3# ============LICENSE_START===============================================
ecaiyanlinux192aa4e2021-06-06 00:13:42 +08004# Copyright (C) 2021 Nordix Foundation. All rights reserved.
ecaiyanlinux426ce5f2020-05-30 15:17:59 +02005# ========================================================================
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:
ecaiyanlinux192aa4e2021-06-06 00:13:42 +080028# ./preparePmsData.sh [policy-agent port] [a1-sim-OSC port] [a1-sim-STD port] [http/https]
ecaiyanlinux426ce5f2020-05-30 15:17:59 +020029
30policy_agent_port=${1:-8081}
31a1_sim_OSC_port=${2:-30001}
ecaiyanlinux192aa4e2021-06-06 00:13:42 +080032a1_sim_STD_port=${3:-30005}
33httpx=${4:-"http"}
34SHELL_FOLDER=$(cd "$(dirname "$0")";pwd)
ecaiyanlinux426ce5f2020-05-30 15:17:59 +020035
36echo "using policy_agent port: "$policy_agent_port
37echo "using a1-sim-OSC port: "$a1_sim_OSC_port
38echo "using a1-sim-STD port: "$a1_sim_STD_port
39echo "using protocol: "$httpx
40echo -e "\n"
41
ecaiyanlinux192aa4e2021-06-06 00:13:42 +080042checkRes (){
43 if [ "$res" != "$expect" ]; then
44 echo "$res is not expected! exit!"
45 exit 1;
46 fi
47}
48
ecaiyanlinux426ce5f2020-05-30 15:17:59 +020049echo "policy agent status:"
ecaiyanlinux192aa4e2021-06-06 00:13:42 +080050curlString="curl -skw %{http_code} $httpx://localhost:$policy_agent_port/status"
51res=$($curlString)
52echo "$res"
53expect="hunky dory200"
54checkRes
ecaiyanlinux426ce5f2020-05-30 15:17:59 +020055echo -e "\n"
56
57echo "ric1 version:"
ecaiyanlinux192aa4e2021-06-06 00:13:42 +080058curlString="curl -skw %{http_code} $httpx://localhost:$a1_sim_OSC_port/counter/interface"
59res=$($curlString)
60echo "$res"
61expect="OSC_2.1.0200"
62checkRes
ecaiyanlinux426ce5f2020-05-30 15:17:59 +020063echo -e "\n"
64
65echo "ric2 version:"
ecaiyanlinux192aa4e2021-06-06 00:13:42 +080066curlString="curl -skw %{http_code} $httpx://localhost:$a1_sim_STD_port/counter/interface"
67res=$($curlString)
68echo "$res"
69expect="STD_2.0.0200"
70checkRes
ecaiyanlinux426ce5f2020-05-30 15:17:59 +020071echo -e "\n"
72
73echo "create policy type 1 to ric1:"
ecaiyanlinux192aa4e2021-06-06 00:13:42 +080074curlString="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"
75res=$($curlString)
76echo "$res"
77expect="Policy type 1 is OK.201"
78checkRes
ecaiyanlinux30f931f2020-11-10 22:45:48 +010079echo -e "\n"
80
ecaiyanlinux192aa4e2021-06-06 00:13:42 +080081echo "create policy type 2 to ric2:"
82curlString="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"
83res=$($curlString)
84echo "$res"
85expect="Policy type 2 is OK.201"
86checkRes
ecaiyanlinux426ce5f2020-05-30 15:17:59 +020087echo -e "\n"
88
ecaiyanlinux192aa4e2021-06-06 00:13:42 +080089for i in {1..60}; do
ecaiyanlinux426ce5f2020-05-30 15:17:59 +020090 echo "policy types from policy agent:"
ecaiyanlinux30f931f2020-11-10 22:45:48 +010091 curlString="curl -skw %{http_code} $httpx://localhost:$policy_agent_port/a1-policy/v2/policy-types"
ecaiyanlinux426ce5f2020-05-30 15:17:59 +020092 res=$($curlString)
93 echo "$res"
ecaiyanlinux30f931f2020-11-10 22:45:48 +010094 expect="{\"policytype_ids\":[\"\",\"1\",\"2\"]}200"
ecaiyanlinux426ce5f2020-05-30 15:17:59 +020095 if [ "$res" == "$expect" ]; then
96 echo -e "\n"
97 break;
98 else
99 sleep $i
100 fi
101done
102
ecaiyanlinux30f931f2020-11-10 22:45:48 +0100103echo "create service ric-registration to policy agent:"
ecaiyanlinux192aa4e2021-06-06 00:13:42 +0800104curlString="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"
105res=$($curlString)
106echo "$res"
107expect="201"
108checkRes
ecaiyanlinux426ce5f2020-05-30 15:17:59 +0200109echo -e "\n"
110
ecaiyanlinux30f931f2020-11-10 22:45:48 +0100111echo "create policy aa8feaa88d944d919ef0e83f2172a5000 to ric1 with type 1 and service controlpanel via policy agent:"
ecaiyanlinux192aa4e2021-06-06 00:13:42 +0800112curlString="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"
113res=$($curlString)
114echo "$res"
115expect="201"
116checkRes
ecaiyanlinux426ce5f2020-05-30 15:17:59 +0200117echo -e "\n"
118
119echo "policy numbers from ric1:"
ecaiyanlinux192aa4e2021-06-06 00:13:42 +0800120curlString="curl -skw %{http_code} $httpx://localhost:$a1_sim_OSC_port/counter/num_instances"
121res=$($curlString)
122echo "$res"
123expect="1200"
124checkRes
ecaiyanlinux426ce5f2020-05-30 15:17:59 +0200125echo -e "\n"
126
ecaiyanlinux30f931f2020-11-10 22:45:48 +0100127echo "create policy aa8feaa88d944d919ef0e83f2172a5100 to ric2 with type 2 and service controlpanel via policy agent:"
ecaiyanlinux192aa4e2021-06-06 00:13:42 +0800128curlString="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"
129res=$($curlString)
130echo "$res"
131expect="201"
132checkRes
ecaiyanlinux426ce5f2020-05-30 15:17:59 +0200133echo -e "\n"
134
ecaiyanlinux192aa4e2021-06-06 00:13:42 +0800135echo "policy numbers from ric2:"
136curlString="curl -skw %{http_code} $httpx://localhost:$a1_sim_STD_port/counter/num_instances"
137res=$($curlString)
138echo "$res"
139expect="1200"
140checkRes
ecaiyanlinux426ce5f2020-05-30 15:17:59 +0200141echo -e "\n"
142
ecaiyanlinux30f931f2020-11-10 22:45:48 +0100143echo "policy id aa8feaa88d944d919ef0e83f2172a5000 from policy agent:"
ecaiyanlinux192aa4e2021-06-06 00:13:42 +0800144curlString="curl -s -o /dev/null -I -w %{http_code} $httpx://localhost:$policy_agent_port/a1-policy/v2/policies/aa8feaa88d944d919ef0e83f2172a5000"
145res=$($curlString)
146echo "$res"
147expect="200"
148checkRes
ecaiyanlinux426ce5f2020-05-30 15:17:59 +0200149echo -e "\n"
150
ecaiyanlinux30f931f2020-11-10 22:45:48 +0100151echo "policy id aa8feaa88d944d919ef0e83f2172a5100 from policy agent:"
ecaiyanlinux192aa4e2021-06-06 00:13:42 +0800152curlString="curl -s -o /dev/null -I -w %{http_code} $httpx://localhost:$policy_agent_port/a1-policy/v2/policies/aa8feaa88d944d919ef0e83f2172a5100"
153res=$($curlString)
154echo "$res"
155expect="200"
156checkRes
157echo -e "\n"