blob: 49194817cc1fcaa32b22b6a95df35bd95f07748c [file] [log] [blame]
sebdetedc7d502021-11-08 15:58:31 +01001#!/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 [a1-sim-OSC url] [a1-sim-STD-2 url] [policy agent url] [http/https]
29
30a1_sim_OSC_url=${1:-localhost:8085}
31a1_sim_STD_v2_url=${2:-localhost:8085}
32policy_agent_url=${3:-localhost:9081}
33httpx=${4:-"http"}
34SHELL_FOLDER=$(cd "$(dirname "$0")";pwd)
35
36echo "using a1-sim-OSC url: "$a1_sim_OSC_url
37echo "using a1-sim-STD-v2 url: "$a1_sim_STD_v2_url
38echo "using policy-agent url: "$policy_agent_url
39echo "using protocol: "$httpx
40echo -e "\n"
41
42checkRes (){
43 if [[ $res != *"$expect"* ]]; then
44 if [ "$res" != "$expect2" ]; then
45 echo "$res is not expected! exit!"
46 exit 1;
47 fi
48 fi
49}
50
51echo "policy agent status:"
52curlString="curl -skw %{http_code} $httpx://$policy_agent_url/status"
53res=$($curlString)
54echo "$res"
55expect="hunky dory200"
56checkRes
57echo -e "\n"
58
59echo "ric1 version:"
60curlString="curl -skw %{http_code} $httpx://$a1_sim_OSC_url/counter/interface"
61res=$($curlString)
62echo "$res"
63expect="OSC_2.1.0200"
64checkRes
65echo -e "\n"
66
67echo "ric2 version:"
68curlString="curl -skw %{http_code} $httpx://$a1_sim_STD_v2_url/counter/interface"
69res=$($curlString)
70echo "$res"
71expect="STD_2.0.0200"
72checkRes
73echo -e "\n"
74
75echo "create policy type 1 to ric1:"
76curlString="curl -X PUT -skw %{http_code} $httpx://$a1_sim_OSC_url/policytype?id=1 -H Content-Type:application/json --data-binary @${SHELL_FOLDER}/../data/OSC/policy_type.json"
77res=$($curlString)
78echo "$res"
79expect="Policy type 1 is OK"
80expect2="The policy type already exists and instances exists400"
81checkRes
82echo -e "\n"
83
84echo "create policy type 2 to ric2:"
85curlString="curl -skw %{http_code} $httpx://$a1_sim_STD_v2_url/policytype?id=2 -X PUT -H Accept:application/json -H Content-Type:application/json -H X-Requested-With:XMLHttpRequest --data-binary @${SHELL_FOLDER}/../data/v2/policy_type.json"
86res=$($curlString)
87echo "$res"
88expect="Policy type 2 is OK"
89expect2="The policy type already exists and instances exists400"
90checkRes
91echo -e "\n"
92
93for i in {1..60}; do
94 echo "policy types from policy agent:"
95 curlString="curl -skw %{http_code} $httpx://$policy_agent_url/a1-policy/v2/policy-types"
96 res=$($curlString)
97 echo "$res"
98 expect="{\"policytype_ids\":[\"\",\"1\",\"2\"]}200"
99 if [ "$res" == "$expect" ]; then
100 echo -e "\n"
101 break;
102 else
103 sleep $i
104 fi
105done
106
107echo "create service ric-registration to policy agent:"
108curlString="curl -k -X PUT -sw %{http_code} -H accept:application/json -H Content-Type:application/json "$httpx://$policy_agent_url/a1-policy/v2/services" --data-binary @${SHELL_FOLDER}/../data/v2/service.json"
109res=$($curlString)
110echo "$res"
111expect="201"
112expect2="200"
113checkRes
114echo -e "\n"
115
116echo "create policy aa8feaa88d944d919ef0e83f2172a5000 to ric1 with type 1 and service controlpanel via policy agent:"
117curlString="curl -k -X PUT -sw %{http_code} -H accept:application/json -H Content-Type:application/json "$httpx://$policy_agent_url/a1-policy/v2/policies" --data-binary @${SHELL_FOLDER}/../data/v2/policy_osc.json"
118res=$($curlString)
119echo "$res"
120expect="201"
121expect2="200"
122checkRes
123echo -e "\n"
124
125sleep 5
126echo "policy numbers from ric1:"
127curlString="curl -skw %{http_code} $httpx://$a1_sim_OSC_url/counter/num_instances"
128res=$($curlString)
129echo "$res"
130expect="7200"
131checkRes
132echo -e "\n"
133
134echo "create policy aa8feaa88d944d919ef0e83f2172a5100 to ric2 with type 2 and service controlpanel via policy agent:"
135curlString="curl -k -X PUT -sw %{http_code} -H accept:application/json -H Content-Type:application/json "$httpx://$policy_agent_url/a1-policy/v2/policies" --data-binary @${SHELL_FOLDER}/../data/v2/policy_std_v2.json"
136res=$($curlString)
137echo "$res"
138expect="201"
139expect2="200"
140checkRes
141echo -e "\n"
142
143echo "policy numbers from ric2:"
144curlString="curl -skw %{http_code} $httpx://$a1_sim_STD_v2_url/counter/num_instances"
145res=$($curlString)
146echo "$res"
147expect="1200"
148checkRes
149echo -e "\n"
150
151echo "policy id aa8feaa88d944d919ef0e83f2172a5000 from policy agent:"
152curlString="curl -s -o /dev/null -I -w %{http_code} $httpx://$policy_agent_url/a1-policy/v2/policies/aa8feaa88d944d919ef0e83f2172a5000"
153res=$($curlString)
154echo "$res"
155expect="200"
156checkRes
157echo -e "\n"
158
159echo "policy id aa8feaa88d944d919ef0e83f2172a5100 from policy agent:"
160curlString="curl -s -o /dev/null -I -w %{http_code} $httpx://$policy_agent_url/a1-policy/v2/policies/aa8feaa88d944d919ef0e83f2172a5100"
161res=$($curlString)
162echo "$res"
163expect="200"
164checkRes
165echo -e "\n"