Add test folder to the smo package installation
[it/dep.git] / smo-install / test / a1-validation / subscripts / prepareDmaapMsg.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 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 # ./prepareDmaapMsg.sh [dmaap-mr url] [a1-sim-OSC url] [a1-sim-STD url] [a1-sim-STD2 url] [http/https]
29
30 dmaap_mr_url=${1:-localhost:3904}
31 a1_sim_OSC_url=${2:-localhost:8085}
32 a1_sim_STD_url=${3:-localhost:8085}
33 a1_sim_STD_v2_url=${4:-localhost:8085}
34 policy_agent_url=${5:-localhost:9081}
35 httpx=${6:-"http"}
36
37 echo "using dmaap-mr url: "$dmaap_mr_url
38 echo "using a1-sim-OSC url: "$a1_sim_OSC_url
39 echo "using a1-sim-STD url: "$a1_sim_STD_url
40 echo "using a1-sim-STD-v2 url: "$a1_sim_STD_v2_url
41 echo "using policy-agent url: "$policy_agent_url
42 echo "using protocol: "$httpx
43 echo -e "\n"
44
45 echo "dmaap-mr topics: $httpx://$dmaap_mr_url/topics/listAll"
46 curl -skw %{http_code} $httpx://$dmaap_mr_url/topics/listAll
47 echo -e "\n"
48
49 echo "dmaap-mr create topic A1-POLICY-AGENT-READ:"
50 curl -skw %{http_code} -X POST "$httpx://$dmaap_mr_url/topics/create" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{  \"topicName\": \"A1-POLICY-AGENT-READ\",  \"topicDescription\": \"test topic\",  \"partitionCount\": 1,  \"replicationCount\": 1,  \"transactionEnabled\": \"false\"}"
51 echo -e "\n"
52
53 echo "dmaap-mr create topic A1-POLICY-AGENT-WRITE:"
54 curl -skw %{http_code} -X POST "$httpx://$dmaap_mr_url/topics/create" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{  \"topicName\": \"A1-POLICY-AGENT-WRITE\",  \"topicDescription\": \"test topic\",  \"partitionCount\": 1,  \"replicationCount\": 1,  \"transactionEnabled\": \"false\"}"
55 echo -e "\n"
56
57 echo "dmaap-mr topics:"
58 curl -skw %{http_code} $httpx://$dmaap_mr_url/topics/listAll
59 echo -e "\n"
60
61 echo "ric1 version:"
62 curl -skw %{http_code} $httpx://$a1_sim_OSC_url/counter/interface
63 echo -e "\n"
64
65 echo "ric2 version:"
66 curl -skw %{http_code} $httpx://$a1_sim_STD_url/counter/interface
67 echo -e "\n"
68
69 echo "ric3 version:"
70 curl -skw %{http_code} $httpx://$a1_sim_STD_v2_url/counter/interface
71 echo -e "\n"
72
73 echo "create policy type 1 to ric1:"
74 curl -X PUT -skw %{http_code} $httpx://$a1_sim_OSC_url/policytype?id=1 -H Content-Type:application/json --data-binary @../data/OSC/policy_type.json
75 echo -e "\n"
76
77 echo "create policy type 2 to ric3:"
78 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 @../data/v2/policy_type.json
79 echo -e "\n"
80
81 for i in {1..60}; do
82         echo "policy types from policy agent:"
83     curlString="curl -skw %{http_code} $httpx://$policy_agent_url/policy_types"
84     res=$($curlString)
85     echo "$res"
86     expect="[\"\",\"1\",\"2\"]200"
87     if [ "$res" == "$expect" ]; then
88         echo -e "\n"
89         break;
90     else
91         sleep $i
92     fi
93 done
94
95 ## Using PMS v1 interface
96 echo "create service 1 to policy agent via dmaap_mr:"
97 curl -k -X POST -sw %{http_code} -H accept:application/json -H Content-Type:application/json "$httpx://$dmaap_mr_url/events/A1-POLICY-AGENT-READ/" --data-binary @../data/dmaap/v1/dmaap-msg-service-create.json
98 echo -e "\n"
99
100 echo "get result from mr of previous request:"
101 curl -X GET "$httpx://$dmaap_mr_url/events/A1-POLICY-AGENT-WRITE/users/policy-agent?timeout=15000&limit=100" -H "accept: application/json" -H "Content-Type: application/json" | jq .
102 echo -e "\n"
103
104 echo "create policies to ric1 & ric2 & ric3 with type1 and service1 via dmaa_mr:"
105 curl -k -X POST -sw %{http_code} -H accept:application/json -H Content-Type:application/json "$httpx://$dmaap_mr_url/events/A1-POLICY-AGENT-READ/" --data-binary @../data/dmaap/v1/dmaap-msg-policy-create.json
106 echo -e "\n"
107
108 echo "get result from mr of previous request:"
109 curl -X GET "$httpx://$dmaap_mr_url/events/A1-POLICY-AGENT-WRITE/users/policy-agent?timeout=15000&limit=100" -H "accept: application/json" -H "Content-Type: application/json" | jq .
110 echo -e "\n"
111
112 echo "get policy from policy agent via dmaap_mr:"
113 curl -k -X POST -sw %{http_code} -H accept:application/json -H Content-Type:application/json "$httpx://$dmaap_mr_url/events/A1-POLICY-AGENT-READ/" --data-binary @../data/dmaap/v1/dmaap-msg-policy-get.json
114 echo -e "\n"
115
116 echo "get result from mr of previous request:"
117 curl -X GET "$httpx://$dmaap_mr_url/events/A1-POLICY-AGENT-WRITE/users/policy-agent?timeout=15000&limit=100" -H "accept: application/json" -H "Content-Type: application/json" | jq .
118 echo -e "\n"
119
120 ## Using PMS v2 interface
121 echo "create service 2 to policy agent via dmaap_mr:"
122 curl -k -X POST -sw %{http_code} -H accept:application/json -H Content-Type:application/json "$httpx://$dmaap_mr_url/events/A1-POLICY-AGENT-READ/" --data-binary @../data/dmaap/v2/dmaap-msg-service-create.json
123 echo -e "\n"
124
125 echo "get result from mr of previous request:"
126 curl -X GET "$httpx://$dmaap_mr_url/events/A1-POLICY-AGENT-WRITE/users/policy-agent?timeout=15000&limit=100" -H "accept: application/json" -H "Content-Type: application/json" | jq .
127 echo -e "\n"
128
129 echo "create policies to ric1 & ric2 & ric3 with type1 and service1 via dmaa_mr:"
130 curl -k -X POST -sw %{http_code} -H accept:application/json -H Content-Type:application/json "$httpx://$dmaap_mr_url/events/A1-POLICY-AGENT-READ/" --data-binary @../data/dmaap/v2/dmaap-msg-policy-create.json
131 echo -e "\n"
132
133 echo "get result from mr of previous request:"
134 curl -X GET "$httpx://$dmaap_mr_url/events/A1-POLICY-AGENT-WRITE/users/policy-agent?timeout=15000&limit=100" -H "accept: application/json" -H "Content-Type: application/json" | jq .
135 echo -e "\n"
136
137 echo "get policy from policy agent via dmaap_mr:"
138 curl -k -X POST -sw %{http_code} -H accept:application/json -H Content-Type:application/json "$httpx://$dmaap_mr_url/events/A1-POLICY-AGENT-READ/" --data-binary @../data/dmaap/v2/dmaap-msg-policy-get.json
139 echo -e "\n"
140
141 echo "get result from mr of previous request:"
142 curl -X GET "$httpx://$dmaap_mr_url/events/A1-POLICY-AGENT-WRITE/users/policy-agent?timeout=15000&limit=100" -H "accept: application/json" -H "Content-Type: application/json" | jq .
143 echo -e "\n"
144
145 ## Get metric from rics
146 echo "policy numbers from ric1:"
147 curl -skw %{http_code} $httpx://$a1_sim_OSC_url/counter/num_instances
148 echo -e "\n"
149
150 echo "policy numbers from ric2:"
151 curl -skw %{http_code} $httpx://$a1_sim_STD_url/counter/num_instances
152 echo -e "\n"
153
154 echo "policy numbers from ric3:"
155 curl -skw %{http_code} $httpx://$a1_sim_STD_v2_url/counter/num_instances
156 echo -e "\n"
157