blob: 62b2f4ceb3523619f1d6d230ce268c4f0a3b23f9 [file] [log] [blame]
Kailash8394cff2019-04-29 09:19:22 -07001*** Settings ***
2Documentation Setup and Teardown Functionality for XOS API Tests
3Library Collections
4Library String
5Library OperatingSystem
6Library XML
7Library RequestsLibrary
8Library HttpLibrary.HTTP
9Library ../Framework/utils/utils.py
10Library ../Framework/restApi.py
11Variables ../Properties/RestApiProperties.py
12
13*** Variables ***
14${test_string} teststring
15${test_string2} teststring2
16${test_float} 3.14
17${test_role} admin
18${test_direction} in
19${test_flavor} m1.small
20${test_vlan_tag} 1000
21${test_email} testuser@opencord.org
22${test_int32} 100
23${test_uint32} 100
24${test_ip_address} 2.2.2.2
25
26*** Keywords ***
27Verify API Functionality
28 [Arguments] ${type} ${endpoint} ${data}=${EMPTY} ${data_id}=${EMPTY} ${key}=${EMPTY}
29 Run Keyword If "${type}" == "RETRIEVE" CORD Get ${endpoint} ${data_id} ${data} ${key}
30 Run Keyword If "${type}" == "CREATE" CORD Post ${endpoint} ${data}
31 Run Keyword If "${type}" == "UPDATE" CORD Put ${endpoint} ${data} ${data_id}
32 Run Keyword If "${type}" == "DELETE" CORD Delete ${endpoint} ${data_id}
33
34CORD Get
35 [Documentation] Make a GET call to the CORD controller
36 [Arguments] ${service} ${id} ${value} ${key}
37 ${resp}= Get Request ${SERVER_IP} ${service}/${id}
38 Log ${resp.content}
39 Should Be Equal As Strings ${resp.status_code} 200
40 ${updated_value}= Run Keyword If '${key}' != 'null' Get Json Value ${resp.content} /${key}
41 ${updated_value}= Run Keyword If '${key}' != 'null' Remove String ${updated_value} "
42 Run Keyword If '${key}' != 'null' Should Contain "${value}" ${updated_value}
43 [Return] ${resp}
44
45CORD Post
46 [Documentation] Make a POST call to the CORD controller
47 [Arguments] ${service} ${data}
48 ${data}= Evaluate json.dumps(${data}) json
49 ${resp}= Post Request ${SERVER_IP} uri=${service} data=${data}
50 Log ${resp.content}
51 Should Be Equal As Strings ${resp.status_code} 200
52 ${id}= Get Json Value ${resp.content} /id
53 Set Suite Variable ${id}
54 [Return] ${resp}
55
56CORD Put
57 [Documentation] Make a PUT call to the CORD controller
58 [Arguments] ${service} ${data} ${data_id}
59 ${data}= Evaluate json.dumps(${data}) json
60 ${resp}= Put Request ${SERVER_IP} uri=${service}/${data_id} data=${data}
61 Log ${resp.content}
62 Should Be Equal As Strings ${resp.status_code} 200
63 ${id}= Get Json Value ${resp.content} /id
64 Set Suite Variable ${id}
65 [Return] ${resp}
66
67CORD Delete
68 [Documentation] Make a DELETE call to the CORD controller
69 [Arguments] ${service} ${data_id}
70 ${resp}= Delete Request ${SERVER_IP} uri=${service}/${data_id}
71 Log ${resp.content}
72 Should Be Equal As Strings ${resp.status_code} 200
73 [Return] ${resp}
74
75Generate JSON Data
76 {%- for m in proto.messages -%}
77 {%- if m.name not in ['XOSBase'] -%}
78 {% autoescape false %}
79 {% endautoescape %}
80 ${json_{{ m.name | lower }}_1}= Set Variable { }
81 ${json_{{ m.name | lower }}_amend_1}= Set Variable { }
82 ${json_{{ m.name | lower}}_amend_key}= Set Variable null
83 Set Suite Variable ${json_{{ m.name | lower}}_amend_key}
84 # set required fields for {{ m.name | lower }} object
85 {% for f in m.fields + xproto_base_fields(m, proto.message_table) -%}
86 {% if f.modifier == "required" and f.options.blank != "True" -%}
87 {% if not f.options.default -%}
88 {% if f.link -%}
Kailash24ec4792019-05-15 14:47:30 -070089 ## check if dependent model exists, if not, create it
90 ${tmp_{{ f.options.model | lower }}_id}= Create Dependent Model {{ f.options.model }}
91 #${tmp_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
Kailash8394cff2019-04-29 09:19:22 -070092 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }}_id ${tmp_{{ f.options.model | lower }}_id}
93 {% elif f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
94 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${test_float}"
95 {% elif f.name == "role" -%}
96 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${test_role}"
97 {% elif f.name == "direction" -%}
98 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${test_direction}"
99 {% elif f.name == "flavor" -%}
100 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${test_flavor}"
101 {% elif f.name == "s_tag" and m.name == "BNGPortMapping" -%}
102 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${test_vlan_tag}"
103 {% else -%}
104 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${test_{{ f.type }}}"
105 {% if f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
106 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${test_float}"
107 {% else -%}
108 {% if loop.index0 == 0 -%}
109 ${json_{{ m.name | lower}}_amend_key}= Set Variable {{ f.name }}
110 ${json_{{ m.name | lower }}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /{{ f.name }} "${test_{{ f.type }}}"
111 {% endif -%}
112 {% endif -%}
113 {% endif -%}
114 {% endif -%}
115 {% endif -%}
116 {% endfor -%}
117 {% if m.name == "User" -%}
118 ${json_{{ m.name | lower}}_email}= Set Variable testuser@opencord.org
119 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /email "${json_{{ m.name | lower }}_email}"
120 ${json_{{ m.name | lower}}_email_amend_1}= Set Variable testuseramend@opencord.org
121 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /email "${json_{{ m.name | lower }}_email_amend_1}"
122 {% endif %}
123 {% if m.name == "Site" -%}
124 ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase
125 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /login_base "${json_{{ m.name | lower }}_login_base_tmp}"
126 {% endif %}
127 {% if m.name == "Flavor" -%}
128 ${json_{{ m.name | lower}}_flavor_tmp}= Set Variable m1.small
129 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /flavor "${json_{{ m.name | lower }}_flavor_tmp}"
130 {% endif %}
131 {% if m.name == "ServiceGraphConstraint" -%}
132 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /constraints "${test_string}"
133 {% endif %}
134 {% if m.name == "Slice" -%}
135 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /name "testloginbase"
136 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /name "testloginbase2"
137 {% endif -%}
138 {% if m.name == "ProgranServiceInstance" -%}
139 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /name "${test_string}"
140 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /CellIndividualOffset "1"
141 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /name "${test_string}"
142 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /CellIndividualOffset "1"
143 {% endif %}
144 {% if m.name == "RCORDSubscriber" -%}
Kailashc0557322019-05-22 16:13:02 -0700145 ## Create req service owner for rcord subscriber
146 Create Dependent Owner Model /xosapi/v1/rcord/rcordservices {"name": "testrcordservice", "access": "unknown"}
Kailash8394cff2019-04-29 09:19:22 -0700147 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /owner_id ${id}
148 ${rcord_tmp_service_id}= Set Variable ${id}
149 Set Suite Variable ${rcord_tmp_service_id}
150 {% endif %}
151 {% if m.name == "HippieOSSServiceInstance" -%}
152 ## Create req service owner for hippie oss service instance
Kailashc0557322019-05-22 16:13:02 -0700153 Create Dependent Owner Model /xosapi/v1/hippie-oss/hippieossservices {"name": "testhippieservice"}
Kailash8394cff2019-04-29 09:19:22 -0700154 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /owner_id ${id}
155 {% endif %}
156 {% if m.name == "MCordSubscriberInstance" -%}
157 ## Create req service owner for hippie oss service instance
Kailashc0557322019-05-22 16:13:02 -0700158 Create Dependent Owner Model /xosapi/v1/mcord/mcordsubscriberservices {"name": "testmcordservice"}
Kailash8394cff2019-04-29 09:19:22 -0700159 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /owner_id ${id}
160 {% endif %}
161 {% if m.name == "AddressManagerServiceInstance" -%}
162 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /public_ip "2.2.2.2"
163 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /public_ip "3.3.3.3"
164 {% endif %}
165 {% if m.name == "RCORDIpAddress" -%}
166 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /ip "2.2.2.2"
167 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /ip "3.3.3.3"
168 {% endif %}
Kailash415a0142019-05-15 15:51:48 -0700169 {% if m.name == "ONUDevice" -%}
170 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /serial_number "testserialnumber"
171 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /serial_number "amendserialnumber"
172 {% endif %}
Kailash1a1ad5c2019-06-20 14:08:14 -0700173 {% if m.name == "TechnologyProfile" -%}
174 ${json_profile}= Set Variable {\\\"test\\\":\\\"test\\\"}
175 ${json_profile2}= Set Variable {\\\"test2\\\":\\\"test2\\\"}
176 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /profile_value "${json_profile}"
177 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /profile_value "${json_profile2}"
178 {% endif %}
Kailash8394cff2019-04-29 09:19:22 -0700179 ${json_{{ m.name | lower }}_1}= To JSON ${json_{{ m.name | lower }}_1}
180 ${json_{{ m.name | lower }}_amend_1}= To JSON ${json_{{ m.name | lower }}_amend_1}
181 Set Suite Variable ${json_{{ m.name | lower }}_1}
182 Set Suite Variable ${json_{{ m.name | lower }}_amend_1}
183 {% endif -%}
184 {% endfor %}
185
186{% for m in proto.messages %}
187{%- if m.name not in ['XOSBase'] -%}
188Create {{ m.name }}
189 ##Creating {{ m.name | lower }} object
190 ${json_{{ m.name | lower }}_tmp}= Set Variable { }
191 # set required fields for {{ m.name | lower }} object
192 {% for f in m.fields + xproto_base_fields(m, proto.message_table) -%}
193 {% if f.link -%}
194 {% if f.modifier == "required" and f.options.blank != "True"-%}
195 # create dependent {{ f.options.model }}
Kailash24ec4792019-05-15 14:47:30 -0700196 ## check if dependent model exists, if not, create it
197 ${dependent_{{ f.options.model | lower }}_id}= Create Dependent Model {{ f.options.model }}
198 #${tmp_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
199 #${dependent_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
Kailash8394cff2019-04-29 09:19:22 -0700200 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }}_id ${dependent_{{ f.options.model | lower }}_id}
201 {% endif -%}
202 {% else -%}
203 {% if f.modifier == "required" and f.options.blank != "True"-%}
204 {% if not f.options.default -%}
205 {% if m.name == "User" and f.name == "email" -%}
206 ${json_user_tmp}= Set Json Value ${json_user_tmp} /email "${test_email}"
207 {% else -%}
208 {% if f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
209 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${test_float}"
210 {% elif f.name == "name" -%}
211 ${json_{{ m.name | lower}}_name_tmp}= Generate Random Value {{ f.type }}
212 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_name_tmp}"
213 {% elif f.name == "role" -%}
214 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${test_role}"
215 {% elif f.name == "direction" -%}
216 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${test_direction}"
217 {% elif f.name == "flavor" -%}
218 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${test_flavor}"
219 {% elif f.name == "s_tag" and m.name == "BNGPortMapping" -%}
220 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${test_vlan_tag}"
221 {% else -%}
222 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${test_{{ f.type }}}"
223 {% endif -%}
224 {% endif -%}
225 {% endif -%}
226 {% endif -%}
227 {% endif -%}
228 {% endfor -%}
229 {% if m.name == "Site" -%}
230 ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase3
231 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /login_base "${json_{{ m.name | lower }}_login_base_tmp}"
232 {% endif %}
233 {% if m.name == "Flavor" -%}
234 ${json_{{ m.name | lower}}_flavor_tmp}= Set Variable m1.small
235 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /flavor "${json_{{ m.name | lower }}_flavor_tmp}"
236 {% endif %}
237 {% if m.name == "ServiceGraphConstraint" -%}
238 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /contraints "${test_string}"
239 {% endif %}
240 {% if m.name == "Slice" -%}
241 ${json_{{ m.name | lower}}_name}= Generate Random Slice Name
242 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /name "${json_{{ m.name | lower}}_name}"
243 {% endif -%}
244 {% if m.name == "Network" -%}
245 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /permit_all_slices true
246 {% endif %}
247 {% if m.name == "RCORDSubscriber" -%}
248 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /owner_id ${rcord_tmp_service_id}
249 {% endif %}
Kailash1a1ad5c2019-06-20 14:08:14 -0700250 {% if m.name == "TechnologyProfile" -%}
251 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /profile_value {'testprofile':'profiletest'}
252 {% endif %}
Kailash8394cff2019-04-29 09:19:22 -0700253 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /no_policy true
Kailash24ec4792019-05-15 14:47:30 -0700254 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /no_sync true
Kailash8394cff2019-04-29 09:19:22 -0700255 ${json_{{ m.name | lower }}_tmp}= To JSON ${json_{{ m.name | lower }}_tmp}
256 ${resp}= CORD Post /xosapi/v1/{{ xproto_unquote(m.options.app_label) }}/{{ xproto_pluralize(m) | lower}} ${json_{{ m.name | lower }}_tmp}
257 ${id_{{ m.name | lower }}_tmp}= Get Json Value ${resp.content} /id
258 Append To List ${dependent_{{ m.name | lower }}_ids} ${id_{{ m.name | lower }}_tmp}
259 [Return] ${id_{{ m.name | lower }}_tmp}
260{% endif %}
261{% endfor -%}
262
Kailash24ec4792019-05-15 14:47:30 -0700263Create Dependent Model
264 [Arguments] ${model}
265 ${result} ${id}= Run Keyword And Ignore Error Create ${model}
266 ${model_id}= Set Variable If "${result}" == "PASS" ${id} 1
267 [Return] ${model_id}
268
Kailashc0557322019-05-22 16:13:02 -0700269Create Dependent Owner Model
270 [Arguments] ${model} ${data}
271 ${condition} ${modelId}= Check If Model Exists ${model}
272 ${resp}= Run Keyword Unless ${condition} CORD Post ${model} ${data}
273 ${id}= Run Keyword Unless ${condition} Get Json Value ${resp.content} /id
274 ${model_id}= Set Variable If ${condition} ${modelId} ${id}
275 [Return] ${model_id}
276
277Check If Model Exists
278 [Arguments] ${service}
279 ${resp}= Get Request ${SERVER_IP} ${service}
280 Log ${resp.content}
281 Should Be Equal As Strings ${resp.status_code} 200
282 ${jsondata}= To Json ${resp.content}
283 ${length}= Get Length ${jsondata['items']}
284 ${value}= Run Keyword If ${length} Get From List ${jsondata['items']} 0
285 ${modelId}= Run Keyword If ${length} Get From Dictionary ${value} id
286 Run Keyword If ${length} Return From Keyword True ${modelId}
287 [Return] False ${NONE}
288
Kailash8394cff2019-04-29 09:19:22 -0700289Setup Tests
290 [Documentation] Find all dependent objects per model and create them and store them for later use
291 {% for m in proto.messages %}
292 {%- if m.name not in ['XOSBase'] -%}
293 ${model}= Set Variable {{ m.name | lower }}s
294 @{dependent_{{ m.name | lower }}_ids}= Create List ${model}
295 Set Suite Variable @{dependent_{{ m.name | lower }}_ids}
296 {% endif -%}
297 {% endfor -%}
298 @{dependent_models}= Create List
299 Set Suite Variable ${dependent_models}
300 ${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
301 ${HEADERS} Create Dictionary Content-Type=application/json
302 Create Session ${SERVER_IP} http://${SERVER_IP}:${SERVER_PORT} auth=${AUTH} headers=${HEADERS}
303 Generate JSON Data
304
305Teardown Tests
306 [Documentation] Delete all dependent objects created in Setup
307 {% for m in proto.messages %}
308 {%- if m.name not in ['XOSBase'] -%}
309 ${len}= Get Length ${dependent_{{ m.name | lower }}_ids}
310 : FOR ${INDEX} IN RANGE 1 ${len}
311 \ Run Keyword And Ignore Error CORD Delete /xosapi/v1/{{ xproto_unquote(m.options.app_label) }}/${dependent_{{ m.name | lower }}_ids[0]} ${dependent_{{ m.name | lower }}_ids[${INDEX}]}
312 {% endif -%}
313 {% endfor -%}
314 Delete All Sessions
Kailash24ec4792019-05-15 14:47:30 -0700315