mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-03 06:28:06 +01:00
Add checkpoint of no deletion for untagged image
1. Add checkpoint of no deletion for untagged image 2. rebase master. Signed-off-by: danfengliu <danfengl@vmware.com>
This commit is contained in:
parent
a2112bfa40
commit
5d3080c2c2
@ -90,10 +90,10 @@ class System(base.Base):
|
|||||||
base._assert_status_code(expect_status_code, status_code)
|
base._assert_status_code(expect_status_code, status_code)
|
||||||
return data
|
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)
|
client = self._get_client(**kwargs)
|
||||||
|
|
||||||
gc_parameters = {'delete_untagged':True}
|
gc_parameters = {'delete_untagged':is_delete_untagged}
|
||||||
|
|
||||||
gc_schedule = swagger_client.AdminJobScheduleObj()
|
gc_schedule = swagger_client.AdminJobScheduleObj()
|
||||||
gc_schedule.type = schedule_type
|
gc_schedule.type = schedule_type
|
||||||
@ -142,8 +142,8 @@ class System(base.Base):
|
|||||||
scan_all_id = self.create_scan_all_schedule('Manual', **kwargs)
|
scan_all_id = self.create_scan_all_schedule('Manual', **kwargs)
|
||||||
return scan_all_id
|
return scan_all_id
|
||||||
|
|
||||||
def gc_now(self, **kwargs):
|
def gc_now(self, is_delete_untagged=False, **kwargs):
|
||||||
gc_id = self.create_gc_schedule('Manual', **kwargs)
|
gc_id = self.create_gc_schedule('Manual', is_delete_untagged, **kwargs)
|
||||||
return gc_id
|
return gc_id
|
||||||
|
|
||||||
def validate_gc_job_status(self, gc_id, expected_gc_status, **kwargs):
|
def validate_gc_job_status(self, gc_id, expected_gc_status, **kwargs):
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
import time
|
||||||
|
|
||||||
from testutils import ADMIN_CLIENT
|
from testutils import ADMIN_CLIENT
|
||||||
from testutils import TEARDOWN
|
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)
|
repo_data = self.repo.list_repositories(TestProjects.project_gc_name, **TestProjects.USER_GC_CLIENT)
|
||||||
_assert_status_code(len(repo_data), 0)
|
_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;
|
#5. Tigger garbage collection operation;
|
||||||
gc_id = self.system.gc_now(**ADMIN_CLIENT)
|
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;
|
#7. Get garbage collection log, check there is a number of files was deleted;
|
||||||
self.system.validate_deletion_success(gc_id, **ADMIN_CLIENT)
|
self.system.validate_deletion_success(gc_id, **ADMIN_CLIENT)
|
||||||
|
|
||||||
#8. Push a image in project(PB) by admin and delete the only tag;
|
artifacts = self.artifact.list_artifacts(TestProjects.project_gc_untag_name, self.repo_name_untag, **TestProjects.USER_GC_CLIENT)
|
||||||
push_special_image_to_project(TestProjects.project_gc_untag_name, harbor_server, admin_name, admin_password, self.repo_name_untag, [self.tag])
|
print artifacts
|
||||||
self.artifact.delete_tag(TestProjects.project_gc_untag_name, self.repo_name_untag, self.tag, self.tag, **ADMIN_CLIENT)
|
_assert_status_code(len(artifacts), 1)
|
||||||
|
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
#9. Tigger garbage collection operation;
|
#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;
|
#10. Check garbage collection job was finished;
|
||||||
self.system.validate_gc_job_status(gc_id, "finished", **ADMIN_CLIENT)
|
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;
|
#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)
|
repo_data_untag = self.repo.list_repositories(TestProjects.project_gc_untag_name, **TestProjects.USER_GC_CLIENT)
|
||||||
print "repo_data_untag:", repo_data_untag
|
print "repo_data_untag:", repo_data_untag
|
||||||
|
Loading…
Reference in New Issue
Block a user