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