2019-09-11 07:34:23 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
import unittest
|
|
|
|
|
2020-11-04 03:13:12 +01:00
|
|
|
from testutils import harbor_server, created_project, created_user, \
|
|
|
|
TEARDOWN, ADMIN_CLIENT,suppress_urllib3_warning
|
2019-09-11 07:34:23 +02:00
|
|
|
from library.repository import Repository
|
2022-09-06 08:15:45 +02:00
|
|
|
from library.repository import push_self_build_image_to_project, push_local_image_to_project
|
2019-09-11 07:34:23 +02:00
|
|
|
from library.system import System
|
|
|
|
|
|
|
|
class TestProjects(unittest.TestCase):
|
2020-11-04 03:13:12 +01:00
|
|
|
@suppress_urllib3_warning
|
2020-03-12 04:50:30 +01:00
|
|
|
def setUp(cls):
|
2020-03-16 03:13:28 +01:00
|
|
|
cls.repo = Repository()
|
2020-03-12 04:50:30 +01:00
|
|
|
cls.system = System()
|
2019-09-11 07:34:23 +02:00
|
|
|
|
2020-11-04 03:13:12 +01:00
|
|
|
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
|
|
|
|
def tearDown(self):
|
2020-07-30 10:04:14 +02:00
|
|
|
print("Case completed")
|
2019-09-11 07:34:23 +02:00
|
|
|
|
|
|
|
def testProjectQuota(self):
|
|
|
|
"""
|
|
|
|
Test case:
|
|
|
|
Project Quota
|
|
|
|
Test step and expected result:
|
|
|
|
1. Create a new user(UA);
|
|
|
|
2. Create a new private project(PA) by user(UA);
|
|
|
|
3. Add user(UA) as a member of project(PA) with project-admin role;
|
2022-09-06 08:15:45 +02:00
|
|
|
4. Check quota is 0
|
|
|
|
5. Push an image to project(PA) by user(UA), then check the project quota usage;
|
|
|
|
6. Check quota change
|
|
|
|
7. Push the image with another tag to project(PA) by user(UA)
|
|
|
|
8. Check quota not changed
|
|
|
|
9. Delete repository(RA) by user(UA);
|
|
|
|
10. Delete image, the quota should be changed to 0.
|
2019-09-11 07:34:23 +02:00
|
|
|
Tear down:
|
|
|
|
1. Delete repository(RA) by user(UA);
|
|
|
|
2. Delete project(PA);
|
|
|
|
3. Delete user(UA);
|
|
|
|
"""
|
|
|
|
user_001_password = "Aa123456"
|
|
|
|
|
2020-03-12 04:50:30 +01:00
|
|
|
#1. Create a new user(UA);
|
|
|
|
with created_user(user_001_password) as (user_id, user_name):
|
|
|
|
#2. Create a new private project(PA) by user(UA);
|
|
|
|
#3. Add user(UA) as a member of project(PA) with project-admin role;
|
|
|
|
with created_project(metadata={"public": "false"}, user_id=user_id) as (project_id, project_name):
|
2022-09-06 08:15:45 +02:00
|
|
|
#4. Check quota is 0
|
|
|
|
quota = self.system.get_project_quota("project", project_id, **ADMIN_CLIENT)
|
|
|
|
self.assertEqual(quota[0].used["storage"], 0)
|
|
|
|
#5. Push an image to project(PA) by user(UA), then check the project quota usage;
|
2020-03-12 04:50:30 +01:00
|
|
|
image, tag = "goharbor/alpine", "3.10"
|
Upgrade docker and containerd
1. Fix E2E quotas issue, push the same image but with different name;
2. Add checkpoint for robot account test;
3. Upgraded docker and containerd in E2E image;
4. Package base image sample(busybox) into E2E image, so in E2E
container, all local docker images can be cleaned up, once base image is needed for
building image, it can be loaded locally;
5. Adapt OIDC service of supporting LDAP user, and add OIDC group user
test;
6. Restart docker deamon before content trust test, both in API and UI
test;
7. Add retry for keyword "Add A Tag Immutability Rule";
8. Fix tag retention test issue, missing click angle icon, and enhance
checkpoint of dry run and real run;
9. Fix schedule test issue for wrong cron string;
10. Disable quotas verification, it's not stable for script defect;
Signed-off-by: danfengliu <danfengl@vmware.com>
2021-01-29 08:52:21 +01:00
|
|
|
image_alias_name = "_alias"
|
2022-09-06 08:15:45 +02:00
|
|
|
push_self_build_image_to_project(project_name, harbor_server, user_name, user_001_password, image, tag)
|
2019-09-11 07:34:23 +02:00
|
|
|
|
2022-09-06 08:15:45 +02:00
|
|
|
#6. Get project quota
|
2020-03-12 04:50:30 +01:00
|
|
|
quota = self.system.get_project_quota("project", project_id, **ADMIN_CLIENT)
|
2022-09-06 08:15:45 +02:00
|
|
|
quota_size = quota[0].used["storage"]
|
|
|
|
self.assertNotEqual(quota_size, 0)
|
2019-09-11 07:34:23 +02:00
|
|
|
|
2022-09-06 08:15:45 +02:00
|
|
|
#7. Push the image with another tag to project(PA) by user(UA), the check the project quota usage;
|
|
|
|
push_local_image_to_project(harbor_server, user_name, user_001_password, "{}/{}/{}".format(harbor_server, project_name, image), tag, "{}/{}/{}{}".format(harbor_server, project_name, image, image_alias_name), tag + image_alias_name)
|
2019-09-11 07:34:23 +02:00
|
|
|
|
2022-09-06 08:15:45 +02:00
|
|
|
#8. Get project quota
|
2020-03-12 04:50:30 +01:00
|
|
|
quota = self.system.get_project_quota("project", project_id, **ADMIN_CLIENT)
|
2022-09-06 08:15:45 +02:00
|
|
|
self.assertEqual(quota[0].used["storage"], quota_size)
|
2019-09-11 07:34:23 +02:00
|
|
|
|
2022-09-06 08:15:45 +02:00
|
|
|
#9. Delete repository(RA) by user(UA);
|
2021-01-16 12:34:43 +01:00
|
|
|
self.repo.delete_repository(project_name, "goharbor%2Falpine", **ADMIN_CLIENT)
|
Upgrade docker and containerd
1. Fix E2E quotas issue, push the same image but with different name;
2. Add checkpoint for robot account test;
3. Upgraded docker and containerd in E2E image;
4. Package base image sample(busybox) into E2E image, so in E2E
container, all local docker images can be cleaned up, once base image is needed for
building image, it can be loaded locally;
5. Adapt OIDC service of supporting LDAP user, and add OIDC group user
test;
6. Restart docker deamon before content trust test, both in API and UI
test;
7. Add retry for keyword "Add A Tag Immutability Rule";
8. Fix tag retention test issue, missing click angle icon, and enhance
checkpoint of dry run and real run;
9. Fix schedule test issue for wrong cron string;
10. Disable quotas verification, it's not stable for script defect;
Signed-off-by: danfengliu <danfengl@vmware.com>
2021-01-29 08:52:21 +01:00
|
|
|
self.repo.delete_repository(project_name, "goharbor%2Falpine"+image_alias_name, **ADMIN_CLIENT)
|
2019-09-11 07:34:23 +02:00
|
|
|
|
2022-09-06 08:15:45 +02:00
|
|
|
#10. Quota should be 0
|
2020-03-12 04:50:30 +01:00
|
|
|
quota = self.system.get_project_quota("project", project_id, **ADMIN_CLIENT)
|
|
|
|
self.assertEqual(quota[0].used["storage"], 0)
|
2019-09-11 07:34:23 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|