From 5d3080c2c26745c2f2d70c8a317cef4e60364ee0 Mon Sep 17 00:00:00 2001 From: danfengliu Date: Wed, 8 Jul 2020 20:06:42 +0800 Subject: [PATCH] Add checkpoint of no deletion for untagged image 1. Add checkpoint of no deletion for untagged image 2. rebase master. Signed-off-by: danfengliu --- tests/apitests/python/library/system.py | 8 ++++---- .../apitests/python/test_garbage_collection.py | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/apitests/python/library/system.py b/tests/apitests/python/library/system.py index e9accfacb..3e2fb1591 100644 --- a/tests/apitests/python/library/system.py +++ b/tests/apitests/python/library/system.py @@ -90,10 +90,10 @@ class System(base.Base): base._assert_status_code(expect_status_code, status_code) return data - def create_gc_schedule(self, schedule_type, cron = None, expect_status_code = 201, expect_response_body = None, **kwargs): + def create_gc_schedule(self, schedule_type, is_delete_untagged, cron = None, expect_status_code = 201, expect_response_body = None, **kwargs): client = self._get_client(**kwargs) - gc_parameters = {'delete_untagged':True} + gc_parameters = {'delete_untagged':is_delete_untagged} gc_schedule = swagger_client.AdminJobScheduleObj() gc_schedule.type = schedule_type @@ -142,8 +142,8 @@ class System(base.Base): scan_all_id = self.create_scan_all_schedule('Manual', **kwargs) return scan_all_id - def gc_now(self, **kwargs): - gc_id = self.create_gc_schedule('Manual', **kwargs) + def gc_now(self, is_delete_untagged=False, **kwargs): + gc_id = self.create_gc_schedule('Manual', is_delete_untagged, **kwargs) return gc_id def validate_gc_job_status(self, gc_id, expected_gc_status, **kwargs): diff --git a/tests/apitests/python/test_garbage_collection.py b/tests/apitests/python/test_garbage_collection.py index 2ea0383aa..c23dd1747 100644 --- a/tests/apitests/python/test_garbage_collection.py +++ b/tests/apitests/python/test_garbage_collection.py @@ -1,6 +1,7 @@ from __future__ import absolute_import import unittest +import time from testutils import ADMIN_CLIENT from testutils import TEARDOWN @@ -81,6 +82,10 @@ class TestProjects(unittest.TestCase): repo_data = self.repo.list_repositories(TestProjects.project_gc_name, **TestProjects.USER_GC_CLIENT) _assert_status_code(len(repo_data), 0) + #8. Push a image in project(PB) by admin and delete the only tag; + push_special_image_to_project(TestProjects.project_gc_untag_name, harbor_server, admin_name, admin_password, self.repo_name_untag, [self.tag]) + self.artifact.delete_tag(TestProjects.project_gc_untag_name, self.repo_name_untag, self.tag, self.tag, **ADMIN_CLIENT) + #5. Tigger garbage collection operation; gc_id = self.system.gc_now(**ADMIN_CLIENT) @@ -90,16 +95,21 @@ class TestProjects(unittest.TestCase): #7. Get garbage collection log, check there is a number of files was deleted; self.system.validate_deletion_success(gc_id, **ADMIN_CLIENT) - #8. Push a image in project(PB) by admin and delete the only tag; - push_special_image_to_project(TestProjects.project_gc_untag_name, harbor_server, admin_name, admin_password, self.repo_name_untag, [self.tag]) - self.artifact.delete_tag(TestProjects.project_gc_untag_name, self.repo_name_untag, self.tag, self.tag, **ADMIN_CLIENT) + artifacts = self.artifact.list_artifacts(TestProjects.project_gc_untag_name, self.repo_name_untag, **TestProjects.USER_GC_CLIENT) + print artifacts + _assert_status_code(len(artifacts), 1) + + time.sleep(5) #9. Tigger garbage collection operation; - gc_id = self.system.gc_now(**ADMIN_CLIENT) + gc_id = self.system.gc_now(is_delete_untagged=True, **ADMIN_CLIENT) #10. Check garbage collection job was finished; self.system.validate_gc_job_status(gc_id, "finished", **ADMIN_CLIENT) + #7. Get garbage collection log, check there is a number of files was deleted; + self.system.validate_deletion_success(gc_id, **ADMIN_CLIENT) + #11. Repository with untag image should be still there; repo_data_untag = self.repo.list_repositories(TestProjects.project_gc_untag_name, **TestProjects.USER_GC_CLIENT) print "repo_data_untag:", repo_data_untag