Improve nonrtric CSIT
[integration/csit.git] / plans / ccsdk-oran / polmansuite / data / preparePmsData.sh
1 #!/bin/bash
2
3 #  ============LICENSE_START===============================================
4 #  Copyright (C) 2021 Nordix Foundation. All rights reserved.
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:
28 # ./preparePmsData.sh [policy-agent port] [a1-sim-OSC port] [a1-sim-STD port] [http/https]
29
30 policy_agent_port=${1:-8081}
31 a1_sim_OSC_port=${2:-30001}
32 a1_sim_STD_port=${3:-30003}
33 httpx=${4:-"http"}
34 SHELL_FOLDER=$(cd "$(dirname "$0")";pwd)
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
42 checkRes (){
43   if [ "$res" != "$expect" ]; then
44       echo "$res is not expected! exit!"
45       exit 1;
46   fi
47 }
48
49 echo "policy agent status:"
50 curlString="curl -skw %{http_code} $httpx://localhost:$policy_agent_port/status"
51 res=$($curlString)
52 echo "$res"
53 expect="hunky dory200"
54 checkRes
55 echo -e "\n"
56
57 echo "ric1 version:"
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
63 echo -e "\n"
64
65 echo "ric2 version:"
66 curlString="curl -skw %{http_code} $httpx://localhost:$a1_sim_STD_port/counter/interface"
67 res=$($curlString)
68 echo "$res"
69 expect="STD_1.1.3200"
70 checkRes
71 echo -e "\n"
72
73 echo "create policy type 1 to ric1:"
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
79 echo -e "\n"
80
81
82 for i in {1..30}; do
83         echo "policy types from policy agent:"
84     curlString="curl -skw %{http_code} $httpx://localhost:$policy_agent_port/v2/policy-types"
85     res=$($curlString)
86     echo "$res"
87     expect="{\"policy_type_ids\":[\"\",\"1\"]}200"
88     if [ "$res" == "$expect" ]; then
89         echo -e "\n"
90         break;
91     else
92         sleep $i
93     fi
94 done
95
96 echo "create service 1 to policy agent:"
97 curlString="curl -k -X PUT -sw  %{http_code} -H accept:application/json -H Content-Type:application/json $httpx://localhost:$policy_agent_port/service --data-binary @testdata/service.json"
98 res=$($curlString)
99 echo $res
100 expect="OK201"
101 checkRes
102 echo -e "\n"
103
104 echo "create policy 2000 to ric1 with type1 and service1 via policy agent:"
105 curlString="curl -k -X PUT -sw %{http_code} -H accept:application/json -H Content-Type:application/json $httpx://localhost:$policy_agent_port/policy?id=2000&ric=ric1&service=service1&type=1 --data-binary @testdata/policy.json"
106 res=$($curlString)
107 echo $res
108 expect="201"
109 checkRes
110 echo -e "\n"
111
112 echo "policy numbers from ric1:"
113 curlString="curl -skw %{http_code} $httpx://localhost:$a1_sim_OSC_port/counter/num_instances"
114 res=$($curlString)
115 echo $res
116 expect="1200"
117 checkRes
118 echo -e "\n"
119
120 echo "create policy 2100 to ric2 with service1 via policy agent, no type:"
121 curlString="curl -k -X PUT -sw %{http_code} -H accept:application/json -H Content-Type:application/json $httpx://localhost:$policy_agent_port/policy?id=2100&ric=ric2&service=service1 --data-binary @testdata/policy.json"
122 res=$($curlString)
123 echo $res
124 expect="201"
125 checkRes
126 echo -e "\n"
127
128 echo "policy numbers from ric2:"
129 curlString="curl -skw %{http_code} $httpx://localhost:$a1_sim_STD_port/counter/num_instances"
130 res=$($curlString)
131 echo $res
132 expect="1200"
133 checkRes
134 echo -e "\n"
135
136 echo "policy id 2000 from policy agent:"
137 curlString="curl -s -o /dev/null -I -w %{http_code} $httpx://localhost:$policy_agent_port/policy?id=2000"
138 res=$($curlString)
139 echo $res
140 expect="200"
141 checkRes
142 echo -e "\n"
143
144 echo "policy id 2100 from policy agent:"
145 curlString="curl -s -o /dev/null -I -w %{http_code} $httpx://localhost:$policy_agent_port/policy?id=2100"
146 res=$($curlString)
147 echo $res
148 expect="200"
149 checkRes
150 echo -e "\n"