+ engine.test("Delete NSTD", "DELETE", "/nst/v1/netslice_templates/{}".format(nst_id), headers_json, None,
+ 204, None, 0)
+
+ # NSDs DELETE
+ test_rest.test("Delete NSD middle", "DELETE", "/nsd/v1/ns_descriptors/{}".format(self.nsd_middle_id),
+ headers_json, None, 204, None, 0)
+
+ test_rest.test("Delete NSD edge", "DELETE", "/nsd/v1/ns_descriptors/{}".format(self.nsd_edge_id), headers_json,
+ None, 204, None, 0)
+
+ # VNFDs DELETE
+ test_rest.test("Delete VNFD edge", "DELETE", "/vnfpkgm/v1/vnf_packages/{}".format(self.vnfd_edge_id),
+ headers_yaml, None, 204, None, 0)
+
+ test_rest.test("Delete VNFD middle", "DELETE", "/vnfpkgm/v1/vnf_packages/{}".format(self.vnfd_middle_id),
+ headers_yaml, None, 204, None, 0)
+
+
+class TestNetSliceInstances:
+ '''
+ Test procedure:
+ 1. Populate databases with VNFD, NSD, NST with the following scenario
+ +-----------------management-----------------+
+ | | |
+ +--+---+ +----+----+ +---+--+
+ | | | | | |
+ | edge +---data1----+ middle +---data2-----+ edge |
+ | | | | | |
+ +------+ +---------+ +------+
+ shared-nss
+ 2. Create NSI-1
+ 3. Instantiate NSI-1
+ 4. Create NSI-2
+ 5. Instantiate NSI-2
+ Manual check - Are 2 slices instantiated correctly?
+ NSI-1 3 nss (2 nss-edges + 1 nss-middle)
+ NSI-2 2 nss (2 nss-edge sharing nss-middle)
+ 6. Terminate NSI-1
+ 7. Delete NSI-1
+ Manual check - Is slice NSI-1 deleted correctly?
+ NSI-2 with 2 nss-edge + 1 nss-middle (The one from NSI-1)
+ 8. Create NSI-3
+ 9. Instantiate NSI-3
+ Manual check - Is slice NSI-3 instantiated correctly?
+ NSI-3 reuse nss-middle. NSI-3 only create 2 nss-edge
+ 10. Delete NSI-2
+ 11. Terminate NSI-2
+ 12. Delete NSI-3
+ 13. Terminate NSI-3
+ Manual check - All cleaned correctly?
+ NSI-2 and NSI-3 were terminated and deleted
+ 14. Cleanup database
+ '''
+
+ description = "Upload a NST to OSM"
+
+ def __init__(self):
+ self.vim_id = None
+ self.vnfd_filename = ("@./slice_shared/vnfd/slice_shared_vnfd.yaml")
+ self.vnfd_filename_middle = ("@./slice_shared/vnfd/slice_shared_middle_vnfd.yaml")
+ self.nsd_filename = ("@./slice_shared/nsd/slice_shared_nsd.yaml")
+ self.nsd_filename_middle = ("@./slice_shared/nsd/slice_shared_middle_nsd.yaml")
+ self.nst_filenames = ("@./slice_shared/slice_shared_nstd.yaml")
+
+ def create_slice(self, engine, nsi_data, name):
+ ns_data_text = yaml.safe_dump(nsi_data, default_flow_style=True, width=256)
+ r = engine.test(name, "POST", "/nsilcm/v1/netslice_instances",
+ headers_yaml, ns_data_text, (201, 202),
+ {"Location": "nsilcm/v1/netslice_instances/", "Content-Type": "application/yaml"}, "yaml")
+ return r
+
+ def instantiate_slice(self, engine, nsi_data, nsi_id, name):
+ ns_data_text = yaml.safe_dump(nsi_data, default_flow_style=True, width=256)
+ engine.test(name, "POST",
+ "/nsilcm/v1/netslice_instances/{}/instantiate".format(nsi_id), headers_yaml, ns_data_text,
+ (201, 202), r_headers_yaml_location_nsilcmop, "yaml")
+
+ def terminate_slice(self, engine, nsi_id, name):
+ engine.test(name, "POST", "/nsilcm/v1/netslice_instances/{}/terminate".format(nsi_id),
+ headers_yaml, None, (201, 202), r_headers_yaml_location_nsilcmop, "yaml")
+
+ def delete_slice(self, engine, nsi_id, name):
+ engine.test(name, "DELETE", "/nsilcm/v1/netslice_instances/{}".format(nsi_id), headers_yaml, None,
+ 204, None, 0)
+
+ def run(self, engine, test_osm, manual_check, test_params=None):
+ # nst CREATE
+ engine.set_test_name("NSI")
+ engine.get_autorization()
+
+ # Onboard VNFDs
+ engine.test("Onboard edge VNFD", "POST", "/vnfpkgm/v1/vnf_packages_content", headers_yaml,
+ self.vnfd_filename, 201, r_headers_yaml_location_vnfd, "yaml")
+ self.vnfd_edge_id = engine.last_id
+
+ engine.test("Onboard middle VNFD", "POST", "/vnfpkgm/v1/vnf_packages_content", headers_yaml,
+ self.vnfd_filename_middle, 201, r_headers_yaml_location_vnfd, "yaml")
+ self.vnfd_middle_id = engine.last_id
+
+ # Onboard NSDs
+ engine.test("Onboard NSD edge", "POST", "/nsd/v1/ns_descriptors_content", headers_yaml,
+ self.nsd_filename, 201, r_headers_yaml_location_nsd, "yaml")
+ self.nsd_edge_id = engine.last_id
+
+ engine.test("Onboard NSD middle", "POST", "/nsd/v1/ns_descriptors_content", headers_yaml,
+ self.nsd_filename_middle, 201, r_headers_yaml_location_nsd, "yaml")
+ self.nsd_middle_id = engine.last_id
+
+ # Onboard NST
+ engine.test("Onboard NST", "POST", "/nst/v1/netslice_templates_content", headers_yaml, self.nst_filenames,
+ 201, r_headers_yaml_location_nst, "yaml")
+ nst_id = engine.last_id
+
+ self.vim_id = engine.get_create_vim(test_osm)
+
+ # CREATE NSI-1
+ ns_data = {'nsiName': 'Deploy-NSI-1', 'vimAccountId': self.vim_id, 'nstId': nst_id, 'nsiDescription': 'default'}
+ r = self.create_slice(engine, ns_data, "Create NSI-1 step 1")
+ if not r:
+ return
+ self.nsi_id1 = engine.last_id
+
+ # INSTANTIATE NSI-1
+ self.instantiate_slice(engine, ns_data, self.nsi_id1, "Instantiate NSI-1 step 2")
+ nsilcmop_id1 = engine.last_id
+
+ # Waiting for NSI-1
+ if test_osm:
+ engine.wait_operation_ready("nsi", nsilcmop_id1, timeout_deploy)
+
+ # CREATE NSI-2
+ ns_data = {'nsiName': 'Deploy-NSI-2', 'vimAccountId': self.vim_id, 'nstId': nst_id, 'nsiDescription': 'default'}
+ r = self.create_slice(engine, ns_data, "Create NSI-2 step 1")
+ if not r:
+ return
+ self.nsi_id2 = engine.last_id
+
+ # INSTANTIATE NSI-2
+ self.instantiate_slice(engine, ns_data, self.nsi_id2, "Instantiate NSI-2 step 2")
+ nsilcmop_id2 = engine.last_id
+
+ # Waiting for NSI-2
+ if test_osm:
+ engine.wait_operation_ready("nsi", nsilcmop_id2, timeout_deploy)
+
+ if manual_check:
+ input('NSI-1 AND NSI-2 has been deployed. Perform manual check and press enter to resume')
+
+ # TERMINATE NSI-1
+ if test_osm:
+ self.terminate_slice(engine, self.nsi_id1, "Terminate NSI-1")
+ nsilcmop1_id = engine.last_id
+
+ # Wait terminate NSI-1
+ engine.wait_operation_ready("nsi", nsilcmop1_id, timeout_deploy)
+
+ # DELETE NSI-1
+ self.delete_slice(engine, self.nsi_id1, "Delete NS")
+
+ if manual_check:
+ input('NSI-1 has been deleted. Perform manual check and press enter to resume')
+
+ # CREATE NSI-3
+ ns_data = {'nsiName': 'Deploy-NSI-3', 'vimAccountId': self.vim_id, 'nstId': nst_id, 'nsiDescription': 'default'}
+ r = self.create_slice(engine, ns_data, "Create NSI-3 step 1")
+
+ if not r:
+ return
+ self.nsi_id3 = engine.last_id
+
+ # INSTANTIATE NSI-3
+ self.instantiate_slice(engine, ns_data, self.nsi_id3, "Instantiate NSI-3 step 2")
+ nsilcmop_id3 = engine.last_id
+
+ # Wait Instantiate NSI-3
+ if test_osm:
+ engine.wait_operation_ready("nsi", nsilcmop_id3, timeout_deploy)
+
+ if manual_check:
+ input('NSI-3 has been deployed. Perform manual check and press enter to resume')
+
+ # TERMINATE NSI-2
+ if test_osm:
+ self.terminate_slice(engine, self.nsi_id2, "Terminate NSI-2")
+ nsilcmop2_id = engine.last_id
+
+ # Wait terminate NSI-2
+ engine.wait_operation_ready("nsi", nsilcmop2_id, timeout_deploy)
+
+ # DELETE NSI-2
+ self.delete_slice(engine, self.nsi_id2, "DELETE NSI-2")
+
+ # TERMINATE NSI-3
+ if test_osm:
+ self. terminate_slice(engine, self.nsi_id3, "Terminate NSI-3")
+ nsilcmop3_id = engine.last_id
+
+ # Wait terminate NSI-3
+ engine.wait_operation_ready("nsi", nsilcmop3_id, timeout_deploy)
+
+ # DELETE NSI-3
+ self.delete_slice(engine, self.nsi_id3, "DELETE NSI-3")
+
+ if manual_check:
+ input('NSI-2 and NSI-3 has been deleted. Perform manual check and press enter to resume')
+
+ # nstd DELETE
+ engine.test("Delete NSTD", "DELETE", "/nst/v1/netslice_templates/{}".format(nst_id), headers_json, None,
+ 204, None, 0)
+
+ # NSDs DELETE
+ test_rest.test("Delete NSD middle", "DELETE", "/nsd/v1/ns_descriptors/{}".format(self.nsd_middle_id),
+ headers_json, None, 204, None, 0)
+
+ test_rest.test("Delete NSD edge", "DELETE", "/nsd/v1/ns_descriptors/{}".format(self.nsd_edge_id), headers_json,
+ None, 204, None, 0)
+
+ # VNFDs DELETE
+ test_rest.test("Delete VNFD edge", "DELETE", "/vnfpkgm/v1/vnf_packages/{}".format(self.vnfd_edge_id),
+ headers_yaml, None, 204, None, 0)
+
+ test_rest.test("Delete VNFD middle", "DELETE", "/vnfpkgm/v1/vnf_packages/{}".format(self.vnfd_middle_id),
+ headers_yaml, None, 204, None, 0)
+
+
+class TestAuthentication:
+ description = "Test Authentication"
+
+ @staticmethod
+ def run(engine, test_osm, manual_check, test_params=None):
+ engine.set_test_name("Authentication")
+ # backend = test_params.get("backend") if test_params else None # UNUSED
+
+ admin_project_id = test_project_id = None
+ project_admin_role_id = project_user_role_id = None
+ test_user_id = empty_user_id = None
+ default_role_id = empty_role_id = token_role_id = None
+
+ engine.get_autorization()
+
+ # GET
+ engine.test("Get tokens", "GET", "/admin/v1/tokens", headers_json, {},
+ (200), {"Content-Type": "application/json"}, "json")
+ engine.test("Get projects", "GET", "/admin/v1/projects", headers_json, {},
+ (200), {"Content-Type": "application/json"}, "json")
+ engine.test("Get users", "GET", "/admin/v1/users", headers_json, {},
+ (200), {"Content-Type": "application/json"}, "json")
+ engine.test("Get roles", "GET", "/admin/v1/roles", headers_json, {},
+ (200), {"Content-Type": "application/json"}, "json")
+ res = engine.test("Get admin project", "GET", "/admin/v1/projects?name=admin", headers_json, {},
+ (200), {"Content-Type": "application/json"}, "json")
+ admin_project_id = res.json()[0]["_id"] if res else None
+ res = engine.test("Get project admin role", "GET", "/admin/v1/roles?name=project_admin", headers_json, {},
+ (200), {"Content-Type": "application/json"}, "json")
+ project_admin_role_id = res.json()[0]["_id"] if res else None
+ res = engine.test("Get project user role", "GET", "/admin/v1/roles?name=project_user", headers_json, {},
+ (200), {"Content-Type": "application/json"}, "json")
+ project_user_role_id = res.json()[0]["_id"] if res else None
+
+ # POST
+ res = engine.test("Create test project", "POST", "/admin/v1/projects", headers_json, {"name": "test"},
+ (201), {"Location": "/admin/v1/projects/", "Content-Type": "application/json"}, "json")
+ test_project_id = engine.last_id if res else None
+ res = engine.test("Create role without permissions", "POST", "/admin/v1/roles", headers_json, {"name": "empty"},
+ (201), {"Content-Type": "application/json"}, "json")
+ empty_role_id = engine.last_id if res else None
+ res = engine.test("Create role with default permissions", "POST", "/admin/v1/roles", headers_json,
+ {"name": "default", "permissions": {"default": True}},
+ (201), {"Location": "/admin/v1/roles/", "Content-Type": "application/json"}, "json")
+ default_role_id = engine.last_id if res else None
+ res = engine.test("Create role with token permissions", "POST", "/admin/v1/roles", headers_json,
+ {"name": "tokens", "permissions": {"tokens": True}}, # is default required ?
+ (201), {"Location": "/admin/v1/roles/", "Content-Type": "application/json"}, "json")
+ token_role_id = engine.last_id if res else None
+ pr = "project-role mappings"
+ res = engine.test("Create user without "+pr, "POST", "/admin/v1/users", headers_json,
+ {"username": "empty", "password": "empty"},
+ 201, {"Content-Type": "application/json"}, "json")
+ empty_user_id = engine.last_id if res else None
+ if admin_project_id and test_project_id and project_admin_role_id and project_user_role_id:
+ data = {"username": "test", "password": "test"}
+ data["project_role_mappings"] = [
+ {"project": test_project_id, "role": project_admin_role_id},
+ {"project": admin_project_id, "role": project_user_role_id}
+ ]
+ res = engine.test("Create user with "+pr, "POST", "/admin/v1/users", headers_json, data,
+ (201), {"Content-Type": "application/json"}, "json")
+ test_user_id = engine.last_id if res else None
+
+ # PUT
+ if test_user_id:
+ engine.test("Modify test user's password", "PUT", "/admin/v1/users/"+test_user_id, headers_json,
+ {"password": "password"},
+ (204), {}, 0)
+ if empty_user_id and admin_project_id and test_project_id and project_admin_role_id and project_user_role_id:
+ data = {"project_role_mappings": [
+ {"project": test_project_id, "role": project_admin_role_id},
+ {"project": admin_project_id, "role": project_user_role_id}
+ ]}
+ engine.test("Modify empty user's "+pr, "PUT", "/admin/v1/users/"+empty_user_id,
+ headers_json,
+ data,
+ (204), {}, 0)
+
+ # DELETE
+ if empty_user_id:
+ engine.test("Delete empty user", "DELETE", "/admin/v1/users/"+empty_user_id, headers_json, {},
+ (204), {}, 0)
+ if test_user_id:
+ engine.test("Delete test user", "DELETE", "/admin/v1/users/"+test_user_id, headers_json, {},
+ (204), {}, 0)
+ if empty_role_id:
+ engine.test("Delete empty role", "DELETE", "/admin/v1/roles/"+empty_role_id, headers_json, {},
+ (204), {}, 0)
+ if default_role_id:
+ engine.test("Delete default role", "DELETE", "/admin/v1/roles/"+default_role_id, headers_json, {},
+ (204), {}, 0)
+ if token_role_id:
+ engine.test("Delete token role", "DELETE", "/admin/v1/roles/"+token_role_id, headers_json, {},
+ (204), {}, 0)
+ if test_project_id:
+ engine.test("Delete test project", "DELETE", "/admin/v1/projects/"+test_project_id, headers_json, {},
+ (204), {}, 0)
+
+ # END Tests
+
+ engine.remove_authorization() # To finish
+
+
+class TestNbiQuotas():
+ description = "Test NBI Quotas"
+
+ @staticmethod
+ def run(engine, test_osm, manual_check, test_params=None):
+ engine.set_test_name("NBI-Quotas_")
+ # backend = test_params.get("backend") if test_params else None # UNUSED
+
+ test_username = "test-nbi-quotas"
+ test_password = "test-nbi-quotas"
+ test_project = "test-nbi-quotas"
+
+ test_vim = "test-nbi-quotas"
+ test_wim = "test-nbi-quotas"
+ test_sdn = "test-nbi-quotas"
+
+ test_user_id = None
+ test_project_id = None
+
+ test_vim_ids = []
+ test_wim_ids = []
+ test_sdn_ids = []
+ test_vnfd_ids = []
+ test_nsd_ids = []
+ test_nst_ids = []
+ test_pdu_ids = []
+ test_nsr_ids = []
+ test_nsi_ids = []
+
+ # Save admin access data
+ admin_username = engine.user
+ admin_password = engine.password
+ admin_project = engine.project
+
+ # Get admin access
+ engine.get_autorization()
+ admin_token = engine.last_id
+
+ # Check that test project,user do not exist
+ res1 = engine.test("Check that test project doesn't exist", "GET", "/admin/v1/projects/"+test_project,
+ headers_json, {}, (404), {}, True)
+ res2 = engine.test("Check that test user doesn't exist", "GET", "/admin/v1/users/"+test_username,
+ headers_json, {}, (404), {}, True)
+ if None in [res1, res2]:
+ engine.remove_authorization()
+ logger.error("Test project and/or user already exist")
+ return
+
+ # Create test project&user
+ res = engine.test("Create test project", "POST", "/admin/v1/projects", headers_json,
+ {"name": test_username,
+ "quotas": {
+ "vnfds": 2,
+ "nsds": 2,
+ "nsts": 1,
+ "pdus": 1,
+ "nsrs": 2,
+ "nsis": 1,
+ "vim_accounts": 1,
+ "wim_accounts": 1,
+ "sdns": 1,
+ }
+ },
+ (201), r_header_json, "json")
+ test_project_id = engine.last_id if res else None
+ res = engine.test("Create test user", "POST", "/admin/v1/users", headers_json,
+ {"username": test_username, "password": test_password,
+ "project_role_mappings": [{"project": test_project, "role": "project_admin"}]},
+ (201), r_header_json, "json")
+ test_user_id = engine.last_id if res else None
+
+ if test_project_id and test_user_id:
+
+ # Get user access
+ engine.token = None
+ engine.user = test_username
+ engine.password = test_password
+ engine.project = test_project
+ engine.get_autorization()
+ user_token = engine.last_id
+
+ # Create test VIM
+ res = engine.test("Create test VIM", "POST", "/admin/v1/vim_accounts", headers_json,
+ {"name": test_vim,
+ "vim_type": "openvim",
+ "vim_user": test_username,
+ "vim_password": test_password,
+ "vim_tenant_name": test_project,
+ "vim_url": "https://0.0.0.0:0/v0.0",
+ },
+ (202), r_header_json, "json")
+ test_vim_ids += [engine.last_id if res else None]
+
+ res = engine.test("Try to create second test VIM", "POST", "/admin/v1/vim_accounts", headers_json,
+ {"name": test_vim + "_2",
+ "vim_type": "openvim",
+ "vim_user": test_username,
+ "vim_password": test_password,
+ "vim_tenant_name": test_project,
+ "vim_url": "https://0.0.0.0:0/v0.0",
+ },
+ (422), r_header_json, "json")
+ test_vim_ids += [engine.last_id if res is None else None]
+
+ res = engine.test("Try to create second test VIM with FORCE",
+ "POST", "/admin/v1/vim_accounts?FORCE", headers_json,
+ {"name": test_vim + "_3",
+ "vim_type": "openvim",
+ "vim_user": test_username,
+ "vim_password": test_password,
+ "vim_tenant_name": test_project,
+ "vim_url": "https://0.0.0.0:0/v0.0",
+ },
+ (202), r_header_json, "json")
+ test_vim_ids += [engine.last_id if res else None]
+
+ if test_vim_ids[0]:
+
+ # Download descriptor files (if required)
+ test_dir = "/tmp/"+test_username+"/"
+ test_url = "https://osm-download.etsi.org/ftp/osm-6.0-six/7th-hackfest/packages/"
+ vnfd_filenames = ["slice_hackfest_vnfd.tar.gz", "slice_hackfest_middle_vnfd.tar.gz"]
+ nsd_filenames = ["slice_hackfest_nsd.tar.gz", "slice_hackfest_middle_nsd.tar.gz"]
+ nst_filenames = ["slice_hackfest_nstd.yaml"]
+ pdu_filenames = ["PDU_router.yaml"]
+ desc_filenames = vnfd_filenames + nsd_filenames + nst_filenames + pdu_filenames
+ if not os.path.exists(test_dir):
+ os.makedirs(test_dir)
+ for filename in desc_filenames:
+ if not os.path.exists(test_dir+filename):
+ res = requests.get(test_url+filename)
+ if res.status_code < 300:
+ with open(test_dir+filename, "wb") as file:
+ file.write(res.content)
+
+ if all([os.path.exists(test_dir+p) for p in desc_filenames]):
+
+ # Test VNFD Quotas
+ res = engine.test("Create test VNFD #1", "POST", "/vnfpkgm/v1/vnf_packages_content",
+ headers_zip_json, "@b"+test_dir+vnfd_filenames[0],
+ (201), r_header_json, "json")
+ test_vnfd_ids += [engine.last_id if res else None]
+ res = engine.test("Create test VNFD #2", "POST", "/vnfpkgm/v1/vnf_packages_content",
+ headers_zip_json, "@b"+test_dir+vnfd_filenames[1],
+ (201), r_header_json, "json")
+ test_vnfd_ids += [engine.last_id if res else None]
+ res = engine.test("Try to create extra test VNFD", "POST",
+ "/vnfpkgm/v1/vnf_packages_content",
+ headers_zip_json, "@b"+test_dir+vnfd_filenames[0],
+ (422), r_header_json, "json")
+ test_vnfd_ids += [engine.last_id if res is None else None]
+ res = engine.test("Try to create extra test VNFD with FORCE",
+ "POST", "/vnfpkgm/v1/vnf_packages_content?FORCE",
+ headers_zip_json, "@b"+test_dir+vnfd_filenames[0],
+ (201), r_header_json, "json")
+ test_vnfd_ids += [engine.last_id if res else None]
+
+ # Remove extra VNFDs to prevent further errors
+ for i in [2, 3]:
+ if test_vnfd_ids[i]:
+ res = engine.test("Delete test VNFD #" + str(i), "DELETE",
+ "/vnfpkgm/v1/vnf_packages_content/"+test_vnfd_ids[i]+"?FORCE",
+ headers_json, {}, (204), {}, 0)
+ if res:
+ test_vnfd_ids[i] = None
+
+ if test_vnfd_ids[0] and test_vnfd_ids[1]:
+
+ # Test NSD Quotas
+ res = engine.test("Create test NSD #1", "POST", "/nsd/v1/ns_descriptors_content",
+ headers_zip_json, "@b"+test_dir+nsd_filenames[0],
+ (201), r_header_json, "json")
+ test_nsd_ids += [engine.last_id if res else None]
+ res = engine.test("Create test NSD #2", "POST", "/nsd/v1/ns_descriptors_content",
+ headers_zip_json, "@b"+test_dir+nsd_filenames[1],
+ (201), r_header_json, "json")
+ test_nsd_ids += [engine.last_id if res else None]
+ res = engine.test("Try to create extra test NSD", "POST", "/nsd/v1/ns_descriptors_content",
+ headers_zip_json, "@b"+test_dir+nsd_filenames[0],
+ (422), r_header_json, "json")
+ test_nsd_ids += [engine.last_id if res is None else None]
+ res = engine.test("Try to create extra test NSD with FORCE",
+ "POST", "/nsd/v1/ns_descriptors_content?FORCE",
+ headers_zip_json, "@b"+test_dir+nsd_filenames[0],
+ (201), r_header_json, "json")
+ test_nsd_ids += [engine.last_id if res else None]
+
+ # Remove extra NSDs to prevent further errors
+ for i in [2, 3]:
+ if test_nsd_ids[i]:
+ res = engine.test("Delete test NSD #" + str(i), "DELETE",
+ "/nsd/v1/ns_descriptors_content/"+test_nsd_ids[i]+"?FORCE",
+ headers_json, {}, (204), {}, 0)
+ if res:
+ test_nsd_ids[i] = None
+
+ if test_nsd_ids[0] and test_nsd_ids[1]:
+
+ # Test NSR Quotas
+ res = engine.test("Create test NSR #1", "POST", "/nslcm/v1/ns_instances_content",
+ headers_json,
+ {"nsName": test_username+"_1",
+ "nsdId": test_nsd_ids[0],
+ "vimAccountId": test_vim_ids[0],
+ },
+ (201), r_header_json, "json")
+ test_nsr_ids += [engine.last_id if res else None]
+ res = engine.test("Create test NSR #2", "POST", "/nslcm/v1/ns_instances_content",
+ headers_json,
+ {"nsName": test_username+"_2",
+ "nsdId": test_nsd_ids[1],
+ "vimAccountId": test_vim_ids[0],
+ },
+ (201), r_header_json, "json")
+ test_nsr_ids += [engine.last_id if res else None]
+ res = engine.test("Try to create extra test NSR", "POST", "/nslcm/v1/ns_instances_content",
+ headers_json,
+ {"nsName": test_username+"_3",
+ "nsdId": test_nsd_ids[0],
+ "vimAccountId": test_vim_ids[0],
+ },
+ (422), r_header_json, "json")
+ test_nsr_ids += [engine.last_id if res is None else None]
+ res = engine.test("Try to create test NSR with FORCE", "POST",
+ "/nslcm/v1/ns_instances_content?FORCE", headers_json,
+ {"nsName": test_username+"_4",
+ "nsdId": test_nsd_ids[0],
+ "vimAccountId": test_vim_ids[0],
+ },
+ (201), r_header_json, "json")
+ test_nsr_ids += [engine.last_id if res else None]
+
+ # Test NST Quotas
+ res = engine.test("Create test NST", "POST", "/nst/v1/netslice_templates_content",
+ headers_txt_json, "@b"+test_dir+nst_filenames[0],
+ (201), r_header_json, "json")
+ test_nst_ids += [engine.last_id if res else None]
+ res = engine.test("Try to create extra test NST", "POST",
+ "/nst/v1/netslice_templates_content",
+ headers_txt_json, "@b"+test_dir+nst_filenames[0],
+ (422), r_header_json, "json")
+ test_nst_ids += [engine.last_id if res is None else None]
+ res = engine.test("Try to create extra test NST with FORCE", "POST",
+ "/nst/v1/netslice_templates_content?FORCE",
+ headers_txt_json, "@b"+test_dir+nst_filenames[0],
+ (201), r_header_json, "json")
+ test_nst_ids += [engine.last_id if res else None]
+
+ if test_nst_ids[0]:
+ # Remove NSR Quota
+ engine.set_header({"Authorization": "Bearer {}".format(admin_token)})
+ res = engine.test("Remove NSR Quota", "PUT", "/admin/v1/projects/"+test_project_id,
+ headers_json,
+ {"quotas": {"nsrs": None}},
+ (204), {}, 0)
+ engine.set_header({"Authorization": "Bearer {}".format(user_token)})
+ if res:
+ # Test NSI Quotas
+ res = engine.test("Create test NSI", "POST",
+ "/nsilcm/v1/netslice_instances_content", headers_json,
+ {"nsiName": test_username,
+ "nstId": test_nst_ids[0],
+ "vimAccountId": test_vim_ids[0],
+ },
+ (201), r_header_json, "json")
+ test_nsi_ids += [engine.last_id if res else None]
+ res = engine.test("Try to create extra test NSI", "POST",
+ "/nsilcm/v1/netslice_instances_content", headers_json,
+ {"nsiName": test_username,
+ "nstId": test_nst_ids[0],
+ "vimAccountId": test_vim_ids[0],
+ },
+ (400), r_header_json, "json")
+ test_nsi_ids += [engine.last_id if res is None else None]
+ res = engine.test("Try to create extra test NSI with FORCE", "POST",
+ "/nsilcm/v1/netslice_instances_content?FORCE", headers_json,
+ {"nsiName": test_username,
+ "nstId": test_nst_ids[0],
+ "vimAccountId": test_vim_ids[0],
+ },
+ (201), r_header_json, "json")
+ test_nsi_ids += [engine.last_id if res else None]
+
+ # Test PDU Quotas
+ with open(test_dir+pdu_filenames[0], "rb") as file:
+ pdu_text = re.sub(r"ip-address: *\[[^\]]*\]", "ip-address: '0.0.0.0'",
+ file.read().decode("utf-8"))
+ with open(test_dir+pdu_filenames[0], "wb") as file:
+ file.write(pdu_text.encode("utf-8"))
+ res = engine.test("Create test PDU", "POST", "/pdu/v1/pdu_descriptors",
+ headers_yaml, "@b"+test_dir+pdu_filenames[0],
+ (201), r_header_yaml, "yaml")
+ test_pdu_ids += [engine.last_id if res else None]
+ res = engine.test("Try to create extra test PDU", "POST", "/pdu/v1/pdu_descriptors",
+ headers_yaml, "@b"+test_dir+pdu_filenames[0],
+ (422), r_header_yaml, "yaml")
+ test_pdu_ids += [engine.last_id if res is None else None]
+ res = engine.test("Try to create extra test PDU with FORCE", "POST",
+ "/pdu/v1/pdu_descriptors?FORCE",
+ headers_yaml, "@b"+test_dir+pdu_filenames[0],
+ (201), r_header_yaml, "yaml")
+ test_pdu_ids += [engine.last_id if res else None]
+
+ # Cleanup
+ for i, id in enumerate(test_nsi_ids):
+ if id:
+ engine.test("Delete test NSI #"+str(i), "DELETE",
+ "/nsilcm/v1/netslice_instances_content/"+id+"?FORCE",
+ headers_json, {}, (204), {}, 0)
+ for i, id in enumerate(test_nsr_ids):
+ if id:
+ engine.test("Delete test NSR #"+str(i), "DELETE",
+ "/nslcm/v1/ns_instances_content/"+id+"?FORCE",
+ headers_json, {}, (204), {}, 0)
+ for i, id in enumerate(test_nst_ids):
+ if id:
+ engine.test("Delete test NST #"+str(i), "DELETE",
+ "/nst/v1/netslice_templates_content/"+id+"?FORCE",
+ headers_json, {}, (204), {}, 0)
+ for i, id in enumerate(test_nsd_ids):
+ if id:
+ engine.test("Delete test NSD #"+str(i), "DELETE",
+ "/nsd/v1/ns_descriptors_content/"+id+"?FORCE",
+ headers_json, {}, (204), {}, 0)
+ for i, id in enumerate(test_vnfd_ids):
+ if id:
+ engine.test("Delete test VNFD #"+str(i), "DELETE",
+ "/vnfpkgm/v1/vnf_packages_content/"+id+"?FORCE",
+ headers_json, {}, (204), {}, 0)
+ for i, id in enumerate(test_pdu_ids):
+ if id:
+ engine.test("Delete test PDU #"+str(i), "DELETE",
+ "/pdu/v1/pdu_descriptors/"+id+"?FORCE",
+ headers_json, {}, (204), {}, 0)
+
+ # END Test NBI Quotas
+
+ # Test WIM Quotas
+ res = engine.test("Create test WIM", "POST", "/admin/v1/wim_accounts", headers_json,
+ {"name": test_wim,
+ "wim_type": "onos",
+ "wim_url": "https://0.0.0.0:0/v0.0",
+ },
+ (202), r_header_json, "json")
+ test_wim_ids += [engine.last_id if res else None]
+ res = engine.test("Try to create second test WIM", "POST", "/admin/v1/wim_accounts", headers_json,
+ {"name": test_wim + "_2",
+ "wim_type": "onos",
+ "wim_url": "https://0.0.0.0:0/v0.0",
+ },
+ (422), r_header_json, "json")
+ test_wim_ids += [engine.last_id if res is None else None]
+ res = engine.test("Try to create second test WIM with FORCE", "POST", "/admin/v1/wim_accounts?FORCE",
+ headers_json,
+ {"name": test_wim + "_3",
+ "wim_type": "onos",
+ "wim_url": "https://0.0.0.0:0/v0.0",
+ },
+ (202), r_header_json, "json")
+ test_wim_ids += [engine.last_id if res else None]
+
+ # Test SDN Quotas
+ res = engine.test("Create test SDN", "POST", "/admin/v1/sdns", headers_json,
+ {"name": test_sdn,
+ "type": "onos",
+ "ip": "0.0.0.0",
+ "port": 9999,
+ "dpid": "00:00:00:00:00:00:00:00",
+ },
+ (202), r_header_json, "json")
+ test_sdn_ids += [engine.last_id if res else None]
+ res = engine.test("Try to create second test SDN", "POST", "/admin/v1/sdns", headers_json,
+ {"name": test_sdn + "_2",
+ "type": "onos",
+ "ip": "0.0.0.0",
+ "port": 9999,
+ "dpid": "00:00:00:00:00:00:00:00",
+ },
+ (422), r_header_json, "json")
+ test_sdn_ids += [engine.last_id if res is None else None]
+ res = engine.test("Try to create second test SDN with FORCE", "POST", "/admin/v1/sdns?FORCE", headers_json,
+ {"name": test_sdn + "_3",
+ "type": "onos",
+ "ip": "0.0.0.0",
+ "port": 9999,
+ "dpid": "00:00:00:00:00:00:00:00",
+ },
+ (202), r_header_json, "json")
+ test_sdn_ids += [engine.last_id if res else None]
+
+ # Cleanup
+ for i, id in enumerate(test_vim_ids):
+ if id:
+ engine.test("Delete test VIM #"+str(i), "DELETE", "/admin/v1/vim_accounts/"+id+"?FORCE",
+ headers_json, {}, (202), {}, 0)
+ for i, id in enumerate(test_wim_ids):
+ if id:
+ engine.test("Delete test WIM #"+str(i), "DELETE", "/admin/v1/wim_accounts/"+id+"?FORCE",
+ headers_json, {}, (202), {}, 0)
+ for i, id in enumerate(test_sdn_ids):
+ if id:
+ engine.test("Delete test SDN #"+str(i), "DELETE", "/admin/v1/sdns/"+id+"?FORCE",
+ headers_json, {}, (202), {}, 0)
+
+ # Release user access
+ engine.remove_authorization()
+
+ # Cleanup
+ engine.user = admin_username
+ engine.password = admin_password
+ engine.project = admin_project
+ engine.get_autorization()
+ if test_user_id:
+ engine.test("Delete test user", "DELETE", "/admin/v1/users/"+test_user_id+"?FORCE",
+ headers_json, {}, (204), {}, 0)
+ if test_project_id:
+ engine.test("Delete test project", "DELETE", "/admin/v1/projects/"+test_project_id+"?FORCE",
+ headers_json, {}, (204), {}, 0)
+ engine.remove_authorization()
+
+ # END class TestNbiQuotas