blob: 6c1d35c02069fdc2b6ae1502dfc10c26e2903c38 [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 Khalasi01f410f2018-10-12 11:54:19 -070090 {% elif f.name == "s_tag" and m.name == "BNGPortMapping" -%}
Kailash Khalasi1f7f30b2018-10-12 11:27:17 -070091 ${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value vlan_tag
92 ${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 -070093 {% else -%}
94 ${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value {{ f.type }}
95 ${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 -070096 {% if f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
97 ${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value float
98 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_1}"
99 {% else -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700100 {% if loop.index0 == 0 -%}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700101 ${json_{{ m.name | lower}}_amend_key}= Set Variable {{ f.name }}
102 ${json_{{ m.name | lower}}_{{ f.name }}_amend_1}= Generate Random Value {{ f.type }}
103 ${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 -0700104 {% endif -%}
105 {% endif -%}
106 {% endif -%}
107 {% endif -%}
Kailash Khalasi1aae9d12018-08-13 18:14:30 -0700108 {% endif -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700109 {% endfor -%}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700110 {% if m.name == "User" -%}
111 ${json_{{ m.name | lower}}_email}= Set Variable testuser@opencord.org
112 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /email "${json_{{ m.name | lower }}_email}"
113 ${json_{{ m.name | lower}}_email_amend_1}= Set Variable testuseramend@opencord.org
114 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /email "${json_{{ m.name | lower }}_email_amend_1}"
115 {% endif %}
Kailash Khalasi72614802018-05-02 09:21:23 -0700116 {% if m.name == "Site" -%}
117 ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase
118 ${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 -0700119 {% endif %}
120 {% if m.name == "Flavor" -%}
121 ${json_{{ m.name | lower}}_flavor_tmp}= Set Variable m1.small
122 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /flavor "${json_{{ m.name | lower }}_flavor_tmp}"
123 {% endif %}
124 {% if m.name == "ServiceGraphConstraint" -%}
125 ${json_{{ m.name | lower}}_constraints_tmp}= Generate Random Value string
126 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /constraints "${json_{{ m.name | lower }}_constraints_tmp}"
127 {% endif %}
Kailash Khalasi72614802018-05-02 09:21:23 -0700128 {% if m.name == "Slice" -%}
129 ${json_{{ m.name | lower}}_name}= Generate Random Slice Name
130 ${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 -0700131 ${json_{{ m.name | lower}}_name_amend_1}= Generate Random Slice Name
132 ${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 -0700133 {% endif -%}
134 {% if m.name == "ProgranServiceInstance" -%}
135 ${json_{{ m.name | lower}}_name}= Generate Random Value string
136 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /name "${json_{{ m.name | lower }}_name}"
137 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /CellIndividualOffset "1"
Kailash Khalasid81b26c2018-09-12 09:06:29 -0700138 ${json_{{ m.name | lower}}_name_amend_1}= Generate Random Value string
139 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /name "${json_{{ m.name | lower}}_name_amend_1}"
140 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /CellIndividualOffset "1"
Kailash Khalasid0d849d2018-08-28 18:34:24 -0700141 {% endif %}
142 {% if m.name == "RCORDSubscriber" -%}
Kailashc9113072018-11-02 09:15:17 -0700143 ## Create req service owner for rcord subscriber and
Kailash Khalasid0d849d2018-08-28 18:34:24 -0700144 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}
Kailashc9113072018-11-02 09:15:17 -0700146 ${rcord_tmp_service_id}= Set Suite Variable ${id}
Kailash Khalasid0d849d2018-08-28 18:34:24 -0700147 {% endif %}
148 {% if m.name == "HippieOSSServiceInstance" -%}
149 ## Create req service owner for hippie oss service instance
150 CORD Post /xosapi/v1/hippie-oss/hippieossservices {"name": "testhippieservice"}
151 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /owner_id ${id}
152 {% endif %}
153 {% if m.name == "AddressManagerServiceInstance" -%}
154 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /public_ip "2.2.2.2"
Kailash Khalasid81b26c2018-09-12 09:06:29 -0700155 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /public_ip "3.3.3.3"
Kailash Khalasi499430a2018-08-20 10:06:07 -0700156 {% endif %}
Kailash Khalasi72614802018-05-02 09:21:23 -0700157 ${json_{{ m.name | lower }}_1}= To JSON ${json_{{ m.name | lower }}_1}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700158 ${json_{{ m.name | lower }}_amend_1}= To JSON ${json_{{ m.name | lower }}_amend_1}
Kailash Khalasi72614802018-05-02 09:21:23 -0700159 Set Suite Variable ${json_{{ m.name | lower }}_1}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700160 Set Suite Variable ${json_{{ m.name | lower }}_amend_1}
Kailash Khalasi72614802018-05-02 09:21:23 -0700161 {% endif -%}
162 {% endfor %}
163
164{% for m in proto.messages %}
165{%- if m.name not in ['XOSBase'] -%}
166Create {{ m.name }}
167 ##Creating {{ m.name | lower }} object
168 ${json_{{ m.name | lower }}_tmp}= Set Variable { }
169 # set required fields for {{ m.name | lower }} object
170 {% for f in m.fields + xproto_base_fields(m, proto.message_table) -%}
171 {% if f.link -%}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700172 {% if f.modifier == "required" and f.options.blank != "True"-%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700173 # create dependent {{ f.options.model }}
174 ${dependent_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
175 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }}_id ${dependent_{{ f.options.model | lower }}_id}
176 {% endif -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700177 {% else -%}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700178 {% if f.modifier == "required" and f.options.blank != "True"-%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700179 {% if not f.options.default -%}
Kailash Khalasifc74e1c2018-08-10 10:50:40 -0700180 {% if m.name == "User" and f.name == "email" -%}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700181 ${json_user_email_tmp}= Generate Random Value {{ f.type }}
Kailash Khalasifc74e1c2018-08-10 10:50:40 -0700182 ${json_user_email_tmp}= Catenate SEPARATOR= ${json_user_email_tmp} @opencord.org
183 ${json_user_tmp}= Set Json Value ${json_user_tmp} /email "${json_user_email_tmp}"
184 {% else -%}
Kailash Khalasicceec832018-08-10 15:46:50 -0700185 {% if f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
186 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value float
187 ${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 -0700188 {% elif f.name == "role" -%}
189 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value role
190 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
191 {% elif f.name == "direction" -%}
192 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value direction
193 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
194 {% elif f.name == "flavor" -%}
195 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value flavor
196 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
Kailash Khalasi01f410f2018-10-12 11:54:19 -0700197 {% elif f.name == "s_tag" and m.name == "BNGPortMapping" -%}
Kailash Khalasib987e9b2018-10-11 11:12:35 -0700198 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value vlan_tag
199 ${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 -0700200 {% else -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700201 ${json_{{ m.name | lower}}_{{ f.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}}_{{ f.name }}_tmp}"
203 {% endif -%}
204 {% endif -%}
205 {% endif -%}
206 {% endif -%}
Kailash Khalasifc74e1c2018-08-10 10:50:40 -0700207 {% endif -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700208 {% endfor -%}
209 {% if m.name == "Site" -%}
210 ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase
211 ${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 -0700212 {% endif %}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700213 {% if m.name == "Flavor" -%}
214 ${json_{{ m.name | lower}}_flavor_tmp}= Set Variable m1.small
215 ${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 -0700216 {% endif %}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700217 {% if m.name == "ServiceGraphConstraint" -%}
218 ${json_{{ m.name | lower}}_contraints_tmp}= Generate Random Value string
219 ${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 -0700220 {% endif %}
Kailash Khalasi72614802018-05-02 09:21:23 -0700221 {% if m.name == "Slice" -%}
222 ${json_{{ m.name | lower}}_name}= Generate Random Slice Name
223 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /name "${json_{{ m.name | lower }}_name}"
224 {% endif -%}
225 {% if m.name == "Network" -%}
226 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /permit_all_slices true
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700227 {% endif %}
Kailashc9113072018-11-02 09:15:17 -0700228 {% if m.name == "RCORDSubscriber" -%}
229 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /owner_id ${rcord_tmp_service_id}
230 {% endif %}
Kailash Khalasi3481f1e2018-09-27 09:13:47 -0700231 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /no_policy true
232 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /no_sync true
Kailash Khalasi72614802018-05-02 09:21:23 -0700233 ${json_{{ m.name | lower }}_tmp}= To JSON ${json_{{ m.name | lower }}_tmp}
Kailash Khalasi9302c182018-05-07 13:46:15 -0600234 ${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 -0700235 ${id_{{ m.name | lower }}_tmp}= Get Json Value ${resp.content} /id
236 Append To List ${dependent_{{ m.name | lower }}_ids} ${id_{{ m.name | lower }}_tmp}
237 [Return] ${id_{{ m.name | lower }}_tmp}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700238{% endif %}
Kailash Khalasi72614802018-05-02 09:21:23 -0700239{% endfor -%}
240
241Setup Tests
242 [Documentation] Find all dependent objects per model and create them and store them for later use
243 {% for m in proto.messages %}
244 {%- if m.name not in ['XOSBase'] -%}
245 ${model}= Set Variable {{ m.name | lower }}s
246 @{dependent_{{ m.name | lower }}_ids}= Create List ${model}
247 Set Suite Variable @{dependent_{{ m.name | lower }}_ids}
248 {% endif -%}
249 {% endfor -%}
250 @{dependent_models}= Create List
251 Set Suite Variable ${dependent_models}
252 ${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
253 ${HEADERS} Create Dictionary Content-Type=application/json
254 Create Session ${SERVER_IP} http://${SERVER_IP}:${SERVER_PORT} auth=${AUTH} headers=${HEADERS}
255 Generate JSON Data
256
257Teardown Tests
258 [Documentation] Delete all dependent objects created in Setup
259 {% for m in proto.messages %}
260 {%- if m.name not in ['XOSBase'] -%}
261 ${len}= Get Length ${dependent_{{ m.name | lower }}_ids}
262 : FOR ${INDEX} IN RANGE 1 ${len}
263 \ 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}]}
264 {% endif -%}
265 {% endfor -%}
Kailash Khalasi2e0e3e12018-07-30 08:23:04 -0700266 Delete All Sessions