def create_project(self, project, **kwargs): if kwargs["branch"] == 1: body = dict(body={ "project_name": project["name"], "metadata": { "public": "true" } }) request(url + "projects", 'post', **body) elif kwargs["branch"] == 2: body = dict( body={ "project_name": project["name"], "metadata": { "public": "true" }, "count_limit": project["count_limit"], "storage_limit": project["storage_limit"] }) request(url + "projects", 'post', **body) elif kwargs["branch"] == 3: if project.get("registry_name") is not None: r = request( url + "registries?name=" + project["registry_name"] + "", 'get') registry_id = int(str(r.json()[0]['id'])) else: registry_id = None body = dict( body={ "project_name": project["name"], "registry_id": registry_id, "metadata": { "public": "true" }, "storage_limit": project["storage_limit"] }) request(url + "projects", 'post', **body) #Project with registry_name is a proxy project, there should be images can be pulled. if project.get("registry_name") is not None: USER_ADMIN = dict(endpoint="https://" + args.endpoint + "/api/v2.0", username="******", password="******") repo = Repository() for _repo in project["repo"]: pull_image(args.endpoint + "/" + project["name"] + "/" + _repo["cache_image_namespace"] + "/" + _repo["cache_image"]) time.sleep(180) repo_name = urllib.parse.quote( _repo["cache_image_namespace"] + "/" + _repo["cache_image"], 'utf-8') repo_data = repo.get_repository(project["name"], repo_name, **USER_ADMIN) return else: raise Exception(r"Error: Feature {} has no branch {}.".format( sys._getframe().f_code.co_name, branch))
class TestProjects(unittest.TestCase): @suppress_urllib3_warning def setUp(self): self.project = Project() self.user = User() self.artifact = Artifact() self.repo = Repository() self.repo_name = "hello-artifact" self.tag = "test_v2" @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def tearDown(self): #1. Delete user(UA); self.user.delete_user(TestProjects.user_sign_image_id, **ADMIN_CLIENT) def testOrasCli(self): """ Test case: Push Artifact With ORAS CLI Test step and expected result: 1. Create user-001 2. Create a new private project(PA) by user(UA); 3. ORAS CLI push artifacts; 4. Get repository from Harbor successfully, and verfiy repository name is repo pushed by ORAS CLI; 5. Get and verify artifacts by tag; 6. ORAS CLI pull artifacts index by tag; 7. Verfiy MD5 between artifacts pushed by ORAS and artifacts pulled by ORAS; Tear down: NA """ url = ADMIN_CLIENT["endpoint"] user_001_password = "******" #1. Create user-001 TestProjects.user_sign_image_id, user_name = self.user.create_user(user_password = user_001_password, **ADMIN_CLIENT) TestProjects.USER_CLIENT=dict(with_signature = True, endpoint = url, username = user_name, password = user_001_password) #2. Create a new private project(PA) by user(UA); TestProjects.project_id, TestProjects.project_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_CLIENT) #3. ORAS CLI push artifacts; md5_list_push = library.oras.oras_push(harbor_server, user_name, user_001_password, TestProjects.project_name, self.repo_name, self.tag) #4. Get repository from Harbor successfully, and verfiy repository name is repo pushed by ORAS CLI; repo_data = self.repo.get_repository(TestProjects.project_name, self.repo_name, **TestProjects.USER_CLIENT) self.assertEqual(repo_data.name, TestProjects.project_name + "/" + self.repo_name) #5. Get and verify artifacts by tag; artifact = self.artifact.get_reference_info(TestProjects.project_name, self.repo_name, self.tag, **TestProjects.USER_CLIENT) self.assertEqual(artifact.tags[0].name, self.tag) #6. ORAS CLI pull artifacts index by tag; md5_list_pull = library.oras.oras_pull(harbor_server, user_name, user_001_password, TestProjects.project_name, self.repo_name, self.tag) #7. Verfiy MD5 between artifacts pushed by ORAS and artifacts pulled by ORAS; if set(md5_list_push) != set(md5_list_pull): raise Exception(r"MD5 check failed with {} and {}.".format(str(md5_list_push), str(md5_list_pull)))
class TestProjects(unittest.TestCase): @classmethod def setUpClass(self): self.project = Project() self.user = User() self.artifact = Artifact(api_type='artifact') self.repo = Repository(api_type='repository') @classmethod def tearDownClass(self): print "Case completed" @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): #1. Delete repository(RA); self.repo.delete_repoitory(TestProjects.project_src_repo_name, (TestProjects.src_repo_name).split('/')[1], **TestProjects.USER_RETAG_CLIENT) #2. Delete repository by retag; self.repo.delete_repoitory(TestProjects.project_dst_repo_name, (TestProjects.dst_repo_name).split('/')[1], **TestProjects.USER_RETAG_CLIENT) #3. Delete project(PA); self.project.delete_project(TestProjects.project_src_repo_id, **TestProjects.USER_RETAG_CLIENT) self.project.delete_project(TestProjects.project_dst_repo_id, **TestProjects.USER_RETAG_CLIENT) #4. Delete user(UA). self.user.delete_user(TestProjects.user_retag_id, **ADMIN_CLIENT) def testRetag(self): """ Test case: Retag Image Test step and expected result: 1. Create a new user(UA); 2. Create a new project(PA) by user(UA); 3. Create a new project(PB) by user(UA); 4. Update role of user-retag as guest member of project(PB); 5. Create a new repository(RA) in project(PA) by user(UA); 6. Get repository in project(PA), there should be one repository which was created by user(UA); 7. Get repository(RA)'s image tag detail information; 8. Retag image in project(PA) to project(PB), it should be forbidden; 9. Update role of user-retag as admin member of project(PB); 10. Retag image in project(PA) to project(PB), it should be successful; 11. Get repository(RB)'s image tag detail information; 12. Read digest of retaged image, it must be the same with the image in repository(RA); 13. Pull image from project(PB) by user_retag, it must be successful; Tear down: 1. Delete repository(RA); 2. Delete repository by retag; 3. Delete project(PA); 4. Delete user(UA). """ url = ADMIN_CLIENT["endpoint"] user_retag_password = "******" pull_tag_name = "latest" dst_repo_sub_name = "repo" #1. Create a new user(UA); TestProjects.user_retag_id, user_retag_name = self.user.create_user( user_password=user_retag_password, **ADMIN_CLIENT) TestProjects.USER_RETAG_CLIENT = dict(endpoint=url, username=user_retag_name, password=user_retag_password) #2. Create a new project(PA) by user(UA); TestProjects.project_src_repo_id, TestProjects.project_src_repo_name = self.project.create_project( metadata={"public": "false"}, **TestProjects.USER_RETAG_CLIENT) #3. Create a new project(PB) by user(UA); TestProjects.project_dst_repo_id, TestProjects.project_dst_repo_name = self.project.create_project( metadata={"public": "false"}, **TestProjects.USER_RETAG_CLIENT) retag_member_id = self.project.get_project_member_id( TestProjects.project_dst_repo_id, user_retag_name, **TestProjects.USER_RETAG_CLIENT) #4. Update role of user-retag as guest member of project(PB); self.project.update_project_member_role( TestProjects.project_dst_repo_id, retag_member_id, 3, **ADMIN_CLIENT) #5. Create a new repository(RA) in project(PA) by user(UA); TestProjects.src_repo_name, tag_name = push_image_to_project( TestProjects.project_src_repo_name, harbor_server, 'admin', 'Harbor12345', "hello-world", pull_tag_name) #6. Get repository in project(PA), there should be one repository which was created by user(UA); src_repo_data = self.repo.get_repository( TestProjects.project_src_repo_name, **TestProjects.USER_RETAG_CLIENT) _assert_status_code(TestProjects.src_repo_name, src_repo_data[0].name) #7. Get repository(RA)'s image tag detail information; src_tag_data = self.artifact.get_reference_info( TestProjects.project_src_repo_name, TestProjects.src_repo_name.split('/')[1], tag_name, **TestProjects.USER_RETAG_CLIENT) TestProjects.dst_repo_name = TestProjects.project_dst_repo_name + "/" + dst_repo_sub_name #8. Retag image in project(PA) to project(PB), it should be forbidden; self.artifact.copy_artifact(TestProjects.project_dst_repo_name, dst_repo_sub_name, TestProjects.src_repo_name + "@" + src_tag_data[0].digest, expect_status_code=403, **TestProjects.USER_RETAG_CLIENT) #9. Update role of user-retag as admin member of project(PB); self.project.update_project_member_role( TestProjects.project_dst_repo_id, retag_member_id, 1, **ADMIN_CLIENT) #10. Retag image in project(PA) to project(PB), it should be successful; self.artifact.copy_artifact( TestProjects.project_dst_repo_name, dst_repo_sub_name, TestProjects.src_repo_name + "@" + src_tag_data[0].digest, **TestProjects.USER_RETAG_CLIENT) #11. Get repository(RB)'s image tag detail information; dst_tag_data = self.artifact.get_reference_info( TestProjects.project_dst_repo_name, dst_repo_sub_name, tag_name, **TestProjects.USER_RETAG_CLIENT) #12. Read digest of retaged image, it must be the same with the image in repository(RA); self.assertEqual(src_tag_data[0].digest, dst_tag_data[0].digest) #13. Pull image from project(PB) by user_retag, it must be successful;" pull_harbor_image(harbor_server, user_retag_name, user_retag_password, TestProjects.dst_repo_name, tag_name)
class TestProjects(unittest.TestCase): """ Test case: Tag Retention Setup: Create Project test-retention Push image test1:1.0, test1:2.0, test1:3.0,latest, test2:1.0, test2:latest, test3:1.0, test4:1.0 Test Steps: 1. Create Retention Policy 2. Add rule "For the repositories matching **, retain always with tags matching latest*" 3. Add rule "For the repositories matching test3*, retain always with tags matching **" 4. Dry run, check execution and tasks 5. Real run, check images retained Tear Down: 1. Delete project test-retention """ @classmethod def setUpClass(self): self.user = User() self.system = System() self.repo = Repository() self.project = Project() self.retention = Retention() def testTagRetention(self): user_ra_password = "******" user_ra_id, user_ra_name = self.user.create_user( user_password=user_ra_password, **ADMIN_CLIENT) print("Created user: %s, id: %s" % (user_ra_name, user_ra_id)) TestProjects.USER_RA_CLIENT = dict(endpoint=ADMIN_CLIENT["endpoint"], username=user_ra_name, password=user_ra_password) TestProjects.user_ra_id = int(user_ra_id) TestProjects.project_src_repo_id, project_src_repo_name = self.project.create_project( metadata={"public": "false"}, **TestProjects.USER_RA_CLIENT) # Push image test1:1.0, test1:2.0, test1:3.0,latest, test2:1.0, test2:latest, test3:1.0 push_special_image_to_project(project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test1", ['1.0']) push_special_image_to_project(project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test1", ['2.0']) push_special_image_to_project(project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test1", ['3.0', 'latest']) push_special_image_to_project(project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test2", ['1.0']) push_special_image_to_project(project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test2", ['latest']) push_special_image_to_project(project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test3", ['1.0']) push_special_image_to_project(project_src_repo_name, harbor_server, user_ra_name, user_ra_password, "test4", ['1.0']) resp = self.repo.get_repository(TestProjects.project_src_repo_id, **TestProjects.USER_RA_CLIENT) self.assertEqual(len(resp), 4) # Create Retention Policy retention_id = self.retention.create_retention_policy( TestProjects.project_src_repo_id, selector_repository="**", selector_tag="latest*", expect_status_code=201, **TestProjects.USER_RA_CLIENT) # Add rule self.retention.update_retention_add_rule(retention_id, selector_repository="test3*", selector_tag="**", expect_status_code=200, **TestProjects.USER_RA_CLIENT) # Dry run self.retention.trigger_retention_policy(retention_id, dry_run=True, **TestProjects.USER_RA_CLIENT) time.sleep(2) resp = self.retention.get_retention_executions( retention_id, **TestProjects.USER_RA_CLIENT) self.assertTrue(len(resp) > 0) execution = resp[0] resp = self.retention.get_retention_exec_tasks( retention_id, execution.id, **TestProjects.USER_RA_CLIENT) self.assertEqual(len(resp), 4) resp = self.retention.get_retention_exec_task_log( retention_id, execution.id, resp[0].id, **TestProjects.USER_RA_CLIENT) print(resp) # Real run self.retention.trigger_retention_policy(retention_id, dry_run=False, **TestProjects.USER_RA_CLIENT) time.sleep(10) resp = self.retention.get_retention_executions( retention_id, **TestProjects.USER_RA_CLIENT) self.assertTrue(len(resp) > 1) execution = resp[0] resp = self.retention.get_retention_exec_tasks( retention_id, execution.id, **TestProjects.USER_RA_CLIENT) self.assertEqual(len(resp), 4) resp = self.retention.get_retention_exec_task_log( retention_id, execution.id, resp[0].id, **TestProjects.USER_RA_CLIENT) print(resp) resp = self.repo.get_repository(TestProjects.project_src_repo_id, **TestProjects.USER_RA_CLIENT) self.assertEqual(len(resp), 3) @classmethod def tearDownClass(self): print "Case completed" @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): resp = self.repo.get_repository(TestProjects.project_src_repo_id, **TestProjects.USER_RA_CLIENT) for repo in resp: self.repo.delete_repoitory(repo.name, **TestProjects.USER_RA_CLIENT) self.project.delete_project(TestProjects.project_src_repo_id, **TestProjects.USER_RA_CLIENT) self.user.delete_user(TestProjects.user_ra_id, **ADMIN_CLIENT)
class TestProjects(unittest.TestCase): @classmethod def setUpClass(self): self.project = Project() self.user = User() self.artifact = Artifact(api_type='artifact') self.repo = Repository(api_type='repository') self.url = ADMIN_CLIENT["endpoint"] self.user_push_chart_password = "******" self.cnab_repo_name = "test_cnab" @classmethod def tearDownClass(self): print "Case completed" @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): #1. Delete repository(RA) by user(UA); self.repo.delete_repoitory(TestProjects.project_push_bundle_name, self.cnab_repo_name, **TestProjects.USER_CLIENT) #2. Delete project(PA); self.project.delete_project(TestProjects.project_push_bundle_id, **TestProjects.USER_CLIENT) #3. Delete user(UA). self.user.delete_user(TestProjects.user_id, **ADMIN_CLIENT) def testPushBundleByCnab(self): """ Test case: Push Bundle By Cnab Test step and expected result: 1. Create a new user(UA); 2. Create a new project(PA) by user(UA); 3. Pull images for bundle; 4. Push bundle to harbor as repository(RA); 5. Get repository from Harbor successfully; 6. Verfiy bundle name; 7. Get artifact by sha256; 8. Verify artifact information. Tear down: 1. Delete repository(RA) by user(UA); 2. Delete project(PA); 3. Delete user(UA). """ #1. Create a new user(UA); TestProjects.user_id, user_name = self.user.create_user( user_password=self.user_push_chart_password, **ADMIN_CLIENT) TestProjects.USER_CLIENT = dict(endpoint=self.url, username=user_name, password=self.user_push_chart_password) #2. Create a new project(PA) by user(UA); TestProjects.project_push_bundle_id, TestProjects.project_push_bundle_name = self.project.create_project( metadata={"public": "false"}, **TestProjects.USER_CLIENT) #3. Pull images for bundle; _docker_api = DockerAPI() _docker_api.docker_image_pull("hello-world", tag="latest") _docker_api.docker_image_pull("busybox", tag="latest") #4. Push bundle to harbor as repository(RA); target = harbor_server + "/" + TestProjects.project_push_bundle_name + "/" + self.cnab_repo_name reference_sha256 = library.cnab.push_cnab_bundle( harbor_server, user_name, self.user_push_chart_password, "hello-world:latest", "busybox:latest", target) #5. Get repository from Harbor successfully; index_data = self.repo.get_repository( TestProjects.project_push_bundle_name, self.cnab_repo_name, **TestProjects.USER_CLIENT) print "index_data:", index_data #6. Verfiy bundle name; self.assertEqual( index_data.name, TestProjects.project_push_bundle_name + "/" + self.cnab_repo_name) #7. Get artifact by sha256; artifact = self.artifact.get_reference_info( TestProjects.project_push_bundle_name, self.cnab_repo_name, reference_sha256, **TestProjects.USER_CLIENT) #8. Verify artifact information; self.assertEqual(artifact[0].type, 'CNAB') self.assertEqual(artifact[0].digest, reference_sha256)
class TestProjects(unittest.TestCase): @classmethod def setUpClass(self): self.project= Project() self.user= User() self.artifact = Artifact() self.repo= Repository() self.url = ADMIN_CLIENT["endpoint"] self.user_push_cnab_password = "******" self.cnab_repo_name = "test_cnab" self.cnab_tag = "test_cnab_tag" @classmethod def tearDownClass(self): print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): #1. Delete repository(RA) by user(UA); self.repo.delete_repoitory(TestProjects.project_push_bundle_name, self.cnab_repo_name, **TestProjects.USER_CLIENT) #2. Delete project(PA); self.project.delete_project(TestProjects.project_push_bundle_id, **TestProjects.USER_CLIENT) #3. Delete user(UA). self.user.delete_user(TestProjects.user_id, **ADMIN_CLIENT) def testPushBundleByCnab(self): """ Test case: Push Bundle By Cnab Test step and expected result: 1. Create a new user(UA); 2. Create a new project(PA) by user(UA); 3. Pull images for bundle; 4. Push bundle to harbor as repository(RA); 5. Get repository from Harbor successfully; 6. Verfiy bundle name; 7. Get artifact by sha256; 8. Verify artifact information. Tear down: 1. Delete repository(RA) by user(UA); 2. Delete project(PA); 3. Delete user(UA). """ #1. Create a new user(UA); TestProjects.user_id, user_name = self.user.create_user(user_password = self.user_push_cnab_password, **ADMIN_CLIENT) TestProjects.USER_CLIENT=dict(endpoint = self.url, username = user_name, password = self.user_push_cnab_password) #2. Create a new project(PA) by user(UA); TestProjects.project_push_bundle_id, TestProjects.project_push_bundle_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_CLIENT) #3. Pull images for bundle; _docker_api = DockerAPI() _docker_api.docker_image_pull("alpine", tag = "latest") _docker_api.docker_image_pull("haproxy", tag = "latest") #4. Push bundle to harbor as repository(RA); target = harbor_server + "/" + TestProjects.project_push_bundle_name + "/" + self.cnab_repo_name + ":" + self.cnab_tag reference_sha256 = library.cnab.push_cnab_bundle(harbor_server, user_name, self.user_push_cnab_password, "alpine:latest", "haproxy:latest", target) #5. Get repository from Harbor successfully; index_data = self.repo.get_repository(TestProjects.project_push_bundle_name, self.cnab_repo_name, **TestProjects.USER_CLIENT) #5.2 Cnab bundle can be pulled by ctr successfully; # This step might not successful since ctr does't support cnab fully, it might be uncomment sometime in future. # Please keep them in comment! #library.containerd.ctr_images_pull(user_name, self.user_push_cnab_password, target) #library.containerd.ctr_images_list(oci_ref = target) #6. Verfiy bundle name; self.assertEqual(index_data.name, TestProjects.project_push_bundle_name + "/" + self.cnab_repo_name) #7. Get artifact by sha256; artifact = self.artifact.get_reference_info(TestProjects.project_push_bundle_name, self.cnab_repo_name, reference_sha256, **TestProjects.USER_CLIENT) #8. Verify artifact information; self.assertEqual(artifact[0].type, 'CNAB') self.assertEqual(artifact[0].digest, reference_sha256)
class TestProjects(unittest.TestCase): @classmethod def setUp(self): self.project = Project() self.user = User() self.artifact = Artifact() self.repo = Repository() self.repo_name = "busybox" self.tag = "1.28" @classmethod def tearDown(self): print("Case completed") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): #1. Delete user(UA); self.user.delete_user(TestProjects.user_sign_image_id, **ADMIN_CLIENT) def testPushSingularity(self): """ Test case: Push Singularity file With Singularity CLI Test step and expected result: 1. Create user-001 2. Create a new private project(PA) by user(UA); 3. Push a sif file to harbor by singularity; 4. Get repository from Harbor successfully, and verfiy repository name is repo pushed by singularity CLI; 5. Get and verify artifacts by tag; 6. Pull sif file from harbor by singularity; Tear down: NA """ url = ADMIN_CLIENT["endpoint"] user_001_password = "******" #1. Create user-001 TestProjects.user_sign_image_id, user_name = self.user.create_user( user_password=user_001_password, **ADMIN_CLIENT) TestProjects.USER_CLIENT = dict(with_signature=True, endpoint=url, username=user_name, password=user_001_password) #2. Create a new private project(PA) by user(UA); TestProjects.project_id, TestProjects.project_name = self.project.create_project( metadata={"public": "false"}, **TestProjects.USER_CLIENT) #3. Push a sif file to harbor by singularity; library.singularity.push_singularity_to_harbor( "library:", "library/default/", harbor_server, user_name, user_001_password, TestProjects.project_name, self.repo_name, self.tag) #4. Get repository from Harbor successfully, and verfiy repository name is repo pushed by singularity CLI; repo_data = self.repo.get_repository(TestProjects.project_name, self.repo_name, **TestProjects.USER_CLIENT) self.assertEqual(repo_data.name, TestProjects.project_name + "/" + self.repo_name) #5. Get and verify artifacts by tag; artifact = self.artifact.get_reference_info(TestProjects.project_name, self.repo_name, self.tag, **TestProjects.USER_CLIENT) self.assertEqual(artifact[0].tags[0].name, self.tag) #6. Pull sif file from harbor by singularity; library.singularity.singularity_pull( TestProjects.project_name + ".sif", "oras://" + harbor_server + "/" + TestProjects.project_name + "/" + self.repo_name + ":" + self.tag)
class TestProjects(unittest.TestCase): @classmethod def setUpClass(self): self.project = Project() self.user = User() self.repo = Repository(api_type='repository') @classmethod def tearDownClass(self): print "Case completed" @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): #1. Delete project(PA); self.project.delete_project(TestProjects.project_del_repo_id, **TestProjects.USER_del_repo_CLIENT) #2. Delete user(UA). self.user.delete_user(TestProjects.user_del_repo_id, **ADMIN_CLIENT) def testDelRepo(self): """ Test case: Delete a repository Test step and expected result: 1. Create a new user(UA); 2. Create a new project(PA) by user(UA); 3. Create a new repository(RA) in project(PA) by user(UA); 4. Get repository in project(PA), there should be one repository which was created by user(UA); 5. Delete repository(RA) by user(UA); 6. Get repository by user(UA), it should get nothing; Tear down: 1. Delete project(PA); 2. Delete user(UA). """ url = ADMIN_CLIENT["endpoint"] user_del_repo_password = "******" #1. Create a new user(UA); TestProjects.user_del_repo_id, user_del_repo_name = self.user.create_user( user_password=user_del_repo_password, **ADMIN_CLIENT) TestProjects.USER_del_repo_CLIENT = dict( endpoint=url, username=user_del_repo_name, password=user_del_repo_password) #2. Create a new project(PA) by user(UA); TestProjects.project_del_repo_id, TestProjects.project_del_repo_name = self.project.create_project( metadata={"public": "false"}, **TestProjects.USER_del_repo_CLIENT) #3. Create a new repository(RA) in project(PA) by user(UA); repo_name, _ = push_image_to_project( TestProjects.project_del_repo_name, harbor_server, 'admin', 'Harbor12345', "hello-world", "latest") #4. Get repository in project(PA), there should be one repository which was created by user(UA); repo_data = self.repo.get_repository( TestProjects.project_del_repo_name, **TestProjects.USER_del_repo_CLIENT) _assert_status_code(repo_name, repo_data[0].name) #5. Delete repository(RA) by user(UA); self.repo.delete_repoitory(TestProjects.project_del_repo_name, repo_name.split('/')[1], **TestProjects.USER_del_repo_CLIENT) #6. Get repository by user(UA), it should get nothing; repo_data = self.repo.get_repository( TestProjects.project_del_repo_name, **TestProjects.USER_del_repo_CLIENT) _assert_status_code(len(repo_data), 0)
class TestProjects(unittest.TestCase): @classmethod def setUp(self): self.system = System() self.project = Project() self.user = User() self.repo = Repository(api_type='repository') @classmethod def tearDown(self): print "Case completed" @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): #2. Delete project(PA); self.project.delete_project(TestProjects.project_gc_id, **TestProjects.USER_GC_CLIENT) #3. Delete user(UA); self.user.delete_user(TestProjects.user_gc_id, **ADMIN_CLIENT) def testGarbageCollection(self): """ Test case: Garbage Collection Test step and expected result: 1. Create a new user(UA); 2. Create a new project(PA) by user(UA); 3. Push a new image(IA) in project(PA) by admin; 4. Delete repository(RA) by user(UA); 5. Get repository by user(UA), it should get nothing; 6. Tigger garbage collection operation; 7. Check garbage collection job was finished; 8. Get garbage collection log, check there is number of files was deleted. Tear down: 1. Delete project(PA); 2. Delete user(UA). """ url = ADMIN_CLIENT["endpoint"] admin_name = ADMIN_CLIENT["username"] admin_password = ADMIN_CLIENT["password"] user_gc_password = "******" #1. Create a new user(UA); TestProjects.user_gc_id, user_gc_name = self.user.create_user( user_password=user_gc_password, **ADMIN_CLIENT) TestProjects.USER_GC_CLIENT = dict(endpoint=url, username=user_gc_name, password=user_gc_password) #2. Create a new project(PA) by user(UA); TestProjects.project_gc_id, TestProjects.project_gc_name = self.project.create_project( metadata={"public": "false"}, **TestProjects.USER_GC_CLIENT) #3. Push a new image(IA) in project(PA) by admin; repo_name, _ = push_image_to_project(TestProjects.project_gc_name, harbor_server, admin_name, admin_password, "tomcat", "latest") #4. Delete repository(RA) by user(UA); self.repo.delete_repoitory(TestProjects.project_gc_name, repo_name.split('/')[1], **TestProjects.USER_GC_CLIENT) #5. Get repository by user(UA), it should get nothing; repo_data = self.repo.get_repository(TestProjects.project_gc_name, **TestProjects.USER_GC_CLIENT) _assert_status_code(len(repo_data), 0) #6. Tigger garbage collection operation; gc_id = self.system.gc_now(**ADMIN_CLIENT) #7. Check garbage collection job was finished; self.system.validate_gc_job_status(gc_id, "finished", **ADMIN_CLIENT) #8. Get garbage collection log, check there is number of files was deleted. self.system.validate_deletion_success(gc_id, **ADMIN_CLIENT)