blob: 6c28b552334b21e1c6ec67ef6044b4351eec03b1 [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" -%}
145 ## Create req service owner for rcord subscriber and
146 CORD Post /xosapi/v1/rcord/rcordservices {"name": "testrcordservice", "access": "unknown"}
147 ${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
153 CORD Post /xosapi/v1/hippie-oss/hippieossservices {"name": "testhippieservice"}
154 ${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
158 CORD Post /xosapi/v1/mcord/mcordsubscriberservices {"name": "testmcordservice"}
159 ${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 %}
169 ${json_{{ m.name | lower }}_1}= To JSON ${json_{{ m.name | lower }}_1}
170 ${json_{{ m.name | lower }}_amend_1}= To JSON ${json_{{ m.name | lower }}_amend_1}
171 Set Suite Variable ${json_{{ m.name | lower }}_1}
172 Set Suite Variable ${json_{{ m.name | lower }}_amend_1}
173 {% endif -%}
174 {% endfor %}
175
176{% for m in proto.messages %}
177{%- if m.name not in ['XOSBase'] -%}
178Create {{ m.name }}
179 ##Creating {{ m.name | lower }} object
180 ${json_{{ m.name | lower }}_tmp}= Set Variable { }
181 # set required fields for {{ m.name | lower }} object
182 {% for f in m.fields + xproto_base_fields(m, proto.message_table) -%}
183 {% if f.link -%}
184 {% if f.modifier == "required" and f.options.blank != "True"-%}
185 # create dependent {{ f.options.model }}
Kailash24ec4792019-05-15 14:47:30 -0700186 ## check if dependent model exists, if not, create it
187 ${dependent_{{ f.options.model | lower }}_id}= Create Dependent Model {{ f.options.model }}
188 #${tmp_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
189 #${dependent_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
Kailash8394cff2019-04-29 09:19:22 -0700190 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }}_id ${dependent_{{ f.options.model | lower }}_id}
191 {% endif -%}
192 {% else -%}
193 {% if f.modifier == "required" and f.options.blank != "True"-%}
194 {% if not f.options.default -%}
195 {% if m.name == "User" and f.name == "email" -%}
196 ${json_user_tmp}= Set Json Value ${json_user_tmp} /email "${test_email}"
197 {% else -%}
198 {% if f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
199 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${test_float}"
200 {% elif f.name == "name" -%}
201 ${json_{{ m.name | lower}}_name_tmp}= Generate Random Value {{ f.type }}
202 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_name_tmp}"
203 {% elif f.name == "role" -%}
204 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${test_role}"
205 {% elif f.name == "direction" -%}
206 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${test_direction}"
207 {% elif f.name == "flavor" -%}
208 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${test_flavor}"
209 {% elif f.name == "s_tag" and m.name == "BNGPortMapping" -%}
210 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${test_vlan_tag}"
211 {% else -%}
212 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${test_{{ f.type }}}"
213 {% endif -%}
214 {% endif -%}
215 {% endif -%}
216 {% endif -%}
217 {% endif -%}
218 {% endfor -%}
219 {% if m.name == "Site" -%}
220 ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase3
221 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /login_base "${json_{{ m.name | lower }}_login_base_tmp}"
222 {% endif %}
223 {% if m.name == "Flavor" -%}
224 ${json_{{ m.name | lower}}_flavor_tmp}= Set Variable m1.small
225 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /flavor "${json_{{ m.name | lower }}_flavor_tmp}"
226 {% endif %}
227 {% if m.name == "ServiceGraphConstraint" -%}
228 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /contraints "${test_string}"
229 {% endif %}
230 {% if m.name == "Slice" -%}
231 ${json_{{ m.name | lower}}_name}= Generate Random Slice Name
232 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /name "${json_{{ m.name | lower}}_name}"
233 {% endif -%}
234 {% if m.name == "Network" -%}
235 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /permit_all_slices true
236 {% endif %}
237 {% if m.name == "RCORDSubscriber" -%}
238 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /owner_id ${rcord_tmp_service_id}
239 {% endif %}
240 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /no_policy true
Kailash24ec4792019-05-15 14:47:30 -0700241 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /no_sync true
Kailash8394cff2019-04-29 09:19:22 -0700242 ${json_{{ m.name | lower }}_tmp}= To JSON ${json_{{ m.name | lower }}_tmp}
243 ${resp}= CORD Post /xosapi/v1/{{ xproto_unquote(m.options.app_label) }}/{{ xproto_pluralize(m) | lower}} ${json_{{ m.name | lower }}_tmp}
244 ${id_{{ m.name | lower }}_tmp}= Get Json Value ${resp.content} /id
245 Append To List ${dependent_{{ m.name | lower }}_ids} ${id_{{ m.name | lower }}_tmp}
246 [Return] ${id_{{ m.name | lower }}_tmp}
247{% endif %}
248{% endfor -%}
249
Kailash24ec4792019-05-15 14:47:30 -0700250Create Dependent Model
251 [Arguments] ${model}
252 ${result} ${id}= Run Keyword And Ignore Error Create ${model}
253 ${model_id}= Set Variable If "${result}" == "PASS" ${id} 1
254 [Return] ${model_id}
255
Kailash8394cff2019-04-29 09:19:22 -0700256Setup Tests
257 [Documentation] Find all dependent objects per model and create them and store them for later use
258 {% for m in proto.messages %}
259 {%- if m.name not in ['XOSBase'] -%}
260 ${model}= Set Variable {{ m.name | lower }}s
261 @{dependent_{{ m.name | lower }}_ids}= Create List ${model}
262 Set Suite Variable @{dependent_{{ m.name | lower }}_ids}
263 {% endif -%}
264 {% endfor -%}
265 @{dependent_models}= Create List
266 Set Suite Variable ${dependent_models}
267 ${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
268 ${HEADERS} Create Dictionary Content-Type=application/json
269 Create Session ${SERVER_IP} http://${SERVER_IP}:${SERVER_PORT} auth=${AUTH} headers=${HEADERS}
270 Generate JSON Data
271
272Teardown Tests
273 [Documentation] Delete all dependent objects created in Setup
274 {% for m in proto.messages %}
275 {%- if m.name not in ['XOSBase'] -%}
276 ${len}= Get Length ${dependent_{{ m.name | lower }}_ids}
277 : FOR ${INDEX} IN RANGE 1 ${len}
278 \ 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}]}
279 {% endif -%}
280 {% endfor -%}
281 Delete All Sessions
Kailash24ec4792019-05-15 14:47:30 -0700282