blob: f33935478b79f58c9de1bf145449feca26c16b75 [file] [log] [blame]
tiernof27c79b2018-03-12 17:08:42 +01001#! /usr/bin/python3
2# -*- coding: utf-8 -*-
3
tiernod125caf2018-11-22 16:05:54 +00004# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13# implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
tiernof27c79b2018-03-12 17:08:42 +010017import getopt
18import sys
19import requests
tiernof27c79b2018-03-12 17:08:42 +010020import json
21import logging
22import yaml
garciadeblas4568a372021-03-24 09:19:48 +010023
tierno2236d202018-05-16 19:05:16 +020024# import json
tiernoc32ba4a2018-05-24 18:06:41 +020025# import tarfile
26from time import sleep
tiernoff6485d2018-11-28 17:19:46 +000027from random import randint
tiernoc32ba4a2018-05-24 18:06:41 +020028import os
tiernoff6485d2018-11-28 17:19:46 +000029from sys import stderr
delacruzramo9742f1d2019-06-05 13:06:47 +020030from uuid import uuid4
delacruzramo16db9492019-09-25 12:01:59 +020031import re
tiernof27c79b2018-03-12 17:08:42 +010032
33__author__ = "Alfonso Tierno, alfonso.tiernosepulveda@telefonica.com"
34__date__ = "$2018-03-01$"
gcalvino337ec512018-07-30 10:30:13 +020035__version__ = "0.3"
36version_date = "Oct 2018"
tiernof27c79b2018-03-12 17:08:42 +010037
38
39def usage():
40 print("Usage: ", sys.argv[0], "[options]")
garciadeblas4568a372021-03-24 09:19:48 +010041 print(
42 " Performs system tests over running NBI. It can be used for real OSM test using option '--test-osm'"
43 )
44 print(
45 " If this is the case env variables 'OSMNBITEST_VIM_NAME' must be supplied to create a VIM if not exist "
46 "where deployment is done"
47 )
tiernoc32ba4a2018-05-24 18:06:41 +020048 print("OPTIONS")
tiernof27c79b2018-03-12 17:08:42 +010049 print(" -h|--help: shows this help")
tiernoc32ba4a2018-05-24 18:06:41 +020050 print(" --insecure: Allows non trusted https NBI server")
51 print(" --list: list available tests")
garciadeblas4568a372021-03-24 09:19:48 +010052 print(
53 " --manual-check: Deployment tests stop after deployed to allow manual inspection. Only make sense with "
54 "'--test-osm'"
55 )
tiernoc32ba4a2018-05-24 18:06:41 +020056 print(" -p|--password PASSWORD: NBI access password. 'admin' by default")
57 print(" ---project PROJECT: NBI access project. 'admin' by default")
garciadeblas4568a372021-03-24 09:19:48 +010058 print(
59 " --test TEST[,...]: Execute only a test or a comma separated list of tests"
60 )
61 print(
62 " --params key=val: params to the previous test. key can be vnfd-files, nsd-file, ns-name, ns-config"
63 )
64 print(
65 " --test-osm: If missing this test is intended for NBI only, no other OSM components are expected. Use "
66 "this flag to test the system. LCM and RO components are expected to be up and running"
67 )
68 print(
69 " --timeout TIMEOUT: General NBI timeout, by default {}s".format(timeout)
70 )
71 print(
72 " --timeout-deploy TIMEOUT: Timeout used for getting NS deployed, by default {}s".format(
73 timeout_deploy
74 )
75 )
76 print(
77 " --timeout-configure TIMEOUT: Timeout used for getting NS deployed and configured,"
78 " by default {}s".format(timeout_configure)
79 )
tiernoc32ba4a2018-05-24 18:06:41 +020080 print(" -u|--user USERNAME: NBI access username. 'admin' by default")
garciadeblas4568a372021-03-24 09:19:48 +010081 print(
82 " --url URL: complete NBI server URL. 'https//localhost:9999/osm' by default"
83 )
tiernof27c79b2018-03-12 17:08:42 +010084 print(" -v|--verbose print debug information, can be used several times")
tiernoc32ba4a2018-05-24 18:06:41 +020085 print(" --no-verbose remove verbosity")
86 print(" --version: prints current version")
87 print("ENV variables used for real deployment tests with option osm-test.")
88 print(" export OSMNBITEST_VIM_NAME=vim-name")
89 print(" export OSMNBITEST_VIM_URL=vim-url")
90 print(" export OSMNBITEST_VIM_TYPE=vim-type")
91 print(" export OSMNBITEST_VIM_TENANT=vim-tenant")
92 print(" export OSMNBITEST_VIM_USER=vim-user")
93 print(" export OSMNBITEST_VIM_PASSWORD=vim-password")
garciadeblas4568a372021-03-24 09:19:48 +010094 print(' export OSMNBITEST_VIM_CONFIG="vim-config"')
95 print(' export OSMNBITEST_NS_NAME="vim-config"')
tiernof27c79b2018-03-12 17:08:42 +010096 return
97
98
99r_header_json = {"Content-type": "application/json"}
tiernof717cbe2018-12-03 16:35:42 +0000100headers_json = {"Content-type": "application/json", "Accept": "application/json"}
tiernof27c79b2018-03-12 17:08:42 +0100101r_header_yaml = {"Content-type": "application/yaml"}
tiernof717cbe2018-12-03 16:35:42 +0000102headers_yaml = {"Content-type": "application/yaml", "Accept": "application/yaml"}
tiernof27c79b2018-03-12 17:08:42 +0100103r_header_text = {"Content-type": "text/plain"}
104r_header_octect = {"Content-type": "application/octet-stream"}
tiernof717cbe2018-12-03 16:35:42 +0000105headers_text = {"Accept": "text/plain,application/yaml"}
tiernof27c79b2018-03-12 17:08:42 +0100106r_header_zip = {"Content-type": "application/zip"}
tiernof717cbe2018-12-03 16:35:42 +0000107headers_zip = {"Accept": "application/zip,application/yaml"}
108headers_zip_yaml = {"Accept": "application/yaml", "Content-type": "application/zip"}
delacruzramo16db9492019-09-25 12:01:59 +0200109headers_zip_json = {"Accept": "application/json", "Content-type": "application/zip"}
110headers_txt_json = {"Accept": "application/json", "Content-type": "text/plain"}
garciadeblas4568a372021-03-24 09:19:48 +0100111r_headers_yaml_location_vnfd = {
112 "Location": "/vnfpkgm/v1/vnf_packages_content/",
113 "Content-Type": "application/yaml",
114}
115r_headers_yaml_location_nsd = {
116 "Location": "/nsd/v1/ns_descriptors_content/",
117 "Content-Type": "application/yaml",
118}
119r_headers_yaml_location_nst = {
120 "Location": "/nst/v1/netslice_templates_content",
121 "Content-Type": "application/yaml",
122}
123r_headers_yaml_location_nslcmop = {
124 "Location": "nslcm/v1/ns_lcm_op_occs/",
125 "Content-Type": "application/yaml",
126}
127r_headers_yaml_location_nsilcmop = {
128 "Location": "/osm/nsilcm/v1/nsi_lcm_op_occs/",
129 "Content-Type": "application/yaml",
130}
tiernof27c79b2018-03-12 17:08:42 +0100131
132# test ones authorized
133test_authorized_list = (
garciadeblas4568a372021-03-24 09:19:48 +0100134 (
135 "AU1",
136 "Invalid vnfd id",
137 "GET",
138 "/vnfpkgm/v1/vnf_packages/non-existing-id",
139 headers_json,
140 None,
141 404,
142 r_header_json,
143 "json",
144 ),
145 (
146 "AU2",
147 "Invalid nsd id",
148 "GET",
149 "/nsd/v1/ns_descriptors/non-existing-id",
150 headers_yaml,
151 None,
152 404,
153 r_header_yaml,
154 "yaml",
155 ),
156 (
157 "AU3",
158 "Invalid nsd id",
159 "DELETE",
160 "/nsd/v1/ns_descriptors_content/non-existing-id",
161 headers_yaml,
162 None,
163 404,
164 r_header_yaml,
165 "yaml",
166 ),
tierno0f98af52018-03-19 10:28:22 +0100167)
garciadeblas4568a372021-03-24 09:19:48 +0100168timeout = 120 # general timeout
169timeout_deploy = 60 * 10 # timeout for NS deploying without charms
170timeout_configure = 60 * 20 # timeout for NS deploying and configuring
tiernof27c79b2018-03-12 17:08:42 +0100171
tierno2236d202018-05-16 19:05:16 +0200172
tiernof27c79b2018-03-12 17:08:42 +0100173class TestException(Exception):
174 pass
175
176
177class TestRest:
garciadeblas4568a372021-03-24 09:19:48 +0100178 def __init__(
179 self,
180 url_base,
181 header_base=None,
182 verify=False,
183 user="admin",
184 password="admin",
185 project="admin",
186 ):
tiernof27c79b2018-03-12 17:08:42 +0100187 self.url_base = url_base
tiernoc32ba4a2018-05-24 18:06:41 +0200188 if header_base is None:
189 self.header_base = {}
190 else:
191 self.header_base = header_base.copy()
tiernof27c79b2018-03-12 17:08:42 +0100192 self.s = requests.session()
tiernoc32ba4a2018-05-24 18:06:41 +0200193 self.s.headers = self.header_base
tiernof27c79b2018-03-12 17:08:42 +0100194 self.verify = verify
tiernoc32ba4a2018-05-24 18:06:41 +0200195 self.token = False
196 self.user = user
197 self.password = password
198 self.project = project
199 self.vim_id = None
tierno0f98af52018-03-19 10:28:22 +0100200 # contains ID of tests obtained from Location response header. "" key contains last obtained id
tiernoff6485d2018-11-28 17:19:46 +0000201 self.last_id = ""
tierno36ec8602018-11-02 17:27:11 +0100202 self.test_name = None
garciadeblas4568a372021-03-24 09:19:48 +0100203 self.step = 0 # number of subtest under test
tiernoff6485d2018-11-28 17:19:46 +0000204 self.passed_tests = 0
205 self.failed_tests = 0
tiernof27c79b2018-03-12 17:08:42 +0100206
tiernoff6485d2018-11-28 17:19:46 +0000207 def set_test_name(self, test_name):
208 self.test_name = test_name
209 self.step = 0
210 self.last_id = ""
delacruzramoc061f562019-04-05 11:00:02 +0200211
tiernof27c79b2018-03-12 17:08:42 +0100212 def set_header(self, header):
213 self.s.headers.update(header)
214
tierno36ec8602018-11-02 17:27:11 +0100215 def set_tet_name(self, test_name):
216 self.test_name = test_name
217
tiernocd54a4a2018-09-12 16:40:35 +0200218 def unset_header(self, key):
219 if key in self.s.headers:
220 del self.s.headers[key]
221
garciadeblas4568a372021-03-24 09:19:48 +0100222 def test(
223 self,
224 description,
225 method,
226 url,
227 headers,
228 payload,
229 expected_codes,
230 expected_headers,
231 expected_payload,
232 store_file=None,
233 pooling=False,
234 ):
tiernof27c79b2018-03-12 17:08:42 +0100235 """
tierno0f98af52018-03-19 10:28:22 +0100236 Performs an http request and check http code response. Exit if different than allowed. It get the returned id
237 that can be used by following test in the URL with {name} where name is the name of the test
tierno0f98af52018-03-19 10:28:22 +0100238 :param description: description of the test
tiernof27c79b2018-03-12 17:08:42 +0100239 :param method: HTTP method: GET,PUT,POST,DELETE,...
240 :param url: complete URL or relative URL
241 :param headers: request headers to add to the base headers
242 :param payload: Can be a dict, transformed to json, a text or a file if starts with '@'
243 :param expected_codes: expected response codes, can be int, int tuple or int range
244 :param expected_headers: expected response headers, dict with key values
tierno49e42062018-10-24 12:50:53 +0200245 :param expected_payload: expected payload, 0 if empty, 'yaml', 'json', 'text', 'zip', 'octet-stream'
246 :param store_file: filename to store content
tiernoff6485d2018-11-28 17:19:46 +0000247 :param pooling: if True do not count neither log this test. Because a pooling is done with many equal requests
tierno0f98af52018-03-19 10:28:22 +0100248 :return: requests response
tiernof27c79b2018-03-12 17:08:42 +0100249 """
tiernoc32ba4a2018-05-24 18:06:41 +0200250 r = None
tiernof27c79b2018-03-12 17:08:42 +0100251 try:
252 if not self.s:
253 self.s = requests.session()
tierno0f98af52018-03-19 10:28:22 +0100254 # URL
tiernof27c79b2018-03-12 17:08:42 +0100255 if not url:
256 url = self.url_base
257 elif not url.startswith("http"):
258 url = self.url_base + url
tierno0f98af52018-03-19 10:28:22 +0100259
tiernoff6485d2018-11-28 17:19:46 +0000260 # replace url <> with the last ID
261 url = url.replace("<>", self.last_id)
tiernof27c79b2018-03-12 17:08:42 +0100262 if payload:
263 if isinstance(payload, str):
264 if payload.startswith("@"):
265 mode = "r"
266 file_name = payload[1:]
267 if payload.startswith("@b"):
268 mode = "rb"
269 file_name = payload[2:]
270 with open(file_name, mode) as f:
271 payload = f.read()
272 elif isinstance(payload, dict):
273 payload = json.dumps(payload)
tierno2236d202018-05-16 19:05:16 +0200274
tiernoff6485d2018-11-28 17:19:46 +0000275 if not pooling:
garciadeblas4568a372021-03-24 09:19:48 +0100276 test_description = "Test {}{} {} {} {}".format(
277 self.test_name, self.step, description, method, url
278 )
tiernoc32ba4a2018-05-24 18:06:41 +0200279 logger.warning(test_description)
tiernoff6485d2018-11-28 17:19:46 +0000280 self.step += 1
tiernof27c79b2018-03-12 17:08:42 +0100281 stream = False
tierno49e42062018-10-24 12:50:53 +0200282 if expected_payload in ("zip", "octet-string") or store_file:
283 stream = True
tiernobee085c2018-12-12 17:03:04 +0000284 __retry = 0
285 while True:
286 try:
garciadeblas4568a372021-03-24 09:19:48 +0100287 r = getattr(self.s, method.lower())(
288 url,
289 data=payload,
290 headers=headers,
291 verify=self.verify,
292 stream=stream,
293 )
tiernobee085c2018-12-12 17:03:04 +0000294 break
295 except requests.exceptions.ConnectionError as e:
296 if __retry == 2:
297 raise
298 logger.error("Exception {}. Retrying".format(e))
299 __retry += 1
300
tierno49e42062018-10-24 12:50:53 +0200301 if expected_payload in ("zip", "octet-string") or store_file:
302 logger.debug("RX {}".format(r.status_code))
303 else:
304 logger.debug("RX {}: {}".format(r.status_code, r.text))
tiernof27c79b2018-03-12 17:08:42 +0100305
306 # check response
307 if expected_codes:
308 if isinstance(expected_codes, int):
309 expected_codes = (expected_codes,)
310 if r.status_code not in expected_codes:
311 raise TestException(
garciadeblas4568a372021-03-24 09:19:48 +0100312 "Got status {}. Expected {}. {}".format(
313 r.status_code, expected_codes, r.text
314 )
315 )
tiernof27c79b2018-03-12 17:08:42 +0100316
317 if expected_headers:
318 for header_key, header_val in expected_headers.items():
319 if header_key.lower() not in r.headers:
320 raise TestException("Header {} not present".format(header_key))
321 if header_val and header_val.lower() not in r.headers[header_key]:
garciadeblas4568a372021-03-24 09:19:48 +0100322 raise TestException(
323 "Header {} does not contain {} but {}".format(
324 header_key, header_val, r.headers[header_key]
325 )
326 )
tiernof27c79b2018-03-12 17:08:42 +0100327
328 if expected_payload is not None:
329 if expected_payload == 0 and len(r.content) > 0:
330 raise TestException("Expected empty payload")
331 elif expected_payload == "json":
332 try:
333 r.json()
334 except Exception as e:
garciadeblas4568a372021-03-24 09:19:48 +0100335 raise TestException(
336 "Expected json response payload, but got Exception {}".format(
337 e
338 )
339 )
tiernof27c79b2018-03-12 17:08:42 +0100340 elif expected_payload == "yaml":
341 try:
342 yaml.safe_load(r.text)
343 except Exception as e:
garciadeblas4568a372021-03-24 09:19:48 +0100344 raise TestException(
345 "Expected yaml response payload, but got Exception {}".format(
346 e
347 )
348 )
tierno49e42062018-10-24 12:50:53 +0200349 elif expected_payload in ("zip", "octet-string"):
tiernof27c79b2018-03-12 17:08:42 +0100350 if len(r.content) == 0:
garciadeblas4568a372021-03-24 09:19:48 +0100351 raise TestException(
352 "Expected some response payload, but got empty"
353 )
tiernof27c79b2018-03-12 17:08:42 +0100354 # try:
355 # tar = tarfile.open(None, 'r:gz', fileobj=r.raw)
356 # for tarinfo in tar:
357 # tarname = tarinfo.name
358 # print(tarname)
359 # except Exception as e:
360 # raise TestException("Expected zip response payload, but got Exception {}".format(e))
361 elif expected_payload == "text":
362 if len(r.content) == 0:
garciadeblas4568a372021-03-24 09:19:48 +0100363 raise TestException(
364 "Expected some response payload, but got empty"
365 )
tierno2236d202018-05-16 19:05:16 +0200366 # r.text
tierno49e42062018-10-24 12:50:53 +0200367 if store_file:
garciadeblas4568a372021-03-24 09:19:48 +0100368 with open(store_file, "wb") as fd:
tierno49e42062018-10-24 12:50:53 +0200369 for chunk in r.iter_content(chunk_size=128):
370 fd.write(chunk)
371
tierno0f98af52018-03-19 10:28:22 +0100372 location = r.headers.get("Location")
373 if location:
garciadeblas4568a372021-03-24 09:19:48 +0100374 _id = location[location.rfind("/") + 1 :]
tierno0f98af52018-03-19 10:28:22 +0100375 if _id:
tiernoff6485d2018-11-28 17:19:46 +0000376 self.last_id = str(_id)
377 if not pooling:
378 self.passed_tests += 1
tiernof27c79b2018-03-12 17:08:42 +0100379 return r
380 except TestException as e:
tiernoff6485d2018-11-28 17:19:46 +0000381 self.failed_tests += 1
tiernoc32ba4a2018-05-24 18:06:41 +0200382 r_status_code = None
383 r_text = None
384 if r:
385 r_status_code = r.status_code
386 r_text = r.text
387 logger.error("{} \nRX code{}: {}".format(e, r_status_code, r_text))
tiernoff6485d2018-11-28 17:19:46 +0000388 return None
389 # exit(1)
tiernof27c79b2018-03-12 17:08:42 +0100390 except IOError as e:
tiernoff6485d2018-11-28 17:19:46 +0000391 if store_file:
392 logger.error("Cannot open file {}: {}".format(store_file, e))
393 else:
394 logger.error("Exception: {}".format(e), exc_info=True)
395 self.failed_tests += 1
396 return None
397 # exit(1)
tiernobee085c2018-12-12 17:03:04 +0000398 except requests.exceptions.RequestException as e:
399 logger.error("Exception: {}".format(e))
tiernof27c79b2018-03-12 17:08:42 +0100400
tiernoc32ba4a2018-05-24 18:06:41 +0200401 def get_autorization(self): # user=None, password=None, project=None):
garciadeblas4568a372021-03-24 09:19:48 +0100402 if (
403 self.token
404 ): # and self.user == user and self.password == password and self.project == project:
tiernoc32ba4a2018-05-24 18:06:41 +0200405 return
406 # self.user = user
407 # self.password = password
408 # self.project = project
garciadeblas4568a372021-03-24 09:19:48 +0100409 r = self.test(
410 "Obtain token",
411 "POST",
412 "/admin/v1/tokens",
413 headers_json,
414 {
415 "username": self.user,
416 "password": self.password,
417 "project_id": self.project,
418 },
419 (200, 201),
420 r_header_json,
421 "json",
422 )
tiernoff6485d2018-11-28 17:19:46 +0000423 if not r:
424 return
tiernoc32ba4a2018-05-24 18:06:41 +0200425 response = r.json()
426 self.token = response["id"]
427 self.set_header({"Authorization": "Bearer {}".format(self.token)})
428
tiernocd54a4a2018-09-12 16:40:35 +0200429 def remove_authorization(self):
430 if self.token:
garciadeblas4568a372021-03-24 09:19:48 +0100431 self.test(
432 "Delete token",
433 "DELETE",
434 "/admin/v1/tokens/{}".format(self.token),
435 headers_json,
436 None,
437 (200, 201, 204),
438 None,
439 None,
440 )
tiernocd54a4a2018-09-12 16:40:35 +0200441 self.token = None
442 self.unset_header("Authorization")
443
tiernoc32ba4a2018-05-24 18:06:41 +0200444 def get_create_vim(self, test_osm):
445 if self.vim_id:
446 return self.vim_id
447 self.get_autorization()
448 if test_osm:
449 vim_name = os.environ.get("OSMNBITEST_VIM_NAME")
450 if not vim_name:
451 raise TestException(
garciadeblas4568a372021-03-24 09:19:48 +0100452 "Needed to define OSMNBITEST_VIM_XXX variables to create a real VIM for deployment"
453 )
tiernoc32ba4a2018-05-24 18:06:41 +0200454 else:
455 vim_name = "fakeVim"
456 # Get VIM
garciadeblas4568a372021-03-24 09:19:48 +0100457 r = self.test(
458 "Get VIM ID",
459 "GET",
460 "/admin/v1/vim_accounts?name={}".format(vim_name),
461 headers_json,
462 None,
463 200,
464 r_header_json,
465 "json",
466 )
tiernoff6485d2018-11-28 17:19:46 +0000467 if not r:
468 return
tiernoc32ba4a2018-05-24 18:06:41 +0200469 vims = r.json()
470 if vims:
471 return vims[0]["_id"]
472 # Add VIM
473 if test_osm:
474 # check needed environ parameters:
garciadeblas4568a372021-03-24 09:19:48 +0100475 if not os.environ.get("OSMNBITEST_VIM_URL") or not os.environ.get(
476 "OSMNBITEST_VIM_TENANT"
477 ):
478 raise TestException(
479 "Env OSMNBITEST_VIM_URL and OSMNBITEST_VIM_TENANT are needed for create a real VIM"
480 " to deploy on whit the --test-osm option"
481 )
482 vim_data = "{{schema_version: '1.0', name: '{}', vim_type: {}, vim_url: '{}', vim_tenant_name: '{}', " "vim_user: {}, vim_password: {}".format(
483 vim_name,
484 os.environ.get("OSMNBITEST_VIM_TYPE", "openstack"),
485 os.environ.get("OSMNBITEST_VIM_URL"),
486 os.environ.get("OSMNBITEST_VIM_TENANT"),
487 os.environ.get("OSMNBITEST_VIM_USER"),
488 os.environ.get("OSMNBITEST_VIM_PASSWORD"),
489 )
tiernoc32ba4a2018-05-24 18:06:41 +0200490 if os.environ.get("OSMNBITEST_VIM_CONFIG"):
garciadeblas4568a372021-03-24 09:19:48 +0100491 vim_data += " ,config: {}".format(
492 os.environ.get("OSMNBITEST_VIM_CONFIG")
493 )
tiernoc32ba4a2018-05-24 18:06:41 +0200494 vim_data += "}"
495 else:
garciadeblas4568a372021-03-24 09:19:48 +0100496 vim_data = (
497 "{schema_version: '1.0', name: fakeVim, vim_type: openstack, vim_url: 'http://10.11.12.13/fake'"
498 ", vim_tenant_name: 'vimtenant', vim_user: vimuser, vim_password: vimpassword}"
499 )
500 self.test(
501 "Create VIM",
502 "POST",
503 "/admin/v1/vim_accounts",
504 headers_yaml,
505 vim_data,
506 (201, 202),
507 {"Location": "/admin/v1/vim_accounts/", "Content-Type": "application/yaml"},
508 "yaml",
509 )
tiernoff6485d2018-11-28 17:19:46 +0000510 return self.last_id
511
512 def print_results(self):
513 print("\n\n\n--------------------------------------------")
garciadeblas4568a372021-03-24 09:19:48 +0100514 print(
515 "TEST RESULTS: Total: {}, Passed: {}, Failed: {}".format(
516 self.passed_tests + self.failed_tests,
517 self.passed_tests,
518 self.failed_tests,
519 )
520 )
tiernoff6485d2018-11-28 17:19:46 +0000521 print("--------------------------------------------")
522
523 def wait_until_delete(self, url_op, timeout_delete):
524 """
525 Make a pooling until topic is not present, because of deleted
526 :param url_op:
527 :param timeout_delete:
528 :return:
529 """
530 description = "Wait to topic being deleted"
garciadeblas4568a372021-03-24 09:19:48 +0100531 test_description = "Test {}{} {} {} {}".format(
532 self.test_name, self.step, description, "GET", url_op
533 )
tiernoff6485d2018-11-28 17:19:46 +0000534 logger.warning(test_description)
535 self.step += 1
536
537 wait = timeout_delete
538 while wait >= 0:
garciadeblas4568a372021-03-24 09:19:48 +0100539 r = self.test(
540 description,
541 "GET",
542 url_op,
543 headers_yaml,
544 None,
545 (200, 404),
546 None,
547 r_header_yaml,
548 "yaml",
549 pooling=True,
550 )
tiernoff6485d2018-11-28 17:19:46 +0000551 if not r:
552 return
553 if r.status_code == 404:
554 self.passed_tests += 1
555 break
556 elif r.status_code == 200:
557 wait -= 5
558 sleep(5)
559 else:
garciadeblas4568a372021-03-24 09:19:48 +0100560 raise TestException(
561 "Topic is not deleted after {} seconds".format(timeout_delete)
562 )
tiernoff6485d2018-11-28 17:19:46 +0000563 self.failed_tests += 1
564
565 def wait_operation_ready(self, ns_nsi, opp_id, timeout, expected_fail=False):
566 """
567 Wait until nslcmop or nsilcmop finished
568 :param ns_nsi: "ns" o "nsi"
569 :param opp_id: Id o fthe operation
570 :param timeout:
571 :param expected_fail:
572 :return: None. Updates passed/failed_tests
573 """
574 if ns_nsi == "ns":
575 url_op = "/nslcm/v1/ns_lcm_op_occs/{}".format(opp_id)
576 else:
577 url_op = "/nsilcm/v1/nsi_lcm_op_occs/{}".format(opp_id)
578 description = "Wait to {} lcm operation complete".format(ns_nsi)
garciadeblas4568a372021-03-24 09:19:48 +0100579 test_description = "Test {}{} {} {} {}".format(
580 self.test_name, self.step, description, "GET", url_op
581 )
tiernoff6485d2018-11-28 17:19:46 +0000582 logger.warning(test_description)
583 self.step += 1
584 wait = timeout
585 while wait >= 0:
garciadeblas4568a372021-03-24 09:19:48 +0100586 r = self.test(
587 description,
588 "GET",
589 url_op,
590 headers_json,
591 None,
592 200,
593 r_header_json,
594 "json",
595 pooling=True,
596 )
tiernoff6485d2018-11-28 17:19:46 +0000597 if not r:
598 return
599 nslcmop = r.json()
600 if "COMPLETED" in nslcmop["operationState"]:
601 if expected_fail:
garciadeblas4568a372021-03-24 09:19:48 +0100602 logger.error(
603 "NS terminate has success, expecting failing: {}".format(
604 nslcmop["detailed-status"]
605 )
606 )
tiernoff6485d2018-11-28 17:19:46 +0000607 self.failed_tests += 1
608 else:
609 self.passed_tests += 1
610 break
611 elif "FAILED" in nslcmop["operationState"]:
612 if not expected_fail:
garciadeblas4568a372021-03-24 09:19:48 +0100613 logger.error(
614 "NS terminate has failed: {}".format(nslcmop["detailed-status"])
615 )
tiernobee085c2018-12-12 17:03:04 +0000616 self.failed_tests += 1
tiernoff6485d2018-11-28 17:19:46 +0000617 else:
618 self.passed_tests += 1
619 break
620
621 print(".", end="", file=stderr)
622 wait -= 10
623 sleep(10)
624 else:
625 self.failed_tests += 1
garciadeblas4568a372021-03-24 09:19:48 +0100626 logger.error(
627 "NS instantiate is not terminate after {} seconds".format(timeout)
628 )
tiernoff6485d2018-11-28 17:19:46 +0000629 return
630 print("", file=stderr)
tiernoc32ba4a2018-05-24 18:06:41 +0200631
632
633class TestNonAuthorized:
tiernobee085c2018-12-12 17:03:04 +0000634 description = "Test invalid URLs. methods and no authorization"
tiernoc32ba4a2018-05-24 18:06:41 +0200635
636 @staticmethod
tiernocd54a4a2018-09-12 16:40:35 +0200637 def run(engine, test_osm, manual_check, test_params=None):
tiernoff6485d2018-11-28 17:19:46 +0000638 engine.set_test_name("NonAuth")
tiernocd54a4a2018-09-12 16:40:35 +0200639 engine.remove_authorization()
tiernoc32ba4a2018-05-24 18:06:41 +0200640 test_not_authorized_list = (
garciadeblas4568a372021-03-24 09:19:48 +0100641 (
642 "Invalid token",
643 "GET",
644 "/admin/v1/users",
645 headers_json,
646 None,
647 401,
648 r_header_json,
649 "json",
650 ),
651 (
652 "Invalid URL",
653 "POST",
654 "/admin/v1/nonexist",
655 headers_yaml,
656 None,
657 405,
658 r_header_yaml,
659 "yaml",
660 ),
661 (
662 "Invalid version",
663 "DELETE",
664 "/admin/v2/users",
665 headers_yaml,
666 None,
667 405,
668 r_header_yaml,
669 "yaml",
670 ),
tiernoc32ba4a2018-05-24 18:06:41 +0200671 )
672 for t in test_not_authorized_list:
673 engine.test(*t)
674
675
tiernocd54a4a2018-09-12 16:40:35 +0200676class TestUsersProjects:
677 description = "test project and user creation"
678
679 @staticmethod
680 def run(engine, test_osm, manual_check, test_params=None):
tiernoff6485d2018-11-28 17:19:46 +0000681 engine.set_test_name("UserProject")
delacruzramo9742f1d2019-06-05 13:06:47 +0200682 # backend = test_params.get("backend") if test_params else None # UNUSED
683
684 # Initialisation
685 p1 = p2 = p3 = None
686 padmin = pbad = None
687 u1 = u2 = u3 = u4 = None
688
tiernocd54a4a2018-09-12 16:40:35 +0200689 engine.get_autorization()
delacruzramo9742f1d2019-06-05 13:06:47 +0200690
garciadeblas4568a372021-03-24 09:19:48 +0100691 res = engine.test(
692 "Create project non admin 1",
693 "POST",
694 "/admin/v1/projects",
695 headers_json,
696 {"name": "P1"},
697 (201, 204),
698 {"Location": "/admin/v1/projects/", "Content-Type": "application/json"},
699 "json",
700 )
delacruzramo9742f1d2019-06-05 13:06:47 +0200701 p1 = engine.last_id if res else None
702
garciadeblas4568a372021-03-24 09:19:48 +0100703 res = engine.test(
704 "Create project admin",
705 "POST",
706 "/admin/v1/projects",
707 headers_json,
708 {"name": "Padmin", "admin": True},
709 (201, 204),
710 {"Location": "/admin/v1/projects/", "Content-Type": "application/json"},
711 "json",
712 )
delacruzramo9742f1d2019-06-05 13:06:47 +0200713 padmin = engine.last_id if res else None
714
garciadeblas4568a372021-03-24 09:19:48 +0100715 res = engine.test(
716 "Create project bad format",
717 "POST",
718 "/admin/v1/projects",
719 headers_json,
720 {"name": 1},
721 (400, 422),
722 r_header_json,
723 "json",
724 )
delacruzramo9742f1d2019-06-05 13:06:47 +0200725 pbad = engine.last_id if res else None
726
garciadeblas4568a372021-03-24 09:19:48 +0100727 res = engine.test(
728 "Get project admin role",
729 "GET",
730 "/admin/v1/roles?name=project_admin",
731 headers_json,
732 {},
733 (200),
734 {"Content-Type": "application/json"},
735 "json",
736 )
delacruzramo9742f1d2019-06-05 13:06:47 +0200737 rpa = res.json()[0]["_id"] if res else None
garciadeblas4568a372021-03-24 09:19:48 +0100738 res = engine.test(
739 "Get project user role",
740 "GET",
741 "/admin/v1/roles?name=project_user",
742 headers_json,
743 {},
744 (200),
745 {"Content-Type": "application/json"},
746 "json",
747 )
delacruzramo9742f1d2019-06-05 13:06:47 +0200748 rpu = res.json()[0]["_id"] if res else None
garciadeblas4568a372021-03-24 09:19:48 +0100749 res = engine.test(
750 "Get system admin role",
751 "GET",
752 "/admin/v1/roles?name=system_admin",
753 headers_json,
754 {},
755 (200),
756 {"Content-Type": "application/json"},
757 "json",
758 )
delacruzramo9742f1d2019-06-05 13:06:47 +0200759 rsa = res.json()[0]["_id"] if res else None
760
761 data = {"username": "U1", "password": "pw1"}
762 p2 = uuid4().hex
763 data["project_role_mappings"] = [
764 {"project": p1, "role": rpa},
765 {"project": p2, "role": rpa},
garciadeblas4568a372021-03-24 09:19:48 +0100766 {"project": padmin, "role": rpu},
delacruzramo9742f1d2019-06-05 13:06:47 +0200767 ]
768 rc = 201
769 xhd = {"Location": "/admin/v1/users/", "Content-Type": "application/json"}
garciadeblas4568a372021-03-24 09:19:48 +0100770 res = engine.test(
771 "Create user with bad project and force",
772 "POST",
773 "/admin/v1/users?FORCE=True",
774 headers_json,
775 data,
776 rc,
777 xhd,
778 "json",
779 )
tiernoff6485d2018-11-28 17:19:46 +0000780 if res:
delacruzramo9742f1d2019-06-05 13:06:47 +0200781 u1 = engine.last_id
782 else:
783 # User is created sometimes even though an exception is raised
garciadeblas4568a372021-03-24 09:19:48 +0100784 res = engine.test(
785 "Get user U1",
786 "GET",
787 "/admin/v1/users?username=U1",
788 headers_json,
789 {},
790 (200),
791 {"Content-Type": "application/json"},
792 "json",
793 )
delacruzramo9742f1d2019-06-05 13:06:47 +0200794 u1 = res.json()[0]["_id"] if res else None
tiernocd54a4a2018-09-12 16:40:35 +0200795
delacruzramo9742f1d2019-06-05 13:06:47 +0200796 data = {"username": "U2", "password": "pw2"}
garciadeblas4568a372021-03-24 09:19:48 +0100797 data["project_role_mappings"] = [
798 {"project": p1, "role": rpa},
799 {"project": padmin, "role": rsa},
800 ]
801 res = engine.test(
802 "Create user 2",
803 "POST",
804 "/admin/v1/users",
805 headers_json,
806 data,
807 201,
808 {"Location": "/admin/v1/users/", "Content-Type": "application/json"},
809 "json",
810 )
delacruzramo9742f1d2019-06-05 13:06:47 +0200811 u2 = engine.last_id if res else None
tiernocd54a4a2018-09-12 16:40:35 +0200812
delacruzramo9742f1d2019-06-05 13:06:47 +0200813 if u1:
814 ftt = "project_role_mappings"
815 xpr = [{"project": p1, "role": rpa}, {"project": padmin, "role": rpu}]
816 data = {ftt: xpr}
garciadeblas4568a372021-03-24 09:19:48 +0100817 engine.test(
818 "Edit user U1, delete P2 project",
819 "PATCH",
820 "/admin/v1/users/" + u1,
821 headers_json,
822 data,
823 204,
824 None,
825 None,
826 )
827 res = engine.test(
828 "Check user U1, contains the right projects",
829 "GET",
830 "/admin/v1/users/" + u1,
831 headers_json,
832 None,
833 200,
834 None,
835 json,
836 )
delacruzramo9742f1d2019-06-05 13:06:47 +0200837 if res:
838 rj = res.json()
839 xpr[0]["project_name"] = "P1"
840 xpr[0]["role_name"] = "project_admin"
841 xpr[1]["project_name"] = "Padmin"
842 xpr[1]["role_name"] = "project_user"
843 ok = True
844 for pr in rj[ftt]:
845 if pr not in xpr:
846 ok = False
847 for pr in xpr:
848 if pr not in rj[ftt]:
849 ok = False
850 if not ok:
garciadeblas4568a372021-03-24 09:19:48 +0100851 logger.error(
852 "User {} '{}' are different than expected '{}'. Edition was not done properly".format(
853 ftt, rj[ftt], xpr
854 )
855 )
delacruzramo9742f1d2019-06-05 13:06:47 +0200856 engine.failed_tests += 1
tiernocd54a4a2018-09-12 16:40:35 +0200857
garciadeblas4568a372021-03-24 09:19:48 +0100858 p2 = None # To prevent deletion attempts
tiernocd54a4a2018-09-12 16:40:35 +0200859
delacruzramo9742f1d2019-06-05 13:06:47 +0200860 # Add a test of 'default project' for Keystone?
tiernocd54a4a2018-09-12 16:40:35 +0200861
delacruzramo9742f1d2019-06-05 13:06:47 +0200862 if u2:
garciadeblas4568a372021-03-24 09:19:48 +0100863 engine.test(
864 "Edit user U2, change password",
865 "PUT",
866 "/admin/v1/users/" + u2,
867 headers_json,
868 {"password": "pw2_new"},
869 204,
870 None,
871 None,
872 )
tiernocd54a4a2018-09-12 16:40:35 +0200873
delacruzramo9742f1d2019-06-05 13:06:47 +0200874 if p1:
garciadeblas4568a372021-03-24 09:19:48 +0100875 engine.test(
876 "Change to project P1 non existing",
877 "POST",
878 "/admin/v1/tokens/",
879 headers_json,
880 {"project_id": p1},
881 401,
882 r_header_json,
883 "json",
884 )
tiernocd54a4a2018-09-12 16:40:35 +0200885
delacruzramo9742f1d2019-06-05 13:06:47 +0200886 if u2 and p1:
garciadeblas4568a372021-03-24 09:19:48 +0100887 res = engine.test(
888 "Change to user U2 project P1",
889 "POST",
890 "/admin/v1/tokens",
891 headers_json,
892 {"username": "U2", "password": "pw2_new", "project_id": "P1"},
893 (200, 201),
894 r_header_json,
895 "json",
896 )
delacruzramo9742f1d2019-06-05 13:06:47 +0200897 if res:
898 rj = res.json()
899 engine.set_header({"Authorization": "Bearer {}".format(rj["id"])})
tiernocd54a4a2018-09-12 16:40:35 +0200900
garciadeblas4568a372021-03-24 09:19:48 +0100901 engine.test(
902 "Edit user projects non admin",
903 "PUT",
904 "/admin/v1/users/U1",
905 headers_json,
906 {"remove_project_role_mappings": [{"project": "P1", "role": None}]},
907 401,
908 r_header_json,
909 "json",
910 )
tiernocd54a4a2018-09-12 16:40:35 +0200911
garciadeblas4568a372021-03-24 09:19:48 +0100912 res = engine.test(
913 "Add new project non admin",
914 "POST",
915 "/admin/v1/projects",
916 headers_json,
917 {"name": "P2"},
918 401,
919 r_header_json,
920 "json",
921 )
delacruzramo9742f1d2019-06-05 13:06:47 +0200922 if res is None or res.status_code == 201:
923 # The project has been created even though it shouldn't
garciadeblas4568a372021-03-24 09:19:48 +0100924 res = engine.test(
925 "Get project P2",
926 "GET",
927 "/admin/v1/projects/P2",
928 headers_json,
929 None,
930 200,
931 r_header_json,
932 "json",
933 )
delacruzramo9742f1d2019-06-05 13:06:47 +0200934 p2 = res.json()["_id"] if res else None
935
936 if p1:
937 data = {"username": "U3", "password": "pw3"}
938 data["project_role_mappings"] = [{"project": p1, "role": rpu}]
garciadeblas4568a372021-03-24 09:19:48 +0100939 res = engine.test(
940 "Add new user non admin",
941 "POST",
942 "/admin/v1/users",
943 headers_json,
944 data,
945 401,
946 r_header_json,
947 "json",
948 )
delacruzramo9742f1d2019-06-05 13:06:47 +0200949 if res is None or res.status_code == 201:
950 # The user has been created even though it shouldn't
garciadeblas4568a372021-03-24 09:19:48 +0100951 res = engine.test(
952 "Get user U3",
953 "GET",
954 "/admin/v1/users/U3",
955 headers_json,
956 None,
957 200,
958 r_header_json,
959 "json",
960 )
delacruzramo9742f1d2019-06-05 13:06:47 +0200961 u3 = res.json()["_id"] if res else None
962 else:
963 u3 = None
964
965 if padmin:
garciadeblas4568a372021-03-24 09:19:48 +0100966 res = engine.test(
967 "Change to user U2 project Padmin",
968 "POST",
969 "/admin/v1/tokens",
970 headers_json,
971 {
972 "project_id": "Padmin"
973 }, # Caused a Keystone authentication error
974 # {"username": "U2", "password": "pw2_new", "project_id": "Padmin"},
975 (200, 201),
976 r_header_json,
977 "json",
978 )
delacruzramo9742f1d2019-06-05 13:06:47 +0200979 if res:
980 rj = res.json()
garciadeblas4568a372021-03-24 09:19:48 +0100981 engine.set_header(
982 {"Authorization": "Bearer {}".format(rj["id"])}
983 )
delacruzramo9742f1d2019-06-05 13:06:47 +0200984
garciadeblas4568a372021-03-24 09:19:48 +0100985 res = engine.test(
986 "Add new project admin",
987 "POST",
988 "/admin/v1/projects",
989 headers_json,
990 {"name": "P3"},
991 (201, 204),
992 {
993 "Location": "/admin/v1/projects/",
994 "Content-Type": "application/json",
995 },
996 "json",
997 )
delacruzramo9742f1d2019-06-05 13:06:47 +0200998 p3 = engine.last_id if res else None
999
1000 if p1:
1001 data = {"username": "U4", "password": "pw4"}
garciadeblas4568a372021-03-24 09:19:48 +01001002 data["project_role_mappings"] = [
1003 {"project": p1, "role": rpa}
1004 ]
1005 res = engine.test(
1006 "Add new user admin",
1007 "POST",
1008 "/admin/v1/users",
1009 headers_json,
1010 data,
1011 (201, 204),
1012 {
1013 "Location": "/admin/v1/users/",
1014 "Content-Type": "application/json",
1015 },
1016 "json",
1017 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001018 u4 = engine.last_id if res else None
1019 else:
1020 u4 = None
1021
1022 if u4 and p3:
garciadeblas4568a372021-03-24 09:19:48 +01001023 data = {
1024 "project_role_mappings": [{"project": p3, "role": rpa}]
1025 }
1026 engine.test(
1027 "Edit user projects admin",
1028 "PUT",
1029 "/admin/v1/users/U4",
1030 headers_json,
1031 data,
1032 204,
1033 None,
1034 None,
1035 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001036 # Project is deleted even though it shouldn't - PROVISIONAL?
garciadeblas4568a372021-03-24 09:19:48 +01001037 res = engine.test(
1038 "Delete project P3 conflict",
1039 "DELETE",
1040 "/admin/v1/projects/" + p3,
1041 headers_json,
1042 None,
1043 409,
1044 None,
1045 None,
1046 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001047 if res and res.status_code in (200, 204):
1048 p3 = None
1049 if p3:
garciadeblas4568a372021-03-24 09:19:48 +01001050 res = engine.test(
1051 "Delete project P3 forcing",
1052 "DELETE",
1053 "/admin/v1/projects/" + p3 + "?FORCE=True",
1054 headers_json,
1055 None,
1056 204,
1057 None,
1058 None,
1059 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001060 if res and res.status_code in (200, 204):
1061 p3 = None
1062
1063 if u2:
garciadeblas4568a372021-03-24 09:19:48 +01001064 res = engine.test(
1065 "Delete user U2. Conflict deleting own user",
1066 "DELETE",
1067 "/admin/v1/users/" + u2,
1068 headers_json,
1069 None,
1070 409,
1071 r_header_json,
1072 "json",
1073 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001074 if res is None or res.status_code in (200, 204):
1075 u2 = None
1076 if u4:
garciadeblas4568a372021-03-24 09:19:48 +01001077 res = engine.test(
1078 "Delete user U4",
1079 "DELETE",
1080 "/admin/v1/users/" + u4,
1081 headers_json,
1082 None,
1083 204,
1084 None,
1085 None,
1086 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001087 if res and res.status_code in (200, 204):
1088 u4 = None
1089 if p3:
garciadeblas4568a372021-03-24 09:19:48 +01001090 res = engine.test(
1091 "Delete project P3",
1092 "DELETE",
1093 "/admin/v1/projects/" + p3,
1094 headers_json,
1095 None,
1096 204,
1097 None,
1098 None,
1099 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001100 if res and res.status_code in (200, 204):
1101 p3 = None
1102
1103 if u3:
garciadeblas4568a372021-03-24 09:19:48 +01001104 res = engine.test(
1105 "Delete user U3",
1106 "DELETE",
1107 "/admin/v1/users/" + u3,
1108 headers_json,
1109 None,
1110 204,
1111 None,
1112 None,
1113 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001114 if res:
1115 u3 = None
1116
tiernocd54a4a2018-09-12 16:40:35 +02001117 # change to admin
garciadeblas4568a372021-03-24 09:19:48 +01001118 engine.remove_authorization() # To force get authorization
tiernocd54a4a2018-09-12 16:40:35 +02001119 engine.get_autorization()
delacruzramo9742f1d2019-06-05 13:06:47 +02001120 if u1:
garciadeblas4568a372021-03-24 09:19:48 +01001121 engine.test(
1122 "Delete user U1",
1123 "DELETE",
1124 "/admin/v1/users/" + u1,
1125 headers_json,
1126 None,
1127 204,
1128 None,
1129 None,
1130 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001131 if u2:
garciadeblas4568a372021-03-24 09:19:48 +01001132 engine.test(
1133 "Delete user U2",
1134 "DELETE",
1135 "/admin/v1/users/" + u2,
1136 headers_json,
1137 None,
1138 204,
1139 None,
1140 None,
1141 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001142 if u3:
garciadeblas4568a372021-03-24 09:19:48 +01001143 engine.test(
1144 "Delete user U3",
1145 "DELETE",
1146 "/admin/v1/users/" + u3,
1147 headers_json,
1148 None,
1149 204,
1150 None,
1151 None,
1152 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001153 if u4:
garciadeblas4568a372021-03-24 09:19:48 +01001154 engine.test(
1155 "Delete user U4",
1156 "DELETE",
1157 "/admin/v1/users/" + u4,
1158 headers_json,
1159 None,
1160 204,
1161 None,
1162 None,
1163 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001164 if p1:
garciadeblas4568a372021-03-24 09:19:48 +01001165 engine.test(
1166 "Delete project P1",
1167 "DELETE",
1168 "/admin/v1/projects/" + p1,
1169 headers_json,
1170 None,
1171 204,
1172 None,
1173 None,
1174 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001175 if p2:
garciadeblas4568a372021-03-24 09:19:48 +01001176 engine.test(
1177 "Delete project P2",
1178 "DELETE",
1179 "/admin/v1/projects/" + p2,
1180 headers_json,
1181 None,
1182 204,
1183 None,
1184 None,
1185 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001186 if p3:
garciadeblas4568a372021-03-24 09:19:48 +01001187 engine.test(
1188 "Delete project P3",
1189 "DELETE",
1190 "/admin/v1/projects/" + p3,
1191 headers_json,
1192 None,
1193 204,
1194 None,
1195 None,
1196 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001197 if padmin:
garciadeblas4568a372021-03-24 09:19:48 +01001198 engine.test(
1199 "Delete project Padmin",
1200 "DELETE",
1201 "/admin/v1/projects/" + padmin,
1202 headers_json,
1203 None,
1204 204,
1205 None,
1206 None,
1207 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001208 if pbad:
garciadeblas4568a372021-03-24 09:19:48 +01001209 engine.test(
1210 "Delete bad project",
1211 "DELETE",
1212 "/admin/v1/projects/" + pbad,
1213 headers_json,
1214 None,
1215 204,
1216 None,
1217 None,
1218 )
tiernocd54a4a2018-09-12 16:40:35 +02001219
delacruzramoc061f562019-04-05 11:00:02 +02001220 # BEGIN New Tests - Addressing Projects/Users by Name/ID
delacruzramo9742f1d2019-06-05 13:06:47 +02001221 pid1 = pid2 = None
1222 uid1 = uid2 = None
garciadeblas4568a372021-03-24 09:19:48 +01001223 res = engine.test(
1224 "Create new project P1",
1225 "POST",
1226 "/admin/v1/projects",
1227 headers_json,
1228 {"name": "P1"},
1229 201,
1230 {"Location": "/admin/v1/projects/", "Content-Type": "application/json"},
1231 "json",
1232 )
delacruzramoc061f562019-04-05 11:00:02 +02001233 if res:
1234 pid1 = res.json()["id"]
1235 # print("# pid =", pid1)
garciadeblas4568a372021-03-24 09:19:48 +01001236 res = engine.test(
1237 "Create new project P2",
1238 "POST",
1239 "/admin/v1/projects",
1240 headers_json,
1241 {"name": "P2"},
1242 201,
1243 {"Location": "/admin/v1/projects/", "Content-Type": "application/json"},
1244 "json",
1245 )
delacruzramoc061f562019-04-05 11:00:02 +02001246 if res:
1247 pid2 = res.json()["id"]
1248 # print("# pid =", pid2)
delacruzramo9742f1d2019-06-05 13:06:47 +02001249 data = {"username": "U1", "password": "pw1"}
1250 data["project_role_mappings"] = [{"project": pid1, "role": rpu}]
garciadeblas4568a372021-03-24 09:19:48 +01001251 res = engine.test(
1252 "Create new user U1",
1253 "POST",
1254 "/admin/v1/users",
1255 headers_json,
1256 data,
1257 201,
1258 {"Location": "/admin/v1/users/", "Content-Type": "application/json"},
1259 "json",
1260 )
delacruzramoc061f562019-04-05 11:00:02 +02001261 if res:
1262 uid1 = res.json()["id"]
1263 # print("# uid =", uid1)
delacruzramo9742f1d2019-06-05 13:06:47 +02001264 data = {"username": "U2", "password": "pw2"}
1265 data["project_role_mappings"] = [{"project": pid2, "role": rpu}]
garciadeblas4568a372021-03-24 09:19:48 +01001266 res = engine.test(
1267 "Create new user U2",
1268 "POST",
1269 "/admin/v1/users",
1270 headers_json,
1271 data,
1272 201,
1273 {"Location": "/admin/v1/users/", "Content-Type": "application/json"},
1274 "json",
1275 )
delacruzramoc061f562019-04-05 11:00:02 +02001276 if res:
1277 uid2 = res.json()["id"]
1278 # print("# uid =", uid2)
delacruzramo9742f1d2019-06-05 13:06:47 +02001279 if pid1:
garciadeblas4568a372021-03-24 09:19:48 +01001280 engine.test(
1281 "Get Project P1 by Name",
1282 "GET",
1283 "/admin/v1/projects/P1",
1284 headers_json,
1285 None,
1286 200,
1287 None,
1288 "json",
1289 )
1290 engine.test(
1291 "Get Project P1 by ID",
1292 "GET",
1293 "/admin/v1/projects/" + pid1,
1294 headers_json,
1295 None,
1296 200,
1297 None,
1298 "json",
1299 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001300 if uid1:
garciadeblas4568a372021-03-24 09:19:48 +01001301 engine.test(
1302 "Get User U1 by Name",
1303 "GET",
1304 "/admin/v1/users/U1",
1305 headers_json,
1306 None,
1307 200,
1308 None,
1309 "json",
1310 )
1311 engine.test(
1312 "Get User U1 by ID",
1313 "GET",
1314 "/admin/v1/users/" + uid1,
1315 headers_json,
1316 None,
1317 200,
1318 None,
1319 "json",
1320 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001321 if pid1:
garciadeblas4568a372021-03-24 09:19:48 +01001322 res = engine.test(
1323 "Rename Project P1 by Name",
1324 "PUT",
1325 "/admin/v1/projects/P1",
1326 headers_json,
1327 {"name": "P3"},
1328 204,
1329 None,
1330 None,
1331 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001332 if res:
garciadeblas4568a372021-03-24 09:19:48 +01001333 engine.test(
1334 "Get Project P1 by new Name",
1335 "GET",
1336 "/admin/v1/projects/P3",
1337 headers_json,
1338 None,
1339 200,
1340 None,
1341 "json",
1342 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001343 if pid2:
garciadeblas4568a372021-03-24 09:19:48 +01001344 res = engine.test(
1345 "Rename Project P2 by ID",
1346 "PUT",
1347 "/admin/v1/projects/" + pid2,
1348 headers_json,
1349 {"name": "P4"},
1350 204,
1351 None,
1352 None,
1353 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001354 if res:
garciadeblas4568a372021-03-24 09:19:48 +01001355 engine.test(
1356 "Get Project P2 by new Name",
1357 "GET",
1358 "/admin/v1/projects/P4",
1359 headers_json,
1360 None,
1361 200,
1362 None,
1363 "json",
1364 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001365
1366 if uid1:
garciadeblas4568a372021-03-24 09:19:48 +01001367 res = engine.test(
1368 "Rename User U1 by Name",
1369 "PUT",
1370 "/admin/v1/users/U1",
1371 headers_json,
1372 {"username": "U3"},
1373 204,
1374 None,
1375 None,
1376 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001377 if res:
garciadeblas4568a372021-03-24 09:19:48 +01001378 engine.test(
1379 "Get User U1 by new Name",
1380 "GET",
1381 "/admin/v1/users/U3",
1382 headers_json,
1383 None,
1384 200,
1385 None,
1386 "json",
1387 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001388
1389 if uid2:
garciadeblas4568a372021-03-24 09:19:48 +01001390 res = engine.test(
1391 "Rename User U2 by ID",
1392 "PUT",
1393 "/admin/v1/users/" + uid2,
1394 headers_json,
1395 {"username": "U4"},
1396 204,
1397 None,
1398 None,
1399 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001400 if res:
garciadeblas4568a372021-03-24 09:19:48 +01001401 engine.test(
1402 "Get User U2 by new Name",
1403 "GET",
1404 "/admin/v1/users/U4",
1405 headers_json,
1406 None,
1407 200,
1408 None,
1409 "json",
1410 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001411 if uid1:
garciadeblas4568a372021-03-24 09:19:48 +01001412 res = engine.test(
1413 "Delete User U1 by Name",
1414 "DELETE",
1415 "/admin/v1/users/U3",
1416 headers_json,
1417 None,
1418 204,
1419 None,
1420 None,
1421 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001422 if res:
1423 uid1 = None
1424
1425 if uid2:
garciadeblas4568a372021-03-24 09:19:48 +01001426 res = engine.test(
1427 "Delete User U2 by ID",
1428 "DELETE",
1429 "/admin/v1/users/" + uid2,
1430 headers_json,
1431 None,
1432 204,
1433 None,
1434 None,
1435 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001436 if res:
1437 uid2 = None
1438
1439 if pid1:
garciadeblas4568a372021-03-24 09:19:48 +01001440 res = engine.test(
1441 "Delete Project P1 by Name",
1442 "DELETE",
1443 "/admin/v1/projects/P3",
1444 headers_json,
1445 None,
1446 204,
1447 None,
1448 None,
1449 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001450 if res:
1451 pid1 = None
1452
1453 if pid2:
garciadeblas4568a372021-03-24 09:19:48 +01001454 res = engine.test(
1455 "Delete Project P2 by ID",
1456 "DELETE",
1457 "/admin/v1/projects/" + pid2,
1458 headers_json,
1459 None,
1460 204,
1461 None,
1462 None,
1463 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001464 if res:
1465 pid2 = None
1466
delacruzramoc061f562019-04-05 11:00:02 +02001467 # END New Tests - Addressing Projects/Users by Name
delacruzramo9742f1d2019-06-05 13:06:47 +02001468
1469 # CLEANUP
1470 if pid1:
garciadeblas4568a372021-03-24 09:19:48 +01001471 engine.test(
1472 "Delete Project P1",
1473 "DELETE",
1474 "/admin/v1/projects/" + pid1,
1475 headers_json,
1476 None,
1477 204,
1478 None,
1479 None,
1480 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001481 if pid2:
garciadeblas4568a372021-03-24 09:19:48 +01001482 engine.test(
1483 "Delete Project P2",
1484 "DELETE",
1485 "/admin/v1/projects/" + pid2,
1486 headers_json,
1487 None,
1488 204,
1489 None,
1490 None,
1491 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001492 if uid1:
garciadeblas4568a372021-03-24 09:19:48 +01001493 engine.test(
1494 "Delete User U1",
1495 "DELETE",
1496 "/admin/v1/users/" + uid1,
1497 headers_json,
1498 None,
1499 204,
1500 None,
1501 None,
1502 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001503 if uid2:
garciadeblas4568a372021-03-24 09:19:48 +01001504 engine.test(
1505 "Delete User U2",
1506 "DELETE",
1507 "/admin/v1/users/" + uid2,
1508 headers_json,
1509 None,
1510 204,
1511 None,
1512 None,
1513 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001514
garciadeblas4568a372021-03-24 09:19:48 +01001515 engine.remove_authorization() # To finish
delacruzramoc061f562019-04-05 11:00:02 +02001516
tiernocd54a4a2018-09-12 16:40:35 +02001517
tierno65ca36d2019-02-12 19:27:52 +01001518class TestProjectsDescriptors:
1519 description = "test descriptors visibility among projects"
1520
1521 @staticmethod
1522 def run(engine, test_osm, manual_check, test_params=None):
1523 vnfd_ids = []
1524 engine.set_test_name("ProjectDescriptors")
1525 engine.get_autorization()
tiernobdebce92019-07-01 15:36:49 +00001526
1527 project_admin_id = None
garciadeblas4568a372021-03-24 09:19:48 +01001528 res = engine.test(
1529 "Get my project Padmin",
1530 "GET",
1531 "/admin/v1/projects/{}".format(engine.project),
1532 headers_json,
1533 None,
1534 200,
1535 r_header_json,
1536 "json",
1537 )
tiernobdebce92019-07-01 15:36:49 +00001538 if res:
1539 response = res.json()
1540 project_admin_id = response["_id"]
garciadeblas4568a372021-03-24 09:19:48 +01001541 engine.test(
1542 "Create project Padmin",
1543 "POST",
1544 "/admin/v1/projects",
1545 headers_json,
1546 {"name": "Padmin", "admin": True},
1547 (201, 204),
1548 {"Location": "/admin/v1/projects/", "Content-Type": "application/json"},
1549 "json",
1550 )
1551 engine.test(
1552 "Create project P2",
1553 "POST",
1554 "/admin/v1/projects",
1555 headers_json,
1556 {"name": "P2"},
1557 (201, 204),
1558 {"Location": "/admin/v1/projects/", "Content-Type": "application/json"},
1559 "json",
1560 )
1561 engine.test(
1562 "Create project P3",
1563 "POST",
1564 "/admin/v1/projects",
1565 headers_json,
1566 {"name": "P3"},
1567 (201, 204),
1568 {"Location": "/admin/v1/projects/", "Content-Type": "application/json"},
1569 "json",
1570 )
tierno65ca36d2019-02-12 19:27:52 +01001571
garciadeblas4568a372021-03-24 09:19:48 +01001572 engine.test(
1573 "Create user U1",
1574 "POST",
1575 "/admin/v1/users",
1576 headers_json,
1577 {
1578 "username": "U1",
1579 "password": "pw1",
1580 "project_role_mappings": [
1581 {"project": "Padmin", "role": "system_admin"},
1582 {"project": "P2", "role": "project_admin"},
1583 {"project": "P3", "role": "project_admin"},
1584 ],
1585 },
1586 201,
1587 {"Location": "/admin/v1/users/", "Content-Type": "application/json"},
1588 "json",
1589 )
tierno65ca36d2019-02-12 19:27:52 +01001590
garciadeblas4568a372021-03-24 09:19:48 +01001591 engine.test(
1592 "Onboard VNFD id1",
1593 "POST",
1594 "/vnfpkgm/v1/vnf_packages_content?id=id1",
1595 headers_yaml,
1596 TestDescriptors.vnfd_empty,
1597 201,
1598 r_headers_yaml_location_vnfd,
1599 "yaml",
1600 )
tierno65ca36d2019-02-12 19:27:52 +01001601 vnfd_ids.append(engine.last_id)
garciadeblas4568a372021-03-24 09:19:48 +01001602 engine.test(
1603 "Onboard VNFD id2 PUBLIC",
1604 "POST",
1605 "/vnfpkgm/v1/vnf_packages_content?id=id2&PUBLIC=TRUE",
1606 headers_yaml,
1607 TestDescriptors.vnfd_empty,
1608 201,
1609 r_headers_yaml_location_vnfd,
1610 "yaml",
1611 )
tierno65ca36d2019-02-12 19:27:52 +01001612 vnfd_ids.append(engine.last_id)
garciadeblas4568a372021-03-24 09:19:48 +01001613 engine.test(
1614 "Onboard VNFD id3",
1615 "POST",
1616 "/vnfpkgm/v1/vnf_packages_content?id=id3&PUBLIC=FALSE",
1617 headers_yaml,
1618 TestDescriptors.vnfd_empty,
1619 201,
1620 r_headers_yaml_location_vnfd,
1621 "yaml",
1622 )
tierno65ca36d2019-02-12 19:27:52 +01001623 vnfd_ids.append(engine.last_id)
1624
garciadeblas4568a372021-03-24 09:19:48 +01001625 res = engine.test(
1626 "Get VNFD descriptors",
1627 "GET",
1628 "/vnfpkgm/v1/vnf_packages?id=id1,id2,id3",
1629 headers_json,
1630 None,
1631 200,
1632 r_header_json,
1633 "json",
1634 )
tierno65ca36d2019-02-12 19:27:52 +01001635 response = res.json()
1636 if len(response) != 3:
garciadeblas4568a372021-03-24 09:19:48 +01001637 logger.error(
1638 "Only 3 vnfds should be present for project admin. {} listed".format(
1639 len(response)
1640 )
1641 )
tierno65ca36d2019-02-12 19:27:52 +01001642 engine.failed_tests += 1
1643
1644 # Change to other project Padmin
garciadeblas4568a372021-03-24 09:19:48 +01001645 res = engine.test(
1646 "Change to user U1 project Padmin",
1647 "POST",
1648 "/admin/v1/tokens",
1649 headers_json,
1650 {"username": "U1", "password": "pw1", "project_id": "Padmin"},
1651 (200, 201),
1652 r_header_json,
1653 "json",
1654 )
tierno65ca36d2019-02-12 19:27:52 +01001655 if res:
1656 response = res.json()
1657 engine.set_header({"Authorization": "Bearer {}".format(response["id"])})
1658
1659 # list vnfds
garciadeblas4568a372021-03-24 09:19:48 +01001660 res = engine.test(
1661 "List VNFD descriptors for Padmin",
1662 "GET",
1663 "/vnfpkgm/v1/vnf_packages",
1664 headers_json,
1665 None,
1666 200,
1667 r_header_json,
1668 "json",
1669 )
tierno65ca36d2019-02-12 19:27:52 +01001670 response = res.json()
1671 if len(response) != 0:
garciadeblas4568a372021-03-24 09:19:48 +01001672 logger.error(
1673 "Only 0 vnfds should be present for project Padmin. {} listed".format(
1674 len(response)
1675 )
1676 )
tierno65ca36d2019-02-12 19:27:52 +01001677 engine.failed_tests += 1
1678
1679 # list Public vnfds
garciadeblas4568a372021-03-24 09:19:48 +01001680 res = engine.test(
1681 "List VNFD public descriptors",
1682 "GET",
1683 "/vnfpkgm/v1/vnf_packages?PUBLIC=True",
1684 headers_json,
1685 None,
1686 200,
1687 r_header_json,
1688 "json",
1689 )
tierno65ca36d2019-02-12 19:27:52 +01001690 response = res.json()
1691 if len(response) != 1:
garciadeblas4568a372021-03-24 09:19:48 +01001692 logger.error(
1693 "Only 1 vnfds should be present for project Padmin. {} listed".format(
1694 len(response)
1695 )
1696 )
tierno65ca36d2019-02-12 19:27:52 +01001697 engine.failed_tests += 1
1698
1699 # list vnfds belonging to project "admin"
garciadeblas4568a372021-03-24 09:19:48 +01001700 res = engine.test(
1701 "List VNFD of admin project",
1702 "GET",
1703 "/vnfpkgm/v1/vnf_packages?ADMIN={}".format(project_admin_id),
1704 headers_json,
1705 None,
1706 200,
1707 r_header_json,
1708 "json",
1709 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001710 if res:
1711 response = res.json()
1712 if len(response) != 3:
garciadeblas4568a372021-03-24 09:19:48 +01001713 logger.error(
1714 "Only 3 vnfds should be present for project Padmin. {} listed".format(
1715 len(response)
1716 )
1717 )
delacruzramo9742f1d2019-06-05 13:06:47 +02001718 engine.failed_tests += 1
tierno65ca36d2019-02-12 19:27:52 +01001719
1720 # Get Public vnfds
garciadeblas4568a372021-03-24 09:19:48 +01001721 engine.test(
1722 "Get VNFD public descriptors",
1723 "GET",
1724 "/vnfpkgm/v1/vnf_packages/{}".format(vnfd_ids[1]),
1725 headers_json,
1726 None,
1727 200,
1728 r_header_json,
1729 "json",
1730 )
tierno65ca36d2019-02-12 19:27:52 +01001731 # Edit not owned vnfd
garciadeblas4568a372021-03-24 09:19:48 +01001732 engine.test(
1733 "Edit VNFD ",
1734 "PATCH",
1735 "/vnfpkgm/v1/vnf_packages/{}".format(vnfd_ids[0]),
1736 headers_yaml,
1737 "{name: pepe}",
1738 404,
1739 r_header_yaml,
1740 "yaml",
1741 )
tierno65ca36d2019-02-12 19:27:52 +01001742
1743 # Add to my catalog
garciadeblas4568a372021-03-24 09:19:48 +01001744 engine.test(
1745 "Add VNFD id2 to my catalog",
1746 "PATCH",
1747 "/vnfpkgm/v1/vnf_packages/{}?SET_PROJECT".format(vnfd_ids[1]),
1748 headers_json,
1749 None,
1750 204,
1751 None,
1752 0,
1753 )
tierno65ca36d2019-02-12 19:27:52 +01001754
1755 # Add a new vnfd
garciadeblas4568a372021-03-24 09:19:48 +01001756 engine.test(
1757 "Onboard VNFD id4",
1758 "POST",
1759 "/vnfpkgm/v1/vnf_packages_content?id=id4",
1760 headers_yaml,
1761 TestDescriptors.vnfd_empty,
1762 201,
1763 r_headers_yaml_location_vnfd,
1764 "yaml",
1765 )
tierno65ca36d2019-02-12 19:27:52 +01001766 vnfd_ids.append(engine.last_id)
1767
1768 # list vnfds
garciadeblas4568a372021-03-24 09:19:48 +01001769 res = engine.test(
1770 "List VNFD public descriptors",
1771 "GET",
1772 "/vnfpkgm/v1/vnf_packages",
1773 headers_json,
1774 None,
1775 200,
1776 r_header_json,
1777 "json",
1778 )
tierno65ca36d2019-02-12 19:27:52 +01001779 response = res.json()
1780 if len(response) != 2:
garciadeblas4568a372021-03-24 09:19:48 +01001781 logger.error(
1782 "Only 2 vnfds should be present for project Padmin. {} listed".format(
1783 len(response)
1784 )
1785 )
tierno65ca36d2019-02-12 19:27:52 +01001786 engine.failed_tests += 1
1787
1788 if manual_check:
garciadeblas4568a372021-03-24 09:19:48 +01001789 input(
1790 "VNFDs have been omboarded. Perform manual check and press enter to resume"
1791 )
tierno65ca36d2019-02-12 19:27:52 +01001792
garciadeblas4568a372021-03-24 09:19:48 +01001793 test_rest.test(
1794 "Delete VNFD id2",
1795 "DELETE",
1796 "/vnfpkgm/v1/vnf_packages/{}".format(vnfd_ids[1]),
1797 headers_yaml,
1798 None,
1799 204,
1800 None,
1801 0,
1802 )
tierno65ca36d2019-02-12 19:27:52 +01001803
1804 # change to admin project
garciadeblas4568a372021-03-24 09:19:48 +01001805 engine.remove_authorization() # To force get authorization
tierno65ca36d2019-02-12 19:27:52 +01001806 engine.get_autorization()
garciadeblas4568a372021-03-24 09:19:48 +01001807 test_rest.test(
1808 "Delete VNFD id1",
1809 "DELETE",
1810 "/vnfpkgm/v1/vnf_packages/{}".format(vnfd_ids[0]),
1811 headers_yaml,
1812 None,
1813 204,
1814 None,
1815 0,
1816 )
1817 test_rest.test(
1818 "Delete VNFD id2",
1819 "DELETE",
1820 "/vnfpkgm/v1/vnf_packages/{}".format(vnfd_ids[1]),
1821 headers_yaml,
1822 None,
1823 204,
1824 None,
1825 0,
1826 )
1827 test_rest.test(
1828 "Delete VNFD id3",
1829 "DELETE",
1830 "/vnfpkgm/v1/vnf_packages/{}".format(vnfd_ids[2]),
1831 headers_yaml,
1832 None,
1833 204,
1834 None,
1835 0,
1836 )
1837 test_rest.test(
1838 "Delete VNFD id4",
1839 "DELETE",
1840 "/vnfpkgm/v1/vnf_packages/{}".format(vnfd_ids[3]),
1841 headers_yaml,
1842 None,
1843 404,
1844 r_header_yaml,
1845 "yaml",
1846 )
1847 test_rest.test(
1848 "Delete VNFD id4",
1849 "DELETE",
1850 "/vnfpkgm/v1/vnf_packages/{}?ADMIN".format(vnfd_ids[3]),
1851 headers_yaml,
1852 None,
1853 204,
1854 None,
1855 0,
1856 )
tierno65ca36d2019-02-12 19:27:52 +01001857 # Get Public vnfds
garciadeblas4568a372021-03-24 09:19:48 +01001858 engine.test(
1859 "Get VNFD deleted id1",
1860 "GET",
1861 "/vnfpkgm/v1/vnf_packages/{}?ADMIN".format(vnfd_ids[0]),
1862 headers_json,
1863 None,
1864 404,
1865 r_header_json,
1866 "json",
1867 )
1868 engine.test(
1869 "Get VNFD deleted id2",
1870 "GET",
1871 "/vnfpkgm/v1/vnf_packages/{}?ADMIN".format(vnfd_ids[1]),
1872 headers_json,
1873 None,
1874 404,
1875 r_header_json,
1876 "json",
1877 )
1878 engine.test(
1879 "Get VNFD deleted id3",
1880 "GET",
1881 "/vnfpkgm/v1/vnf_packages/{}?ADMIN".format(vnfd_ids[2]),
1882 headers_json,
1883 None,
1884 404,
1885 r_header_json,
1886 "json",
1887 )
1888 engine.test(
1889 "Get VNFD deleted id4",
1890 "GET",
1891 "/vnfpkgm/v1/vnf_packages/{}?ADMIN".format(vnfd_ids[3]),
1892 headers_json,
1893 None,
1894 404,
1895 r_header_json,
1896 "json",
1897 )
tierno65ca36d2019-02-12 19:27:52 +01001898
garciadeblas4568a372021-03-24 09:19:48 +01001899 engine.test(
1900 "Delete user U1",
1901 "DELETE",
1902 "/admin/v1/users/U1",
1903 headers_json,
1904 None,
1905 204,
1906 None,
1907 None,
1908 )
1909 engine.test(
1910 "Delete project Padmin",
1911 "DELETE",
1912 "/admin/v1/projects/Padmin",
1913 headers_json,
1914 None,
1915 204,
1916 None,
1917 None,
1918 )
1919 engine.test(
1920 "Delete project P2",
1921 "DELETE",
1922 "/admin/v1/projects/P2",
1923 headers_json,
1924 None,
1925 204,
1926 None,
1927 None,
1928 )
1929 engine.test(
1930 "Delete project P3",
1931 "DELETE",
1932 "/admin/v1/projects/P3",
1933 headers_json,
1934 None,
1935 204,
1936 None,
1937 None,
1938 )
tierno65ca36d2019-02-12 19:27:52 +01001939
1940
tiernoc32ba4a2018-05-24 18:06:41 +02001941class TestFakeVim:
1942 description = "Creates/edit/delete fake VIMs and SDN controllers"
1943
1944 def __init__(self):
1945 self.vim = {
1946 "schema_version": "1.0",
1947 "schema_type": "No idea",
1948 "name": "myVim",
1949 "description": "Descriptor name",
1950 "vim_type": "openstack",
1951 "vim_url": "http://localhost:/vim",
1952 "vim_tenant_name": "vimTenant",
1953 "vim_user": "user",
1954 "vim_password": "password",
garciadeblas4568a372021-03-24 09:19:48 +01001955 "config": {"config_param": 1},
tiernoc32ba4a2018-05-24 18:06:41 +02001956 }
1957 self.sdn = {
1958 "name": "sdn-name",
1959 "description": "sdn-description",
1960 "dpid": "50:50:52:54:00:94:21:21",
1961 "ip": "192.168.15.17",
1962 "port": 8080,
1963 "type": "opendaylight",
1964 "version": "3.5.6",
1965 "user": "user",
garciadeblas4568a372021-03-24 09:19:48 +01001966 "password": "passwd",
tiernoc32ba4a2018-05-24 18:06:41 +02001967 }
1968 self.port_mapping = [
garciadeblas4568a372021-03-24 09:19:48 +01001969 {
1970 "compute_node": "compute node 1",
1971 "ports": [
1972 {
1973 "pci": "0000:81:00.0",
1974 "switch_port": "port-2/1",
1975 "switch_mac": "52:54:00:94:21:21",
1976 },
1977 {
1978 "pci": "0000:81:00.1",
1979 "switch_port": "port-2/2",
1980 "switch_mac": "52:54:00:94:21:22",
1981 },
1982 ],
1983 },
1984 {
1985 "compute_node": "compute node 2",
1986 "ports": [
1987 {
1988 "pci": "0000:81:00.0",
1989 "switch_port": "port-2/3",
1990 "switch_mac": "52:54:00:94:21:23",
1991 },
1992 {
1993 "pci": "0000:81:00.1",
1994 "switch_port": "port-2/4",
1995 "switch_mac": "52:54:00:94:21:24",
1996 },
1997 ],
1998 },
tiernoc32ba4a2018-05-24 18:06:41 +02001999 ]
2000
tiernocd54a4a2018-09-12 16:40:35 +02002001 def run(self, engine, test_osm, manual_check, test_params=None):
tiernoc32ba4a2018-05-24 18:06:41 +02002002
2003 vim_bad = self.vim.copy()
2004 vim_bad.pop("name")
2005
tiernoff6485d2018-11-28 17:19:46 +00002006 engine.set_test_name("FakeVim")
tiernoc32ba4a2018-05-24 18:06:41 +02002007 engine.get_autorization()
garciadeblas4568a372021-03-24 09:19:48 +01002008 engine.test(
2009 "Create VIM",
2010 "POST",
2011 "/admin/v1/vim_accounts",
2012 headers_json,
2013 self.vim,
2014 (201, 202),
2015 {"Location": "/admin/v1/vim_accounts/", "Content-Type": "application/json"},
2016 "json",
2017 )
tiernoff6485d2018-11-28 17:19:46 +00002018 vim_id = engine.last_id
garciadeblas4568a372021-03-24 09:19:48 +01002019 engine.test(
2020 "Create VIM without name, bad schema",
2021 "POST",
2022 "/admin/v1/vim_accounts",
2023 headers_json,
2024 vim_bad,
2025 422,
2026 None,
2027 headers_json,
2028 )
2029 engine.test(
2030 "Create VIM name repeated",
2031 "POST",
2032 "/admin/v1/vim_accounts",
2033 headers_json,
2034 self.vim,
2035 409,
2036 None,
2037 headers_json,
2038 )
2039 engine.test(
2040 "Show VIMs",
2041 "GET",
2042 "/admin/v1/vim_accounts",
2043 headers_yaml,
2044 None,
2045 200,
2046 r_header_yaml,
2047 "yaml",
2048 )
2049 engine.test(
2050 "Show VIM",
2051 "GET",
2052 "/admin/v1/vim_accounts/{}".format(vim_id),
2053 headers_yaml,
2054 None,
2055 200,
2056 r_header_yaml,
2057 "yaml",
2058 )
tiernoc32ba4a2018-05-24 18:06:41 +02002059 if not test_osm:
2060 # delete with FORCE
garciadeblas4568a372021-03-24 09:19:48 +01002061 engine.test(
2062 "Delete VIM",
2063 "DELETE",
2064 "/admin/v1/vim_accounts/{}?FORCE=True".format(vim_id),
2065 headers_yaml,
2066 None,
2067 202,
2068 None,
2069 0,
2070 )
2071 engine.test(
2072 "Check VIM is deleted",
2073 "GET",
2074 "/admin/v1/vim_accounts/{}".format(vim_id),
2075 headers_yaml,
2076 None,
2077 404,
2078 r_header_yaml,
2079 "yaml",
2080 )
tiernoc32ba4a2018-05-24 18:06:41 +02002081 else:
2082 # delete and wait until is really deleted
garciadeblas4568a372021-03-24 09:19:48 +01002083 engine.test(
2084 "Delete VIM",
2085 "DELETE",
2086 "/admin/v1/vim_accounts/{}".format(vim_id),
2087 headers_yaml,
2088 None,
2089 202,
2090 None,
2091 0,
2092 )
2093 engine.wait_until_delete(
2094 "/admin/v1/vim_accounts/{}".format(vim_id), timeout
2095 )
tiernoc32ba4a2018-05-24 18:06:41 +02002096
2097
2098class TestVIMSDN(TestFakeVim):
2099 description = "Creates VIM with SDN editing SDN controllers and port_mapping"
2100
2101 def __init__(self):
2102 TestFakeVim.__init__(self)
tierno55ba2e62018-12-11 17:22:22 +00002103 self.wim = {
2104 "schema_version": "1.0",
2105 "schema_type": "No idea",
2106 "name": "myWim",
2107 "description": "Descriptor name",
2108 "wim_type": "odl",
2109 "wim_url": "http://localhost:/wim",
2110 "user": "user",
2111 "password": "password",
garciadeblas4568a372021-03-24 09:19:48 +01002112 "config": {"config_param": 1},
tierno55ba2e62018-12-11 17:22:22 +00002113 }
tiernoc32ba4a2018-05-24 18:06:41 +02002114
tiernocd54a4a2018-09-12 16:40:35 +02002115 def run(self, engine, test_osm, manual_check, test_params=None):
tiernoff6485d2018-11-28 17:19:46 +00002116 engine.set_test_name("VimSdn")
tiernoc32ba4a2018-05-24 18:06:41 +02002117 engine.get_autorization()
2118 # Added SDN
garciadeblas4568a372021-03-24 09:19:48 +01002119 engine.test(
2120 "Create SDN",
2121 "POST",
2122 "/admin/v1/sdns",
2123 headers_json,
2124 self.sdn,
2125 (201, 202),
2126 {"Location": "/admin/v1/sdns/", "Content-Type": "application/json"},
2127 "json",
2128 )
tiernoff6485d2018-11-28 17:19:46 +00002129 sdnc_id = engine.last_id
tiernocd54a4a2018-09-12 16:40:35 +02002130 # sleep(5)
tiernoc32ba4a2018-05-24 18:06:41 +02002131 # Edit SDN
garciadeblas4568a372021-03-24 09:19:48 +01002132 engine.test(
2133 "Edit SDN",
2134 "PATCH",
2135 "/admin/v1/sdns/{}".format(sdnc_id),
2136 headers_json,
2137 {"name": "new_sdn_name"},
2138 (202, 204),
2139 None,
2140 None,
2141 )
tiernocd54a4a2018-09-12 16:40:35 +02002142 # sleep(5)
tiernoc32ba4a2018-05-24 18:06:41 +02002143 # VIM with SDN
tiernoff6485d2018-11-28 17:19:46 +00002144 self.vim["config"]["sdn-controller"] = sdnc_id
tiernoc32ba4a2018-05-24 18:06:41 +02002145 self.vim["config"]["sdn-port-mapping"] = self.port_mapping
garciadeblas4568a372021-03-24 09:19:48 +01002146 engine.test(
2147 "Create VIM",
2148 "POST",
2149 "/admin/v1/vim_accounts",
2150 headers_json,
2151 self.vim,
2152 (200, 202, 201),
2153 {"Location": "/admin/v1/vim_accounts/", "Content-Type": "application/json"},
2154 "json",
2155 ),
tiernoc32ba4a2018-05-24 18:06:41 +02002156
tiernoff6485d2018-11-28 17:19:46 +00002157 vim_id = engine.last_id
tiernoc32ba4a2018-05-24 18:06:41 +02002158 self.port_mapping[0]["compute_node"] = "compute node XX"
garciadeblas4568a372021-03-24 09:19:48 +01002159 engine.test(
2160 "Edit VIM change port-mapping",
2161 "PUT",
2162 "/admin/v1/vim_accounts/{}".format(vim_id),
2163 headers_json,
2164 {"config": {"sdn-port-mapping": self.port_mapping}},
2165 (202, 204),
2166 None,
2167 None,
2168 )
2169 engine.test(
2170 "Edit VIM remove port-mapping",
2171 "PUT",
2172 "/admin/v1/vim_accounts/{}".format(vim_id),
2173 headers_json,
2174 {"config": {"sdn-port-mapping": None}},
2175 (202, 204),
2176 None,
2177 None,
2178 )
tiernocd54a4a2018-09-12 16:40:35 +02002179
garciadeblas4568a372021-03-24 09:19:48 +01002180 engine.test(
2181 "Create WIM",
2182 "POST",
2183 "/admin/v1/wim_accounts",
2184 headers_json,
2185 self.wim,
2186 (200, 202, 201),
2187 {"Location": "/admin/v1/wim_accounts/", "Content-Type": "application/json"},
2188 "json",
2189 ),
tierno55ba2e62018-12-11 17:22:22 +00002190 wim_id = engine.last_id
2191
tiernocd54a4a2018-09-12 16:40:35 +02002192 if not test_osm:
2193 # delete with FORCE
garciadeblas4568a372021-03-24 09:19:48 +01002194 engine.test(
2195 "Delete VIM remove port-mapping",
2196 "DELETE",
2197 "/admin/v1/vim_accounts/{}?FORCE=True".format(vim_id),
2198 headers_json,
2199 None,
2200 202,
2201 None,
2202 0,
2203 )
2204 engine.test(
2205 "Delete SDNC",
2206 "DELETE",
2207 "/admin/v1/sdns/{}?FORCE=True".format(sdnc_id),
2208 headers_json,
2209 None,
2210 202,
2211 None,
2212 0,
2213 )
tiernocd54a4a2018-09-12 16:40:35 +02002214
garciadeblas4568a372021-03-24 09:19:48 +01002215 engine.test(
2216 "Delete WIM",
2217 "DELETE",
2218 "/admin/v1/wim_accounts/{}?FORCE=True".format(wim_id),
2219 headers_json,
2220 None,
2221 202,
2222 None,
2223 0,
2224 )
2225 engine.test(
2226 "Check VIM is deleted",
2227 "GET",
2228 "/admin/v1/vim_accounts/{}".format(vim_id),
2229 headers_yaml,
2230 None,
2231 404,
2232 r_header_yaml,
2233 "yaml",
2234 )
2235 engine.test(
2236 "Check SDN is deleted",
2237 "GET",
2238 "/admin/v1/sdns/{}".format(sdnc_id),
2239 headers_yaml,
2240 None,
2241 404,
2242 r_header_yaml,
2243 "yaml",
2244 )
2245 engine.test(
2246 "Check WIM is deleted",
2247 "GET",
2248 "/admin/v1/wim_accounts/{}".format(wim_id),
2249 headers_yaml,
2250 None,
2251 404,
2252 r_header_yaml,
2253 "yaml",
2254 )
tiernocd54a4a2018-09-12 16:40:35 +02002255 else:
tierno55ba2e62018-12-11 17:22:22 +00002256 if manual_check:
garciadeblas4568a372021-03-24 09:19:48 +01002257 input(
2258 "VIM, SDN, WIM has been deployed. Perform manual check and press enter to resume"
2259 )
tiernocd54a4a2018-09-12 16:40:35 +02002260 # delete and wait until is really deleted
garciadeblas4568a372021-03-24 09:19:48 +01002261 engine.test(
2262 "Delete VIM remove port-mapping",
2263 "DELETE",
2264 "/admin/v1/vim_accounts/{}".format(vim_id),
2265 headers_json,
2266 None,
2267 (202, 201, 204),
2268 None,
2269 0,
2270 )
2271 engine.test(
2272 "Delete SDN",
2273 "DELETE",
2274 "/admin/v1/sdns/{}".format(sdnc_id),
2275 headers_json,
2276 None,
2277 (202, 201, 204),
2278 None,
2279 0,
2280 )
2281 engine.test(
2282 "Delete VIM",
2283 "DELETE",
2284 "/admin/v1/wim_accounts/{}".format(wim_id),
2285 headers_json,
2286 None,
2287 (202, 201, 204),
2288 None,
2289 0,
2290 )
2291 engine.wait_until_delete(
2292 "/admin/v1/vim_accounts/{}".format(vim_id), timeout
2293 )
tiernoff6485d2018-11-28 17:19:46 +00002294 engine.wait_until_delete("/admin/v1/sdns/{}".format(sdnc_id), timeout)
garciadeblas4568a372021-03-24 09:19:48 +01002295 engine.wait_until_delete(
2296 "/admin/v1/wim_accounts/{}".format(wim_id), timeout
2297 )
tiernoc32ba4a2018-05-24 18:06:41 +02002298
2299
2300class TestDeploy:
2301 description = "Base class for downloading descriptors from ETSI, onboard and deploy in real VIM"
2302
2303 def __init__(self):
tiernoff6485d2018-11-28 17:19:46 +00002304 self.test_name = "DEPLOY"
tiernoc32ba4a2018-05-24 18:06:41 +02002305 self.nsd_id = None
2306 self.vim_id = None
gcalvino337ec512018-07-30 10:30:13 +02002307 self.ns_id = None
tiernocc103432018-10-19 14:10:35 +02002308 self.vnfds_id = []
garciadeblas4568a372021-03-24 09:19:48 +01002309 self.descriptor_url = (
2310 "https://osm-download.etsi.org/ftp/osm-3.0-three/2nd-hackfest/packages/"
2311 )
tiernoc32ba4a2018-05-24 18:06:41 +02002312 self.vnfd_filenames = ("cirros_vnf.tar.gz",)
2313 self.nsd_filename = "cirros_2vnf_ns.tar.gz"
tierno36ec8602018-11-02 17:27:11 +01002314 self.descriptor_edit = None
tiernoc32ba4a2018-05-24 18:06:41 +02002315 self.uses_configuration = False
tiernobee085c2018-12-12 17:03:04 +00002316 self.users = {}
2317 self.passwords = {}
2318 self.commands = {}
gcalvino337ec512018-07-30 10:30:13 +02002319 self.keys = {}
2320 self.timeout = 120
tierno36ec8602018-11-02 17:27:11 +01002321 self.qforce = ""
tiernobee085c2018-12-12 17:03:04 +00002322 self.ns_params = None
kuuse587aeea2019-04-26 12:33:07 +02002323 self.vnfr_ip_list = {}
tiernoc32ba4a2018-05-24 18:06:41 +02002324
2325 def create_descriptors(self, engine):
gcalvino337ec512018-07-30 10:30:13 +02002326 temp_dir = os.path.dirname(os.path.abspath(__file__)) + "/temp/"
tiernoc32ba4a2018-05-24 18:06:41 +02002327 if not os.path.exists(temp_dir):
2328 os.makedirs(temp_dir)
tierno36ec8602018-11-02 17:27:11 +01002329 for vnfd_index, vnfd_filename in enumerate(self.vnfd_filenames):
tiernoc32ba4a2018-05-24 18:06:41 +02002330 if "/" in vnfd_filename:
2331 vnfd_filename_path = vnfd_filename
2332 if not os.path.exists(vnfd_filename_path):
garciadeblas4568a372021-03-24 09:19:48 +01002333 raise TestException(
2334 "File '{}' does not exist".format(vnfd_filename_path)
2335 )
tiernoc32ba4a2018-05-24 18:06:41 +02002336 else:
2337 vnfd_filename_path = temp_dir + vnfd_filename
2338 if not os.path.exists(vnfd_filename_path):
2339 with open(vnfd_filename_path, "wb") as file:
2340 response = requests.get(self.descriptor_url + vnfd_filename)
2341 if response.status_code >= 300:
garciadeblas4568a372021-03-24 09:19:48 +01002342 raise TestException(
2343 "Error downloading descriptor from '{}': {}".format(
2344 self.descriptor_url + vnfd_filename,
2345 response.status_code,
2346 )
2347 )
tiernoc32ba4a2018-05-24 18:06:41 +02002348 file.write(response.content)
2349 if vnfd_filename_path.endswith(".yaml"):
2350 headers = headers_yaml
2351 else:
2352 headers = headers_zip_yaml
tiernoff6485d2018-11-28 17:19:46 +00002353 if randint(0, 1) == 0:
tiernoc32ba4a2018-05-24 18:06:41 +02002354 # vnfd CREATE AND UPLOAD in one step:
garciadeblas4568a372021-03-24 09:19:48 +01002355 engine.test(
2356 "Onboard VNFD in one step",
2357 "POST",
2358 "/vnfpkgm/v1/vnf_packages_content" + self.qforce,
2359 headers,
2360 "@b" + vnfd_filename_path,
2361 201,
2362 r_headers_yaml_location_vnfd,
2363 "yaml",
2364 )
tiernoff6485d2018-11-28 17:19:46 +00002365 self.vnfds_id.append(engine.last_id)
tiernoc32ba4a2018-05-24 18:06:41 +02002366 else:
2367 # vnfd CREATE AND UPLOAD ZIP
garciadeblas4568a372021-03-24 09:19:48 +01002368 engine.test(
2369 "Onboard VNFD step 1",
2370 "POST",
2371 "/vnfpkgm/v1/vnf_packages",
2372 headers_json,
2373 None,
2374 201,
2375 {
2376 "Location": "/vnfpkgm/v1/vnf_packages/",
2377 "Content-Type": "application/json",
2378 },
2379 "json",
2380 )
tiernoff6485d2018-11-28 17:19:46 +00002381 self.vnfds_id.append(engine.last_id)
garciadeblas4568a372021-03-24 09:19:48 +01002382 engine.test(
2383 "Onboard VNFD step 2 as ZIP",
2384 "PUT",
2385 "/vnfpkgm/v1/vnf_packages/<>/package_content" + self.qforce,
2386 headers,
2387 "@b" + vnfd_filename_path,
2388 204,
2389 None,
2390 0,
2391 )
tiernoc32ba4a2018-05-24 18:06:41 +02002392
tierno36ec8602018-11-02 17:27:11 +01002393 if self.descriptor_edit:
2394 if "vnfd{}".format(vnfd_index) in self.descriptor_edit:
2395 # Modify VNFD
garciadeblas4568a372021-03-24 09:19:48 +01002396 engine.test(
2397 "Edit VNFD ",
2398 "PATCH",
2399 "/vnfpkgm/v1/vnf_packages/{}".format(self.vnfds_id[-1]),
2400 headers_yaml,
2401 self.descriptor_edit["vnfd{}".format(vnfd_index)],
2402 204,
2403 None,
2404 None,
2405 )
tierno36ec8602018-11-02 17:27:11 +01002406
tiernoc32ba4a2018-05-24 18:06:41 +02002407 if "/" in self.nsd_filename:
2408 nsd_filename_path = self.nsd_filename
2409 if not os.path.exists(nsd_filename_path):
garciadeblas4568a372021-03-24 09:19:48 +01002410 raise TestException(
2411 "File '{}' does not exist".format(nsd_filename_path)
2412 )
tiernoc32ba4a2018-05-24 18:06:41 +02002413 else:
2414 nsd_filename_path = temp_dir + self.nsd_filename
2415 if not os.path.exists(nsd_filename_path):
2416 with open(nsd_filename_path, "wb") as file:
2417 response = requests.get(self.descriptor_url + self.nsd_filename)
2418 if response.status_code >= 300:
garciadeblas4568a372021-03-24 09:19:48 +01002419 raise TestException(
2420 "Error downloading descriptor from '{}': {}".format(
2421 self.descriptor_url + self.nsd_filename,
2422 response.status_code,
2423 )
2424 )
tiernoc32ba4a2018-05-24 18:06:41 +02002425 file.write(response.content)
2426 if nsd_filename_path.endswith(".yaml"):
2427 headers = headers_yaml
2428 else:
2429 headers = headers_zip_yaml
2430
tiernoff6485d2018-11-28 17:19:46 +00002431 if randint(0, 1) == 0:
tiernoc32ba4a2018-05-24 18:06:41 +02002432 # nsd CREATE AND UPLOAD in one step:
garciadeblas4568a372021-03-24 09:19:48 +01002433 engine.test(
2434 "Onboard NSD in one step",
2435 "POST",
2436 "/nsd/v1/ns_descriptors_content" + self.qforce,
2437 headers,
2438 "@b" + nsd_filename_path,
2439 201,
2440 r_headers_yaml_location_nsd,
2441 yaml,
2442 )
tiernoff6485d2018-11-28 17:19:46 +00002443 self.nsd_id = engine.last_id
tiernoc32ba4a2018-05-24 18:06:41 +02002444 else:
2445 # nsd CREATE AND UPLOAD ZIP
garciadeblas4568a372021-03-24 09:19:48 +01002446 engine.test(
2447 "Onboard NSD step 1",
2448 "POST",
2449 "/nsd/v1/ns_descriptors",
2450 headers_json,
2451 None,
2452 201,
2453 {
2454 "Location": "/nsd/v1/ns_descriptors/",
2455 "Content-Type": "application/json",
2456 },
2457 "json",
2458 )
tiernoff6485d2018-11-28 17:19:46 +00002459 self.nsd_id = engine.last_id
garciadeblas4568a372021-03-24 09:19:48 +01002460 engine.test(
2461 "Onboard NSD step 2 as ZIP",
2462 "PUT",
2463 "/nsd/v1/ns_descriptors/<>/nsd_content" + self.qforce,
2464 headers,
2465 "@b" + nsd_filename_path,
2466 204,
2467 None,
2468 0,
2469 )
tierno36ec8602018-11-02 17:27:11 +01002470
2471 if self.descriptor_edit and "nsd" in self.descriptor_edit:
2472 # Modify NSD
garciadeblas4568a372021-03-24 09:19:48 +01002473 engine.test(
2474 "Edit NSD ",
2475 "PATCH",
2476 "/nsd/v1/ns_descriptors/{}".format(self.nsd_id),
2477 headers_yaml,
2478 self.descriptor_edit["nsd"],
2479 204,
2480 None,
2481 None,
2482 )
tiernoc32ba4a2018-05-24 18:06:41 +02002483
2484 def delete_descriptors(self, engine):
2485 # delete descriptors
garciadeblas4568a372021-03-24 09:19:48 +01002486 engine.test(
2487 "Delete NSSD SOL005",
2488 "DELETE",
2489 "/nsd/v1/ns_descriptors/{}".format(self.nsd_id),
2490 headers_yaml,
2491 None,
2492 204,
2493 None,
2494 0,
2495 )
tierno36ec8602018-11-02 17:27:11 +01002496 for vnfd_id in self.vnfds_id:
garciadeblas4568a372021-03-24 09:19:48 +01002497 engine.test(
2498 "Delete VNFD SOL005",
2499 "DELETE",
2500 "/vnfpkgm/v1/vnf_packages/{}".format(vnfd_id),
2501 headers_yaml,
2502 None,
2503 204,
2504 None,
2505 0,
2506 )
tiernoc32ba4a2018-05-24 18:06:41 +02002507
2508 def instantiate(self, engine, ns_data):
2509 ns_data_text = yaml.safe_dump(ns_data, default_flow_style=True, width=256)
2510 # create NS Two steps
garciadeblas4568a372021-03-24 09:19:48 +01002511 r = engine.test(
2512 "Create NS step 1",
2513 "POST",
2514 "/nslcm/v1/ns_instances",
2515 headers_yaml,
2516 ns_data_text,
2517 (201, 202),
2518 {"Location": "nslcm/v1/ns_instances/", "Content-Type": "application/yaml"},
2519 "yaml",
2520 )
tiernoff6485d2018-11-28 17:19:46 +00002521 if not r:
2522 return
2523 self.ns_id = engine.last_id
garciadeblas4568a372021-03-24 09:19:48 +01002524 engine.test(
2525 "Instantiate NS step 2",
2526 "POST",
2527 "/nslcm/v1/ns_instances/{}/instantiate".format(self.ns_id),
2528 headers_yaml,
2529 ns_data_text,
2530 (201, 202),
2531 r_headers_yaml_location_nslcmop,
2532 "yaml",
2533 )
tiernoff6485d2018-11-28 17:19:46 +00002534 nslcmop_id = engine.last_id
tiernoc32ba4a2018-05-24 18:06:41 +02002535
2536 if test_osm:
2537 # Wait until status is Ok
tiernoff6485d2018-11-28 17:19:46 +00002538 timeout = timeout_configure if self.uses_configuration else timeout_deploy
2539 engine.wait_operation_ready("ns", nslcmop_id, timeout)
tiernoc32ba4a2018-05-24 18:06:41 +02002540
2541 def terminate(self, engine):
2542 # remove deployment
2543 if test_osm:
garciadeblas4568a372021-03-24 09:19:48 +01002544 engine.test(
2545 "Terminate NS",
2546 "POST",
2547 "/nslcm/v1/ns_instances/{}/terminate".format(self.ns_id),
2548 headers_yaml,
2549 None,
2550 (201, 202),
2551 r_headers_yaml_location_nslcmop,
2552 "yaml",
2553 )
tiernoff6485d2018-11-28 17:19:46 +00002554 nslcmop2_id = engine.last_id
tiernoc32ba4a2018-05-24 18:06:41 +02002555 # Wait until status is Ok
tiernoff6485d2018-11-28 17:19:46 +00002556 engine.wait_operation_ready("ns", nslcmop2_id, timeout_deploy)
tiernoc32ba4a2018-05-24 18:06:41 +02002557
garciadeblas4568a372021-03-24 09:19:48 +01002558 engine.test(
2559 "Delete NS",
2560 "DELETE",
2561 "/nslcm/v1/ns_instances/{}".format(self.ns_id),
2562 headers_yaml,
2563 None,
2564 204,
2565 None,
2566 0,
2567 )
tiernoc32ba4a2018-05-24 18:06:41 +02002568 else:
garciadeblas4568a372021-03-24 09:19:48 +01002569 engine.test(
2570 "Delete NS with FORCE",
2571 "DELETE",
2572 "/nslcm/v1/ns_instances/{}?FORCE=True".format(self.ns_id),
2573 headers_yaml,
2574 None,
2575 204,
2576 None,
2577 0,
2578 )
tiernoc32ba4a2018-05-24 18:06:41 +02002579
2580 # check all it is deleted
garciadeblas4568a372021-03-24 09:19:48 +01002581 engine.test(
2582 "Check NS is deleted",
2583 "GET",
2584 "/nslcm/v1/ns_instances/{}".format(self.ns_id),
2585 headers_yaml,
2586 None,
2587 404,
2588 None,
2589 "yaml",
2590 )
2591 r = engine.test(
2592 "Check NSLCMOPs are deleted",
2593 "GET",
2594 "/nslcm/v1/ns_lcm_op_occs?nsInstanceId={}".format(self.ns_id),
2595 headers_json,
2596 None,
2597 200,
2598 None,
2599 "json",
2600 )
tiernoff6485d2018-11-28 17:19:46 +00002601 if not r:
2602 return
tiernoc32ba4a2018-05-24 18:06:41 +02002603 nslcmops = r.json()
2604 if not isinstance(nslcmops, list) or nslcmops:
garciadeblas4568a372021-03-24 09:19:48 +01002605 raise TestException(
2606 "NS {} deleted but with ns_lcm_op_occ active: {}".format(
2607 self.ns_id, nslcmops
2608 )
2609 )
tiernoc32ba4a2018-05-24 18:06:41 +02002610
garciadeblas4568a372021-03-24 09:19:48 +01002611 def test_ns(
2612 self,
2613 engine,
2614 test_osm,
2615 commands=None,
2616 users=None,
2617 passwds=None,
2618 keys=None,
2619 timeout=0,
2620 ):
gcalvino337ec512018-07-30 10:30:13 +02002621
garciadeblas4568a372021-03-24 09:19:48 +01002622 r = engine.test(
2623 "GET VNFR IDs",
2624 "GET",
2625 "/nslcm/v1/ns_instances/{}".format(self.ns_id),
2626 headers_json,
2627 None,
2628 200,
2629 r_header_json,
2630 "json",
2631 )
tiernoff6485d2018-11-28 17:19:46 +00002632 if not r:
2633 return
gcalvino337ec512018-07-30 10:30:13 +02002634 ns_data = r.json()
2635
garciadeblas4568a372021-03-24 09:19:48 +01002636 vnfr_list = ns_data["constituent-vnfr-ref"]
gcalvino337ec512018-07-30 10:30:13 +02002637 time = 0
tiernobee085c2018-12-12 17:03:04 +00002638 _commands = commands if commands is not None else self.commands
2639 _users = users if users is not None else self.users
2640 _passwds = passwds if passwds is not None else self.passwords
2641 _keys = keys if keys is not None else self.keys
2642 _timeout = timeout if timeout != 0 else self.timeout
gcalvino337ec512018-07-30 10:30:13 +02002643
kuuse587aeea2019-04-26 12:33:07 +02002644 # vnfr_list=[d8272263-6bd3-4680-84ca-6a4be23b3f2d, 88b22e2f-994a-4b61-94fd-4a3c90de3dc4]
gcalvino337ec512018-07-30 10:30:13 +02002645 for vnfr_id in vnfr_list:
garciadeblas4568a372021-03-24 09:19:48 +01002646 r = engine.test(
2647 "Get VNFR to get IP_ADDRESS",
2648 "GET",
2649 "/nslcm/v1/vnfrs/{}".format(vnfr_id),
2650 headers_json,
2651 None,
2652 200,
2653 r_header_json,
2654 "json",
2655 )
tiernoff6485d2018-11-28 17:19:46 +00002656 if not r:
2657 continue
gcalvino337ec512018-07-30 10:30:13 +02002658 vnfr_data = r.json()
2659
tiernoff6485d2018-11-28 17:19:46 +00002660 vnf_index = str(vnfr_data["member-vnf-index-ref"])
kuuse587aeea2019-04-26 12:33:07 +02002661
2662 ip_address = self.get_vnfr_ip(engine, vnf_index)
garciadeblas4568a372021-03-24 09:19:48 +01002663 description = "Exec command='{}' at VNFR={} IP={}".format(
2664 _commands.get(vnf_index)[0], vnf_index, ip_address
2665 )
kuuse587aeea2019-04-26 12:33:07 +02002666 engine.step += 1
garciadeblas4568a372021-03-24 09:19:48 +01002667 test_description = "{}{} {}".format(
2668 engine.test_name, engine.step, description
2669 )
kuuse587aeea2019-04-26 12:33:07 +02002670 logger.warning(test_description)
2671 while _timeout >= time:
garciadeblas4568a372021-03-24 09:19:48 +01002672 result, message = self.do_checks(
2673 [ip_address],
2674 vnf_index=vnfr_data["member-vnf-index-ref"],
2675 commands=_commands.get(vnf_index),
2676 user=_users.get(vnf_index),
2677 passwd=_passwds.get(vnf_index),
2678 key=_keys.get(vnf_index),
2679 )
kuuse587aeea2019-04-26 12:33:07 +02002680 if result == 1:
2681 engine.passed_tests += 1
2682 logger.debug(message)
2683 break
2684 elif result == 0:
2685 time += 20
2686 sleep(20)
2687 elif result == -1:
2688 engine.failed_tests += 1
2689 logger.error(message)
2690 break
gcalvino337ec512018-07-30 10:30:13 +02002691 else:
2692 time -= 20
tiernoff6485d2018-11-28 17:19:46 +00002693 engine.failed_tests += 1
2694 logger.error(message)
gcalvino337ec512018-07-30 10:30:13 +02002695 else:
tiernoff6485d2018-11-28 17:19:46 +00002696 engine.failed_tests += 1
garciadeblas4568a372021-03-24 09:19:48 +01002697 logger.error(
2698 "VNFR {} has not mgmt address. Check failed".format(vnf_index)
2699 )
gcalvino337ec512018-07-30 10:30:13 +02002700
2701 def do_checks(self, ip, vnf_index, commands=[], user=None, passwd=None, key=None):
2702 try:
2703 import urllib3
2704 from pssh.clients import ParallelSSHClient
2705 from pssh.utils import load_private_key
2706 from ssh2 import exceptions as ssh2Exception
2707 except ImportError as e:
garciadeblas4568a372021-03-24 09:19:48 +01002708 logger.critical(
2709 "Package <pssh> or/and <urllib3> is not installed. Please add them with 'pip3 install "
2710 "parallel-ssh urllib3': {}".format(e)
2711 )
tiernoff6485d2018-11-28 17:19:46 +00002712 return -1, "install needed packages 'pip3 install parallel-ssh urllib3'"
gcalvino337ec512018-07-30 10:30:13 +02002713 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
2714 try:
2715 p_host = os.environ.get("PROXY_HOST")
2716 p_user = os.environ.get("PROXY_USER")
2717 p_password = os.environ.get("PROXY_PASSWD")
2718
2719 if key:
2720 pkey = load_private_key(key)
2721 else:
2722 pkey = None
2723
garciadeblas4568a372021-03-24 09:19:48 +01002724 client = ParallelSSHClient(
2725 ip,
2726 user=user,
2727 password=passwd,
2728 pkey=pkey,
2729 proxy_host=p_host,
2730 proxy_user=p_user,
2731 proxy_password=p_password,
2732 timeout=10,
2733 num_retries=0,
2734 )
gcalvino337ec512018-07-30 10:30:13 +02002735 for cmd in commands:
2736 output = client.run_command(cmd)
2737 client.join(output)
2738 if output[ip[0]].exit_code:
garciadeblas4568a372021-03-24 09:19:48 +01002739 return -1, "VNFR {} command '{}' returns error: '{}'".format(
2740 ip[0], cmd, "\n".join(output[ip[0]].stderr)
2741 )
gcalvino337ec512018-07-30 10:30:13 +02002742 else:
tiernobee085c2018-12-12 17:03:04 +00002743 return 1, "VNFR {} command '{}' successful".format(ip[0], cmd)
garciadeblas4568a372021-03-24 09:19:48 +01002744 except (
2745 ssh2Exception.ChannelFailure,
2746 ssh2Exception.SocketDisconnectError,
2747 ssh2Exception.SocketTimeout,
2748 ssh2Exception.SocketRecvError,
2749 ) as e:
gcalvino337ec512018-07-30 10:30:13 +02002750 return 0, "Timeout accessing the VNFR {}: {}".format(ip[0], str(e))
2751 except Exception as e:
2752 return -1, "ERROR checking the VNFR {}: {}".format(ip[0], str(e))
tiernoc32ba4a2018-05-24 18:06:41 +02002753
tiernobee085c2018-12-12 17:03:04 +00002754 def additional_operations(self, engine, test_osm, manual_check):
tiernoc32ba4a2018-05-24 18:06:41 +02002755 pass
2756
2757 def run(self, engine, test_osm, manual_check, test_params=None):
tiernoff6485d2018-11-28 17:19:46 +00002758 engine.set_test_name(self.test_name)
tiernoc32ba4a2018-05-24 18:06:41 +02002759 engine.get_autorization()
2760 nsname = os.environ.get("OSMNBITEST_NS_NAME", "OSMNBITEST")
2761 if test_params:
2762 if "vnfd-files" in test_params:
2763 self.vnfd_filenames = test_params["vnfd-files"].split(",")
2764 if "nsd-file" in test_params:
2765 self.nsd_filename = test_params["nsd-file"]
2766 if test_params.get("ns-name"):
2767 nsname = test_params["ns-name"]
2768 self.create_descriptors(engine)
2769
2770 # create real VIM if not exist
2771 self.vim_id = engine.get_create_vim(test_osm)
garciadeblas4568a372021-03-24 09:19:48 +01002772 ns_data = {
2773 "nsDescription": "default description",
2774 "nsName": nsname,
2775 "nsdId": self.nsd_id,
2776 "vimAccountId": self.vim_id,
2777 }
tiernobee085c2018-12-12 17:03:04 +00002778 if self.ns_params:
2779 ns_data.update(self.ns_params)
tiernoc32ba4a2018-05-24 18:06:41 +02002780 if test_params and test_params.get("ns-config"):
2781 if isinstance(test_params["ns-config"], str):
delacruzramob19cadc2019-10-08 10:18:02 +02002782 ns_data.update(yaml.load(test_params["ns-config"]), Loader=yaml.Loader)
tiernoc32ba4a2018-05-24 18:06:41 +02002783 else:
2784 ns_data.update(test_params["ns-config"])
2785 self.instantiate(engine, ns_data)
2786
2787 if manual_check:
garciadeblas4568a372021-03-24 09:19:48 +01002788 input(
2789 "NS has been deployed. Perform manual check and press enter to resume"
2790 )
tiernobee085c2018-12-12 17:03:04 +00002791 if test_osm and self.commands:
2792 self.test_ns(engine, test_osm)
2793 self.additional_operations(engine, test_osm, manual_check)
tiernoc32ba4a2018-05-24 18:06:41 +02002794 self.terminate(engine)
2795 self.delete_descriptors(engine)
2796
kuuse587aeea2019-04-26 12:33:07 +02002797 def get_first_ip(self, ip_string):
2798 # When using a floating IP, the vnfr_data['ip-address'] contains a semicolon-separated list of IP:s.
2799 first_ip = ip_string.split(";")[0] if ip_string else ""
2800 return first_ip
2801
2802 def get_vnfr_ip(self, engine, vnfr_index_wanted):
2803 # If the IP address list has been obtained before, it has been stored in 'vnfr_ip_list'
2804 ip = self.vnfr_ip_list.get(vnfr_index_wanted, "")
garciadeblas4568a372021-03-24 09:19:48 +01002805 if ip:
kuuse587aeea2019-04-26 12:33:07 +02002806 return self.get_first_ip(ip)
garciadeblas4568a372021-03-24 09:19:48 +01002807 r = engine.test(
2808 "Get VNFR to get IP_ADDRESS",
2809 "GET",
2810 "/nslcm/v1/vnfrs?member-vnf-index-ref={}&nsr-id-ref={}".format(
2811 vnfr_index_wanted, self.ns_id
2812 ),
2813 headers_json,
2814 None,
2815 200,
2816 r_header_json,
2817 "json",
2818 )
kuuse587aeea2019-04-26 12:33:07 +02002819 if not r:
2820 return ""
2821 vnfr_data = r.json()
2822 if not (vnfr_data and vnfr_data[0]):
2823 return ""
2824 # Store the IP (or list of IPs) in 'vnfr_ip_list'
2825 ip_list = vnfr_data[0].get("ip-address", "")
2826 if ip_list:
2827 self.vnfr_ip_list[vnfr_index_wanted] = ip_list
2828 ip = self.get_first_ip(ip_list)
2829 return ip
2830
tiernoc32ba4a2018-05-24 18:06:41 +02002831
2832class TestDeployHackfestCirros(TestDeploy):
2833 description = "Load and deploy Hackfest cirros_2vnf_ns example"
2834
2835 def __init__(self):
2836 super().__init__()
tiernoff6485d2018-11-28 17:19:46 +00002837 self.test_name = "CIRROS"
tiernoc32ba4a2018-05-24 18:06:41 +02002838 self.vnfd_filenames = ("cirros_vnf.tar.gz",)
2839 self.nsd_filename = "cirros_2vnf_ns.tar.gz"
garciadeblas4568a372021-03-24 09:19:48 +01002840 self.commands = {
2841 "1": [
2842 "ls -lrt",
2843 ],
2844 "2": [
2845 "ls -lrt",
2846 ],
2847 }
2848 self.users = {"1": "cirros", "2": "cirros"}
2849 self.passwords = {"1": "cubswin:)", "2": "cubswin:)"}
tiernoc32ba4a2018-05-24 18:06:41 +02002850
tierno932499c2019-01-28 17:28:10 +00002851 def terminate(self, engine):
2852 # Make a delete in one step, overriding the normal two step of TestDeploy that launched terminate and delete
2853 if test_osm:
garciadeblas4568a372021-03-24 09:19:48 +01002854 engine.test(
2855 "Terminate and delete NS in one step",
2856 "DELETE",
2857 "/nslcm/v1/ns_instances_content/{}".format(self.ns_id),
2858 headers_yaml,
2859 None,
2860 202,
2861 None,
2862 "yaml",
2863 )
tierno932499c2019-01-28 17:28:10 +00002864
garciadeblas4568a372021-03-24 09:19:48 +01002865 engine.wait_until_delete(
2866 "/nslcm/v1/ns_instances/{}".format(self.ns_id), timeout_deploy
2867 )
tierno932499c2019-01-28 17:28:10 +00002868 else:
garciadeblas4568a372021-03-24 09:19:48 +01002869 engine.test(
2870 "Delete NS with FORCE",
2871 "DELETE",
2872 "/nslcm/v1/ns_instances/{}?FORCE=True".format(self.ns_id),
2873 headers_yaml,
2874 None,
2875 204,
2876 None,
2877 0,
2878 )
tierno932499c2019-01-28 17:28:10 +00002879
2880 # check all it is deleted
garciadeblas4568a372021-03-24 09:19:48 +01002881 engine.test(
2882 "Check NS is deleted",
2883 "GET",
2884 "/nslcm/v1/ns_instances/{}".format(self.ns_id),
2885 headers_yaml,
2886 None,
2887 404,
2888 None,
2889 "yaml",
2890 )
2891 r = engine.test(
2892 "Check NSLCMOPs are deleted",
2893 "GET",
2894 "/nslcm/v1/ns_lcm_op_occs?nsInstanceId={}".format(self.ns_id),
2895 headers_json,
2896 None,
2897 200,
2898 None,
2899 "json",
2900 )
tierno932499c2019-01-28 17:28:10 +00002901 if not r:
2902 return
2903 nslcmops = r.json()
2904 if not isinstance(nslcmops, list) or nslcmops:
garciadeblas4568a372021-03-24 09:19:48 +01002905 raise TestException(
2906 "NS {} deleted but with ns_lcm_op_occ active: {}".format(
2907 self.ns_id, nslcmops
2908 )
2909 )
tierno932499c2019-01-28 17:28:10 +00002910
tiernoc32ba4a2018-05-24 18:06:41 +02002911
tiernocc103432018-10-19 14:10:35 +02002912class TestDeployHackfest1(TestDeploy):
2913 description = "Load and deploy Hackfest_1_vnfd example"
2914
2915 def __init__(self):
2916 super().__init__()
tiernoff6485d2018-11-28 17:19:46 +00002917 self.test_name = "HACKFEST1-"
tiernocc103432018-10-19 14:10:35 +02002918 self.vnfd_filenames = ("hackfest_1_vnfd.tar.gz",)
2919 self.nsd_filename = "hackfest_1_nsd.tar.gz"
tiernobee085c2018-12-12 17:03:04 +00002920 # self.commands = {'1': ['ls -lrt', ], '2': ['ls -lrt', ]}
2921 # self.users = {'1': "cirros", '2': "cirros"}
2922 # self.passwords = {'1': "cubswin:)", '2': "cubswin:)"}
tiernocc103432018-10-19 14:10:35 +02002923
2924
2925class TestDeployHackfestCirrosScaling(TestDeploy):
garciadeblas4568a372021-03-24 09:19:48 +01002926 description = (
2927 "Load and deploy Hackfest cirros_2vnf_ns example with scaling modifications"
2928 )
tiernocc103432018-10-19 14:10:35 +02002929
2930 def __init__(self):
2931 super().__init__()
tiernoff6485d2018-11-28 17:19:46 +00002932 self.test_name = "CIRROS-SCALE"
tiernocc103432018-10-19 14:10:35 +02002933 self.vnfd_filenames = ("cirros_vnf.tar.gz",)
2934 self.nsd_filename = "cirros_2vnf_ns.tar.gz"
tiernocc103432018-10-19 14:10:35 +02002935 # Modify VNFD to add scaling and count=2
tiernoff6485d2018-11-28 17:19:46 +00002936 self.descriptor_edit = {
2937 "vnfd0": {
garciadeblas4568a372021-03-24 09:19:48 +01002938 "vdu": {"$id: 'cirros_vnfd-VM'": {"count": 2}},
2939 "scaling-group-descriptor": [
2940 {
2941 "name": "scale_cirros",
2942 "max-instance-count": 2,
2943 "vdu": [{"vdu-id-ref": "cirros_vnfd-VM", "count": 2}],
2944 }
2945 ],
tiernoff6485d2018-11-28 17:19:46 +00002946 }
2947 }
tiernocc103432018-10-19 14:10:35 +02002948
tiernobee085c2018-12-12 17:03:04 +00002949 def additional_operations(self, engine, test_osm, manual_check):
tiernocc103432018-10-19 14:10:35 +02002950 if not test_osm:
2951 return
2952 # 2 perform scale out twice
garciadeblas4568a372021-03-24 09:19:48 +01002953 payload = (
2954 "{scaleType: SCALE_VNF, scaleVnfData: {scaleVnfType: SCALE_OUT, scaleByStepData: "
2955 '{scaling-group-descriptor: scale_cirros, member-vnf-index: "1"}}}'
2956 )
tiernocc103432018-10-19 14:10:35 +02002957 for i in range(0, 2):
garciadeblas4568a372021-03-24 09:19:48 +01002958 engine.test(
2959 "Execute scale action over NS",
2960 "POST",
2961 "/nslcm/v1/ns_instances/{}/scale".format(self.ns_id),
2962 headers_yaml,
2963 payload,
2964 (201, 202),
2965 r_headers_yaml_location_nslcmop,
2966 "yaml",
2967 )
tiernoff6485d2018-11-28 17:19:46 +00002968 nslcmop2_scale_out = engine.last_id
2969 engine.wait_operation_ready("ns", nslcmop2_scale_out, timeout_deploy)
tiernocc103432018-10-19 14:10:35 +02002970 if manual_check:
garciadeblas4568a372021-03-24 09:19:48 +01002971 input("NS scale out done. Check that two more vdus are there")
tiernocc103432018-10-19 14:10:35 +02002972 # TODO check automatic
2973
2974 # 2 perform scale in
garciadeblas4568a372021-03-24 09:19:48 +01002975 payload = (
2976 "{scaleType: SCALE_VNF, scaleVnfData: {scaleVnfType: SCALE_IN, scaleByStepData: "
2977 '{scaling-group-descriptor: scale_cirros, member-vnf-index: "1"}}}'
2978 )
tiernocc103432018-10-19 14:10:35 +02002979 for i in range(0, 2):
garciadeblas4568a372021-03-24 09:19:48 +01002980 engine.test(
2981 "Execute scale IN action over NS",
2982 "POST",
2983 "/nslcm/v1/ns_instances/{}/scale".format(self.ns_id),
2984 headers_yaml,
2985 payload,
2986 (201, 202),
2987 r_headers_yaml_location_nslcmop,
2988 "yaml",
2989 )
tiernoff6485d2018-11-28 17:19:46 +00002990 nslcmop2_scale_in = engine.last_id
2991 engine.wait_operation_ready("ns", nslcmop2_scale_in, timeout_deploy)
tiernocc103432018-10-19 14:10:35 +02002992 if manual_check:
garciadeblas4568a372021-03-24 09:19:48 +01002993 input("NS scale in done. Check that two less vdus are there")
tiernocc103432018-10-19 14:10:35 +02002994 # TODO check automatic
2995
2996 # perform scale in that must fail as reached limit
garciadeblas4568a372021-03-24 09:19:48 +01002997 engine.test(
2998 "Execute scale IN out of limit action over NS",
2999 "POST",
3000 "/nslcm/v1/ns_instances/{}/scale".format(self.ns_id),
3001 headers_yaml,
3002 payload,
3003 (201, 202),
3004 r_headers_yaml_location_nslcmop,
3005 "yaml",
3006 )
tiernoff6485d2018-11-28 17:19:46 +00003007 nslcmop2_scale_in = engine.last_id
garciadeblas4568a372021-03-24 09:19:48 +01003008 engine.wait_operation_ready(
3009 "ns", nslcmop2_scale_in, timeout_deploy, expected_fail=True
3010 )
tiernocc103432018-10-19 14:10:35 +02003011
3012
tiernoc32ba4a2018-05-24 18:06:41 +02003013class TestDeployIpMac(TestDeploy):
3014 description = "Load and deploy descriptor examples setting mac, ip address at descriptor and instantiate params"
3015
3016 def __init__(self):
3017 super().__init__()
tiernoff6485d2018-11-28 17:19:46 +00003018 self.test_name = "SetIpMac"
garciadeblas4568a372021-03-24 09:19:48 +01003019 self.vnfd_filenames = (
3020 "vnfd_2vdu_set_ip_mac2.yaml",
3021 "vnfd_2vdu_set_ip_mac.yaml",
3022 )
tiernoc32ba4a2018-05-24 18:06:41 +02003023 self.nsd_filename = "scenario_2vdu_set_ip_mac.yaml"
garciadeblas4568a372021-03-24 09:19:48 +01003024 self.descriptor_url = "https://osm.etsi.org/gitweb/?p=osm/RO.git;a=blob_plain;f=test/RO_tests/v3_2vdu_set_ip_mac/"
3025 self.commands = {
3026 "1": [
3027 "ls -lrt",
3028 ],
3029 "2": [
3030 "ls -lrt",
3031 ],
3032 }
3033 self.users = {"1": "osm", "2": "osm"}
3034 self.passwords = {"1": "osm4u", "2": "osm4u"}
gcalvino337ec512018-07-30 10:30:13 +02003035 self.timeout = 360
tiernoc32ba4a2018-05-24 18:06:41 +02003036
3037 def run(self, engine, test_osm, manual_check, test_params=None):
3038 # super().run(engine, test_osm, manual_check, test_params)
3039 # run again setting IPs with instantiate parameters
3040 instantiation_params = {
3041 "vnf": [
3042 {
3043 "member-vnf-index": "1",
3044 "internal-vld": [
3045 {
garciadeblas4568a372021-03-24 09:19:48 +01003046 "name": "internal_vld1", # net_internal
tiernoc32ba4a2018-05-24 18:06:41 +02003047 "ip-profile": {
3048 "ip-version": "ipv4",
3049 "subnet-address": "10.9.8.0/24",
garciadeblas4568a372021-03-24 09:19:48 +01003050 "dhcp-params": {
3051 "count": 100,
3052 "start-address": "10.9.8.100",
3053 },
tiernoc32ba4a2018-05-24 18:06:41 +02003054 },
3055 "internal-connection-point": [
3056 {
3057 "id-ref": "eth2",
3058 "ip-address": "10.9.8.2",
3059 },
3060 {
3061 "id-ref": "eth3",
3062 "ip-address": "10.9.8.3",
garciadeblas4568a372021-03-24 09:19:48 +01003063 },
3064 ],
tiernoc32ba4a2018-05-24 18:06:41 +02003065 },
3066 ],
tiernoc32ba4a2018-05-24 18:06:41 +02003067 "vdu": [
3068 {
3069 "id": "VM1",
3070 "interface": [
tierno7ce1db92018-07-25 12:50:52 +02003071 # {
3072 # "name": "iface11",
3073 # "floating-ip-required": True,
3074 # },
garciadeblas4568a372021-03-24 09:19:48 +01003075 {"name": "iface13", "mac-address": "52:33:44:55:66:13"},
tiernoc32ba4a2018-05-24 18:06:41 +02003076 ],
3077 },
3078 {
3079 "id": "VM2",
3080 "interface": [
3081 {
3082 "name": "iface21",
gcalvino337ec512018-07-30 10:30:13 +02003083 "ip-address": "10.31.31.22",
garciadeblas4568a372021-03-24 09:19:48 +01003084 "mac-address": "52:33:44:55:66:21",
tiernoc32ba4a2018-05-24 18:06:41 +02003085 },
3086 ],
3087 },
garciadeblas4568a372021-03-24 09:19:48 +01003088 ],
tiernoc32ba4a2018-05-24 18:06:41 +02003089 },
3090 ]
3091 }
gcalvino337ec512018-07-30 10:30:13 +02003092
garciadeblas4568a372021-03-24 09:19:48 +01003093 super().run(
3094 engine,
3095 test_osm,
3096 manual_check,
3097 test_params={"ns-config": instantiation_params},
3098 )
tiernoc32ba4a2018-05-24 18:06:41 +02003099
3100
3101class TestDeployHackfest4(TestDeploy):
3102 description = "Load and deploy Hackfest 4 example."
3103
3104 def __init__(self):
3105 super().__init__()
tiernoff6485d2018-11-28 17:19:46 +00003106 self.test_name = "HACKFEST4-"
tiernoc32ba4a2018-05-24 18:06:41 +02003107 self.vnfd_filenames = ("hackfest_4_vnfd.tar.gz",)
3108 self.nsd_filename = "hackfest_4_nsd.tar.gz"
3109 self.uses_configuration = True
garciadeblas4568a372021-03-24 09:19:48 +01003110 self.commands = {
3111 "1": [
3112 "ls -lrt",
3113 ],
3114 "2": [
3115 "ls -lrt",
3116 ],
3117 }
3118 self.users = {"1": "ubuntu", "2": "ubuntu"}
3119 self.passwords = {"1": "osm4u", "2": "osm4u"}
tiernoc32ba4a2018-05-24 18:06:41 +02003120 # Modify VNFD to add scaling
tierno932499c2019-01-28 17:28:10 +00003121 # self.descriptor_edit = {
3122 # "vnfd0": {
3123 # 'vnf-configuration': {
3124 # 'config-primitive': [{
3125 # 'name': 'touch',
3126 # 'parameter': [{
3127 # 'name': 'filename',
3128 # 'data-type': 'STRING',
3129 # 'default-value': '/home/ubuntu/touched'
3130 # }]
3131 # }]
3132 # },
3133 # 'scaling-group-descriptor': [{
3134 # 'name': 'scale_dataVM',
3135 # 'scaling-policy': [{
3136 # 'threshold-time': 0,
3137 # 'name': 'auto_cpu_util_above_threshold',
3138 # 'scaling-type': 'automatic',
3139 # 'scaling-criteria': [{
3140 # 'name': 'cpu_util_above_threshold',
3141 # 'vnf-monitoring-param-ref': 'all_aaa_cpu_util',
3142 # 'scale-out-relational-operation': 'GE',
3143 # 'scale-in-threshold': 15,
3144 # 'scale-out-threshold': 60,
3145 # 'scale-in-relational-operation': 'LE'
3146 # }],
3147 # 'cooldown-time': 60
3148 # }],
3149 # 'max-instance-count': 10,
3150 # 'scaling-config-action': [
3151 # {'vnf-config-primitive-name-ref': 'touch',
3152 # 'trigger': 'post-scale-out'},
3153 # {'vnf-config-primitive-name-ref': 'touch',
3154 # 'trigger': 'pre-scale-in'}
3155 # ],
3156 # 'vdu': [{
3157 # 'vdu-id-ref': 'dataVM',
3158 # 'count': 1
3159 # }]
3160 # }]
3161 # }
3162 # }
tiernoc32ba4a2018-05-24 18:06:41 +02003163
tiernoc32ba4a2018-05-24 18:06:41 +02003164
3165class TestDeployHackfest3Charmed(TestDeploy):
tiernobee085c2018-12-12 17:03:04 +00003166 description = "Load and deploy Hackfest 3charmed_ns example"
tiernoc32ba4a2018-05-24 18:06:41 +02003167
3168 def __init__(self):
3169 super().__init__()
tiernoff6485d2018-11-28 17:19:46 +00003170 self.test_name = "HACKFEST3-"
tiernoc32ba4a2018-05-24 18:06:41 +02003171 self.vnfd_filenames = ("hackfest_3charmed_vnfd.tar.gz",)
3172 self.nsd_filename = "hackfest_3charmed_nsd.tar.gz"
3173 self.uses_configuration = True
garciadeblas4568a372021-03-24 09:19:48 +01003174 self.commands = {
3175 "1": ["ls -lrt /home/ubuntu/first-touch"],
3176 "2": ["ls -lrt /home/ubuntu/first-touch"],
3177 }
3178 self.users = {"1": "ubuntu", "2": "ubuntu"}
3179 self.passwords = {"1": "osm4u", "2": "osm4u"}
kuuse587aeea2019-04-26 12:33:07 +02003180 self.descriptor_edit = {
tierno65ca36d2019-02-12 19:27:52 +01003181 "vnfd0": yaml.safe_load(
kuuse587aeea2019-04-26 12:33:07 +02003182 """
3183 vnf-configuration:
3184 terminate-config-primitive:
3185 - seq: '1'
3186 name: touch
3187 parameter:
3188 - name: filename
3189 value: '/home/ubuntu/last-touch1'
3190 - seq: '3'
3191 name: touch
3192 parameter:
3193 - name: filename
3194 value: '/home/ubuntu/last-touch3'
3195 - seq: '2'
3196 name: touch
3197 parameter:
3198 - name: filename
3199 value: '/home/ubuntu/last-touch2'
garciadeblas4568a372021-03-24 09:19:48 +01003200 """
3201 )
kuuse587aeea2019-04-26 12:33:07 +02003202 }
tiernoc32ba4a2018-05-24 18:06:41 +02003203
tiernobee085c2018-12-12 17:03:04 +00003204 def additional_operations(self, engine, test_osm, manual_check):
tiernoc32ba4a2018-05-24 18:06:41 +02003205 if not test_osm:
3206 return
3207 # 1 perform action
kuuse587aeea2019-04-26 12:33:07 +02003208 vnfr_index_selected = "2"
tiernoc32ba4a2018-05-24 18:06:41 +02003209 payload = '{member_vnf_index: "2", primitive: touch, primitive_params: { filename: /home/ubuntu/OSMTESTNBI }}'
garciadeblas4568a372021-03-24 09:19:48 +01003210 engine.test(
3211 "Exec service primitive over NS",
3212 "POST",
3213 "/nslcm/v1/ns_instances/{}/action".format(self.ns_id),
3214 headers_yaml,
3215 payload,
3216 (201, 202),
3217 r_headers_yaml_location_nslcmop,
3218 "yaml",
3219 )
tiernoff6485d2018-11-28 17:19:46 +00003220 nslcmop2_action = engine.last_id
tiernoc32ba4a2018-05-24 18:06:41 +02003221 # Wait until status is Ok
tiernoff6485d2018-11-28 17:19:46 +00003222 engine.wait_operation_ready("ns", nslcmop2_action, timeout_deploy)
kuuse587aeea2019-04-26 12:33:07 +02003223 vnfr_ip = self.get_vnfr_ip(engine, vnfr_index_selected)
tiernoc32ba4a2018-05-24 18:06:41 +02003224 if manual_check:
kuuse587aeea2019-04-26 12:33:07 +02003225 input(
3226 "NS service primitive has been executed."
garciadeblas4568a372021-03-24 09:19:48 +01003227 "Check that file /home/ubuntu/OSMTESTNBI is present at {}".format(
3228 vnfr_ip
3229 )
3230 )
tiernoff6485d2018-11-28 17:19:46 +00003231 if test_osm:
garciadeblas4568a372021-03-24 09:19:48 +01003232 commands = {
3233 "1": [""],
3234 "2": [
3235 "ls -lrt /home/ubuntu/OSMTESTNBI",
3236 ],
3237 }
tiernobee085c2018-12-12 17:03:04 +00003238 self.test_ns(engine, test_osm, commands=commands)
tiernoc32ba4a2018-05-24 18:06:41 +02003239
3240 # # 2 perform scale out
3241 # payload = '{scaleType: SCALE_VNF, scaleVnfData: {scaleVnfType: SCALE_OUT, scaleByStepData: ' \
3242 # '{scaling-group-descriptor: scale_dataVM, member-vnf-index: "1"}}}'
tiernoff6485d2018-11-28 17:19:46 +00003243 # engine.test("Execute scale action over NS", "POST",
3244 # "/nslcm/v1/ns_instances/{}/scale".format(self.ns_id), headers_yaml, payload,
tiernobdebce92019-07-01 15:36:49 +00003245 # (201, 202), r_headers_yaml_location_nslcmop, "yaml")
tiernoff6485d2018-11-28 17:19:46 +00003246 # nslcmop2_scale_out = engine.last_id
3247 # engine.wait_operation_ready("ns", nslcmop2_scale_out, timeout_deploy)
tiernoc32ba4a2018-05-24 18:06:41 +02003248 # if manual_check:
3249 # input('NS scale out done. Check that file /home/ubuntu/touched is present and new VM is created')
3250 # # TODO check automatic
3251 #
3252 # # 2 perform scale in
3253 # payload = '{scaleType: SCALE_VNF, scaleVnfData: {scaleVnfType: SCALE_IN, scaleByStepData: ' \
3254 # '{scaling-group-descriptor: scale_dataVM, member-vnf-index: "1"}}}'
tiernoff6485d2018-11-28 17:19:46 +00003255 # engine.test("Execute scale action over NS", "POST",
3256 # "/nslcm/v1/ns_instances/{}/scale".format(self.ns_id), headers_yaml, payload,
tiernobdebce92019-07-01 15:36:49 +00003257 # (201, 202), r_headers_yaml_location_nslcmop, "yaml")
tiernoff6485d2018-11-28 17:19:46 +00003258 # nslcmop2_scale_in = engine.last_id
3259 # engine.wait_operation_ready("ns", nslcmop2_scale_in, timeout_deploy)
tiernoc32ba4a2018-05-24 18:06:41 +02003260 # if manual_check:
3261 # input('NS scale in done. Check that file /home/ubuntu/touched is updated and new VM is deleted')
3262 # # TODO check automatic
3263
tiernof27c79b2018-03-12 17:08:42 +01003264
tiernoff6485d2018-11-28 17:19:46 +00003265class TestDeployHackfest3Charmed2(TestDeployHackfest3Charmed):
garciadeblas4568a372021-03-24 09:19:48 +01003266 description = (
3267 "Load and deploy Hackfest 3charmed_ns example modified version of descriptors to have dots in "
3268 "ids and member-vnf-index."
3269 )
tiernoff6485d2018-11-28 17:19:46 +00003270
3271 def __init__(self):
3272 super().__init__()
tiernobee085c2018-12-12 17:03:04 +00003273 self.test_name = "HACKFEST3v2-"
tiernoff6485d2018-11-28 17:19:46 +00003274 self.qforce = "?FORCE=True"
3275 self.descriptor_edit = {
3276 "vnfd0": {
3277 "vdu": {
3278 "$[0]": {
garciadeblas4568a372021-03-24 09:19:48 +01003279 "interface": {
3280 "$[0]": {"external-connection-point-ref": "pdu-mgmt"}
3281 }
tiernoff6485d2018-11-28 17:19:46 +00003282 },
garciadeblas4568a372021-03-24 09:19:48 +01003283 "$[1]": None,
tiernoff6485d2018-11-28 17:19:46 +00003284 },
3285 "vnf-configuration": None,
3286 "connection-point": {
3287 "$[0]": {
3288 "id": "pdu-mgmt",
3289 "name": "pdu-mgmt",
garciadeblas4568a372021-03-24 09:19:48 +01003290 "short-name": "pdu-mgmt",
tiernoff6485d2018-11-28 17:19:46 +00003291 },
garciadeblas4568a372021-03-24 09:19:48 +01003292 "$[1]": None,
tiernoff6485d2018-11-28 17:19:46 +00003293 },
3294 "mgmt-interface": {"cp": "pdu-mgmt"},
3295 "description": "A vnf single vdu to be used as PDU",
3296 "id": "vdu-as-pdu",
3297 "internal-vld": {
3298 "$[0]": {
3299 "id": "pdu_internal",
3300 "name": "pdu_internal",
3301 "internal-connection-point": {"$[1]": None},
3302 "short-name": "pdu_internal",
garciadeblas4568a372021-03-24 09:19:48 +01003303 "type": "ELAN",
tiernoff6485d2018-11-28 17:19:46 +00003304 }
garciadeblas4568a372021-03-24 09:19:48 +01003305 },
tiernoff6485d2018-11-28 17:19:46 +00003306 },
tiernoff6485d2018-11-28 17:19:46 +00003307 # Modify NSD accordingly
3308 "nsd": {
3309 "constituent-vnfd": {
3310 "$[0]": {"vnfd-id-ref": "vdu-as-pdu"},
3311 "$[1]": None,
3312 },
3313 "description": "A nsd to deploy the vnf to act as as PDU",
3314 "id": "nsd-as-pdu",
3315 "name": "nsd-as-pdu",
3316 "short-name": "nsd-as-pdu",
3317 "vld": {
3318 "$[0]": {
3319 "id": "mgmt_pdu",
3320 "name": "mgmt_pdu",
3321 "short-name": "mgmt_pdu",
3322 "vnfd-connection-point-ref": {
3323 "$[0]": {
3324 "vnfd-connection-point-ref": "pdu-mgmt",
3325 "vnfd-id-ref": "vdu-as-pdu",
3326 },
garciadeblas4568a372021-03-24 09:19:48 +01003327 "$[1]": None,
tiernoff6485d2018-11-28 17:19:46 +00003328 },
garciadeblas4568a372021-03-24 09:19:48 +01003329 "type": "ELAN",
tiernoff6485d2018-11-28 17:19:46 +00003330 },
3331 "$[1]": None,
garciadeblas4568a372021-03-24 09:19:48 +01003332 },
3333 },
tiernoff6485d2018-11-28 17:19:46 +00003334 }
3335
3336
tiernobee085c2018-12-12 17:03:04 +00003337class TestDeployHackfest3Charmed3(TestDeployHackfest3Charmed):
3338 description = "Load and deploy Hackfest 3charmed_ns example modified version to test scaling and NS parameters"
3339
3340 def __init__(self):
3341 super().__init__()
3342 self.test_name = "HACKFEST3v3-"
garciadeblas4568a372021-03-24 09:19:48 +01003343 self.commands = {
3344 "1": ["ls -lrt /home/ubuntu/first-touch-1"],
3345 "2": ["ls -lrt /home/ubuntu/first-touch-2"],
3346 }
tiernobee085c2018-12-12 17:03:04 +00003347 self.descriptor_edit = {
3348 "vnfd0": yaml.load(
3349 """
3350 scaling-group-descriptor:
3351 - name: "scale_dataVM"
3352 max-instance-count: 10
3353 scaling-policy:
3354 - name: "auto_cpu_util_above_threshold"
3355 scaling-type: "automatic"
3356 threshold-time: 0
3357 cooldown-time: 60
3358 scaling-criteria:
3359 - name: "cpu_util_above_threshold"
3360 scale-in-threshold: 15
3361 scale-in-relational-operation: "LE"
3362 scale-out-threshold: 60
3363 scale-out-relational-operation: "GE"
3364 vnf-monitoring-param-ref: "monitor1"
3365 vdu:
3366 - vdu-id-ref: dataVM
3367 count: 1
3368 scaling-config-action:
3369 - trigger: post-scale-out
3370 vnf-config-primitive-name-ref: touch
3371 - trigger: pre-scale-in
3372 vnf-config-primitive-name-ref: touch
3373 vdu:
3374 "$id: dataVM":
3375 monitoring-param:
3376 - id: "dataVM_cpu_util"
3377 nfvi-metric: "cpu_utilization"
3378
3379 monitoring-param:
3380 - id: "monitor1"
3381 name: "monitor1"
3382 aggregation-type: AVERAGE
3383 vdu-monitoring-param:
3384 vdu-ref: "dataVM"
3385 vdu-monitoring-param-ref: "dataVM_cpu_util"
3386 vnf-configuration:
3387 initial-config-primitive:
3388 "$[1]":
3389 parameter:
3390 "$[0]":
tiernoe4a07d52019-05-16 15:25:37 +00003391 value: "<touch_filename>" # default-value: /home/ubuntu/first-touch
tiernoa1c1b532019-01-16 14:12:22 +00003392 config-primitive:
3393 "$[0]":
3394 parameter:
3395 "$[0]":
tiernoe4a07d52019-05-16 15:25:37 +00003396 default-value: "<touch_filename2>"
delacruzramob19cadc2019-10-08 10:18:02 +02003397 """,
garciadeblas4568a372021-03-24 09:19:48 +01003398 Loader=yaml.Loader,
3399 )
tiernobee085c2018-12-12 17:03:04 +00003400 }
3401 self.ns_params = {
3402 "additionalParamsForVnf": [
garciadeblas4568a372021-03-24 09:19:48 +01003403 {
3404 "member-vnf-index": "1",
3405 "additionalParams": {
3406 "touch_filename": "/home/ubuntu/first-touch-1",
3407 "touch_filename2": "/home/ubuntu/second-touch-1",
3408 },
3409 },
3410 {
3411 "member-vnf-index": "2",
3412 "additionalParams": {
3413 "touch_filename": "/home/ubuntu/first-touch-2",
3414 "touch_filename2": "/home/ubuntu/second-touch-2",
3415 },
3416 },
tiernobee085c2018-12-12 17:03:04 +00003417 ]
3418 }
3419
3420 def additional_operations(self, engine, test_osm, manual_check):
3421 super().additional_operations(engine, test_osm, manual_check)
3422 if not test_osm:
3423 return
3424
3425 # 2 perform scale out
garciadeblas4568a372021-03-24 09:19:48 +01003426 payload = (
3427 "{scaleType: SCALE_VNF, scaleVnfData: {scaleVnfType: SCALE_OUT, scaleByStepData: "
3428 '{scaling-group-descriptor: scale_dataVM, member-vnf-index: "1"}}}'
3429 )
3430 engine.test(
3431 "Execute scale action over NS",
3432 "POST",
3433 "/nslcm/v1/ns_instances/{}/scale".format(self.ns_id),
3434 headers_yaml,
3435 payload,
3436 (201, 202),
3437 r_headers_yaml_location_nslcmop,
3438 "yaml",
3439 )
tiernobee085c2018-12-12 17:03:04 +00003440 nslcmop2_scale_out = engine.last_id
3441 engine.wait_operation_ready("ns", nslcmop2_scale_out, timeout_deploy)
3442 if manual_check:
garciadeblas4568a372021-03-24 09:19:48 +01003443 input(
3444 "NS scale out done. Check that file /home/ubuntu/second-touch-1 is present and new VM is created"
3445 )
tiernobee085c2018-12-12 17:03:04 +00003446 if test_osm:
garciadeblas4568a372021-03-24 09:19:48 +01003447 commands = {
3448 "1": [
3449 "ls -lrt /home/ubuntu/second-touch-1",
3450 ]
3451 }
tiernobee085c2018-12-12 17:03:04 +00003452 self.test_ns(engine, test_osm, commands=commands)
3453 # TODO check automatic connection to scaled VM
3454
3455 # 2 perform scale in
garciadeblas4568a372021-03-24 09:19:48 +01003456 payload = (
3457 "{scaleType: SCALE_VNF, scaleVnfData: {scaleVnfType: SCALE_IN, scaleByStepData: "
3458 '{scaling-group-descriptor: scale_dataVM, member-vnf-index: "1"}}}'
3459 )
3460 engine.test(
3461 "Execute scale action over NS",
3462 "POST",
3463 "/nslcm/v1/ns_instances/{}/scale".format(self.ns_id),
3464 headers_yaml,
3465 payload,
3466 (201, 202),
3467 r_headers_yaml_location_nslcmop,
3468 "yaml",
3469 )
tiernobee085c2018-12-12 17:03:04 +00003470 nslcmop2_scale_in = engine.last_id
3471 engine.wait_operation_ready("ns", nslcmop2_scale_in, timeout_deploy)
3472 if manual_check:
garciadeblas4568a372021-03-24 09:19:48 +01003473 input(
3474 "NS scale in done. Check that file /home/ubuntu/second-touch-1 is updated and new VM is deleted"
3475 )
tiernobee085c2018-12-12 17:03:04 +00003476 # TODO check automatic
3477
3478
3479class TestDeploySimpleCharm(TestDeploy):
3480 description = "Deploy hackfest-4 hackfest_simplecharm example"
3481
3482 def __init__(self):
3483 super().__init__()
3484 self.test_name = "HACKFEST-SIMPLE"
garciadeblas4568a372021-03-24 09:19:48 +01003485 self.descriptor_url = (
3486 "https://osm-download.etsi.org/ftp/osm-4.0-four/4th-hackfest/packages/"
3487 )
tiernobee085c2018-12-12 17:03:04 +00003488 self.vnfd_filenames = ("hackfest_simplecharm_vnf.tar.gz",)
3489 self.nsd_filename = "hackfest_simplecharm_ns.tar.gz"
3490 self.uses_configuration = True
garciadeblas4568a372021-03-24 09:19:48 +01003491 self.commands = {
3492 "1": [""],
3493 "2": [
3494 "ls -lrt /home/ubuntu/first-touch",
3495 ],
3496 }
3497 self.users = {"1": "ubuntu", "2": "ubuntu"}
3498 self.passwords = {"1": "osm4u", "2": "osm4u"}
tiernobee085c2018-12-12 17:03:04 +00003499
3500
3501class TestDeploySimpleCharm2(TestDeploySimpleCharm):
garciadeblas4568a372021-03-24 09:19:48 +01003502 description = (
3503 "Deploy hackfest-4 hackfest_simplecharm example changing naming to contain dots on ids and "
3504 "vnf-member-index"
3505 )
tiernobee085c2018-12-12 17:03:04 +00003506
3507 def __init__(self):
3508 super().__init__()
3509 self.test_name = "HACKFEST-SIMPLE2-"
3510 self.qforce = "?FORCE=True"
3511 self.descriptor_edit = {
garciadeblas4568a372021-03-24 09:19:48 +01003512 "vnfd0": {"id": "hackfest.simplecharm.vnf"},
tiernobee085c2018-12-12 17:03:04 +00003513 "nsd": {
3514 "id": "hackfest.simplecharm.ns",
3515 "constituent-vnfd": {
garciadeblas4568a372021-03-24 09:19:48 +01003516 "$[0]": {
3517 "vnfd-id-ref": "hackfest.simplecharm.vnf",
3518 "member-vnf-index": "$1",
3519 },
3520 "$[1]": {
3521 "vnfd-id-ref": "hackfest.simplecharm.vnf",
3522 "member-vnf-index": "$2",
3523 },
tiernobee085c2018-12-12 17:03:04 +00003524 },
3525 "vld": {
3526 "$[0]": {
garciadeblas4568a372021-03-24 09:19:48 +01003527 "vnfd-connection-point-ref": {
3528 "$[0]": {
3529 "member-vnf-index-ref": "$1",
3530 "vnfd-id-ref": "hackfest.simplecharm.vnf",
3531 },
3532 "$[1]": {
3533 "member-vnf-index-ref": "$2",
3534 "vnfd-id-ref": "hackfest.simplecharm.vnf",
3535 },
3536 },
tiernobee085c2018-12-12 17:03:04 +00003537 },
3538 "$[1]": {
garciadeblas4568a372021-03-24 09:19:48 +01003539 "vnfd-connection-point-ref": {
3540 "$[0]": {
3541 "member-vnf-index-ref": "$1",
3542 "vnfd-id-ref": "hackfest.simplecharm.vnf",
3543 },
3544 "$[1]": {
3545 "member-vnf-index-ref": "$2",
3546 "vnfd-id-ref": "hackfest.simplecharm.vnf",
3547 },
3548 },
tiernobee085c2018-12-12 17:03:04 +00003549 },
garciadeblas4568a372021-03-24 09:19:48 +01003550 },
3551 },
tiernobee085c2018-12-12 17:03:04 +00003552 }
3553
3554
tierno36ec8602018-11-02 17:27:11 +01003555class TestDeploySingleVdu(TestDeployHackfest3Charmed):
garciadeblas4568a372021-03-24 09:19:48 +01003556 description = (
3557 "Generate a single VDU base on editing Hackfest3Charmed descriptors and deploy"
3558 )
tierno36ec8602018-11-02 17:27:11 +01003559
3560 def __init__(self):
3561 super().__init__()
tiernoff6485d2018-11-28 17:19:46 +00003562 self.test_name = "SingleVDU"
tierno36ec8602018-11-02 17:27:11 +01003563 self.qforce = "?FORCE=True"
3564 self.descriptor_edit = {
3565 # Modify VNFD to remove one VDU
3566 "vnfd0": {
3567 "vdu": {
3568 "$[0]": {
garciadeblas4568a372021-03-24 09:19:48 +01003569 "interface": {
3570 "$[0]": {"external-connection-point-ref": "pdu-mgmt"}
3571 }
tierno36ec8602018-11-02 17:27:11 +01003572 },
garciadeblas4568a372021-03-24 09:19:48 +01003573 "$[1]": None,
tierno36ec8602018-11-02 17:27:11 +01003574 },
3575 "vnf-configuration": None,
3576 "connection-point": {
3577 "$[0]": {
3578 "id": "pdu-mgmt",
3579 "name": "pdu-mgmt",
garciadeblas4568a372021-03-24 09:19:48 +01003580 "short-name": "pdu-mgmt",
tierno36ec8602018-11-02 17:27:11 +01003581 },
garciadeblas4568a372021-03-24 09:19:48 +01003582 "$[1]": None,
tierno36ec8602018-11-02 17:27:11 +01003583 },
3584 "mgmt-interface": {"cp": "pdu-mgmt"},
3585 "description": "A vnf single vdu to be used as PDU",
3586 "id": "vdu-as-pdu",
3587 "internal-vld": {
3588 "$[0]": {
3589 "id": "pdu_internal",
3590 "name": "pdu_internal",
3591 "internal-connection-point": {"$[1]": None},
3592 "short-name": "pdu_internal",
garciadeblas4568a372021-03-24 09:19:48 +01003593 "type": "ELAN",
tierno36ec8602018-11-02 17:27:11 +01003594 }
garciadeblas4568a372021-03-24 09:19:48 +01003595 },
tierno36ec8602018-11-02 17:27:11 +01003596 },
tierno36ec8602018-11-02 17:27:11 +01003597 # Modify NSD accordingly
3598 "nsd": {
3599 "constituent-vnfd": {
3600 "$[0]": {"vnfd-id-ref": "vdu-as-pdu"},
3601 "$[1]": None,
3602 },
3603 "description": "A nsd to deploy the vnf to act as as PDU",
3604 "id": "nsd-as-pdu",
3605 "name": "nsd-as-pdu",
3606 "short-name": "nsd-as-pdu",
3607 "vld": {
3608 "$[0]": {
3609 "id": "mgmt_pdu",
3610 "name": "mgmt_pdu",
3611 "short-name": "mgmt_pdu",
3612 "vnfd-connection-point-ref": {
3613 "$[0]": {
3614 "vnfd-connection-point-ref": "pdu-mgmt",
3615 "vnfd-id-ref": "vdu-as-pdu",
3616 },
garciadeblas4568a372021-03-24 09:19:48 +01003617 "$[1]": None,
tierno36ec8602018-11-02 17:27:11 +01003618 },
garciadeblas4568a372021-03-24 09:19:48 +01003619 "type": "ELAN",
tierno36ec8602018-11-02 17:27:11 +01003620 },
3621 "$[1]": None,
garciadeblas4568a372021-03-24 09:19:48 +01003622 },
3623 },
tierno36ec8602018-11-02 17:27:11 +01003624 }
3625
3626
3627class TestDeployHnfd(TestDeployHackfest3Charmed):
garciadeblas4568a372021-03-24 09:19:48 +01003628 description = (
3629 "Generate a HNFD base on editing Hackfest3Charmed descriptors and deploy"
3630 )
tierno36ec8602018-11-02 17:27:11 +01003631
3632 def __init__(self):
3633 super().__init__()
tiernoff6485d2018-11-28 17:19:46 +00003634 self.test_name = "HNFD"
tierno36ec8602018-11-02 17:27:11 +01003635 self.pduDeploy = TestDeploySingleVdu()
3636 self.pdu_interface_0 = {}
3637 self.pdu_interface_1 = {}
3638
3639 self.pdu_id = None
3640 # self.vnf_to_pdu = """
3641 # vdu:
3642 # "$[0]":
3643 # pdu-type: PDU-TYPE-1
3644 # interface:
3645 # "$[0]":
3646 # name: mgmt-iface
3647 # "$[1]":
3648 # name: pdu-iface-internal
3649 # id: hfn1
3650 # description: HFND, one PDU + One VDU
3651 # name: hfn1
3652 # short-name: hfn1
3653 #
3654 # """
3655
3656 self.pdu_descriptor = {
3657 "name": "my-PDU",
3658 "type": "PDU-TYPE-1",
3659 "vim_accounts": "to-override",
3660 "interfaces": [
3661 {
3662 "name": "mgmt-iface",
3663 "mgmt": True,
3664 "type": "overlay",
3665 "ip-address": "to override",
3666 "mac-address": "mac_address",
3667 "vim-network-name": "mgmt",
3668 },
3669 {
3670 "name": "pdu-iface-internal",
3671 "mgmt": False,
3672 "type": "overlay",
3673 "ip-address": "to override",
3674 "mac-address": "mac_address",
3675 "vim-network-name": "pdu_internal", # OSMNBITEST-PDU-pdu_internal
3676 },
garciadeblas4568a372021-03-24 09:19:48 +01003677 ],
tierno36ec8602018-11-02 17:27:11 +01003678 }
garciadeblas4568a372021-03-24 09:19:48 +01003679 self.vnfd_filenames = (
3680 "hackfest_3charmed_vnfd.tar.gz",
3681 "hackfest_3charmed_vnfd.tar.gz",
3682 )
tierno36ec8602018-11-02 17:27:11 +01003683
3684 self.descriptor_edit = {
3685 "vnfd0": {
3686 "id": "hfnd1",
3687 "name": "hfn1",
3688 "short-name": "hfn1",
3689 "vdu": {
3690 "$[0]": {
3691 "pdu-type": "PDU-TYPE-1",
3692 "interface": {
3693 "$[0]": {"name": "mgmt-iface"},
3694 "$[1]": {"name": "pdu-iface-internal"},
garciadeblas4568a372021-03-24 09:19:48 +01003695 },
tierno36ec8602018-11-02 17:27:11 +01003696 }
garciadeblas4568a372021-03-24 09:19:48 +01003697 },
tierno36ec8602018-11-02 17:27:11 +01003698 },
3699 "nsd": {
garciadeblas4568a372021-03-24 09:19:48 +01003700 "constituent-vnfd": {"$[1]": {"vnfd-id-ref": "hfnd1"}},
tiernoff6485d2018-11-28 17:19:46 +00003701 "vld": {
garciadeblas4568a372021-03-24 09:19:48 +01003702 "$[0]": {
3703 "vnfd-connection-point-ref": {"$[1]": {"vnfd-id-ref": "hfnd1"}}
3704 },
3705 "$[1]": {
3706 "vnfd-connection-point-ref": {"$[1]": {"vnfd-id-ref": "hfnd1"}}
3707 },
3708 },
3709 },
tierno36ec8602018-11-02 17:27:11 +01003710 }
3711
3712 def create_descriptors(self, engine):
3713 super().create_descriptors(engine)
3714
3715 # Create PDU
3716 self.pdu_descriptor["interfaces"][0].update(self.pdu_interface_0)
3717 self.pdu_descriptor["interfaces"][1].update(self.pdu_interface_1)
3718 self.pdu_descriptor["vim_accounts"] = [self.vim_id]
3719 # TODO get vim-network-name from vnfr.vld.name
3720 self.pdu_descriptor["interfaces"][1]["vim-network-name"] = "{}-{}-{}".format(
3721 os.environ.get("OSMNBITEST_NS_NAME", "OSMNBITEST"),
garciadeblas4568a372021-03-24 09:19:48 +01003722 "PDU",
3723 self.pdu_descriptor["interfaces"][1]["vim-network-name"],
3724 )
3725 engine.test(
3726 "Onboard PDU descriptor",
3727 "POST",
3728 "/pdu/v1/pdu_descriptors",
3729 {
3730 "Location": "/pdu/v1/pdu_descriptors/",
3731 "Content-Type": "application/yaml",
3732 },
3733 self.pdu_descriptor,
3734 201,
3735 r_header_yaml,
3736 "yaml",
3737 )
tiernoff6485d2018-11-28 17:19:46 +00003738 self.pdu_id = engine.last_id
tierno36ec8602018-11-02 17:27:11 +01003739
3740 def run(self, engine, test_osm, manual_check, test_params=None):
3741 engine.get_autorization()
tiernoff6485d2018-11-28 17:19:46 +00003742 engine.set_test_name(self.test_name)
tierno36ec8602018-11-02 17:27:11 +01003743 nsname = os.environ.get("OSMNBITEST_NS_NAME", "OSMNBITEST")
3744
3745 # create real VIM if not exist
3746 self.vim_id = engine.get_create_vim(test_osm)
tiernoff6485d2018-11-28 17:19:46 +00003747 # instantiate PDU
tierno36ec8602018-11-02 17:27:11 +01003748 self.pduDeploy.create_descriptors(engine)
garciadeblas4568a372021-03-24 09:19:48 +01003749 self.pduDeploy.instantiate(
3750 engine,
3751 {
3752 "nsDescription": "to be used as PDU",
3753 "nsName": nsname + "-PDU",
3754 "nsdId": self.pduDeploy.nsd_id,
3755 "vimAccountId": self.vim_id,
3756 },
3757 )
tierno36ec8602018-11-02 17:27:11 +01003758 if manual_check:
garciadeblas4568a372021-03-24 09:19:48 +01003759 input(
3760 "VNF to be used as PDU has been deployed. Perform manual check and press enter to resume"
3761 )
tiernoff6485d2018-11-28 17:19:46 +00003762 if test_osm:
tiernobee085c2018-12-12 17:03:04 +00003763 self.pduDeploy.test_ns(engine, test_osm)
tierno36ec8602018-11-02 17:27:11 +01003764
3765 if test_osm:
garciadeblas4568a372021-03-24 09:19:48 +01003766 r = engine.test(
3767 "Get VNFR to obtain IP_ADDRESS",
3768 "GET",
3769 "/nslcm/v1/vnfrs?nsr-id-ref={}".format(self.pduDeploy.ns_id),
3770 headers_json,
3771 None,
3772 200,
3773 r_header_json,
3774 "json",
3775 )
tiernoff6485d2018-11-28 17:19:46 +00003776 if not r:
3777 return
tierno36ec8602018-11-02 17:27:11 +01003778 vnfr_data = r.json()
3779 # print(vnfr_data)
3780
garciadeblas4568a372021-03-24 09:19:48 +01003781 self.pdu_interface_0["ip-address"] = vnfr_data[0]["vdur"][0]["interfaces"][
3782 0
3783 ].get("ip-address")
3784 self.pdu_interface_1["ip-address"] = vnfr_data[0]["vdur"][0]["interfaces"][
3785 1
3786 ].get("ip-address")
3787 self.pdu_interface_0["mac-address"] = vnfr_data[0]["vdur"][0]["interfaces"][
3788 0
3789 ].get("mac-address")
3790 self.pdu_interface_1["mac-address"] = vnfr_data[0]["vdur"][0]["interfaces"][
3791 1
3792 ].get("mac-address")
tierno36ec8602018-11-02 17:27:11 +01003793 if not self.pdu_interface_0["ip-address"]:
3794 raise TestException("Vnfr has not managment ip address")
3795 else:
3796 self.pdu_interface_0["ip-address"] = "192.168.10.10"
3797 self.pdu_interface_1["ip-address"] = "192.168.11.10"
3798 self.pdu_interface_0["mac-address"] = "52:33:44:55:66:13"
3799 self.pdu_interface_1["mac-address"] = "52:33:44:55:66:14"
3800
3801 self.create_descriptors(engine)
3802
garciadeblas4568a372021-03-24 09:19:48 +01003803 ns_data = {
3804 "nsDescription": "default description",
3805 "nsName": nsname,
3806 "nsdId": self.nsd_id,
3807 "vimAccountId": self.vim_id,
3808 }
tierno36ec8602018-11-02 17:27:11 +01003809 if test_params and test_params.get("ns-config"):
3810 if isinstance(test_params["ns-config"], str):
delacruzramob19cadc2019-10-08 10:18:02 +02003811 ns_data.update(yaml.load(test_params["ns-config"]), Loader=yaml.Loader)
tierno36ec8602018-11-02 17:27:11 +01003812 else:
3813 ns_data.update(test_params["ns-config"])
3814
3815 self.instantiate(engine, ns_data)
3816 if manual_check:
garciadeblas4568a372021-03-24 09:19:48 +01003817 input(
3818 "NS has been deployed. Perform manual check and press enter to resume"
3819 )
tiernoff6485d2018-11-28 17:19:46 +00003820 if test_osm:
tiernobee085c2018-12-12 17:03:04 +00003821 self.test_ns(engine, test_osm)
3822 self.additional_operations(engine, test_osm, manual_check)
tierno36ec8602018-11-02 17:27:11 +01003823 self.terminate(engine)
3824 self.pduDeploy.terminate(engine)
3825 self.delete_descriptors(engine)
3826 self.pduDeploy.delete_descriptors(engine)
3827
tierno36ec8602018-11-02 17:27:11 +01003828 def delete_descriptors(self, engine):
3829 super().delete_descriptors(engine)
3830 # delete pdu
garciadeblas4568a372021-03-24 09:19:48 +01003831 engine.test(
3832 "Delete PDU SOL005",
3833 "DELETE",
3834 "/pdu/v1/pdu_descriptors/{}".format(self.pdu_id),
3835 headers_yaml,
3836 None,
3837 204,
3838 None,
3839 0,
3840 )
tierno36ec8602018-11-02 17:27:11 +01003841
3842
tierno49e42062018-10-24 12:50:53 +02003843class TestDescriptors:
3844 description = "Test VNFD, NSD, PDU descriptors CRUD and dependencies"
tierno65ca36d2019-02-12 19:27:52 +01003845 vnfd_empty = """vnfd:vnfd-catalog:
3846 vnfd:
3847 - name: prova
3848 short-name: prova
3849 id: prova
3850 """
3851 vnfd_prova = """vnfd:vnfd-catalog:
3852 vnfd:
3853 - connection-point:
3854 - name: cp_0h8m
3855 type: VPORT
3856 id: prova
3857 name: prova
3858 short-name: prova
3859 vdu:
3860 - id: vdu_z4bm
3861 image: ubuntu
3862 interface:
3863 - external-connection-point-ref: cp_0h8m
3864 name: eth0
3865 virtual-interface:
3866 type: VIRTIO
3867 name: vdu_z4bm
3868 version: '1.0'
3869 """
tierno49e42062018-10-24 12:50:53 +02003870
3871 def __init__(self):
tierno49e42062018-10-24 12:50:53 +02003872 self.vnfd_filename = "hackfest_3charmed_vnfd.tar.gz"
3873 self.nsd_filename = "hackfest_3charmed_nsd.tar.gz"
garciadeblas4568a372021-03-24 09:19:48 +01003874 self.descriptor_url = (
3875 "https://osm-download.etsi.org/ftp/osm-3.0-three/2nd-hackfest/packages/"
3876 )
tierno49e42062018-10-24 12:50:53 +02003877 self.vnfd_id = None
3878 self.nsd_id = None
3879
3880 def run(self, engine, test_osm, manual_check, test_params=None):
tiernoff6485d2018-11-28 17:19:46 +00003881 engine.set_test_name("Descriptors")
tierno49e42062018-10-24 12:50:53 +02003882 engine.get_autorization()
3883 temp_dir = os.path.dirname(os.path.abspath(__file__)) + "/temp/"
3884 if not os.path.exists(temp_dir):
3885 os.makedirs(temp_dir)
3886
3887 # download files
3888 for filename in (self.vnfd_filename, self.nsd_filename):
3889 filename_path = temp_dir + filename
3890 if not os.path.exists(filename_path):
3891 with open(filename_path, "wb") as file:
3892 response = requests.get(self.descriptor_url + filename)
3893 if response.status_code >= 300:
garciadeblas4568a372021-03-24 09:19:48 +01003894 raise TestException(
3895 "Error downloading descriptor from '{}': {}".format(
3896 self.descriptor_url + filename, response.status_code
3897 )
3898 )
tierno49e42062018-10-24 12:50:53 +02003899 file.write(response.content)
3900
3901 vnfd_filename_path = temp_dir + self.vnfd_filename
3902 nsd_filename_path = temp_dir + self.nsd_filename
3903
garciadeblas4568a372021-03-24 09:19:48 +01003904 engine.test(
3905 "Onboard empty VNFD in one step",
3906 "POST",
3907 "/vnfpkgm/v1/vnf_packages_content",
3908 headers_yaml,
3909 self.vnfd_empty,
3910 201,
3911 r_headers_yaml_location_vnfd,
3912 "yaml",
3913 )
tiernoff6485d2018-11-28 17:19:46 +00003914 self.vnfd_id = engine.last_id
tierno49e42062018-10-24 12:50:53 +02003915
tiernof717cbe2018-12-03 16:35:42 +00003916 # test bug 605
garciadeblas4568a372021-03-24 09:19:48 +01003917 engine.test(
3918 "Upload invalid VNFD ",
3919 "PUT",
3920 "/vnfpkgm/v1/vnf_packages/{}/package_content".format(self.vnfd_id),
3921 headers_yaml,
3922 self.vnfd_prova,
3923 422,
3924 r_header_yaml,
3925 "yaml",
3926 )
tiernof717cbe2018-12-03 16:35:42 +00003927
garciadeblas4568a372021-03-24 09:19:48 +01003928 engine.test(
3929 "Upload VNFD {}".format(self.vnfd_filename),
3930 "PUT",
3931 "/vnfpkgm/v1/vnf_packages/{}/package_content".format(self.vnfd_id),
3932 headers_zip_yaml,
3933 "@b" + vnfd_filename_path,
3934 204,
3935 None,
3936 0,
3937 )
tiernof717cbe2018-12-03 16:35:42 +00003938
garciadeblas4568a372021-03-24 09:19:48 +01003939 queries = [
3940 "mgmt-interface.cp=mgmt",
3941 "vdu.0.interface.0.external-connection-point-ref=mgmt",
3942 "vdu.0.interface.1.internal-connection-point-ref=internal",
3943 "internal-vld.0.internal-connection-point.0.id-ref=internal",
3944 # Detection of duplicated VLD names in VNF Descriptors
3945 # URL: internal-vld=[
3946 # {id: internal1, name: internal, type:ELAN,
3947 # internal-connection-point: [{id-ref: mgmtVM-internal}, {id-ref: dataVM-internal}]},
3948 # {id: internal2, name: internal, type:ELAN,
3949 # internal-connection-point: [{id-ref: mgmtVM-internal}, {id-ref: dataVM-internal}]}
3950 # ]
3951 "internal-vld=%5B%7Bid%3A%20internal1%2C%20name%3A%20internal%2C%20type%3A%20ELAN%2C%20"
3952 "internal-connection-point%3A%20%5B%7Bid-ref%3A%20mgmtVM-internal%7D%2C%20%7Bid-ref%3A%20"
3953 "dataVM-internal%7D%5D%7D%2C%20%7Bid%3A%20internal2%2C%20name%3A%20internal%2C%20type%3A%20"
3954 "ELAN%2C%20internal-connection-point%3A%20%5B%7Bid-ref%3A%20mgmtVM-internal%7D%2C%20%7B"
3955 "id-ref%3A%20dataVM-internal%7D%5D%7D%5D",
3956 ]
gcalvino95f94c22019-01-10 13:03:30 +01003957 for query in queries:
garciadeblas4568a372021-03-24 09:19:48 +01003958 engine.test(
3959 "Upload invalid VNFD ",
3960 "PUT",
3961 "/vnfpkgm/v1/vnf_packages/{}/package_content?{}".format(
3962 self.vnfd_id, query
3963 ),
3964 headers_zip_yaml,
3965 "@b" + vnfd_filename_path,
3966 422,
3967 r_header_yaml,
3968 "yaml",
3969 )
gcalvino95f94c22019-01-10 13:03:30 +01003970
tiernof717cbe2018-12-03 16:35:42 +00003971 # test bug 605
garciadeblas4568a372021-03-24 09:19:48 +01003972 engine.test(
3973 "Upload invalid VNFD ",
3974 "PUT",
3975 "/vnfpkgm/v1/vnf_packages/{}/package_content".format(self.vnfd_id),
3976 headers_yaml,
3977 self.vnfd_prova,
3978 422,
3979 r_header_yaml,
3980 "yaml",
3981 )
tiernof717cbe2018-12-03 16:35:42 +00003982
tierno49e42062018-10-24 12:50:53 +02003983 # get vnfd descriptor
garciadeblas4568a372021-03-24 09:19:48 +01003984 engine.test(
3985 "Get VNFD descriptor",
3986 "GET",
3987 "/vnfpkgm/v1/vnf_packages/{}".format(self.vnfd_id),
3988 headers_yaml,
3989 None,
3990 200,
3991 r_header_yaml,
3992 "yaml",
3993 )
tierno49e42062018-10-24 12:50:53 +02003994
3995 # get vnfd file descriptor
garciadeblas4568a372021-03-24 09:19:48 +01003996 engine.test(
3997 "Get VNFD file descriptor",
3998 "GET",
3999 "/vnfpkgm/v1/vnf_packages/{}/vnfd".format(self.vnfd_id),
4000 headers_text,
4001 None,
4002 200,
4003 r_header_text,
4004 "text",
4005 temp_dir + "vnfd-yaml",
4006 )
tierno49e42062018-10-24 12:50:53 +02004007 # TODO compare files: diff vnfd-yaml hackfest_3charmed_vnfd/hackfest_3charmed_vnfd.yaml
4008
4009 # get vnfd zip file package
garciadeblas4568a372021-03-24 09:19:48 +01004010 engine.test(
4011 "Get VNFD zip package",
4012 "GET",
4013 "/vnfpkgm/v1/vnf_packages/{}/package_content".format(self.vnfd_id),
4014 headers_zip,
4015 None,
4016 200,
4017 r_header_zip,
4018 "zip",
4019 temp_dir + "vnfd-zip",
4020 )
tierno49e42062018-10-24 12:50:53 +02004021 # TODO compare files: diff vnfd-zip hackfest_3charmed_vnfd.tar.gz
4022
4023 # get vnfd artifact
garciadeblas4568a372021-03-24 09:19:48 +01004024 engine.test(
4025 "Get VNFD artifact package",
4026 "GET",
4027 "/vnfpkgm/v1/vnf_packages/{}/artifacts/icons/osm.png".format(self.vnfd_id),
4028 headers_zip,
4029 None,
4030 200,
4031 r_header_octect,
4032 "octet-string",
4033 temp_dir + "vnfd-icon",
4034 )
tierno49e42062018-10-24 12:50:53 +02004035 # TODO compare files: diff vnfd-icon hackfest_3charmed_vnfd/icons/osm.png
4036
4037 # nsd CREATE AND UPLOAD in one step:
garciadeblas4568a372021-03-24 09:19:48 +01004038 engine.test(
4039 "Onboard NSD in one step",
4040 "POST",
4041 "/nsd/v1/ns_descriptors_content",
4042 headers_zip_yaml,
4043 "@b" + nsd_filename_path,
4044 201,
4045 r_headers_yaml_location_nsd,
4046 "yaml",
4047 )
tiernoff6485d2018-11-28 17:19:46 +00004048 self.nsd_id = engine.last_id
tierno49e42062018-10-24 12:50:53 +02004049
gcalvino95f94c22019-01-10 13:03:30 +01004050 queries = ["vld.0.vnfd-connection-point-ref.0.vnfd-id-ref=hf"]
4051 for query in queries:
garciadeblas4568a372021-03-24 09:19:48 +01004052 engine.test(
4053 "Upload invalid NSD ",
4054 "PUT",
4055 "/nsd/v1/ns_descriptors/{}/nsd_content?{}".format(self.nsd_id, query),
4056 headers_zip_yaml,
4057 "@b" + nsd_filename_path,
4058 422,
4059 r_header_yaml,
4060 "yaml",
4061 )
gcalvino95f94c22019-01-10 13:03:30 +01004062
tierno49e42062018-10-24 12:50:53 +02004063 # get nsd descriptor
garciadeblas4568a372021-03-24 09:19:48 +01004064 engine.test(
4065 "Get NSD descriptor",
4066 "GET",
4067 "/nsd/v1/ns_descriptors/{}".format(self.nsd_id),
4068 headers_yaml,
4069 None,
4070 200,
4071 r_header_yaml,
4072 "yaml",
4073 )
tierno49e42062018-10-24 12:50:53 +02004074
4075 # get nsd file descriptor
garciadeblas4568a372021-03-24 09:19:48 +01004076 engine.test(
4077 "Get NSD file descriptor",
4078 "GET",
4079 "/nsd/v1/ns_descriptors/{}/nsd".format(self.nsd_id),
4080 headers_text,
4081 None,
4082 200,
4083 r_header_text,
4084 "text",
4085 temp_dir + "nsd-yaml",
4086 )
tierno49e42062018-10-24 12:50:53 +02004087 # TODO compare files: diff nsd-yaml hackfest_3charmed_nsd/hackfest_3charmed_nsd.yaml
4088
4089 # get nsd zip file package
garciadeblas4568a372021-03-24 09:19:48 +01004090 engine.test(
4091 "Get NSD zip package",
4092 "GET",
4093 "/nsd/v1/ns_descriptors/{}/nsd_content".format(self.nsd_id),
4094 headers_zip,
4095 None,
4096 200,
4097 r_header_zip,
4098 "zip",
4099 temp_dir + "nsd-zip",
4100 )
tierno49e42062018-10-24 12:50:53 +02004101 # TODO compare files: diff nsd-zip hackfest_3charmed_nsd.tar.gz
4102
4103 # get nsd artifact
garciadeblas4568a372021-03-24 09:19:48 +01004104 engine.test(
4105 "Get NSD artifact package",
4106 "GET",
4107 "/nsd/v1/ns_descriptors/{}/artifacts/icons/osm.png".format(self.nsd_id),
4108 headers_zip,
4109 None,
4110 200,
4111 r_header_octect,
4112 "octet-string",
4113 temp_dir + "nsd-icon",
4114 )
tierno49e42062018-10-24 12:50:53 +02004115 # TODO compare files: diff nsd-icon hackfest_3charmed_nsd/icons/osm.png
4116
4117 # vnfd DELETE
garciadeblas4568a372021-03-24 09:19:48 +01004118 test_rest.test(
4119 "Delete VNFD conflict",
4120 "DELETE",
4121 "/vnfpkgm/v1/vnf_packages/{}".format(self.vnfd_id),
4122 headers_yaml,
4123 None,
4124 409,
4125 None,
4126 None,
4127 )
tierno49e42062018-10-24 12:50:53 +02004128
garciadeblas4568a372021-03-24 09:19:48 +01004129 test_rest.test(
4130 "Delete VNFD force",
4131 "DELETE",
4132 "/vnfpkgm/v1/vnf_packages/{}?FORCE=TRUE".format(self.vnfd_id),
4133 headers_yaml,
4134 None,
4135 204,
4136 None,
4137 0,
4138 )
tierno49e42062018-10-24 12:50:53 +02004139
4140 # nsd DELETE
garciadeblas4568a372021-03-24 09:19:48 +01004141 test_rest.test(
4142 "Delete NSD",
4143 "DELETE",
4144 "/nsd/v1/ns_descriptors/{}".format(self.nsd_id),
4145 headers_yaml,
4146 None,
4147 204,
4148 None,
4149 0,
4150 )
tierno49e42062018-10-24 12:50:53 +02004151
4152
Felipe Vicense36ab852018-11-23 14:12:09 +01004153class TestNetSliceTemplates:
Felipe Vicensb57758d2018-10-16 16:00:20 +02004154 description = "Upload a NST to OSM"
4155
4156 def __init__(self):
garciadeblas4568a372021-03-24 09:19:48 +01004157 self.vnfd_filename = "@./slice_shared/vnfd/slice_shared_vnfd.yaml"
4158 self.vnfd_filename_middle = "@./slice_shared/vnfd/slice_shared_middle_vnfd.yaml"
4159 self.nsd_filename = "@./slice_shared/nsd/slice_shared_nsd.yaml"
4160 self.nsd_filename_middle = "@./slice_shared/nsd/slice_shared_middle_nsd.yaml"
4161 self.nst_filenames = "@./slice_shared/slice_shared_nstd.yaml"
Felipe Vicensb57758d2018-10-16 16:00:20 +02004162
4163 def run(self, engine, test_osm, manual_check, test_params=None):
4164 # nst CREATE
Felipe Vicens09e65422019-01-22 15:06:46 +01004165 engine.set_test_name("NST step ")
Felipe Vicensb57758d2018-10-16 16:00:20 +02004166 engine.get_autorization()
Felipe Vicens09e65422019-01-22 15:06:46 +01004167 temp_dir = os.path.dirname(os.path.abspath(__file__)) + "/temp/"
4168 if not os.path.exists(temp_dir):
4169 os.makedirs(temp_dir)
4170
4171 # Onboard VNFDs
garciadeblas4568a372021-03-24 09:19:48 +01004172 engine.test(
4173 "Onboard edge VNFD",
4174 "POST",
4175 "/vnfpkgm/v1/vnf_packages_content",
4176 headers_yaml,
4177 self.vnfd_filename,
4178 201,
4179 r_headers_yaml_location_vnfd,
4180 "yaml",
4181 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004182 self.vnfd_edge_id = engine.last_id
4183
garciadeblas4568a372021-03-24 09:19:48 +01004184 engine.test(
4185 "Onboard middle VNFD",
4186 "POST",
4187 "/vnfpkgm/v1/vnf_packages_content",
4188 headers_yaml,
4189 self.vnfd_filename_middle,
4190 201,
4191 r_headers_yaml_location_vnfd,
4192 "yaml",
4193 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004194 self.vnfd_middle_id = engine.last_id
4195
4196 # Onboard NSDs
garciadeblas4568a372021-03-24 09:19:48 +01004197 engine.test(
4198 "Onboard NSD edge",
4199 "POST",
4200 "/nsd/v1/ns_descriptors_content",
4201 headers_yaml,
4202 self.nsd_filename,
4203 201,
4204 r_headers_yaml_location_nsd,
4205 "yaml",
4206 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004207 self.nsd_edge_id = engine.last_id
4208
garciadeblas4568a372021-03-24 09:19:48 +01004209 engine.test(
4210 "Onboard NSD middle",
4211 "POST",
4212 "/nsd/v1/ns_descriptors_content",
4213 headers_yaml,
4214 self.nsd_filename_middle,
4215 201,
4216 r_headers_yaml_location_nsd,
4217 "yaml",
4218 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004219 self.nsd_middle_id = engine.last_id
4220
4221 # Onboard NST
garciadeblas4568a372021-03-24 09:19:48 +01004222 engine.test(
4223 "Onboard NST",
4224 "POST",
4225 "/nst/v1/netslice_templates_content",
4226 headers_yaml,
4227 self.nst_filenames,
4228 201,
4229 r_headers_yaml_location_nst,
4230 "yaml",
4231 )
tiernoff6485d2018-11-28 17:19:46 +00004232 nst_id = engine.last_id
Felipe Vicensb57758d2018-10-16 16:00:20 +02004233
4234 # nstd SHOW OSM format
garciadeblas4568a372021-03-24 09:19:48 +01004235 engine.test(
4236 "Show NSTD OSM format",
4237 "GET",
4238 "/nst/v1/netslice_templates/{}".format(nst_id),
4239 headers_json,
4240 None,
4241 200,
4242 r_header_json,
4243 "json",
4244 )
Felipe Vicensb57758d2018-10-16 16:00:20 +02004245
4246 # nstd DELETE
garciadeblas4568a372021-03-24 09:19:48 +01004247 engine.test(
4248 "Delete NSTD",
4249 "DELETE",
4250 "/nst/v1/netslice_templates/{}".format(nst_id),
4251 headers_json,
4252 None,
4253 204,
4254 None,
4255 0,
4256 )
Felipe Vicensb57758d2018-10-16 16:00:20 +02004257
Felipe Vicens09e65422019-01-22 15:06:46 +01004258 # NSDs DELETE
garciadeblas4568a372021-03-24 09:19:48 +01004259 test_rest.test(
4260 "Delete NSD middle",
4261 "DELETE",
4262 "/nsd/v1/ns_descriptors/{}".format(self.nsd_middle_id),
4263 headers_json,
4264 None,
4265 204,
4266 None,
4267 0,
4268 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004269
garciadeblas4568a372021-03-24 09:19:48 +01004270 test_rest.test(
4271 "Delete NSD edge",
4272 "DELETE",
4273 "/nsd/v1/ns_descriptors/{}".format(self.nsd_edge_id),
4274 headers_json,
4275 None,
4276 204,
4277 None,
4278 0,
4279 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004280
4281 # VNFDs DELETE
garciadeblas4568a372021-03-24 09:19:48 +01004282 test_rest.test(
4283 "Delete VNFD edge",
4284 "DELETE",
4285 "/vnfpkgm/v1/vnf_packages/{}".format(self.vnfd_edge_id),
4286 headers_yaml,
4287 None,
4288 204,
4289 None,
4290 0,
4291 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004292
garciadeblas4568a372021-03-24 09:19:48 +01004293 test_rest.test(
4294 "Delete VNFD middle",
4295 "DELETE",
4296 "/vnfpkgm/v1/vnf_packages/{}".format(self.vnfd_middle_id),
4297 headers_yaml,
4298 None,
4299 204,
4300 None,
4301 0,
4302 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004303
Felipe Vicensb57758d2018-10-16 16:00:20 +02004304
Felipe Vicense36ab852018-11-23 14:12:09 +01004305class TestNetSliceInstances:
garciadeblas4568a372021-03-24 09:19:48 +01004306 """
Felipe Vicens09e65422019-01-22 15:06:46 +01004307 Test procedure:
4308 1. Populate databases with VNFD, NSD, NST with the following scenario
4309 +-----------------management-----------------+
4310 | | |
4311 +--+---+ +----+----+ +---+--+
4312 | | | | | |
4313 | edge +---data1----+ middle +---data2-----+ edge |
4314 | | | | | |
4315 +------+ +---------+ +------+
4316 shared-nss
4317 2. Create NSI-1
4318 3. Instantiate NSI-1
4319 4. Create NSI-2
4320 5. Instantiate NSI-2
4321 Manual check - Are 2 slices instantiated correctly?
4322 NSI-1 3 nss (2 nss-edges + 1 nss-middle)
4323 NSI-2 2 nss (2 nss-edge sharing nss-middle)
4324 6. Terminate NSI-1
4325 7. Delete NSI-1
4326 Manual check - Is slice NSI-1 deleted correctly?
4327 NSI-2 with 2 nss-edge + 1 nss-middle (The one from NSI-1)
4328 8. Create NSI-3
4329 9. Instantiate NSI-3
4330 Manual check - Is slice NSI-3 instantiated correctly?
4331 NSI-3 reuse nss-middle. NSI-3 only create 2 nss-edge
4332 10. Delete NSI-2
4333 11. Terminate NSI-2
4334 12. Delete NSI-3
4335 13. Terminate NSI-3
4336 Manual check - All cleaned correctly?
4337 NSI-2 and NSI-3 were terminated and deleted
4338 14. Cleanup database
garciadeblas4568a372021-03-24 09:19:48 +01004339 """
Felipe Vicens09e65422019-01-22 15:06:46 +01004340
Felipe Vicense36ab852018-11-23 14:12:09 +01004341 description = "Upload a NST to OSM"
4342
4343 def __init__(self):
tiernoff6485d2018-11-28 17:19:46 +00004344 self.vim_id = None
garciadeblas4568a372021-03-24 09:19:48 +01004345 self.vnfd_filename = "@./slice_shared/vnfd/slice_shared_vnfd.yaml"
4346 self.vnfd_filename_middle = "@./slice_shared/vnfd/slice_shared_middle_vnfd.yaml"
4347 self.nsd_filename = "@./slice_shared/nsd/slice_shared_nsd.yaml"
4348 self.nsd_filename_middle = "@./slice_shared/nsd/slice_shared_middle_nsd.yaml"
4349 self.nst_filenames = "@./slice_shared/slice_shared_nstd.yaml"
Felipe Vicens09e65422019-01-22 15:06:46 +01004350
4351 def create_slice(self, engine, nsi_data, name):
4352 ns_data_text = yaml.safe_dump(nsi_data, default_flow_style=True, width=256)
garciadeblas4568a372021-03-24 09:19:48 +01004353 r = engine.test(
4354 name,
4355 "POST",
4356 "/nsilcm/v1/netslice_instances",
4357 headers_yaml,
4358 ns_data_text,
4359 (201, 202),
4360 {
4361 "Location": "nsilcm/v1/netslice_instances/",
4362 "Content-Type": "application/yaml",
4363 },
4364 "yaml",
4365 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004366 return r
4367
4368 def instantiate_slice(self, engine, nsi_data, nsi_id, name):
4369 ns_data_text = yaml.safe_dump(nsi_data, default_flow_style=True, width=256)
garciadeblas4568a372021-03-24 09:19:48 +01004370 engine.test(
4371 name,
4372 "POST",
4373 "/nsilcm/v1/netslice_instances/{}/instantiate".format(nsi_id),
4374 headers_yaml,
4375 ns_data_text,
4376 (201, 202),
4377 r_headers_yaml_location_nsilcmop,
4378 "yaml",
4379 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004380
4381 def terminate_slice(self, engine, nsi_id, name):
garciadeblas4568a372021-03-24 09:19:48 +01004382 engine.test(
4383 name,
4384 "POST",
4385 "/nsilcm/v1/netslice_instances/{}/terminate".format(nsi_id),
4386 headers_yaml,
4387 None,
4388 (201, 202),
4389 r_headers_yaml_location_nsilcmop,
4390 "yaml",
4391 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004392
4393 def delete_slice(self, engine, nsi_id, name):
garciadeblas4568a372021-03-24 09:19:48 +01004394 engine.test(
4395 name,
4396 "DELETE",
4397 "/nsilcm/v1/netslice_instances/{}".format(nsi_id),
4398 headers_yaml,
4399 None,
4400 204,
4401 None,
4402 0,
4403 )
Felipe Vicense36ab852018-11-23 14:12:09 +01004404
4405 def run(self, engine, test_osm, manual_check, test_params=None):
4406 # nst CREATE
tiernoff6485d2018-11-28 17:19:46 +00004407 engine.set_test_name("NSI")
Felipe Vicense36ab852018-11-23 14:12:09 +01004408 engine.get_autorization()
Felipe Vicens09e65422019-01-22 15:06:46 +01004409
4410 # Onboard VNFDs
garciadeblas4568a372021-03-24 09:19:48 +01004411 engine.test(
4412 "Onboard edge VNFD",
4413 "POST",
4414 "/vnfpkgm/v1/vnf_packages_content",
4415 headers_yaml,
4416 self.vnfd_filename,
4417 201,
4418 r_headers_yaml_location_vnfd,
4419 "yaml",
4420 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004421 self.vnfd_edge_id = engine.last_id
4422
garciadeblas4568a372021-03-24 09:19:48 +01004423 engine.test(
4424 "Onboard middle VNFD",
4425 "POST",
4426 "/vnfpkgm/v1/vnf_packages_content",
4427 headers_yaml,
4428 self.vnfd_filename_middle,
4429 201,
4430 r_headers_yaml_location_vnfd,
4431 "yaml",
4432 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004433 self.vnfd_middle_id = engine.last_id
4434
4435 # Onboard NSDs
garciadeblas4568a372021-03-24 09:19:48 +01004436 engine.test(
4437 "Onboard NSD edge",
4438 "POST",
4439 "/nsd/v1/ns_descriptors_content",
4440 headers_yaml,
4441 self.nsd_filename,
4442 201,
4443 r_headers_yaml_location_nsd,
4444 "yaml",
4445 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004446 self.nsd_edge_id = engine.last_id
4447
garciadeblas4568a372021-03-24 09:19:48 +01004448 engine.test(
4449 "Onboard NSD middle",
4450 "POST",
4451 "/nsd/v1/ns_descriptors_content",
4452 headers_yaml,
4453 self.nsd_filename_middle,
4454 201,
4455 r_headers_yaml_location_nsd,
4456 "yaml",
4457 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004458 self.nsd_middle_id = engine.last_id
4459
4460 # Onboard NST
garciadeblas4568a372021-03-24 09:19:48 +01004461 engine.test(
4462 "Onboard NST",
4463 "POST",
4464 "/nst/v1/netslice_templates_content",
4465 headers_yaml,
4466 self.nst_filenames,
4467 201,
4468 r_headers_yaml_location_nst,
4469 "yaml",
4470 )
tiernoff6485d2018-11-28 17:19:46 +00004471 nst_id = engine.last_id
Felipe Vicense36ab852018-11-23 14:12:09 +01004472
tiernoff6485d2018-11-28 17:19:46 +00004473 self.vim_id = engine.get_create_vim(test_osm)
4474
Felipe Vicens09e65422019-01-22 15:06:46 +01004475 # CREATE NSI-1
garciadeblas4568a372021-03-24 09:19:48 +01004476 ns_data = {
4477 "nsiName": "Deploy-NSI-1",
4478 "vimAccountId": self.vim_id,
4479 "nstId": nst_id,
4480 "nsiDescription": "default",
4481 }
Felipe Vicens09e65422019-01-22 15:06:46 +01004482 r = self.create_slice(engine, ns_data, "Create NSI-1 step 1")
4483 if not r:
4484 return
4485 self.nsi_id1 = engine.last_id
Felipe Vicense36ab852018-11-23 14:12:09 +01004486
Felipe Vicens09e65422019-01-22 15:06:46 +01004487 # INSTANTIATE NSI-1
garciadeblas4568a372021-03-24 09:19:48 +01004488 self.instantiate_slice(
4489 engine, ns_data, self.nsi_id1, "Instantiate NSI-1 step 2"
4490 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004491 nsilcmop_id1 = engine.last_id
Felipe Vicense36ab852018-11-23 14:12:09 +01004492
Felipe Vicens09e65422019-01-22 15:06:46 +01004493 # Waiting for NSI-1
tiernoe4a07d52019-05-16 15:25:37 +00004494 if test_osm:
4495 engine.wait_operation_ready("nsi", nsilcmop_id1, timeout_deploy)
Felipe Vicens09e65422019-01-22 15:06:46 +01004496
4497 # CREATE NSI-2
garciadeblas4568a372021-03-24 09:19:48 +01004498 ns_data = {
4499 "nsiName": "Deploy-NSI-2",
4500 "vimAccountId": self.vim_id,
4501 "nstId": nst_id,
4502 "nsiDescription": "default",
4503 }
Felipe Vicens09e65422019-01-22 15:06:46 +01004504 r = self.create_slice(engine, ns_data, "Create NSI-2 step 1")
4505 if not r:
4506 return
4507 self.nsi_id2 = engine.last_id
4508
4509 # INSTANTIATE NSI-2
garciadeblas4568a372021-03-24 09:19:48 +01004510 self.instantiate_slice(
4511 engine, ns_data, self.nsi_id2, "Instantiate NSI-2 step 2"
4512 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004513 nsilcmop_id2 = engine.last_id
4514
4515 # Waiting for NSI-2
tiernoe4a07d52019-05-16 15:25:37 +00004516 if test_osm:
4517 engine.wait_operation_ready("nsi", nsilcmop_id2, timeout_deploy)
Felipe Vicens09e65422019-01-22 15:06:46 +01004518
4519 if manual_check:
garciadeblas4568a372021-03-24 09:19:48 +01004520 input(
4521 "NSI-1 AND NSI-2 has been deployed. Perform manual check and press enter to resume"
4522 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004523
4524 # TERMINATE NSI-1
tiernoe4a07d52019-05-16 15:25:37 +00004525 if test_osm:
4526 self.terminate_slice(engine, self.nsi_id1, "Terminate NSI-1")
4527 nsilcmop1_id = engine.last_id
Felipe Vicens09e65422019-01-22 15:06:46 +01004528
tiernoe4a07d52019-05-16 15:25:37 +00004529 # Wait terminate NSI-1
4530 engine.wait_operation_ready("nsi", nsilcmop1_id, timeout_deploy)
Felipe Vicens09e65422019-01-22 15:06:46 +01004531
4532 # DELETE NSI-1
4533 self.delete_slice(engine, self.nsi_id1, "Delete NS")
4534
4535 if manual_check:
garciadeblas4568a372021-03-24 09:19:48 +01004536 input(
4537 "NSI-1 has been deleted. Perform manual check and press enter to resume"
4538 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004539
4540 # CREATE NSI-3
garciadeblas4568a372021-03-24 09:19:48 +01004541 ns_data = {
4542 "nsiName": "Deploy-NSI-3",
4543 "vimAccountId": self.vim_id,
4544 "nstId": nst_id,
4545 "nsiDescription": "default",
4546 }
Felipe Vicens09e65422019-01-22 15:06:46 +01004547 r = self.create_slice(engine, ns_data, "Create NSI-3 step 1")
4548
4549 if not r:
4550 return
4551 self.nsi_id3 = engine.last_id
4552
4553 # INSTANTIATE NSI-3
garciadeblas4568a372021-03-24 09:19:48 +01004554 self.instantiate_slice(
4555 engine, ns_data, self.nsi_id3, "Instantiate NSI-3 step 2"
4556 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004557 nsilcmop_id3 = engine.last_id
4558
4559 # Wait Instantiate NSI-3
tiernoe4a07d52019-05-16 15:25:37 +00004560 if test_osm:
4561 engine.wait_operation_ready("nsi", nsilcmop_id3, timeout_deploy)
Felipe Vicens09e65422019-01-22 15:06:46 +01004562
4563 if manual_check:
garciadeblas4568a372021-03-24 09:19:48 +01004564 input(
4565 "NSI-3 has been deployed. Perform manual check and press enter to resume"
4566 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004567
4568 # TERMINATE NSI-2
tiernoe4a07d52019-05-16 15:25:37 +00004569 if test_osm:
4570 self.terminate_slice(engine, self.nsi_id2, "Terminate NSI-2")
4571 nsilcmop2_id = engine.last_id
Felipe Vicens09e65422019-01-22 15:06:46 +01004572
tiernoe4a07d52019-05-16 15:25:37 +00004573 # Wait terminate NSI-2
4574 engine.wait_operation_ready("nsi", nsilcmop2_id, timeout_deploy)
garciadeblas4568a372021-03-24 09:19:48 +01004575
Felipe Vicens09e65422019-01-22 15:06:46 +01004576 # DELETE NSI-2
4577 self.delete_slice(engine, self.nsi_id2, "DELETE NSI-2")
4578
4579 # TERMINATE NSI-3
tiernoe4a07d52019-05-16 15:25:37 +00004580 if test_osm:
garciadeblas4568a372021-03-24 09:19:48 +01004581 self.terminate_slice(engine, self.nsi_id3, "Terminate NSI-3")
tiernoe4a07d52019-05-16 15:25:37 +00004582 nsilcmop3_id = engine.last_id
4583
4584 # Wait terminate NSI-3
4585 engine.wait_operation_ready("nsi", nsilcmop3_id, timeout_deploy)
Felipe Vicens09e65422019-01-22 15:06:46 +01004586
4587 # DELETE NSI-3
4588 self.delete_slice(engine, self.nsi_id3, "DELETE NSI-3")
4589
4590 if manual_check:
garciadeblas4568a372021-03-24 09:19:48 +01004591 input(
4592 "NSI-2 and NSI-3 has been deleted. Perform manual check and press enter to resume"
4593 )
Felipe Vicense36ab852018-11-23 14:12:09 +01004594
4595 # nstd DELETE
garciadeblas4568a372021-03-24 09:19:48 +01004596 engine.test(
4597 "Delete NSTD",
4598 "DELETE",
4599 "/nst/v1/netslice_templates/{}".format(nst_id),
4600 headers_json,
4601 None,
4602 204,
4603 None,
4604 0,
4605 )
Felipe Vicense36ab852018-11-23 14:12:09 +01004606
Felipe Vicens09e65422019-01-22 15:06:46 +01004607 # NSDs DELETE
garciadeblas4568a372021-03-24 09:19:48 +01004608 test_rest.test(
4609 "Delete NSD middle",
4610 "DELETE",
4611 "/nsd/v1/ns_descriptors/{}".format(self.nsd_middle_id),
4612 headers_json,
4613 None,
4614 204,
4615 None,
4616 0,
4617 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004618
garciadeblas4568a372021-03-24 09:19:48 +01004619 test_rest.test(
4620 "Delete NSD edge",
4621 "DELETE",
4622 "/nsd/v1/ns_descriptors/{}".format(self.nsd_edge_id),
4623 headers_json,
4624 None,
4625 204,
4626 None,
4627 0,
4628 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004629
4630 # VNFDs DELETE
garciadeblas4568a372021-03-24 09:19:48 +01004631 test_rest.test(
4632 "Delete VNFD edge",
4633 "DELETE",
4634 "/vnfpkgm/v1/vnf_packages/{}".format(self.vnfd_edge_id),
4635 headers_yaml,
4636 None,
4637 204,
4638 None,
4639 0,
4640 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004641
garciadeblas4568a372021-03-24 09:19:48 +01004642 test_rest.test(
4643 "Delete VNFD middle",
4644 "DELETE",
4645 "/vnfpkgm/v1/vnf_packages/{}".format(self.vnfd_middle_id),
4646 headers_yaml,
4647 None,
4648 204,
4649 None,
4650 0,
4651 )
Felipe Vicens09e65422019-01-22 15:06:46 +01004652
Felipe Vicense36ab852018-11-23 14:12:09 +01004653
delacruzramo9742f1d2019-06-05 13:06:47 +02004654class TestAuthentication:
4655 description = "Test Authentication"
4656
4657 @staticmethod
4658 def run(engine, test_osm, manual_check, test_params=None):
4659 engine.set_test_name("Authentication")
4660 # backend = test_params.get("backend") if test_params else None # UNUSED
4661
4662 admin_project_id = test_project_id = None
4663 project_admin_role_id = project_user_role_id = None
4664 test_user_id = empty_user_id = None
4665 default_role_id = empty_role_id = token_role_id = None
4666
4667 engine.get_autorization()
4668
4669 # GET
garciadeblas4568a372021-03-24 09:19:48 +01004670 engine.test(
4671 "Get tokens",
4672 "GET",
4673 "/admin/v1/tokens",
4674 headers_json,
4675 {},
4676 (200),
4677 {"Content-Type": "application/json"},
4678 "json",
4679 )
4680 engine.test(
4681 "Get projects",
4682 "GET",
4683 "/admin/v1/projects",
4684 headers_json,
4685 {},
4686 (200),
4687 {"Content-Type": "application/json"},
4688 "json",
4689 )
4690 engine.test(
4691 "Get users",
4692 "GET",
4693 "/admin/v1/users",
4694 headers_json,
4695 {},
4696 (200),
4697 {"Content-Type": "application/json"},
4698 "json",
4699 )
4700 engine.test(
4701 "Get roles",
4702 "GET",
4703 "/admin/v1/roles",
4704 headers_json,
4705 {},
4706 (200),
4707 {"Content-Type": "application/json"},
4708 "json",
4709 )
4710 res = engine.test(
4711 "Get admin project",
4712 "GET",
4713 "/admin/v1/projects?name=admin",
4714 headers_json,
4715 {},
4716 (200),
4717 {"Content-Type": "application/json"},
4718 "json",
4719 )
delacruzramo9742f1d2019-06-05 13:06:47 +02004720 admin_project_id = res.json()[0]["_id"] if res else None
garciadeblas4568a372021-03-24 09:19:48 +01004721 res = engine.test(
4722 "Get project admin role",
4723 "GET",
4724 "/admin/v1/roles?name=project_admin",
4725 headers_json,
4726 {},
4727 (200),
4728 {"Content-Type": "application/json"},
4729 "json",
4730 )
delacruzramo9742f1d2019-06-05 13:06:47 +02004731 project_admin_role_id = res.json()[0]["_id"] if res else None
garciadeblas4568a372021-03-24 09:19:48 +01004732 res = engine.test(
4733 "Get project user role",
4734 "GET",
4735 "/admin/v1/roles?name=project_user",
4736 headers_json,
4737 {},
4738 (200),
4739 {"Content-Type": "application/json"},
4740 "json",
4741 )
delacruzramo9742f1d2019-06-05 13:06:47 +02004742 project_user_role_id = res.json()[0]["_id"] if res else None
4743
4744 # POST
garciadeblas4568a372021-03-24 09:19:48 +01004745 res = engine.test(
4746 "Create test project",
4747 "POST",
4748 "/admin/v1/projects",
4749 headers_json,
4750 {"name": "test"},
4751 (201),
4752 {"Location": "/admin/v1/projects/", "Content-Type": "application/json"},
4753 "json",
4754 )
delacruzramo9742f1d2019-06-05 13:06:47 +02004755 test_project_id = engine.last_id if res else None
garciadeblas4568a372021-03-24 09:19:48 +01004756 res = engine.test(
4757 "Create role without permissions",
4758 "POST",
4759 "/admin/v1/roles",
4760 headers_json,
4761 {"name": "empty"},
4762 (201),
4763 {"Content-Type": "application/json"},
4764 "json",
4765 )
delacruzramo9742f1d2019-06-05 13:06:47 +02004766 empty_role_id = engine.last_id if res else None
garciadeblas4568a372021-03-24 09:19:48 +01004767 res = engine.test(
4768 "Create role with default permissions",
4769 "POST",
4770 "/admin/v1/roles",
4771 headers_json,
4772 {"name": "default", "permissions": {"default": True}},
4773 (201),
4774 {"Location": "/admin/v1/roles/", "Content-Type": "application/json"},
4775 "json",
4776 )
delacruzramo9742f1d2019-06-05 13:06:47 +02004777 default_role_id = engine.last_id if res else None
garciadeblas4568a372021-03-24 09:19:48 +01004778 res = engine.test(
4779 "Create role with token permissions",
4780 "POST",
4781 "/admin/v1/roles",
4782 headers_json,
4783 {
4784 "name": "tokens",
4785 "permissions": {"tokens": True},
4786 }, # is default required ?
4787 (201),
4788 {"Location": "/admin/v1/roles/", "Content-Type": "application/json"},
4789 "json",
4790 )
delacruzramo9742f1d2019-06-05 13:06:47 +02004791 token_role_id = engine.last_id if res else None
4792 pr = "project-role mappings"
garciadeblas4568a372021-03-24 09:19:48 +01004793 res = engine.test(
4794 "Create user without " + pr,
4795 "POST",
4796 "/admin/v1/users",
4797 headers_json,
4798 {"username": "empty", "password": "empty"},
4799 201,
4800 {"Content-Type": "application/json"},
4801 "json",
4802 )
delacruzramo9742f1d2019-06-05 13:06:47 +02004803 empty_user_id = engine.last_id if res else None
garciadeblas4568a372021-03-24 09:19:48 +01004804 if (
4805 admin_project_id
4806 and test_project_id
4807 and project_admin_role_id
4808 and project_user_role_id
4809 ):
delacruzramo9742f1d2019-06-05 13:06:47 +02004810 data = {"username": "test", "password": "test"}
4811 data["project_role_mappings"] = [
4812 {"project": test_project_id, "role": project_admin_role_id},
garciadeblas4568a372021-03-24 09:19:48 +01004813 {"project": admin_project_id, "role": project_user_role_id},
delacruzramo9742f1d2019-06-05 13:06:47 +02004814 ]
garciadeblas4568a372021-03-24 09:19:48 +01004815 res = engine.test(
4816 "Create user with " + pr,
4817 "POST",
4818 "/admin/v1/users",
4819 headers_json,
4820 data,
4821 (201),
4822 {"Content-Type": "application/json"},
4823 "json",
4824 )
delacruzramo9742f1d2019-06-05 13:06:47 +02004825 test_user_id = engine.last_id if res else None
4826
4827 # PUT
4828 if test_user_id:
garciadeblas4568a372021-03-24 09:19:48 +01004829 engine.test(
4830 "Modify test user's password",
4831 "PUT",
4832 "/admin/v1/users/" + test_user_id,
4833 headers_json,
4834 {"password": "password"},
4835 (204),
4836 {},
4837 0,
4838 )
4839 if (
4840 empty_user_id
4841 and admin_project_id
4842 and test_project_id
4843 and project_admin_role_id
4844 and project_user_role_id
4845 ):
4846 data = {
4847 "project_role_mappings": [
4848 {"project": test_project_id, "role": project_admin_role_id},
4849 {"project": admin_project_id, "role": project_user_role_id},
4850 ]
4851 }
4852 engine.test(
4853 "Modify empty user's " + pr,
4854 "PUT",
4855 "/admin/v1/users/" + empty_user_id,
4856 headers_json,
4857 data,
4858 (204),
4859 {},
4860 0,
4861 )
delacruzramo9742f1d2019-06-05 13:06:47 +02004862
4863 # DELETE
4864 if empty_user_id:
garciadeblas4568a372021-03-24 09:19:48 +01004865 engine.test(
4866 "Delete empty user",
4867 "DELETE",
4868 "/admin/v1/users/" + empty_user_id,
4869 headers_json,
4870 {},
4871 (204),
4872 {},
4873 0,
4874 )
delacruzramo9742f1d2019-06-05 13:06:47 +02004875 if test_user_id:
garciadeblas4568a372021-03-24 09:19:48 +01004876 engine.test(
4877 "Delete test user",
4878 "DELETE",
4879 "/admin/v1/users/" + test_user_id,
4880 headers_json,
4881 {},
4882 (204),
4883 {},
4884 0,
4885 )
delacruzramo9742f1d2019-06-05 13:06:47 +02004886 if empty_role_id:
garciadeblas4568a372021-03-24 09:19:48 +01004887 engine.test(
4888 "Delete empty role",
4889 "DELETE",
4890 "/admin/v1/roles/" + empty_role_id,
4891 headers_json,
4892 {},
4893 (204),
4894 {},
4895 0,
4896 )
delacruzramo9742f1d2019-06-05 13:06:47 +02004897 if default_role_id:
garciadeblas4568a372021-03-24 09:19:48 +01004898 engine.test(
4899 "Delete default role",
4900 "DELETE",
4901 "/admin/v1/roles/" + default_role_id,
4902 headers_json,
4903 {},
4904 (204),
4905 {},
4906 0,
4907 )
delacruzramo9742f1d2019-06-05 13:06:47 +02004908 if token_role_id:
garciadeblas4568a372021-03-24 09:19:48 +01004909 engine.test(
4910 "Delete token role",
4911 "DELETE",
4912 "/admin/v1/roles/" + token_role_id,
4913 headers_json,
4914 {},
4915 (204),
4916 {},
4917 0,
4918 )
delacruzramo9742f1d2019-06-05 13:06:47 +02004919 if test_project_id:
garciadeblas4568a372021-03-24 09:19:48 +01004920 engine.test(
4921 "Delete test project",
4922 "DELETE",
4923 "/admin/v1/projects/" + test_project_id,
4924 headers_json,
4925 {},
4926 (204),
4927 {},
4928 0,
4929 )
delacruzramo9742f1d2019-06-05 13:06:47 +02004930
4931 # END Tests
4932
garciadeblas4568a372021-03-24 09:19:48 +01004933 engine.remove_authorization() # To finish
delacruzramo9742f1d2019-06-05 13:06:47 +02004934
4935
garciadeblas4568a372021-03-24 09:19:48 +01004936class TestNbiQuotas:
delacruzramo16db9492019-09-25 12:01:59 +02004937 description = "Test NBI Quotas"
4938
4939 @staticmethod
4940 def run(engine, test_osm, manual_check, test_params=None):
4941 engine.set_test_name("NBI-Quotas_")
4942 # backend = test_params.get("backend") if test_params else None # UNUSED
4943
4944 test_username = "test-nbi-quotas"
4945 test_password = "test-nbi-quotas"
4946 test_project = "test-nbi-quotas"
4947
4948 test_vim = "test-nbi-quotas"
4949 test_wim = "test-nbi-quotas"
4950 test_sdn = "test-nbi-quotas"
4951
4952 test_user_id = None
4953 test_project_id = None
4954
4955 test_vim_ids = []
4956 test_wim_ids = []
4957 test_sdn_ids = []
4958 test_vnfd_ids = []
4959 test_nsd_ids = []
4960 test_nst_ids = []
4961 test_pdu_ids = []
4962 test_nsr_ids = []
4963 test_nsi_ids = []
4964
4965 # Save admin access data
4966 admin_username = engine.user
4967 admin_password = engine.password
4968 admin_project = engine.project
4969
4970 # Get admin access
4971 engine.get_autorization()
4972 admin_token = engine.last_id
4973
4974 # Check that test project,user do not exist
garciadeblas4568a372021-03-24 09:19:48 +01004975 res1 = engine.test(
4976 "Check that test project doesn't exist",
4977 "GET",
4978 "/admin/v1/projects/" + test_project,
4979 headers_json,
4980 {},
4981 (404),
4982 {},
4983 True,
4984 )
4985 res2 = engine.test(
4986 "Check that test user doesn't exist",
4987 "GET",
4988 "/admin/v1/users/" + test_username,
4989 headers_json,
4990 {},
4991 (404),
4992 {},
4993 True,
4994 )
delacruzramo16db9492019-09-25 12:01:59 +02004995 if None in [res1, res2]:
4996 engine.remove_authorization()
4997 logger.error("Test project and/or user already exist")
4998 return
4999
5000 # Create test project&user
garciadeblas4568a372021-03-24 09:19:48 +01005001 res = engine.test(
5002 "Create test project",
5003 "POST",
5004 "/admin/v1/projects",
5005 headers_json,
5006 {
5007 "name": test_username,
5008 "quotas": {
5009 "vnfds": 2,
5010 "nsds": 2,
5011 "nsts": 1,
5012 "pdus": 1,
5013 "nsrs": 2,
5014 "nsis": 1,
5015 "vim_accounts": 1,
5016 "wim_accounts": 1,
5017 "sdns": 1,
5018 },
5019 },
5020 (201),
5021 r_header_json,
5022 "json",
5023 )
delacruzramo16db9492019-09-25 12:01:59 +02005024 test_project_id = engine.last_id if res else None
garciadeblas4568a372021-03-24 09:19:48 +01005025 res = engine.test(
5026 "Create test user",
5027 "POST",
5028 "/admin/v1/users",
5029 headers_json,
5030 {
5031 "username": test_username,
5032 "password": test_password,
5033 "project_role_mappings": [
5034 {"project": test_project, "role": "project_admin"}
5035 ],
5036 },
5037 (201),
5038 r_header_json,
5039 "json",
5040 )
delacruzramo16db9492019-09-25 12:01:59 +02005041 test_user_id = engine.last_id if res else None
5042
5043 if test_project_id and test_user_id:
5044
5045 # Get user access
5046 engine.token = None
5047 engine.user = test_username
5048 engine.password = test_password
5049 engine.project = test_project
5050 engine.get_autorization()
5051 user_token = engine.last_id
5052
5053 # Create test VIM
garciadeblas4568a372021-03-24 09:19:48 +01005054 res = engine.test(
5055 "Create test VIM",
5056 "POST",
5057 "/admin/v1/vim_accounts",
5058 headers_json,
5059 {
5060 "name": test_vim,
5061 "vim_type": "openvim",
5062 "vim_user": test_username,
5063 "vim_password": test_password,
5064 "vim_tenant_name": test_project,
5065 "vim_url": "https://0.0.0.0:0/v0.0",
5066 },
5067 (202),
5068 r_header_json,
5069 "json",
5070 )
delacruzramo16db9492019-09-25 12:01:59 +02005071 test_vim_ids += [engine.last_id if res else None]
5072
garciadeblas4568a372021-03-24 09:19:48 +01005073 res = engine.test(
5074 "Try to create second test VIM",
5075 "POST",
5076 "/admin/v1/vim_accounts",
5077 headers_json,
5078 {
5079 "name": test_vim + "_2",
5080 "vim_type": "openvim",
5081 "vim_user": test_username,
5082 "vim_password": test_password,
5083 "vim_tenant_name": test_project,
5084 "vim_url": "https://0.0.0.0:0/v0.0",
5085 },
5086 (422),
5087 r_header_json,
5088 "json",
5089 )
delacruzramo16db9492019-09-25 12:01:59 +02005090 test_vim_ids += [engine.last_id if res is None else None]
5091
garciadeblas4568a372021-03-24 09:19:48 +01005092 res = engine.test(
5093 "Try to create second test VIM with FORCE",
5094 "POST",
5095 "/admin/v1/vim_accounts?FORCE",
5096 headers_json,
5097 {
5098 "name": test_vim + "_3",
5099 "vim_type": "openvim",
5100 "vim_user": test_username,
5101 "vim_password": test_password,
5102 "vim_tenant_name": test_project,
5103 "vim_url": "https://0.0.0.0:0/v0.0",
5104 },
5105 (202),
5106 r_header_json,
5107 "json",
5108 )
delacruzramo16db9492019-09-25 12:01:59 +02005109 test_vim_ids += [engine.last_id if res else None]
5110
5111 if test_vim_ids[0]:
5112
5113 # Download descriptor files (if required)
garciadeblas4568a372021-03-24 09:19:48 +01005114 test_dir = "/tmp/" + test_username + "/"
delacruzramo16db9492019-09-25 12:01:59 +02005115 test_url = "https://osm-download.etsi.org/ftp/osm-6.0-six/7th-hackfest/packages/"
garciadeblas4568a372021-03-24 09:19:48 +01005116 vnfd_filenames = [
5117 "slice_hackfest_vnfd.tar.gz",
5118 "slice_hackfest_middle_vnfd.tar.gz",
5119 ]
5120 nsd_filenames = [
5121 "slice_hackfest_nsd.tar.gz",
5122 "slice_hackfest_middle_nsd.tar.gz",
5123 ]
delacruzramo16db9492019-09-25 12:01:59 +02005124 nst_filenames = ["slice_hackfest_nstd.yaml"]
5125 pdu_filenames = ["PDU_router.yaml"]
garciadeblas4568a372021-03-24 09:19:48 +01005126 desc_filenames = (
5127 vnfd_filenames + nsd_filenames + nst_filenames + pdu_filenames
5128 )
delacruzramo16db9492019-09-25 12:01:59 +02005129 if not os.path.exists(test_dir):
5130 os.makedirs(test_dir)
5131 for filename in desc_filenames:
garciadeblas4568a372021-03-24 09:19:48 +01005132 if not os.path.exists(test_dir + filename):
5133 res = requests.get(test_url + filename)
delacruzramo16db9492019-09-25 12:01:59 +02005134 if res.status_code < 300:
garciadeblas4568a372021-03-24 09:19:48 +01005135 with open(test_dir + filename, "wb") as file:
delacruzramo16db9492019-09-25 12:01:59 +02005136 file.write(res.content)
5137
garciadeblas4568a372021-03-24 09:19:48 +01005138 if all([os.path.exists(test_dir + p) for p in desc_filenames]):
delacruzramo16db9492019-09-25 12:01:59 +02005139
5140 # Test VNFD Quotas
garciadeblas4568a372021-03-24 09:19:48 +01005141 res = engine.test(
5142 "Create test VNFD #1",
5143 "POST",
5144 "/vnfpkgm/v1/vnf_packages_content",
5145 headers_zip_json,
5146 "@b" + test_dir + vnfd_filenames[0],
5147 (201),
5148 r_header_json,
5149 "json",
5150 )
delacruzramo16db9492019-09-25 12:01:59 +02005151 test_vnfd_ids += [engine.last_id if res else None]
garciadeblas4568a372021-03-24 09:19:48 +01005152 res = engine.test(
5153 "Create test VNFD #2",
5154 "POST",
5155 "/vnfpkgm/v1/vnf_packages_content",
5156 headers_zip_json,
5157 "@b" + test_dir + vnfd_filenames[1],
5158 (201),
5159 r_header_json,
5160 "json",
5161 )
delacruzramo16db9492019-09-25 12:01:59 +02005162 test_vnfd_ids += [engine.last_id if res else None]
garciadeblas4568a372021-03-24 09:19:48 +01005163 res = engine.test(
5164 "Try to create extra test VNFD",
5165 "POST",
5166 "/vnfpkgm/v1/vnf_packages_content",
5167 headers_zip_json,
5168 "@b" + test_dir + vnfd_filenames[0],
5169 (422),
5170 r_header_json,
5171 "json",
5172 )
delacruzramo16db9492019-09-25 12:01:59 +02005173 test_vnfd_ids += [engine.last_id if res is None else None]
garciadeblas4568a372021-03-24 09:19:48 +01005174 res = engine.test(
5175 "Try to create extra test VNFD with FORCE",
5176 "POST",
5177 "/vnfpkgm/v1/vnf_packages_content?FORCE",
5178 headers_zip_json,
5179 "@b" + test_dir + vnfd_filenames[0],
5180 (201),
5181 r_header_json,
5182 "json",
5183 )
delacruzramo16db9492019-09-25 12:01:59 +02005184 test_vnfd_ids += [engine.last_id if res else None]
5185
5186 # Remove extra VNFDs to prevent further errors
5187 for i in [2, 3]:
5188 if test_vnfd_ids[i]:
garciadeblas4568a372021-03-24 09:19:48 +01005189 res = engine.test(
5190 "Delete test VNFD #" + str(i),
5191 "DELETE",
5192 "/vnfpkgm/v1/vnf_packages_content/"
5193 + test_vnfd_ids[i]
5194 + "?FORCE",
5195 headers_json,
5196 {},
5197 (204),
5198 {},
5199 0,
5200 )
delacruzramo16db9492019-09-25 12:01:59 +02005201 if res:
5202 test_vnfd_ids[i] = None
5203
5204 if test_vnfd_ids[0] and test_vnfd_ids[1]:
5205
5206 # Test NSD Quotas
garciadeblas4568a372021-03-24 09:19:48 +01005207 res = engine.test(
5208 "Create test NSD #1",
5209 "POST",
5210 "/nsd/v1/ns_descriptors_content",
5211 headers_zip_json,
5212 "@b" + test_dir + nsd_filenames[0],
5213 (201),
5214 r_header_json,
5215 "json",
5216 )
delacruzramo16db9492019-09-25 12:01:59 +02005217 test_nsd_ids += [engine.last_id if res else None]
garciadeblas4568a372021-03-24 09:19:48 +01005218 res = engine.test(
5219 "Create test NSD #2",
5220 "POST",
5221 "/nsd/v1/ns_descriptors_content",
5222 headers_zip_json,
5223 "@b" + test_dir + nsd_filenames[1],
5224 (201),
5225 r_header_json,
5226 "json",
5227 )
delacruzramo16db9492019-09-25 12:01:59 +02005228 test_nsd_ids += [engine.last_id if res else None]
garciadeblas4568a372021-03-24 09:19:48 +01005229 res = engine.test(
5230 "Try to create extra test NSD",
5231 "POST",
5232 "/nsd/v1/ns_descriptors_content",
5233 headers_zip_json,
5234 "@b" + test_dir + nsd_filenames[0],
5235 (422),
5236 r_header_json,
5237 "json",
5238 )
delacruzramo16db9492019-09-25 12:01:59 +02005239 test_nsd_ids += [engine.last_id if res is None else None]
garciadeblas4568a372021-03-24 09:19:48 +01005240 res = engine.test(
5241 "Try to create extra test NSD with FORCE",
5242 "POST",
5243 "/nsd/v1/ns_descriptors_content?FORCE",
5244 headers_zip_json,
5245 "@b" + test_dir + nsd_filenames[0],
5246 (201),
5247 r_header_json,
5248 "json",
5249 )
delacruzramo16db9492019-09-25 12:01:59 +02005250 test_nsd_ids += [engine.last_id if res else None]
5251
5252 # Remove extra NSDs to prevent further errors
5253 for i in [2, 3]:
5254 if test_nsd_ids[i]:
garciadeblas4568a372021-03-24 09:19:48 +01005255 res = engine.test(
5256 "Delete test NSD #" + str(i),
5257 "DELETE",
5258 "/nsd/v1/ns_descriptors_content/"
5259 + test_nsd_ids[i]
5260 + "?FORCE",
5261 headers_json,
5262 {},
5263 (204),
5264 {},
5265 0,
5266 )
delacruzramo16db9492019-09-25 12:01:59 +02005267 if res:
5268 test_nsd_ids[i] = None
5269
5270 if test_nsd_ids[0] and test_nsd_ids[1]:
5271
5272 # Test NSR Quotas
garciadeblas4568a372021-03-24 09:19:48 +01005273 res = engine.test(
5274 "Create test NSR #1",
5275 "POST",
5276 "/nslcm/v1/ns_instances_content",
5277 headers_json,
5278 {
5279 "nsName": test_username + "_1",
5280 "nsdId": test_nsd_ids[0],
5281 "vimAccountId": test_vim_ids[0],
5282 },
5283 (201),
5284 r_header_json,
5285 "json",
5286 )
delacruzramo16db9492019-09-25 12:01:59 +02005287 test_nsr_ids += [engine.last_id if res else None]
garciadeblas4568a372021-03-24 09:19:48 +01005288 res = engine.test(
5289 "Create test NSR #2",
5290 "POST",
5291 "/nslcm/v1/ns_instances_content",
5292 headers_json,
5293 {
5294 "nsName": test_username + "_2",
5295 "nsdId": test_nsd_ids[1],
5296 "vimAccountId": test_vim_ids[0],
5297 },
5298 (201),
5299 r_header_json,
5300 "json",
5301 )
delacruzramo16db9492019-09-25 12:01:59 +02005302 test_nsr_ids += [engine.last_id if res else None]
garciadeblas4568a372021-03-24 09:19:48 +01005303 res = engine.test(
5304 "Try to create extra test NSR",
5305 "POST",
5306 "/nslcm/v1/ns_instances_content",
5307 headers_json,
5308 {
5309 "nsName": test_username + "_3",
5310 "nsdId": test_nsd_ids[0],
5311 "vimAccountId": test_vim_ids[0],
5312 },
5313 (422),
5314 r_header_json,
5315 "json",
5316 )
delacruzramo16db9492019-09-25 12:01:59 +02005317 test_nsr_ids += [engine.last_id if res is None else None]
garciadeblas4568a372021-03-24 09:19:48 +01005318 res = engine.test(
5319 "Try to create test NSR with FORCE",
5320 "POST",
5321 "/nslcm/v1/ns_instances_content?FORCE",
5322 headers_json,
5323 {
5324 "nsName": test_username + "_4",
5325 "nsdId": test_nsd_ids[0],
5326 "vimAccountId": test_vim_ids[0],
5327 },
5328 (201),
5329 r_header_json,
5330 "json",
5331 )
delacruzramo16db9492019-09-25 12:01:59 +02005332 test_nsr_ids += [engine.last_id if res else None]
5333
5334 # Test NST Quotas
garciadeblas4568a372021-03-24 09:19:48 +01005335 res = engine.test(
5336 "Create test NST",
5337 "POST",
5338 "/nst/v1/netslice_templates_content",
5339 headers_txt_json,
5340 "@b" + test_dir + nst_filenames[0],
5341 (201),
5342 r_header_json,
5343 "json",
5344 )
delacruzramo16db9492019-09-25 12:01:59 +02005345 test_nst_ids += [engine.last_id if res else None]
garciadeblas4568a372021-03-24 09:19:48 +01005346 res = engine.test(
5347 "Try to create extra test NST",
5348 "POST",
5349 "/nst/v1/netslice_templates_content",
5350 headers_txt_json,
5351 "@b" + test_dir + nst_filenames[0],
5352 (422),
5353 r_header_json,
5354 "json",
5355 )
delacruzramo16db9492019-09-25 12:01:59 +02005356 test_nst_ids += [engine.last_id if res is None else None]
garciadeblas4568a372021-03-24 09:19:48 +01005357 res = engine.test(
5358 "Try to create extra test NST with FORCE",
5359 "POST",
5360 "/nst/v1/netslice_templates_content?FORCE",
5361 headers_txt_json,
5362 "@b" + test_dir + nst_filenames[0],
5363 (201),
5364 r_header_json,
5365 "json",
5366 )
delacruzramo16db9492019-09-25 12:01:59 +02005367 test_nst_ids += [engine.last_id if res else None]
5368
5369 if test_nst_ids[0]:
5370 # Remove NSR Quota
garciadeblas4568a372021-03-24 09:19:48 +01005371 engine.set_header(
5372 {"Authorization": "Bearer {}".format(admin_token)}
5373 )
5374 res = engine.test(
5375 "Remove NSR Quota",
5376 "PUT",
5377 "/admin/v1/projects/" + test_project_id,
5378 headers_json,
5379 {"quotas": {"nsrs": None}},
5380 (204),
5381 {},
5382 0,
5383 )
5384 engine.set_header(
5385 {"Authorization": "Bearer {}".format(user_token)}
5386 )
delacruzramo16db9492019-09-25 12:01:59 +02005387 if res:
5388 # Test NSI Quotas
garciadeblas4568a372021-03-24 09:19:48 +01005389 res = engine.test(
5390 "Create test NSI",
5391 "POST",
5392 "/nsilcm/v1/netslice_instances_content",
5393 headers_json,
5394 {
5395 "nsiName": test_username,
5396 "nstId": test_nst_ids[0],
5397 "vimAccountId": test_vim_ids[0],
5398 },
5399 (201),
5400 r_header_json,
5401 "json",
5402 )
delacruzramo16db9492019-09-25 12:01:59 +02005403 test_nsi_ids += [engine.last_id if res else None]
garciadeblas4568a372021-03-24 09:19:48 +01005404 res = engine.test(
5405 "Try to create extra test NSI",
5406 "POST",
5407 "/nsilcm/v1/netslice_instances_content",
5408 headers_json,
5409 {
5410 "nsiName": test_username,
5411 "nstId": test_nst_ids[0],
5412 "vimAccountId": test_vim_ids[0],
5413 },
5414 (400),
5415 r_header_json,
5416 "json",
5417 )
5418 test_nsi_ids += [
5419 engine.last_id if res is None else None
5420 ]
5421 res = engine.test(
5422 "Try to create extra test NSI with FORCE",
5423 "POST",
5424 "/nsilcm/v1/netslice_instances_content?FORCE",
5425 headers_json,
5426 {
5427 "nsiName": test_username,
5428 "nstId": test_nst_ids[0],
5429 "vimAccountId": test_vim_ids[0],
5430 },
5431 (201),
5432 r_header_json,
5433 "json",
5434 )
delacruzramo16db9492019-09-25 12:01:59 +02005435 test_nsi_ids += [engine.last_id if res else None]
5436
5437 # Test PDU Quotas
garciadeblas4568a372021-03-24 09:19:48 +01005438 with open(test_dir + pdu_filenames[0], "rb") as file:
5439 pdu_text = re.sub(
5440 r"ip-address: *\[[^\]]*\]",
5441 "ip-address: '0.0.0.0'",
5442 file.read().decode("utf-8"),
5443 )
5444 with open(test_dir + pdu_filenames[0], "wb") as file:
delacruzramo16db9492019-09-25 12:01:59 +02005445 file.write(pdu_text.encode("utf-8"))
garciadeblas4568a372021-03-24 09:19:48 +01005446 res = engine.test(
5447 "Create test PDU",
5448 "POST",
5449 "/pdu/v1/pdu_descriptors",
5450 headers_yaml,
5451 "@b" + test_dir + pdu_filenames[0],
5452 (201),
5453 r_header_yaml,
5454 "yaml",
5455 )
delacruzramo16db9492019-09-25 12:01:59 +02005456 test_pdu_ids += [engine.last_id if res else None]
garciadeblas4568a372021-03-24 09:19:48 +01005457 res = engine.test(
5458 "Try to create extra test PDU",
5459 "POST",
5460 "/pdu/v1/pdu_descriptors",
5461 headers_yaml,
5462 "@b" + test_dir + pdu_filenames[0],
5463 (422),
5464 r_header_yaml,
5465 "yaml",
5466 )
delacruzramo16db9492019-09-25 12:01:59 +02005467 test_pdu_ids += [engine.last_id if res is None else None]
garciadeblas4568a372021-03-24 09:19:48 +01005468 res = engine.test(
5469 "Try to create extra test PDU with FORCE",
5470 "POST",
5471 "/pdu/v1/pdu_descriptors?FORCE",
5472 headers_yaml,
5473 "@b" + test_dir + pdu_filenames[0],
5474 (201),
5475 r_header_yaml,
5476 "yaml",
5477 )
delacruzramo16db9492019-09-25 12:01:59 +02005478 test_pdu_ids += [engine.last_id if res else None]
5479
5480 # Cleanup
5481 for i, id in enumerate(test_nsi_ids):
5482 if id:
garciadeblas4568a372021-03-24 09:19:48 +01005483 engine.test(
5484 "Delete test NSI #" + str(i),
5485 "DELETE",
5486 "/nsilcm/v1/netslice_instances_content/"
5487 + id
5488 + "?FORCE",
5489 headers_json,
5490 {},
5491 (204),
5492 {},
5493 0,
5494 )
delacruzramo16db9492019-09-25 12:01:59 +02005495 for i, id in enumerate(test_nsr_ids):
5496 if id:
garciadeblas4568a372021-03-24 09:19:48 +01005497 engine.test(
5498 "Delete test NSR #" + str(i),
5499 "DELETE",
5500 "/nslcm/v1/ns_instances_content/" + id + "?FORCE",
5501 headers_json,
5502 {},
5503 (204),
5504 {},
5505 0,
5506 )
delacruzramo16db9492019-09-25 12:01:59 +02005507 for i, id in enumerate(test_nst_ids):
5508 if id:
garciadeblas4568a372021-03-24 09:19:48 +01005509 engine.test(
5510 "Delete test NST #" + str(i),
5511 "DELETE",
5512 "/nst/v1/netslice_templates_content/" + id + "?FORCE",
5513 headers_json,
5514 {},
5515 (204),
5516 {},
5517 0,
5518 )
delacruzramo16db9492019-09-25 12:01:59 +02005519 for i, id in enumerate(test_nsd_ids):
5520 if id:
garciadeblas4568a372021-03-24 09:19:48 +01005521 engine.test(
5522 "Delete test NSD #" + str(i),
5523 "DELETE",
5524 "/nsd/v1/ns_descriptors_content/" + id + "?FORCE",
5525 headers_json,
5526 {},
5527 (204),
5528 {},
5529 0,
5530 )
delacruzramo16db9492019-09-25 12:01:59 +02005531 for i, id in enumerate(test_vnfd_ids):
5532 if id:
garciadeblas4568a372021-03-24 09:19:48 +01005533 engine.test(
5534 "Delete test VNFD #" + str(i),
5535 "DELETE",
5536 "/vnfpkgm/v1/vnf_packages_content/" + id + "?FORCE",
5537 headers_json,
5538 {},
5539 (204),
5540 {},
5541 0,
5542 )
delacruzramo16db9492019-09-25 12:01:59 +02005543 for i, id in enumerate(test_pdu_ids):
5544 if id:
garciadeblas4568a372021-03-24 09:19:48 +01005545 engine.test(
5546 "Delete test PDU #" + str(i),
5547 "DELETE",
5548 "/pdu/v1/pdu_descriptors/" + id + "?FORCE",
5549 headers_json,
5550 {},
5551 (204),
5552 {},
5553 0,
5554 )
delacruzramo16db9492019-09-25 12:01:59 +02005555
5556 # END Test NBI Quotas
5557
5558 # Test WIM Quotas
garciadeblas4568a372021-03-24 09:19:48 +01005559 res = engine.test(
5560 "Create test WIM",
5561 "POST",
5562 "/admin/v1/wim_accounts",
5563 headers_json,
5564 {
5565 "name": test_wim,
5566 "wim_type": "onos",
5567 "wim_url": "https://0.0.0.0:0/v0.0",
5568 },
5569 (202),
5570 r_header_json,
5571 "json",
5572 )
delacruzramo16db9492019-09-25 12:01:59 +02005573 test_wim_ids += [engine.last_id if res else None]
garciadeblas4568a372021-03-24 09:19:48 +01005574 res = engine.test(
5575 "Try to create second test WIM",
5576 "POST",
5577 "/admin/v1/wim_accounts",
5578 headers_json,
5579 {
5580 "name": test_wim + "_2",
5581 "wim_type": "onos",
5582 "wim_url": "https://0.0.0.0:0/v0.0",
5583 },
5584 (422),
5585 r_header_json,
5586 "json",
5587 )
delacruzramo16db9492019-09-25 12:01:59 +02005588 test_wim_ids += [engine.last_id if res is None else None]
garciadeblas4568a372021-03-24 09:19:48 +01005589 res = engine.test(
5590 "Try to create second test WIM with FORCE",
5591 "POST",
5592 "/admin/v1/wim_accounts?FORCE",
5593 headers_json,
5594 {
5595 "name": test_wim + "_3",
5596 "wim_type": "onos",
5597 "wim_url": "https://0.0.0.0:0/v0.0",
5598 },
5599 (202),
5600 r_header_json,
5601 "json",
5602 )
delacruzramo16db9492019-09-25 12:01:59 +02005603 test_wim_ids += [engine.last_id if res else None]
5604
5605 # Test SDN Quotas
garciadeblas4568a372021-03-24 09:19:48 +01005606 res = engine.test(
5607 "Create test SDN",
5608 "POST",
5609 "/admin/v1/sdns",
5610 headers_json,
5611 {
5612 "name": test_sdn,
5613 "type": "onos",
5614 "ip": "0.0.0.0",
5615 "port": 9999,
5616 "dpid": "00:00:00:00:00:00:00:00",
5617 },
5618 (202),
5619 r_header_json,
5620 "json",
5621 )
delacruzramo16db9492019-09-25 12:01:59 +02005622 test_sdn_ids += [engine.last_id if res else None]
garciadeblas4568a372021-03-24 09:19:48 +01005623 res = engine.test(
5624 "Try to create second test SDN",
5625 "POST",
5626 "/admin/v1/sdns",
5627 headers_json,
5628 {
5629 "name": test_sdn + "_2",
5630 "type": "onos",
5631 "ip": "0.0.0.0",
5632 "port": 9999,
5633 "dpid": "00:00:00:00:00:00:00:00",
5634 },
5635 (422),
5636 r_header_json,
5637 "json",
5638 )
delacruzramo16db9492019-09-25 12:01:59 +02005639 test_sdn_ids += [engine.last_id if res is None else None]
garciadeblas4568a372021-03-24 09:19:48 +01005640 res = engine.test(
5641 "Try to create second test SDN with FORCE",
5642 "POST",
5643 "/admin/v1/sdns?FORCE",
5644 headers_json,
5645 {
5646 "name": test_sdn + "_3",
5647 "type": "onos",
5648 "ip": "0.0.0.0",
5649 "port": 9999,
5650 "dpid": "00:00:00:00:00:00:00:00",
5651 },
5652 (202),
5653 r_header_json,
5654 "json",
5655 )
delacruzramo16db9492019-09-25 12:01:59 +02005656 test_sdn_ids += [engine.last_id if res else None]
5657
5658 # Cleanup
5659 for i, id in enumerate(test_vim_ids):
5660 if id:
garciadeblas4568a372021-03-24 09:19:48 +01005661 engine.test(
5662 "Delete test VIM #" + str(i),
5663 "DELETE",
5664 "/admin/v1/vim_accounts/" + id + "?FORCE",
5665 headers_json,
5666 {},
5667 (202),
5668 {},
5669 0,
5670 )
delacruzramo16db9492019-09-25 12:01:59 +02005671 for i, id in enumerate(test_wim_ids):
5672 if id:
garciadeblas4568a372021-03-24 09:19:48 +01005673 engine.test(
5674 "Delete test WIM #" + str(i),
5675 "DELETE",
5676 "/admin/v1/wim_accounts/" + id + "?FORCE",
5677 headers_json,
5678 {},
5679 (202),
5680 {},
5681 0,
5682 )
delacruzramo16db9492019-09-25 12:01:59 +02005683 for i, id in enumerate(test_sdn_ids):
5684 if id:
garciadeblas4568a372021-03-24 09:19:48 +01005685 engine.test(
5686 "Delete test SDN #" + str(i),
5687 "DELETE",
5688 "/admin/v1/sdns/" + id + "?FORCE",
5689 headers_json,
5690 {},
5691 (202),
5692 {},
5693 0,
5694 )
delacruzramo16db9492019-09-25 12:01:59 +02005695
5696 # Release user access
5697 engine.remove_authorization()
5698
5699 # Cleanup
5700 engine.user = admin_username
5701 engine.password = admin_password
5702 engine.project = admin_project
5703 engine.get_autorization()
5704 if test_user_id:
garciadeblas4568a372021-03-24 09:19:48 +01005705 engine.test(
5706 "Delete test user",
5707 "DELETE",
5708 "/admin/v1/users/" + test_user_id + "?FORCE",
5709 headers_json,
5710 {},
5711 (204),
5712 {},
5713 0,
5714 )
delacruzramo16db9492019-09-25 12:01:59 +02005715 if test_project_id:
garciadeblas4568a372021-03-24 09:19:48 +01005716 engine.test(
5717 "Delete test project",
5718 "DELETE",
5719 "/admin/v1/projects/" + test_project_id + "?FORCE",
5720 headers_json,
5721 {},
5722 (204),
5723 {},
5724 0,
5725 )
delacruzramo16db9492019-09-25 12:01:59 +02005726 engine.remove_authorization()
5727
5728 # END class TestNbiQuotas
5729
5730
tiernof27c79b2018-03-12 17:08:42 +01005731if __name__ == "__main__":
5732 global logger
5733 test = ""
tierno0f98af52018-03-19 10:28:22 +01005734
5735 # Disable warnings from self-signed certificates.
5736 requests.packages.urllib3.disable_warnings()
tiernof27c79b2018-03-12 17:08:42 +01005737 try:
5738 logging.basicConfig(format="%(levelname)s %(message)s", level=logging.ERROR)
garciadeblas4568a372021-03-24 09:19:48 +01005739 logger = logging.getLogger("NBI")
tiernof27c79b2018-03-12 17:08:42 +01005740 # load parameters and configuration
garciadeblas4568a372021-03-24 09:19:48 +01005741 opts, args = getopt.getopt(
5742 sys.argv[1:],
5743 "hvu:p:",
5744 [
5745 "url=",
5746 "user=",
5747 "password=",
5748 "help",
5749 "version",
5750 "verbose",
5751 "no-verbose",
5752 "project=",
5753 "insecure",
5754 "timeout",
5755 "timeout-deploy",
5756 "timeout-configure",
5757 "test=",
5758 "list",
5759 "test-osm",
5760 "manual-check",
5761 "params=",
5762 "fail-fast",
5763 ],
5764 )
tiernof27c79b2018-03-12 17:08:42 +01005765 url = "https://localhost:9999/osm"
5766 user = password = project = "admin"
tiernoc32ba4a2018-05-24 18:06:41 +02005767 test_osm = False
5768 manual_check = False
tiernof27c79b2018-03-12 17:08:42 +01005769 verbose = 0
5770 verify = True
tiernoff6485d2018-11-28 17:19:46 +00005771 fail_fast = False
tiernoc32ba4a2018-05-24 18:06:41 +02005772 test_classes = {
5773 "NonAuthorized": TestNonAuthorized,
5774 "FakeVIM": TestFakeVim,
tierno65ca36d2019-02-12 19:27:52 +01005775 "Users-Projects": TestUsersProjects,
5776 "Projects-Descriptors": TestProjectsDescriptors,
tiernoc32ba4a2018-05-24 18:06:41 +02005777 "VIM-SDN": TestVIMSDN,
5778 "Deploy-Custom": TestDeploy,
5779 "Deploy-Hackfest-Cirros": TestDeployHackfestCirros,
tiernocc103432018-10-19 14:10:35 +02005780 "Deploy-Hackfest-Cirros-Scaling": TestDeployHackfestCirrosScaling,
tiernoc32ba4a2018-05-24 18:06:41 +02005781 "Deploy-Hackfest-3Charmed": TestDeployHackfest3Charmed,
tiernobee085c2018-12-12 17:03:04 +00005782 "Deploy-Hackfest-3Charmed2": TestDeployHackfest3Charmed2,
5783 "Deploy-Hackfest-3Charmed3": TestDeployHackfest3Charmed3,
tiernoc32ba4a2018-05-24 18:06:41 +02005784 "Deploy-Hackfest-4": TestDeployHackfest4,
5785 "Deploy-CirrosMacIp": TestDeployIpMac,
tierno65ca36d2019-02-12 19:27:52 +01005786 "Descriptors": TestDescriptors,
5787 "Deploy-Hackfest1": TestDeployHackfest1,
gcalvino337ec512018-07-30 10:30:13 +02005788 # "Deploy-MultiVIM": TestDeployMultiVIM,
tierno65ca36d2019-02-12 19:27:52 +01005789 "Deploy-SingleVdu": TestDeploySingleVdu,
5790 "Deploy-Hnfd": TestDeployHnfd,
Felipe Vicens09e65422019-01-22 15:06:46 +01005791 "Upload-Slice-Template": TestNetSliceTemplates,
5792 "Deploy-Slice-Instance": TestNetSliceInstances,
tierno65ca36d2019-02-12 19:27:52 +01005793 "Deploy-SimpleCharm": TestDeploySimpleCharm,
5794 "Deploy-SimpleCharm2": TestDeploySimpleCharm2,
delacruzramo9742f1d2019-06-05 13:06:47 +02005795 "Authentication": TestAuthentication,
delacruzramo16db9492019-09-25 12:01:59 +02005796 "NBI-Quotas": TestNbiQuotas,
tiernoc32ba4a2018-05-24 18:06:41 +02005797 }
5798 test_to_do = []
5799 test_params = {}
tiernof27c79b2018-03-12 17:08:42 +01005800
5801 for o, a in opts:
tiernoc32ba4a2018-05-24 18:06:41 +02005802 # print("parameter:", o, a)
tiernof27c79b2018-03-12 17:08:42 +01005803 if o == "--version":
garciadeblas4568a372021-03-24 09:19:48 +01005804 print("test version " + __version__ + " " + version_date)
tiernoc32ba4a2018-05-24 18:06:41 +02005805 exit()
5806 elif o == "--list":
tiernobee085c2018-12-12 17:03:04 +00005807 for test, test_class in sorted(test_classes.items()):
5808 print("{:32} {}".format(test + ":", test_class.description))
tiernoc32ba4a2018-05-24 18:06:41 +02005809 exit()
tiernof27c79b2018-03-12 17:08:42 +01005810 elif o in ("-v", "--verbose"):
5811 verbose += 1
tierno2236d202018-05-16 19:05:16 +02005812 elif o == "no-verbose":
tiernof27c79b2018-03-12 17:08:42 +01005813 verbose = -1
5814 elif o in ("-h", "--help"):
5815 usage()
5816 sys.exit()
tiernoc32ba4a2018-05-24 18:06:41 +02005817 elif o == "--test-osm":
5818 test_osm = True
5819 elif o == "--manual-check":
5820 manual_check = True
tierno2236d202018-05-16 19:05:16 +02005821 elif o == "--url":
tiernof27c79b2018-03-12 17:08:42 +01005822 url = a
5823 elif o in ("-u", "--user"):
5824 user = a
5825 elif o in ("-p", "--password"):
5826 password = a
tierno2236d202018-05-16 19:05:16 +02005827 elif o == "--project":
tiernof27c79b2018-03-12 17:08:42 +01005828 project = a
tiernoff6485d2018-11-28 17:19:46 +00005829 elif o == "--fail-fast":
5830 fail_fast = True
tiernoc32ba4a2018-05-24 18:06:41 +02005831 elif o == "--test":
tiernoc32ba4a2018-05-24 18:06:41 +02005832 for _test in a.split(","):
5833 if _test not in test_classes:
garciadeblas4568a372021-03-24 09:19:48 +01005834 print(
5835 "Invalid test name '{}'. Use option '--list' to show available tests".format(
5836 _test
5837 ),
5838 file=sys.stderr,
5839 )
tiernoc32ba4a2018-05-24 18:06:41 +02005840 exit(1)
5841 test_to_do.append(_test)
5842 elif o == "--params":
5843 param_key, _, param_value = a.partition("=")
5844 text_index = len(test_to_do)
5845 if text_index not in test_params:
5846 test_params[text_index] = {}
5847 test_params[text_index][param_key] = param_value
tierno2236d202018-05-16 19:05:16 +02005848 elif o == "--insecure":
tiernof27c79b2018-03-12 17:08:42 +01005849 verify = False
tiernoc32ba4a2018-05-24 18:06:41 +02005850 elif o == "--timeout":
5851 timeout = int(a)
5852 elif o == "--timeout-deploy":
5853 timeout_deploy = int(a)
5854 elif o == "--timeout-configure":
5855 timeout_configure = int(a)
tiernof27c79b2018-03-12 17:08:42 +01005856 else:
5857 assert False, "Unhandled option"
5858 if verbose == 0:
5859 logger.setLevel(logging.WARNING)
5860 elif verbose > 1:
5861 logger.setLevel(logging.DEBUG)
5862 else:
5863 logger.setLevel(logging.ERROR)
5864
tiernoc32ba4a2018-05-24 18:06:41 +02005865 test_rest = TestRest(url, user=user, password=password, project=project)
5866 # print("tests to do:", test_to_do)
5867 if test_to_do:
5868 text_index = 0
5869 for test in test_to_do:
tiernoff6485d2018-11-28 17:19:46 +00005870 if fail_fast and test_rest.failed_tests:
5871 break
tiernoc32ba4a2018-05-24 18:06:41 +02005872 text_index += 1
5873 test_class = test_classes[test]
garciadeblas4568a372021-03-24 09:19:48 +01005874 test_class().run(
5875 test_rest, test_osm, manual_check, test_params.get(text_index)
5876 )
tiernoc32ba4a2018-05-24 18:06:41 +02005877 else:
delacruzramoc061f562019-04-05 11:00:02 +02005878 for test, test_class in sorted(test_classes.items()):
tiernoff6485d2018-11-28 17:19:46 +00005879 if fail_fast and test_rest.failed_tests:
5880 break
tiernoc32ba4a2018-05-24 18:06:41 +02005881 test_class().run(test_rest, test_osm, manual_check, test_params.get(0))
tiernoff6485d2018-11-28 17:19:46 +00005882 test_rest.print_results()
5883 exit(1 if test_rest.failed_tests else 0)
tiernof27c79b2018-03-12 17:08:42 +01005884
tiernoc32ba4a2018-05-24 18:06:41 +02005885 except TestException as e:
5886 logger.error(test + "Test {} Exception: {}".format(test, str(e)))
5887 exit(1)
5888 except getopt.GetoptError as e:
5889 logger.error(e)
5890 print(e, file=sys.stderr)
5891 exit(1)
tiernof27c79b2018-03-12 17:08:42 +01005892 except Exception as e:
tiernoc32ba4a2018-05-24 18:06:41 +02005893 logger.critical(test + " Exception: " + str(e), exc_info=True)