Update scripts to populate policy data for E2E testing of nonrtric
[it/dep.git] / nonrtric / data / run_in_k8s / populate_policy_data.sh
1 #!/bin/bash
2
3 #  ============LICENSE_START===============================================
4 #  Copyright (C) 2020 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 service in policy agent
23 # one policy-type and one policy in a1-sim-OSC_0
24 # one policy in a1-sim-STD_0 (with no policy-type)
25 # one policy-type and one policy in a1-sim-STD2_0
26
27 policy_agent_host="policymanagementservice"
28 policy_agent_port="9080"
29 a1_sim_osc_0_host="a1-sim-osc-0.a1-sim"
30 a1_sim_osc_0_port="8085"
31 a1_sim_osc_1_host="a1-sim-osc-1.a1-sim"
32 a1_sim_osc_1_port="8085"
33 a1_sim_std_0_host="a1-sim-std-0.a1-sim"
34 a1_sim_std_0_port="8085"
35 a1_sim_std_1_host="a1-sim-std-1.a1-sim"
36 a1_sim_std_1_port="8085"
37 a1_sim_std2_0_host="a1-sim-std2-0.a1-sim"
38 a1_sim_std2_0_port="8085"
39 a1_sim_std2_1_host="a1-sim-std2-1.a1-sim"
40 a1_sim_std2_1_port="8085"
41 httpx=http
42
43 echo "policy agent status:"
44 curl -skw " %{http_code}" $httpx://$policy_agent_host:$policy_agent_port/status
45 echo -e "\n"
46
47 echo "ric1 version:"
48 curl -skw " %{http_code}" $httpx://$a1_sim_osc_0_host:$a1_sim_osc_0_port/counter/interface
49 echo -e "\n"
50
51 echo "ric2 version:"
52 curl -skw " %{http_code}" $httpx://$a1_sim_osc_1_host:$a1_sim_osc_1_port/counter/interface
53 echo -e "\n"
54
55 echo "ric3 version:"
56 curl -skw " %{http_code}" $httpx://$a1_sim_std_0_host:$a1_sim_std_0_port/counter/interface
57 echo -e "\n"
58
59 echo "ric4 version:"
60 curl -skw " %{http_code}" $httpx://$a1_sim_std_1_host:$a1_sim_std_1_port/counter/interface
61 echo -e "\n"
62
63 echo "ric5 version:"
64 curl -skw " %{http_code}" $httpx://$a1_sim_std2_0_host:$a1_sim_std_0_port/counter/interface
65 echo -e "\n"
66
67 echo "ric6 version:"
68 curl -skw " %{http_code}" $httpx://$a1_sim_std2_1_host:$a1_sim_std_1_port/counter/interface
69 echo -e "\n"
70
71 echo "create policy type 1 to ric1:"
72 curl -X PUT -skw " %{http_code}" $httpx://$a1_sim_osc_0_host:$a1_sim_osc_0_port/policytype?id=1 -H Content-Type:application/json --data-binary @testdata/OSC/policy_type.json
73 echo -e "\n"
74
75 echo "create policy type 1 to ric2:"
76 curl -X PUT -skw " %{http_code}" $httpx://$a1_sim_osc_1_host:$a1_sim_osc_1_port/policytype?id=1 -H Content-Type:application/json --data-binary @testdata/OSC/policy_type.json
77 echo -e "\n"
78
79 echo "create policy type 2 to STD2 ric5:"
80 curl -X PUT -skw " %{http_code}" $httpx://$a1_sim_std2_0_host:$a1_sim_std2_0_port/policytype?id=2 -H Content-Type:application/json --data-binary @testdata/STD/v2/policy_type.json
81 echo -e "\n"
82
83 echo "create policy type 2 to STD2 ric6:"
84 curl -X PUT -skw " %{http_code}" $httpx://$a1_sim_std2_1_host:$a1_sim_std2_1_port/policytype?id=2 -H Content-Type:application/json --data-binary @testdata/STD/v2/policy_type.json
85 echo -e "\n"
86
87 for i in {1..12}; do
88         echo "policy types from policy agent:"
89     curlString="curl -skw %{http_code} $httpx://$policy_agent_host:$policy_agent_port/a1-policy/v2/policy-types"
90     res=$($curlString)
91     echo "$res"
92     expect="{\"policytype_ids\":[\"\",\"1\",\"2\"]}200"
93     if [ "$res" == "$expect" ]; then
94         echo -e "\n"
95         break;
96     else
97         sleep $i
98     fi
99 done
100
101 echo "create service1 to policy agent:"
102 curl -k -X PUT -sw " %{http_code}" -H accept:application/json -H Content-Type:application/json "$httpx://$policy_agent_host:$policy_agent_port/a1-policy/v2/services" --data-binary @testdata/service.json
103 echo -e "\n"
104
105 echo "create policy aa8feaa88d944d919ef0e83f2172a5000 to ric1 with type1 and service1 via policy agent:"
106 curl -k -X PUT -sw " %{http_code}" -H accept:application/json -H Content-Type:application/json "$httpx://$policy_agent_host:$policy_agent_port/a1-policy/v2/policies" --data-binary @testdata/OSC/policy.json
107 echo -e "\n"
108
109 echo "create policy aa8feaa88d944d919ef0e83f2172a5100 to ric3 with service1 via policy agent, no type:"
110 curl -k -X PUT -sw " %{http_code}" -H accept:application/json -H Content-Type:application/json "$httpx://$policy_agent_host:$policy_agent_port/policy?id=aa8feaa88d944d919ef0e83f2172a5100&ric=ric3&service=service1" --data-binary @testdata/STD/v1/policy.json
111 echo -e "\n"
112
113 echo "create policy aa8feaa88d944d919ef0e83f2172a5200 to ric5 with type2 and service1 via policy agent:"
114 curl -k -X PUT -sw " %{http_code}" -H accept:application/json -H Content-Type:application/json "$httpx://$policy_agent_host:$policy_agent_port/a1-policy/v2/policies" --data-binary @testdata/STD/v2/policy.json
115 echo -e "\n"
116
117 echo "policy numbers from ric1:"
118 curl -skw " %{http_code}" $httpx://$a1_sim_osc_0_host:$a1_sim_osc_0_port/counter/num_instances
119 echo -e "\n"
120
121 echo "policy numbers from ric3:"
122 curl -skw " %{http_code}" $httpx://$a1_sim_std_0_host:$a1_sim_std_0_port/counter/num_instances
123 echo -e "\n"
124
125 echo "policy numbers from ric5:"
126 curl -skw " %{http_code}" $httpx://$a1_sim_std2_0_host:$a1_sim_std2_0_port/counter/num_instances
127 echo -e "\n"
128
129 echo "policy id aa8feaa88d944d919ef0e83f2172a5000 from policy agent:"
130 curl -k -X GET -sw " %{http_code}" $httpx://$policy_agent_host:$policy_agent_port/a1-policy/v2/policies/aa8feaa88d944d919ef0e83f2172a5000
131 echo -e "\n"
132
133 echo "policy id aa8feaa88d944d919ef0e83f2172a5100 from policy agent:"
134 curl -k -X GET -sw " %{http_code}" $httpx://$policy_agent_host:$policy_agent_port/a1-policy/v2/policies/aa8feaa88d944d919ef0e83f2172a5100
135 echo -e "\n"
136
137 echo "policy id aa8feaa88d944d919ef0e83f2172a5200 from policy agent:"
138 curl -k -X GET -sw " %{http_code}" $httpx://$policy_agent_host:$policy_agent_port/a1-policy/v2/policies/aa8feaa88d944d919ef0e83f2172a5200
139 echo -e "\n"
140