blob: 35af65402db4c3559de8f37bf2c41054fa29edc0 [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 -%}
89 ${tmp_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
90 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }}_id ${tmp_{{ f.options.model | lower }}_id}
91 {% elif f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
92 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${test_float}"
93 {% elif f.name == "role" -%}
94 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${test_role}"
95 {% elif f.name == "direction" -%}
96 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${test_direction}"
97 {% elif f.name == "flavor" -%}
98 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${test_flavor}"
99 {% elif f.name == "s_tag" and m.name == "BNGPortMapping" -%}
100 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${test_vlan_tag}"
101 {% else -%}
102 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${test_{{ f.type }}}"
103 {% if f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
104 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${test_float}"
105 {% else -%}
106 {% if loop.index0 == 0 -%}
107 ${json_{{ m.name | lower}}_amend_key}= Set Variable {{ f.name }}
108 ${json_{{ m.name | lower }}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /{{ f.name }} "${test_{{ f.type }}}"
109 {% endif -%}
110 {% endif -%}
111 {% endif -%}
112 {% endif -%}
113 {% endif -%}
114 {% endfor -%}
115 {% if m.name == "User" -%}
116 ${json_{{ m.name | lower}}_email}= Set Variable testuser@opencord.org
117 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /email "${json_{{ m.name | lower }}_email}"
118 ${json_{{ m.name | lower}}_email_amend_1}= Set Variable testuseramend@opencord.org
119 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /email "${json_{{ m.name | lower }}_email_amend_1}"
120 {% endif %}
121 {% if m.name == "Site" -%}
122 ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase
123 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /login_base "${json_{{ m.name | lower }}_login_base_tmp}"
124 {% endif %}
125 {% if m.name == "Flavor" -%}
126 ${json_{{ m.name | lower}}_flavor_tmp}= Set Variable m1.small
127 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /flavor "${json_{{ m.name | lower }}_flavor_tmp}"
128 {% endif %}
129 {% if m.name == "ServiceGraphConstraint" -%}
130 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /constraints "${test_string}"
131 {% endif %}
132 {% if m.name == "Slice" -%}
133 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /name "testloginbase"
134 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /name "testloginbase2"
135 {% endif -%}
136 {% if m.name == "ProgranServiceInstance" -%}
137 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /name "${test_string}"
138 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /CellIndividualOffset "1"
139 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /name "${test_string}"
140 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /CellIndividualOffset "1"
141 {% endif %}
142 {% if m.name == "RCORDSubscriber" -%}
143 ## Create req service owner for rcord subscriber and
144 CORD Post /xosapi/v1/rcord/rcordservices {"name": "testrcordservice", "access": "unknown"}
145 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /owner_id ${id}
146 ${rcord_tmp_service_id}= Set Variable ${id}
147 Set Suite Variable ${rcord_tmp_service_id}
148 {% endif %}
149 {% if m.name == "HippieOSSServiceInstance" -%}
150 ## Create req service owner for hippie oss service instance
151 CORD Post /xosapi/v1/hippie-oss/hippieossservices {"name": "testhippieservice"}
152 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /owner_id ${id}
153 {% endif %}
154 {% if m.name == "MCordSubscriberInstance" -%}
155 ## Create req service owner for hippie oss service instance
156 CORD Post /xosapi/v1/mcord/mcordsubscriberservices {"name": "testmcordservice"}
157 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /owner_id ${id}
158 {% endif %}
159 {% if m.name == "AddressManagerServiceInstance" -%}
160 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /public_ip "2.2.2.2"
161 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /public_ip "3.3.3.3"
162 {% endif %}
163 {% if m.name == "RCORDIpAddress" -%}
164 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /ip "2.2.2.2"
165 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /ip "3.3.3.3"
166 {% endif %}
167 ${json_{{ m.name | lower }}_1}= To JSON ${json_{{ m.name | lower }}_1}
168 ${json_{{ m.name | lower }}_amend_1}= To JSON ${json_{{ m.name | lower }}_amend_1}
169 Set Suite Variable ${json_{{ m.name | lower }}_1}
170 Set Suite Variable ${json_{{ m.name | lower }}_amend_1}
171 {% endif -%}
172 {% endfor %}
173
174{% for m in proto.messages %}
175{%- if m.name not in ['XOSBase'] -%}
176Create {{ m.name }}
177 ##Creating {{ m.name | lower }} object
178 ${json_{{ m.name | lower }}_tmp}= Set Variable { }
179 # set required fields for {{ m.name | lower }} object
180 {% for f in m.fields + xproto_base_fields(m, proto.message_table) -%}
181 {% if f.link -%}
182 {% if f.modifier == "required" and f.options.blank != "True"-%}
183 # create dependent {{ f.options.model }}
184 ${dependent_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
185 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }}_id ${dependent_{{ f.options.model | lower }}_id}
186 {% endif -%}
187 {% else -%}
188 {% if f.modifier == "required" and f.options.blank != "True"-%}
189 {% if not f.options.default -%}
190 {% if m.name == "User" and f.name == "email" -%}
191 ${json_user_tmp}= Set Json Value ${json_user_tmp} /email "${test_email}"
192 {% else -%}
193 {% if f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
194 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${test_float}"
195 {% elif f.name == "name" -%}
196 ${json_{{ m.name | lower}}_name_tmp}= Generate Random Value {{ f.type }}
197 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_name_tmp}"
198 {% elif f.name == "role" -%}
199 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${test_role}"
200 {% elif f.name == "direction" -%}
201 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${test_direction}"
202 {% elif f.name == "flavor" -%}
203 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${test_flavor}"
204 {% elif f.name == "s_tag" and m.name == "BNGPortMapping" -%}
205 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${test_vlan_tag}"
206 {% else -%}
207 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${test_{{ f.type }}}"
208 {% endif -%}
209 {% endif -%}
210 {% endif -%}
211 {% endif -%}
212 {% endif -%}
213 {% endfor -%}
214 {% if m.name == "Site" -%}
215 ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase3
216 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /login_base "${json_{{ m.name | lower }}_login_base_tmp}"
217 {% endif %}
218 {% if m.name == "Flavor" -%}
219 ${json_{{ m.name | lower}}_flavor_tmp}= Set Variable m1.small
220 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /flavor "${json_{{ m.name | lower }}_flavor_tmp}"
221 {% endif %}
222 {% if m.name == "ServiceGraphConstraint" -%}
223 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /contraints "${test_string}"
224 {% endif %}
225 {% if m.name == "Slice" -%}
226 ${json_{{ m.name | lower}}_name}= Generate Random Slice Name
227 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /name "${json_{{ m.name | lower}}_name}"
228 {% endif -%}
229 {% if m.name == "Network" -%}
230 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /permit_all_slices true
231 {% endif %}
232 {% if m.name == "RCORDSubscriber" -%}
233 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /owner_id ${rcord_tmp_service_id}
234 {% endif %}
235 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /no_policy true
236 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /no_sync true
237 ${json_{{ m.name | lower }}_tmp}= To JSON ${json_{{ m.name | lower }}_tmp}
238 ${resp}= CORD Post /xosapi/v1/{{ xproto_unquote(m.options.app_label) }}/{{ xproto_pluralize(m) | lower}} ${json_{{ m.name | lower }}_tmp}
239 ${id_{{ m.name | lower }}_tmp}= Get Json Value ${resp.content} /id
240 Append To List ${dependent_{{ m.name | lower }}_ids} ${id_{{ m.name | lower }}_tmp}
241 [Return] ${id_{{ m.name | lower }}_tmp}
242{% endif %}
243{% endfor -%}
244
245Setup Tests
246 [Documentation] Find all dependent objects per model and create them and store them for later use
247 {% for m in proto.messages %}
248 {%- if m.name not in ['XOSBase'] -%}
249 ${model}= Set Variable {{ m.name | lower }}s
250 @{dependent_{{ m.name | lower }}_ids}= Create List ${model}
251 Set Suite Variable @{dependent_{{ m.name | lower }}_ids}
252 {% endif -%}
253 {% endfor -%}
254 @{dependent_models}= Create List
255 Set Suite Variable ${dependent_models}
256 ${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
257 ${HEADERS} Create Dictionary Content-Type=application/json
258 Create Session ${SERVER_IP} http://${SERVER_IP}:${SERVER_PORT} auth=${AUTH} headers=${HEADERS}
259 Generate JSON Data
260
261Teardown Tests
262 [Documentation] Delete all dependent objects created in Setup
263 {% for m in proto.messages %}
264 {%- if m.name not in ['XOSBase'] -%}
265 ${len}= Get Length ${dependent_{{ m.name | lower }}_ids}
266 : FOR ${INDEX} IN RANGE 1 ${len}
267 \ 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}]}
268 {% endif -%}
269 {% endfor -%}
270 Delete All Sessions