+ # BEGIN New Tests - Addressing Projects/Users by Name/ID
+ res = engine.test("Create new project P1", "POST", "/admin/v1/projects", headers_json, {"name": "P1"},
+ 201, {"Location": "/admin/v1/projects/", "Content-Type": "application/json"}, "json")
+ if res:
+ pid1 = res.json()["id"]
+ # print("# pid =", pid1)
+ res = engine.test("Create new project P2", "POST", "/admin/v1/projects", headers_json, {"name": "P2"},
+ 201, {"Location": "/admin/v1/projects/", "Content-Type": "application/json"}, "json")
+ if res:
+ pid2 = res.json()["id"]
+ # print("# pid =", pid2)
+ res = engine.test("Create new user U1", "POST", "/admin/v1/users", headers_json,
+ {"username": "U1", "projects": ["P1"], "password": "pw1"}, 201,
+ {"Location": "/admin/v1/users/", "Content-Type": "application/json"}, "json")
+ if res:
+ uid1 = res.json()["id"]
+ # print("# uid =", uid1)
+ res = engine.test("Create new user U2", "POST", "/admin/v1/users", headers_json,
+ {"username": "U2", "projects": ["P2"], "password": "pw2"}, 201,
+ {"Location": "/admin/v1/users/", "Content-Type": "application/json"}, "json")
+ if res:
+ uid2 = res.json()["id"]
+ # print("# uid =", uid2)
+ engine.test("Get Project P1 by Name", "GET", "/admin/v1/projects/P1", headers_json, None, 200, None, "json")
+ engine.test("Get Project P1 by ID", "GET", "/admin/v1/projects/"+pid1, headers_json, None, 200, None, "json")
+ engine.test("Get User U1 by Name", "GET", "/admin/v1/users/U1", headers_json, None, 200, None, "json")
+ engine.test("Get User U1 by ID", "GET", "/admin/v1/users/"+uid1, headers_json, None, 200, None, "json")
+ engine.test("Rename Project P1 by Name", "PUT", "/admin/v1/projects/P1", headers_json,
+ {"name": "P3"}, 204, None, None)
+ engine.test("Rename Project P2 by ID", "PUT", "/admin/v1/projects/"+pid2, headers_json,
+ {"name": "P4"}, 204, None, None)
+ engine.test("Rename User U1 by Name", "PUT", "/admin/v1/users/U1", headers_json,
+ {"username": "U3"}, 204, None, None)
+ engine.test("Rename User U2 by ID", "PUT", "/admin/v1/users/"+uid2, headers_json,
+ {"username": "U4"}, 204, None, None)
+ engine.test("Get Project P1 by new Name", "GET", "/admin/v1/projects/P3", headers_json, None, 200, None, "json")
+ engine.test("Get User U1 by new Name", "GET", "/admin/v1/users/U3", headers_json, None, 200, None, "json")
+ engine.test("Delete User U1 by Name", "DELETE", "/admin/v1/users/U3", headers_json, None, 204, None, None)
+ engine.test("Delete User U2 by ID", "DELETE", "/admin/v1/users/"+uid2, headers_json, None, 204, None, None)
+ engine.test("Delete Project P1 by Name", "DELETE", "/admin/v1/projects/P3", headers_json, None, 204, None,
+ None)
+ engine.test("Delete Project P2 by ID", "DELETE", "/admin/v1/projects/"+pid2, headers_json, None, 204, None,
+ None)
+ # END New Tests - Addressing Projects/Users by Name
+ engine.remove_authorization() # To finish
+
+
+class TestProjectsDescriptors:
+ description = "test descriptors visibility among projects"
+
+ @staticmethod
+ def run(engine, test_osm, manual_check, test_params=None):
+ vnfd_ids = []
+ engine.set_test_name("ProjectDescriptors")
+ engine.get_autorization()
+
+ project_admin_id = None
+ res = engine.test("Get my project Padmin", "GET", "/admin/v1/projects/{}".format(engine.project), headers_json,
+ None, 200, r_header_json, "json")
+ if res:
+ response = res.json()
+ project_admin_id = response["_id"]
+ engine.test("Create project Padmin", "POST", "/admin/v1/projects", headers_json,
+ {"name": "Padmin", "admin": True}, (201, 204),
+ {"Location": "/admin/v1/projects/", "Content-Type": "application/json"}, "json")
+ engine.test("Create project P2", "POST", "/admin/v1/projects", headers_json, {"name": "P2"},
+ (201, 204), {"Location": "/admin/v1/projects/", "Content-Type": "application/json"}, "json")
+ engine.test("Create project P3", "POST", "/admin/v1/projects", headers_json, {"name": "P3"},
+ (201, 204), {"Location": "/admin/v1/projects/", "Content-Type": "application/json"}, "json")
+
+ engine.test("Create user U1", "POST", "/admin/v1/users", headers_json,
+ {"username": "U1", "password": "pw1",
+ "project_role_mappings": [{"project": "Padmin", "role": "system_admin"},
+ {"project": "P2", "role": "project_admin"},
+ {"project": "P3", "role": "project_admin"}],
+ }, 201, {"Location": "/admin/v1/users/", "Content-Type": "application/json"}, "json")
+
+ engine.test("Onboard VNFD id1", "POST", "/vnfpkgm/v1/vnf_packages_content?id=id1", headers_yaml,
+ TestDescriptors.vnfd_empty, 201, r_headers_yaml_location_vnfd, "yaml")
+ vnfd_ids.append(engine.last_id)
+ engine.test("Onboard VNFD id2 PUBLIC", "POST", "/vnfpkgm/v1/vnf_packages_content?id=id2&PUBLIC=TRUE",
+ headers_yaml, TestDescriptors.vnfd_empty, 201, r_headers_yaml_location_vnfd, "yaml")
+ vnfd_ids.append(engine.last_id)
+ engine.test("Onboard VNFD id3", "POST", "/vnfpkgm/v1/vnf_packages_content?id=id3&PUBLIC=FALSE", headers_yaml,
+ TestDescriptors.vnfd_empty, 201, r_headers_yaml_location_vnfd, "yaml")
+ vnfd_ids.append(engine.last_id)
+
+ res = engine.test("Get VNFD descriptors", "GET", "/vnfpkgm/v1/vnf_packages?id=id1,id2,id3",
+ headers_json, None, 200, r_header_json, "json")
+ response = res.json()
+ if len(response) != 3:
+ logger.error("Only 3 vnfds should be present for project admin. {} listed".format(len(response)))
+ engine.failed_tests += 1
+
+ # Change to other project Padmin
+ res = engine.test("Change to user U1 project Padmin", "POST", "/admin/v1/tokens", headers_json,
+ {"username": "U1", "password": "pw1", "project_id": "Padmin"}, (200, 201),
+ r_header_json, "json")
+ if res:
+ response = res.json()
+ engine.set_header({"Authorization": "Bearer {}".format(response["id"])})
+
+ # list vnfds
+ res = engine.test("List VNFD descriptors for Padmin", "GET", "/vnfpkgm/v1/vnf_packages",
+ headers_json, None, 200, r_header_json, "json")
+ response = res.json()
+ if len(response) != 0:
+ logger.error("Only 0 vnfds should be present for project Padmin. {} listed".format(len(response)))
+ engine.failed_tests += 1
+
+ # list Public vnfds
+ res = engine.test("List VNFD public descriptors", "GET", "/vnfpkgm/v1/vnf_packages?PUBLIC=True",
+ headers_json, None, 200, r_header_json, "json")
+ response = res.json()
+ if len(response) != 1:
+ logger.error("Only 1 vnfds should be present for project Padmin. {} listed".format(len(response)))
+ engine.failed_tests += 1
+
+ # list vnfds belonging to project "admin"
+ res = engine.test("List VNFD of admin project", "GET",
+ "/vnfpkgm/v1/vnf_packages?ADMIN={}".format(project_admin_id),
+ headers_json, None, 200, r_header_json, "json")
+ response = res.json()
+ if len(response) != 3:
+ logger.error("Only 3 vnfds should be present for project Padmin. {} listed".format(len(response)))
+ engine.failed_tests += 1
+
+ # Get Public vnfds
+ engine.test("Get VNFD public descriptors", "GET", "/vnfpkgm/v1/vnf_packages/{}".format(vnfd_ids[1]),
+ headers_json, None, 200, r_header_json, "json")
+ # Edit not owned vnfd
+ engine.test("Edit VNFD ", "PATCH", "/vnfpkgm/v1/vnf_packages/{}".format(vnfd_ids[0]),
+ headers_yaml, '{name: pepe}', 404, r_header_yaml, "yaml")
+
+ # Add to my catalog
+ engine.test("Add VNFD id2 to my catalog", "PATCH", "/vnfpkgm/v1/vnf_packages/{}?SET_PROJECT".
+ format(vnfd_ids[1]), headers_json, None, 204, None, 0)
+
+ # Add a new vnfd
+ engine.test("Onboard VNFD id4", "POST", "/vnfpkgm/v1/vnf_packages_content?id=id4", headers_yaml,
+ TestDescriptors.vnfd_empty, 201, r_headers_yaml_location_vnfd, "yaml")
+ vnfd_ids.append(engine.last_id)
+
+ # list vnfds
+ res = engine.test("List VNFD public descriptors", "GET", "/vnfpkgm/v1/vnf_packages",
+ headers_json, None, 200, r_header_json, "json")
+ response = res.json()
+ if len(response) != 2:
+ logger.error("Only 2 vnfds should be present for project Padmin. {} listed".format(len(response)))
+ engine.failed_tests += 1
+
+ if manual_check:
+ input('VNFDs have been omboarded. Perform manual check and press enter to resume')
+
+ test_rest.test("Delete VNFD id2", "DELETE", "/vnfpkgm/v1/vnf_packages/{}".format(vnfd_ids[1]),
+ headers_yaml, None, 204, None, 0)
+
+ # change to admin project
+ engine.remove_authorization() # To force get authorization
+ engine.get_autorization()
+ test_rest.test("Delete VNFD id1", "DELETE", "/vnfpkgm/v1/vnf_packages/{}".format(vnfd_ids[0]),
+ headers_yaml, None, 204, None, 0)
+ test_rest.test("Delete VNFD id2", "DELETE", "/vnfpkgm/v1/vnf_packages/{}".format(vnfd_ids[1]),
+ headers_yaml, None, 204, None, 0)
+ test_rest.test("Delete VNFD id3", "DELETE", "/vnfpkgm/v1/vnf_packages/{}".format(vnfd_ids[2]),
+ headers_yaml, None, 204, None, 0)
+ test_rest.test("Delete VNFD id4", "DELETE", "/vnfpkgm/v1/vnf_packages/{}".format(vnfd_ids[3]),
+ headers_yaml, None, 404, r_header_yaml, "yaml")
+ test_rest.test("Delete VNFD id4", "DELETE", "/vnfpkgm/v1/vnf_packages/{}?ADMIN".format(vnfd_ids[3]),
+ headers_yaml, None, 204, None, 0)
+ # Get Public vnfds
+ engine.test("Get VNFD deleted id1", "GET", "/vnfpkgm/v1/vnf_packages/{}?ADMIN".format(vnfd_ids[0]),
+ headers_json, None, 404, r_header_json, "json")
+ engine.test("Get VNFD deleted id2", "GET", "/vnfpkgm/v1/vnf_packages/{}?ADMIN".format(vnfd_ids[1]),
+ headers_json, None, 404, r_header_json, "json")
+ engine.test("Get VNFD deleted id3", "GET", "/vnfpkgm/v1/vnf_packages/{}?ADMIN".format(vnfd_ids[2]),
+ headers_json, None, 404, r_header_json, "json")
+ engine.test("Get VNFD deleted id4", "GET", "/vnfpkgm/v1/vnf_packages/{}?ADMIN".format(vnfd_ids[3]),
+ headers_json, None, 404, r_header_json, "json")
+
+ engine.test("Delete user U1", "DELETE", "/admin/v1/users/U1", headers_json, None, 204, None, None)
+ engine.test("Delete project Padmin", "DELETE", "/admin/v1/projects/Padmin", headers_json, None, 204, None, None)
+ engine.test("Delete project P2", "DELETE", "/admin/v1/projects/P2", headers_json, None, 204, None, None)
+ engine.test("Delete project P3", "DELETE", "/admin/v1/projects/P3", headers_json, None, 204, None, None)
+