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