mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-23 00:57:44 +01:00
add e2e test case for project quota
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; 4. Push an image to project(PA) by user(UA), then check the project quota usage; 5. Check quota change 6. Delete image, the quota should be changed to 0. Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
parent
76f1580634
commit
6b5fd36bb3
@ -3600,7 +3600,6 @@ paths:
|
|||||||
description: List quotas
|
description: List quotas
|
||||||
tags:
|
tags:
|
||||||
- Products
|
- Products
|
||||||
- Quota
|
|
||||||
parameters:
|
parameters:
|
||||||
- name: reference
|
- name: reference
|
||||||
in: query
|
in: query
|
||||||
|
@ -25,7 +25,7 @@ class DockerAPI(object):
|
|||||||
if str(err).lower().find(expected_error_message.lower()) < 0:
|
if str(err).lower().find(expected_error_message.lower()) < 0:
|
||||||
raise Exception(r"Docker login: Return message {} is not as expected {}".format(str(err), expected_error_message))
|
raise Exception(r"Docker login: Return message {} is not as expected {}".format(str(err), expected_error_message))
|
||||||
else:
|
else:
|
||||||
raise Exception(r" Docker login {} failed, error is [{}]".format (image, err.message))
|
raise Exception(r" Docker login failed, error is [{}]".format (err.message))
|
||||||
|
|
||||||
def docker_image_pull(self, image, tag = None, expected_error_message = None):
|
def docker_image_pull(self, image, tag = None, expected_error_message = None):
|
||||||
if tag is not None:
|
if tag is not None:
|
||||||
|
@ -182,3 +182,13 @@ class System(base.Base):
|
|||||||
def get_cve_whitelist(self, **kwargs):
|
def get_cve_whitelist(self, **kwargs):
|
||||||
client = self._get_client(**kwargs)
|
client = self._get_client(**kwargs)
|
||||||
return client.system_cve_whitelist_get()
|
return client.system_cve_whitelist_get()
|
||||||
|
|
||||||
|
def get_project_quota(self, reference, reference_id, **kwargs):
|
||||||
|
params={}
|
||||||
|
params['reference'] = reference
|
||||||
|
params['reference_id'] = reference_id
|
||||||
|
|
||||||
|
client = self._get_client(**kwargs)
|
||||||
|
data, status_code, _ = client.quotas_get_with_http_info(**params)
|
||||||
|
base._assert_status_code(200, status_code)
|
||||||
|
return data
|
88
tests/apitests/python/test_project_quota.py
Normal file
88
tests/apitests/python/test_project_quota.py
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
from __future__ import absolute_import
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from testutils import harbor_server
|
||||||
|
from testutils import TEARDOWN
|
||||||
|
from testutils import ADMIN_CLIENT
|
||||||
|
from library.project import Project
|
||||||
|
from library.user import User
|
||||||
|
from library.repository import Repository
|
||||||
|
from library.repository import push_image_to_project
|
||||||
|
from library.system import System
|
||||||
|
|
||||||
|
class TestProjects(unittest.TestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUp(self):
|
||||||
|
project = Project()
|
||||||
|
self.project= project
|
||||||
|
|
||||||
|
user = User()
|
||||||
|
self.user= user
|
||||||
|
|
||||||
|
repo = Repository()
|
||||||
|
self.repo= repo
|
||||||
|
|
||||||
|
self.system = System()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDown(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_test_quota_id, **ADMIN_CLIENT)
|
||||||
|
|
||||||
|
#2. Delete user(UA);
|
||||||
|
self.user.delete_user(TestProjects.user_test_quota_id, **ADMIN_CLIENT)
|
||||||
|
|
||||||
|
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;
|
||||||
|
4. Push an image to project(PA) by user(UA), then check the project quota usage;
|
||||||
|
5. Check quota change
|
||||||
|
6. Delete image, the quota should be changed to 0.
|
||||||
|
Tear down:
|
||||||
|
1. Delete repository(RA) by user(UA);
|
||||||
|
2. Delete project(PA);
|
||||||
|
3. Delete user(UA);
|
||||||
|
"""
|
||||||
|
url = ADMIN_CLIENT["endpoint"]
|
||||||
|
user_001_password = "Aa123456"
|
||||||
|
|
||||||
|
#1. Create user-001
|
||||||
|
TestProjects.user_test_quota_id, user_test_quota_name = self.user.create_user(user_password = user_001_password, **ADMIN_CLIENT)
|
||||||
|
TestProjects.USER_TEST_QUOTA_CLIENT=dict(endpoint = url, username = user_test_quota_name, password = user_001_password)
|
||||||
|
|
||||||
|
#2. Create a new private project(PA) by user(UA);
|
||||||
|
TestProjects.project_test_quota_id, project_test_quota_name = self.project.create_project(metadata = {"public": "false"}, **ADMIN_CLIENT)
|
||||||
|
|
||||||
|
#3. Add user(UA) as a member of project(PA) with project-admin role;
|
||||||
|
self.project.add_project_members(TestProjects.project_test_quota_id, TestProjects.user_test_quota_id, **ADMIN_CLIENT)
|
||||||
|
|
||||||
|
#4.Push an image to project(PA) by user(UA), then check the project quota usage; -- {"count": 1, "storage": 2791709}
|
||||||
|
image = "alpine"
|
||||||
|
src_tag = "3.10"
|
||||||
|
TestProjects.repo_name, _ = push_image_to_project(project_test_quota_name, harbor_server, user_test_quota_name, user_001_password, image, src_tag)
|
||||||
|
|
||||||
|
#5. Get project quota
|
||||||
|
quota = self.system.get_project_quota("project", TestProjects.project_test_quota_id, **ADMIN_CLIENT)
|
||||||
|
self.assertEqual(quota[0].used["count"], 1)
|
||||||
|
self.assertEqual(quota[0].used["storage"], 2791709)
|
||||||
|
|
||||||
|
#6. Delete repository(RA) by user(UA);
|
||||||
|
self.repo.delete_repoitory(TestProjects.repo_name, **ADMIN_CLIENT)
|
||||||
|
|
||||||
|
#6. Quota should be 0
|
||||||
|
quota = self.system.get_project_quota("project", TestProjects.project_test_quota_id, **ADMIN_CLIENT)
|
||||||
|
self.assertEqual(quota[0].used["count"], 0)
|
||||||
|
self.assertEqual(quota[0].used["storage"], 0)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
@ -49,6 +49,8 @@ Test Case - Robot Account
|
|||||||
Harbor API Test ./tests/apitests/python/test_robot_account.py
|
Harbor API Test ./tests/apitests/python/test_robot_account.py
|
||||||
Test Case - Sign A Image
|
Test Case - Sign A Image
|
||||||
Harbor API Test ./tests/apitests/python/test_sign_image.py
|
Harbor API Test ./tests/apitests/python/test_sign_image.py
|
||||||
|
Test Case - Project Quota
|
||||||
|
Harbor API Test ./tests/apitests/python/test_project_quota.py
|
||||||
Test Case - System Level CVE Whitelist
|
Test Case - System Level CVE Whitelist
|
||||||
Harbor API Test ./tests/apitests/python/test_sys_cve_whitelists.py
|
Harbor API Test ./tests/apitests/python/test_sys_cve_whitelists.py
|
||||||
Test Case - Project Level CVE Whitelist
|
Test Case - Project Level CVE Whitelist
|
||||||
|
Loading…
Reference in New Issue
Block a user