blob: bb4a864b74de3bab9e077cc15fbdf0903e532c57 [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}
Kailasha2848a42018-11-02 09:36:41 -0700146 ${rcord_tmp_service_id}= Set Variable ${id}
147 Set Suite Variable ${rcord_tmp_service_id}
Kailash Khalasid0d849d2018-08-28 18:34:24 -0700148 {% 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 == "AddressManagerServiceInstance" -%}
155 ${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 -0700156 ${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 -0700157 {% endif %}
Kailash Khalasi72614802018-05-02 09:21:23 -0700158 ${json_{{ m.name | lower }}_1}= To JSON ${json_{{ m.name | lower }}_1}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700159 ${json_{{ m.name | lower }}_amend_1}= To JSON ${json_{{ m.name | lower }}_amend_1}
Kailash Khalasi72614802018-05-02 09:21:23 -0700160 Set Suite Variable ${json_{{ m.name | lower }}_1}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700161 Set Suite Variable ${json_{{ m.name | lower }}_amend_1}
Kailash Khalasi72614802018-05-02 09:21:23 -0700162 {% endif -%}
163 {% endfor %}
164
165{% for m in proto.messages %}
166{%- if m.name not in ['XOSBase'] -%}
167Create {{ m.name }}
168 ##Creating {{ m.name | lower }} object
169 ${json_{{ m.name | lower }}_tmp}= Set Variable { }
170 # set required fields for {{ m.name | lower }} object
171 {% for f in m.fields + xproto_base_fields(m, proto.message_table) -%}
172 {% if f.link -%}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700173 {% if f.modifier == "required" and f.options.blank != "True"-%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700174 # create dependent {{ f.options.model }}
175 ${dependent_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
176 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }}_id ${dependent_{{ f.options.model | lower }}_id}
177 {% endif -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700178 {% else -%}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700179 {% if f.modifier == "required" and f.options.blank != "True"-%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700180 {% if not f.options.default -%}
Kailash Khalasifc74e1c2018-08-10 10:50:40 -0700181 {% if m.name == "User" and f.name == "email" -%}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700182 ${json_user_email_tmp}= Generate Random Value {{ f.type }}
Kailash Khalasifc74e1c2018-08-10 10:50:40 -0700183 ${json_user_email_tmp}= Catenate SEPARATOR= ${json_user_email_tmp} @opencord.org
184 ${json_user_tmp}= Set Json Value ${json_user_tmp} /email "${json_user_email_tmp}"
185 {% else -%}
Kailash Khalasicceec832018-08-10 15:46:50 -0700186 {% if f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
187 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value float
188 ${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 -0700189 {% elif f.name == "role" -%}
190 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value role
191 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
192 {% elif f.name == "direction" -%}
193 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value direction
194 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
195 {% elif f.name == "flavor" -%}
196 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value flavor
197 ${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 -0700198 {% elif f.name == "s_tag" and m.name == "BNGPortMapping" -%}
Kailash Khalasib987e9b2018-10-11 11:12:35 -0700199 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value vlan_tag
200 ${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 -0700201 {% else -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700202 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value {{ f.type }}
203 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
204 {% endif -%}
205 {% endif -%}
206 {% endif -%}
207 {% endif -%}
Kailash Khalasifc74e1c2018-08-10 10:50:40 -0700208 {% endif -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700209 {% endfor -%}
210 {% if m.name == "Site" -%}
211 ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase
212 ${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 -0700213 {% endif %}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700214 {% if m.name == "Flavor" -%}
215 ${json_{{ m.name | lower}}_flavor_tmp}= Set Variable m1.small
216 ${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 -0700217 {% endif %}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700218 {% if m.name == "ServiceGraphConstraint" -%}
219 ${json_{{ m.name | lower}}_contraints_tmp}= Generate Random Value string
220 ${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 -0700221 {% endif %}
Kailash Khalasi72614802018-05-02 09:21:23 -0700222 {% if m.name == "Slice" -%}
223 ${json_{{ m.name | lower}}_name}= Generate Random Slice Name
224 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /name "${json_{{ m.name | lower }}_name}"
225 {% endif -%}
226 {% if m.name == "Network" -%}
227 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /permit_all_slices true
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700228 {% endif %}
Kailashc9113072018-11-02 09:15:17 -0700229 {% if m.name == "RCORDSubscriber" -%}
230 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /owner_id ${rcord_tmp_service_id}
231 {% endif %}
Kailash Khalasi3481f1e2018-09-27 09:13:47 -0700232 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /no_policy true
233 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /no_sync true
Kailash Khalasi72614802018-05-02 09:21:23 -0700234 ${json_{{ m.name | lower }}_tmp}= To JSON ${json_{{ m.name | lower }}_tmp}
Kailash Khalasi9302c182018-05-07 13:46:15 -0600235 ${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 -0700236 ${id_{{ m.name | lower }}_tmp}= Get Json Value ${resp.content} /id
237 Append To List ${dependent_{{ m.name | lower }}_ids} ${id_{{ m.name | lower }}_tmp}
238 [Return] ${id_{{ m.name | lower }}_tmp}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700239{% endif %}
Kailash Khalasi72614802018-05-02 09:21:23 -0700240{% endfor -%}
241
242Setup Tests
243 [Documentation] Find all dependent objects per model and create them and store them for later use
244 {% for m in proto.messages %}
245 {%- if m.name not in ['XOSBase'] -%}
246 ${model}= Set Variable {{ m.name | lower }}s
247 @{dependent_{{ m.name | lower }}_ids}= Create List ${model}
248 Set Suite Variable @{dependent_{{ m.name | lower }}_ids}
249 {% endif -%}
250 {% endfor -%}
251 @{dependent_models}= Create List
252 Set Suite Variable ${dependent_models}
253 ${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
254 ${HEADERS} Create Dictionary Content-Type=application/json
255 Create Session ${SERVER_IP} http://${SERVER_IP}:${SERVER_PORT} auth=${AUTH} headers=${HEADERS}
256 Generate JSON Data
257
258Teardown Tests
259 [Documentation] Delete all dependent objects created in Setup
260 {% for m in proto.messages %}
261 {%- if m.name not in ['XOSBase'] -%}
262 ${len}= Get Length ${dependent_{{ m.name | lower }}_ids}
263 : FOR ${INDEX} IN RANGE 1 ${len}
264 \ 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}]}
265 {% endif -%}
266 {% endfor -%}
Kailash Khalasi2e0e3e12018-07-30 08:23:04 -0700267 Delete All Sessions