blob: f052731681932c2dc4c16cb4b73eafc52f06e81e [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" -%}
143 ## Create req service owner for rcord subscriber
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 {% endif %}
147 {% if m.name == "HippieOSSServiceInstance" -%}
148 ## Create req service owner for hippie oss service instance
149 CORD Post /xosapi/v1/hippie-oss/hippieossservices {"name": "testhippieservice"}
150 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /owner_id ${id}
151 {% endif %}
152 {% if m.name == "AddressManagerServiceInstance" -%}
153 ${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 -0700154 ${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 -0700155 {% endif %}
Kailash Khalasi72614802018-05-02 09:21:23 -0700156 ${json_{{ m.name | lower }}_1}= To JSON ${json_{{ m.name | lower }}_1}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700157 ${json_{{ m.name | lower }}_amend_1}= To JSON ${json_{{ m.name | lower }}_amend_1}
Kailash Khalasi72614802018-05-02 09:21:23 -0700158 Set Suite Variable ${json_{{ m.name | lower }}_1}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700159 Set Suite Variable ${json_{{ m.name | lower }}_amend_1}
Kailash Khalasi72614802018-05-02 09:21:23 -0700160 {% endif -%}
161 {% endfor %}
162
163{% for m in proto.messages %}
164{%- if m.name not in ['XOSBase'] -%}
165Create {{ m.name }}
166 ##Creating {{ m.name | lower }} object
167 ${json_{{ m.name | lower }}_tmp}= Set Variable { }
168 # set required fields for {{ m.name | lower }} object
169 {% for f in m.fields + xproto_base_fields(m, proto.message_table) -%}
170 {% if f.link -%}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700171 {% if f.modifier == "required" and f.options.blank != "True"-%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700172 # create dependent {{ f.options.model }}
173 ${dependent_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
174 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }}_id ${dependent_{{ f.options.model | lower }}_id}
175 {% endif -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700176 {% else -%}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700177 {% if f.modifier == "required" and f.options.blank != "True"-%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700178 {% if not f.options.default -%}
Kailash Khalasifc74e1c2018-08-10 10:50:40 -0700179 {% if m.name == "User" and f.name == "email" -%}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700180 ${json_user_email_tmp}= Generate Random Value {{ f.type }}
Kailash Khalasifc74e1c2018-08-10 10:50:40 -0700181 ${json_user_email_tmp}= Catenate SEPARATOR= ${json_user_email_tmp} @opencord.org
182 ${json_user_tmp}= Set Json Value ${json_user_tmp} /email "${json_user_email_tmp}"
183 {% else -%}
Kailash Khalasicceec832018-08-10 15:46:50 -0700184 {% if f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
185 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value float
186 ${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 -0700187 {% elif f.name == "role" -%}
188 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value role
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 == "direction" -%}
191 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value direction
192 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
193 {% elif f.name == "flavor" -%}
194 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value flavor
195 ${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 -0700196 {% elif f.name == "s_tag" and m.name == "BNGPortMapping" -%}
Kailash Khalasib987e9b2018-10-11 11:12:35 -0700197 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value vlan_tag
198 ${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 -0700199 {% else -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700200 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value {{ f.type }}
201 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
202 {% endif -%}
203 {% endif -%}
204 {% endif -%}
205 {% endif -%}
Kailash Khalasifc74e1c2018-08-10 10:50:40 -0700206 {% endif -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700207 {% endfor -%}
208 {% if m.name == "Site" -%}
209 ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase
210 ${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 -0700211 {% endif %}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700212 {% if m.name == "Flavor" -%}
213 ${json_{{ m.name | lower}}_flavor_tmp}= Set Variable m1.small
214 ${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 -0700215 {% endif %}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700216 {% if m.name == "ServiceGraphConstraint" -%}
217 ${json_{{ m.name | lower}}_contraints_tmp}= Generate Random Value string
218 ${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 -0700219 {% endif %}
Kailash Khalasi72614802018-05-02 09:21:23 -0700220 {% if m.name == "Slice" -%}
221 ${json_{{ m.name | lower}}_name}= Generate Random Slice Name
222 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /name "${json_{{ m.name | lower }}_name}"
223 {% endif -%}
224 {% if m.name == "Network" -%}
225 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /permit_all_slices true
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700226 {% endif %}
Kailash Khalasi3481f1e2018-09-27 09:13:47 -0700227 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /no_policy true
228 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /no_sync true
Kailash Khalasi72614802018-05-02 09:21:23 -0700229 ${json_{{ m.name | lower }}_tmp}= To JSON ${json_{{ m.name | lower }}_tmp}
Kailash Khalasi9302c182018-05-07 13:46:15 -0600230 ${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 -0700231 ${id_{{ m.name | lower }}_tmp}= Get Json Value ${resp.content} /id
232 Append To List ${dependent_{{ m.name | lower }}_ids} ${id_{{ m.name | lower }}_tmp}
233 [Return] ${id_{{ m.name | lower }}_tmp}
Kailash Khalasi96dd8992018-08-28 10:52:31 -0700234{% endif %}
Kailash Khalasi72614802018-05-02 09:21:23 -0700235{% endfor -%}
236
237Setup Tests
238 [Documentation] Find all dependent objects per model and create them and store them for later use
239 {% for m in proto.messages %}
240 {%- if m.name not in ['XOSBase'] -%}
241 ${model}= Set Variable {{ m.name | lower }}s
242 @{dependent_{{ m.name | lower }}_ids}= Create List ${model}
243 Set Suite Variable @{dependent_{{ m.name | lower }}_ids}
244 {% endif -%}
245 {% endfor -%}
246 @{dependent_models}= Create List
247 Set Suite Variable ${dependent_models}
248 ${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
249 ${HEADERS} Create Dictionary Content-Type=application/json
250 Create Session ${SERVER_IP} http://${SERVER_IP}:${SERVER_PORT} auth=${AUTH} headers=${HEADERS}
251 Generate JSON Data
252
253Teardown Tests
254 [Documentation] Delete all dependent objects created in Setup
255 {% for m in proto.messages %}
256 {%- if m.name not in ['XOSBase'] -%}
257 ${len}= Get Length ${dependent_{{ m.name | lower }}_ids}
258 : FOR ${INDEX} IN RANGE 1 ${len}
259 \ 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}]}
260 {% endif -%}
261 {% endfor -%}
Kailash Khalasi2e0e3e12018-07-30 08:23:04 -0700262 Delete All Sessions