blob: ac5f70e744a37e97edb020cd11585cc06eeb5a36 [file] [log] [blame]
Kailash Khalasi72614802018-05-02 09:21:23 -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*** Keywords ***
14Verify API Functionality
15 [Arguments] ${type} ${endpoint} ${data}=${EMPTY} ${data_id}=${EMPTY} ${key}=${EMPTY}
16 Run Keyword If "${type}" == "RETRIEVE" CORD Get ${endpoint} ${data_id} ${data} ${key}
17 Run Keyword If "${type}" == "CREATE" CORD Post ${endpoint} ${data}
18 Run Keyword If "${type}" == "UPDATE" CORD Put ${endpoint} ${data} ${data_id}
19 Run Keyword If "${type}" == "DELETE" CORD Delete ${endpoint} ${data_id}
20
21CORD Get
22 [Documentation] Make a GET call to the CORD controller
23 [Arguments] ${service} ${id} ${value} ${key}
24 ${resp}= Get Request ${SERVER_IP} ${service}/${id}
25 Log ${resp.content}
26 Should Be Equal As Strings ${resp.status_code} 200
27 ${updated_value}= Run Keyword If '${key}' != 'null' Get Json Value ${resp.content} /${key}
28 ${updated_value}= Run Keyword If '${key}' != 'null' Remove String ${updated_value} "
29 Run Keyword If '${key}' != 'null' Should Contain "${value}" ${updated_value}
30 [Return] ${resp}
31
32CORD Post
33 [Documentation] Make a POST call to the CORD controller
34 [Arguments] ${service} ${data}
35 ${data}= Evaluate json.dumps(${data}) json
36 ${resp}= Post Request ${SERVER_IP} uri=${service} data=${data}
37 Log ${resp.content}
38 Should Be Equal As Strings ${resp.status_code} 200
39 ${id}= Get Json Value ${resp.content} /id
40 Set Suite Variable ${id}
41 [Return] ${resp}
42
43CORD Put
44 [Documentation] Make a PUT call to the CORD controller
45 [Arguments] ${service} ${data} ${data_id}
46 ${data}= Evaluate json.dumps(${data}) json
47 ${resp}= Put Request ${SERVER_IP} uri=${service}/${data_id} data=${data}
48 Log ${resp.content}
49 Should Be Equal As Strings ${resp.status_code} 200
50 ${id}= Get Json Value ${resp.content} /id
51 Set Suite Variable ${id}
52 [Return] ${resp}
53
54CORD Delete
55 [Documentation] Make a DELETE call to the CORD controller
56 [Arguments] ${service} ${data_id}
57 ${resp}= Delete Request ${SERVER_IP} uri=${service}/${data_id}
58 Log ${resp.content}
59 Should Be Equal As Strings ${resp.status_code} 200
60 [Return] ${resp}
61
62Generate JSON Data
Kailash Khalasi96dd8992018-08-28 10:52:31 -070063 {%- for m in proto.messages -%}
Kailash Khalasi72614802018-05-02 09:21:23 -070064 {%- if m.name not in ['XOSBase'] -%}
65 {% autoescape false %}
66 {% endautoescape %}
67 ${json_{{ m.name | lower }}_1}= Set Variable { }
Kailash Khalasi96dd8992018-08-28 10:52:31 -070068 ${json_{{ m.name | lower }}_amend_1}= Set Variable { }
69 ${json_{{ m.name | lower}}_amend_key}= Set Variable null
70 Set Suite Variable ${json_{{ m.name | lower}}_amend_key}
Kailash Khalasi72614802018-05-02 09:21:23 -070071 # set required fields for {{ m.name | lower }} object
72 {% for f in m.fields + xproto_base_fields(m, proto.message_table) -%}
Kailash Khalasi96dd8992018-08-28 10:52:31 -070073 {% if f.modifier == "required" and f.options.blank != "True" -%}
Kailash Khalasi72614802018-05-02 09:21:23 -070074 {% if not f.options.default -%}
75 {% if f.link -%}
76 ${tmp_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
77 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }}_id ${tmp_{{ f.options.model | lower }}_id}
Kailash Khalasi96dd8992018-08-28 10:52:31 -070078 {% elif f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
79 ${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value float
80 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_1}"
81 {% elif f.name == "role" -%}
82 ${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value role
83 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_1}"
84 {% elif f.name == "direction" -%}
85 ${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value direction
86 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_1}"
87 {% elif f.name == "flavor" -%}
88 ${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value flavor
89 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_1}"
Kailash Khalasi72614802018-05-02 09:21:23 -070090 {% else -%}
91 ${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value {{ f.type }}
92 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_1}"
Kailash Khalasi72090662018-08-13 17:50:46 -070093 {% if f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
94 ${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value float
95 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_1}"
96 {% else -%}
Kailash Khalasi72614802018-05-02 09:21:23 -070097 {% if loop.index0 == 0 -%}
Kailash Khalasi96dd8992018-08-28 10:52:31 -070098 ${json_{{ m.name | lower}}_amend_key}= Set Variable {{ f.name }}
99 ${json_{{ m.name | lower}}_{{ f.name }}_amend_1}= Generate Random Value {{ f.type }}
100 ${json_{{ m.name | lower }}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_amend_1}"
Kailash Khalasi72614802018-05-02 09:21:23 -0700101 {% endif -%}
102 {% endif -%}
103 {% endif -%}
104 {% endif -%}
Kailash Khalasi1aae9d12018-08-13 18:14:30 -0700105 {% endif -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700106 {% endfor -%}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700107 {% if m.name == "User" -%}
108 ${json_{{ m.name | lower}}_email}= Set Variable testuser@opencord.org
109 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /email "${json_{{ m.name | lower }}_email}"
110 ${json_{{ m.name | lower}}_email_amend_1}= Set Variable testuseramend@opencord.org
111 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /email "${json_{{ m.name | lower }}_email_amend_1}"
112 {% endif %}
Kailash Khalasi72614802018-05-02 09:21:23 -0700113 {% if m.name == "Site" -%}
114 ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase
115 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /login_base "${json_{{ m.name | lower }}_login_base_tmp}"
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700116 {% endif %}
117 {% if m.name == "Flavor" -%}
118 ${json_{{ m.name | lower}}_flavor_tmp}= Set Variable m1.small
119 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /flavor "${json_{{ m.name | lower }}_flavor_tmp}"
120 {% endif %}
121 {% if m.name == "ServiceGraphConstraint" -%}
122 ${json_{{ m.name | lower}}_constraints_tmp}= Generate Random Value string
123 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /constraints "${json_{{ m.name | lower }}_constraints_tmp}"
124 {% endif %}
Kailash Khalasi72614802018-05-02 09:21:23 -0700125 {% if m.name == "Slice" -%}
126 ${json_{{ m.name | lower}}_name}= Generate Random Slice Name
127 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /name "${json_{{ m.name | lower }}_name}"
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700128 ${json_{{ m.name | lower}}_name_amend_1}= Generate Random Slice Name
129 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /name "${json_{{ m.name | lower}}_name_amend_1}"
Kailash Khalasid0d849d2018-08-28 18:34:24 -0700130 {% endif -%}
131 {% if m.name == "ProgranServiceInstance" -%}
132 ${json_{{ m.name | lower}}_name}= Generate Random Value string
133 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /name "${json_{{ m.name | lower }}_name}"
134 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /CellIndividualOffset "1"
135 ${json_{{ m.name | lower}}_name_updated_1}= Generate Random Value string
136 ${json_{{ m.name | lower}}_updated_1}= Set Json Value ${json_{{ m.name | lower }}_updated_1} /name "${json_{{ m.name | lower}}_name_updated_1}"
137 ${json_{{ m.name | lower}}_updated_1}= Set Json Value ${json_{{ m.name | lower }}_updated_1} /CellIndividualOffset "1"
138 {% endif %}
139 {% if m.name == "RCORDSubscriber" -%}
140 ## Create req service owner for rcord subscriber
141 CORD Post /xosapi/v1/rcord/rcordservices {"name": "testrcordservice", "access": "unknown"}
142 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /owner_id ${id}
143 {% endif %}
144 {% if m.name == "HippieOSSServiceInstance" -%}
145 ## Create req service owner for hippie oss service instance
146 CORD Post /xosapi/v1/hippie-oss/hippieossservices {"name": "testhippieservice"}
147 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /owner_id ${id}
148 {% endif %}
149 {% if m.name == "AddressManagerServiceInstance" -%}
150 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /public_ip "2.2.2.2"
151 ${json_{{ m.name | lower}}_updated_1}= Set Json Value ${json_{{ m.name | lower }}_updated_1} /public_ip "3.3.3.3"
Kailash Khalasi499430a2018-08-20 10:06:07 -0700152 {% endif %}
Kailash Khalasi72614802018-05-02 09:21:23 -0700153 ${json_{{ m.name | lower }}_1}= To JSON ${json_{{ m.name | lower }}_1}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700154 ${json_{{ m.name | lower }}_amend_1}= To JSON ${json_{{ m.name | lower }}_amend_1}
Kailash Khalasi72614802018-05-02 09:21:23 -0700155 Set Suite Variable ${json_{{ m.name | lower }}_1}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700156 Set Suite Variable ${json_{{ m.name | lower }}_amend_1}
Kailash Khalasi72614802018-05-02 09:21:23 -0700157 {% endif -%}
158 {% endfor %}
159
160{% for m in proto.messages %}
161{%- if m.name not in ['XOSBase'] -%}
162Create {{ m.name }}
163 ##Creating {{ m.name | lower }} object
164 ${json_{{ m.name | lower }}_tmp}= Set Variable { }
165 # set required fields for {{ m.name | lower }} object
166 {% for f in m.fields + xproto_base_fields(m, proto.message_table) -%}
167 {% if f.link -%}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700168 {% if f.modifier == "required" and f.options.blank != "True"-%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700169 # create dependent {{ f.options.model }}
170 ${dependent_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
171 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }}_id ${dependent_{{ f.options.model | lower }}_id}
172 {% endif -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700173 {% else -%}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700174 {% if f.modifier == "required" and f.options.blank != "True"-%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700175 {% if not f.options.default -%}
Kailash Khalasifc74e1c2018-08-10 10:50:40 -0700176 {% if m.name == "User" and f.name == "email" -%}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700177 ${json_user_email_tmp}= Generate Random Value {{ f.type }}
Kailash Khalasifc74e1c2018-08-10 10:50:40 -0700178 ${json_user_email_tmp}= Catenate SEPARATOR= ${json_user_email_tmp} @opencord.org
179 ${json_user_tmp}= Set Json Value ${json_user_tmp} /email "${json_user_email_tmp}"
180 {% else -%}
Kailash Khalasicceec832018-08-10 15:46:50 -0700181 {% if f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
182 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value float
183 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700184 {% elif f.name == "role" -%}
185 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value role
186 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
187 {% elif f.name == "direction" -%}
188 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value direction
189 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
190 {% elif f.name == "flavor" -%}
191 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value flavor
192 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
Kailash Khalasicceec832018-08-10 15:46:50 -0700193 {% else -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700194 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value {{ f.type }}
195 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
196 {% endif -%}
197 {% endif -%}
198 {% endif -%}
199 {% endif -%}
Kailash Khalasifc74e1c2018-08-10 10:50:40 -0700200 {% endif -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700201 {% endfor -%}
202 {% if m.name == "Site" -%}
203 ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase
204 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /login_base "${json_{{ m.name | lower }}_login_base_tmp}"
Kailash Khalasi78f2a342018-08-23 10:50:21 -0700205 {% endif %}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700206 {% if m.name == "Flavor" -%}
207 ${json_{{ m.name | lower}}_flavor_tmp}= Set Variable m1.small
208 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /flavor "${json_{{ m.name | lower }}_flavor_tmp}"
Kailash Khalasi0e2bb702018-08-23 14:46:16 -0700209 {% endif %}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700210 {% if m.name == "ServiceGraphConstraint" -%}
211 ${json_{{ m.name | lower}}_contraints_tmp}= Generate Random Value string
212 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /contraints "${json_{{ m.name | lower }}_contraints_tmp}"
Kailash Khalasi0e2bb702018-08-23 14:46:16 -0700213 {% endif %}
Kailash Khalasi72614802018-05-02 09:21:23 -0700214 {% if m.name == "Slice" -%}
215 ${json_{{ m.name | lower}}_name}= Generate Random Slice Name
216 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /name "${json_{{ m.name | lower }}_name}"
217 {% endif -%}
218 {% if m.name == "Network" -%}
219 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /permit_all_slices true
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700220 {% endif %}
Kailash Khalasi72614802018-05-02 09:21:23 -0700221 ${json_{{ m.name | lower }}_tmp}= To JSON ${json_{{ m.name | lower }}_tmp}
Kailash Khalasi9302c182018-05-07 13:46:15 -0600222 ${resp}= CORD Post /xosapi/v1/{{ xproto_unquote(m.options.app_label) }}/{{ xproto_pluralize(m) | lower}} ${json_{{ m.name | lower }}_tmp}
Kailash Khalasi72614802018-05-02 09:21:23 -0700223 ${id_{{ m.name | lower }}_tmp}= Get Json Value ${resp.content} /id
224 Append To List ${dependent_{{ m.name | lower }}_ids} ${id_{{ m.name | lower }}_tmp}
225 [Return] ${id_{{ m.name | lower }}_tmp}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700226{% endif %}
Kailash Khalasi72614802018-05-02 09:21:23 -0700227{% endfor -%}
228
229Setup Tests
230 [Documentation] Find all dependent objects per model and create them and store them for later use
231 {% for m in proto.messages %}
232 {%- if m.name not in ['XOSBase'] -%}
233 ${model}= Set Variable {{ m.name | lower }}s
234 @{dependent_{{ m.name | lower }}_ids}= Create List ${model}
235 Set Suite Variable @{dependent_{{ m.name | lower }}_ids}
236 {% endif -%}
237 {% endfor -%}
238 @{dependent_models}= Create List
239 Set Suite Variable ${dependent_models}
240 ${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
241 ${HEADERS} Create Dictionary Content-Type=application/json
242 Create Session ${SERVER_IP} http://${SERVER_IP}:${SERVER_PORT} auth=${AUTH} headers=${HEADERS}
243 Generate JSON Data
244
245Teardown Tests
246 [Documentation] Delete all dependent objects created in Setup
247 {% for m in proto.messages %}
248 {%- if m.name not in ['XOSBase'] -%}
249 ${len}= Get Length ${dependent_{{ m.name | lower }}_ids}
250 : FOR ${INDEX} IN RANGE 1 ${len}
251 \ 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}]}
252 {% endif -%}
253 {% endfor -%}
Kailash Khalasi2e0e3e12018-07-30 08:23:04 -0700254 Delete All Sessions