| 
									
										
										
										
											2018-08-01 06:38:23 +08:00
										 |  |  | import time | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | import sys | 
					
						
							| 
									
										
										
										
											2020-11-04 10:13:12 +08:00
										 |  |  | import warnings | 
					
						
							|  |  |  | from functools import wraps | 
					
						
							| 
									
										
										
										
											2018-10-31 13:13:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-10 17:33:09 +08:00
										 |  |  | sys.path.insert(0, os.environ.get("SWAGGER_CLIENT_PATH", '')) | 
					
						
							| 
									
										
										
										
											2020-08-07 14:56:18 +08:00
										 |  |  | path=os.getcwd() + "/library" | 
					
						
							|  |  |  | sys.path.insert(0, path) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | path=os.getcwd() + "/tests/apitests/python/library" | 
					
						
							|  |  |  | sys.path.insert(0, path) | 
					
						
							| 
									
										
										
										
											2020-11-10 17:33:09 +08:00
										 |  |  | path=os.getcwd() + "/tests/apitests/python/" | 
					
						
							|  |  |  | sys.path.insert(0, path) | 
					
						
							|  |  |  | print(sys.path) | 
					
						
							| 
									
										
										
										
											2020-02-25 10:40:29 +08:00
										 |  |  | import v2_swagger_client | 
					
						
							| 
									
										
										
										
											2018-08-01 06:38:23 +08:00
										 |  |  | from swagger_client.rest import ApiException | 
					
						
							|  |  |  | import swagger_client.models | 
					
						
							|  |  |  | from pprint import pprint | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 14:24:13 +08:00
										 |  |  | admin_user = "admin" | 
					
						
							|  |  |  | admin_pwd = "Harbor12345" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-10 17:33:09 +08:00
										 |  |  | harbor_server = os.environ.get("HARBOR_HOST", '') | 
					
						
							| 
									
										
										
										
											2020-12-16 18:06:41 +08:00
										 |  |  | harbor_url = "https://{}".format(harbor_server) | 
					
						
							| 
									
										
										
										
											2018-11-20 14:24:13 +08:00
										 |  |  | #CLIENT=dict(endpoint="https://"+harbor_server+"/api") | 
					
						
							| 
									
										
										
										
											2020-02-07 15:04:25 +08:00
										 |  |  | ADMIN_CLIENT=dict(endpoint = os.environ.get("HARBOR_HOST_SCHEMA", "https")+ "://"+harbor_server+"/api/v2.0", username = admin_user, password =  admin_pwd) | 
					
						
							| 
									
										
										
										
											2020-03-31 12:35:03 +08:00
										 |  |  | CHART_API_CLIENT=dict(endpoint = os.environ.get("HARBOR_HOST_SCHEMA", "https")+ "://"+harbor_server+"/api", username = admin_user, password =  admin_pwd) | 
					
						
							| 
									
										
										
										
											2018-11-01 18:26:04 +08:00
										 |  |  | USER_ROLE=dict(admin=0,normal=1) | 
					
						
							| 
									
										
										
										
											2020-02-20 23:20:34 +08:00
										 |  |  | TEARDOWN = os.environ.get('TEARDOWN', 'true').lower() in ('true', 'yes') | 
					
						
							| 
									
										
										
										
											2020-06-04 18:17:26 +08:00
										 |  |  | notary_url = os.environ.get('NOTARY_URL', 'https://'+harbor_server+':4443') | 
					
						
							| 
									
										
										
										
											2020-11-10 17:33:09 +08:00
										 |  |  | DOCKER_USER = os.environ.get('DOCKER_USER', '') | 
					
						
							|  |  |  | DOCKER_PWD = os.environ.get('DOCKER_PWD', '') | 
					
						
							| 
									
										
										
										
											2021-01-07 18:34:01 +08:00
										 |  |  | METRIC_URL = os.environ.get('METRIC_URL', 'http://'+harbor_server+':9090') | 
					
						
							| 
									
										
										
											
												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 15:52:21 +08:00
										 |  |  | BASE_IMAGE = dict(name='busybox', tag='latest') | 
					
						
							|  |  |  | BASE_IMAGE_ABS_PATH_NAME = '/' + BASE_IMAGE['name'] + '.tar' | 
					
						
							| 
									
										
										
										
											2018-10-31 13:13:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-10 17:33:09 +08:00
										 |  |  | def GetProductApi(username, password, harbor_server= os.environ.get("HARBOR_HOST", '')): | 
					
						
							| 
									
										
										
										
											2019-05-06 11:34:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-01 06:38:23 +08:00
										 |  |  |     cfg = swagger_client.Configuration() | 
					
						
							| 
									
										
										
										
											2020-02-07 15:04:25 +08:00
										 |  |  |     cfg.host = "https://"+harbor_server+"/api/v2.0" | 
					
						
							| 
									
										
										
										
											2018-08-01 06:38:23 +08:00
										 |  |  |     cfg.username = username | 
					
						
							|  |  |  |     cfg.password = password | 
					
						
							|  |  |  |     cfg.verify_ssl = False | 
					
						
							|  |  |  |     cfg.debug = True | 
					
						
							|  |  |  |     api_client = swagger_client.ApiClient(cfg) | 
					
						
							|  |  |  |     api_instance = swagger_client.ProductsApi(api_client) | 
					
						
							| 
									
										
										
										
											2018-11-29 18:27:53 +08:00
										 |  |  |     return api_instance | 
					
						
							| 
									
										
										
										
											2020-02-25 10:40:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-10 17:33:09 +08:00
										 |  |  | def GetRepositoryApi(username, password, harbor_server= os.environ.get("HARBOR_HOST", '')): | 
					
						
							| 
									
										
										
										
											2020-02-25 10:40:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     cfg = v2_swagger_client.Configuration() | 
					
						
							|  |  |  |     cfg.host = "https://"+harbor_server+"/api/v2.0" | 
					
						
							|  |  |  |     cfg.username = username | 
					
						
							|  |  |  |     cfg.password = password | 
					
						
							|  |  |  |     cfg.verify_ssl = False | 
					
						
							|  |  |  |     cfg.debug = True | 
					
						
							|  |  |  |     api_client = v2_swagger_client.ApiClient(cfg) | 
					
						
							|  |  |  |     api_instance = v2_swagger_client.RepositoryApi(api_client) | 
					
						
							|  |  |  |     return api_instance | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-29 18:27:53 +08:00
										 |  |  | class TestResult(object): | 
					
						
							|  |  |  |     def __init__(self): | 
					
						
							|  |  |  |         self.num_errors = 0 | 
					
						
							|  |  |  |         self.error_message = [] | 
					
						
							|  |  |  |     def add_test_result(self, error_message): | 
					
						
							|  |  |  |         self.num_errors = self.num_errors + 1 | 
					
						
							|  |  |  |         self.error_message.append(error_message) | 
					
						
							|  |  |  |     def get_final_result(self): | 
					
						
							|  |  |  |         if self.num_errors > 0: | 
					
						
							|  |  |  |             for each_err_msg in self.error_message: | 
					
						
							| 
									
										
										
										
											2020-07-30 16:04:14 +08:00
										 |  |  |                 print("Error message:", each_err_msg) | 
					
						
							| 
									
										
										
										
											2018-11-29 18:27:53 +08:00
										 |  |  |             raise Exception(r"Test case failed with {} errors.".format(self.num_errors)) | 
					
						
							| 
									
										
										
										
											2020-03-12 11:50:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-04 10:13:12 +08:00
										 |  |  | def suppress_urllib3_warning(func): | 
					
						
							|  |  |  |     @wraps(func) | 
					
						
							|  |  |  |     def inner_func(*args): | 
					
						
							|  |  |  |         warnings.filterwarnings(action="ignore", | 
					
						
							|  |  |  |                                 message="unclosed", | 
					
						
							|  |  |  |                                 category=ResourceWarning) | 
					
						
							| 
									
										
										
										
											2020-11-10 17:33:09 +08:00
										 |  |  |         warnings.filterwarnings(action='ignore', message='Unverified HTTPS request') | 
					
						
							| 
									
										
										
										
											2020-11-04 10:13:12 +08:00
										 |  |  |         func(*args) | 
					
						
							|  |  |  |     return inner_func | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-12 11:50:30 +08:00
										 |  |  | from contextlib import contextmanager | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @contextmanager | 
					
						
							| 
									
										
										
										
											2020-12-16 18:06:41 +08:00
										 |  |  | def created_user(password, _teardown=None): | 
					
						
							| 
									
										
										
										
											2020-03-12 11:50:30 +08:00
										 |  |  |     from library.user import User | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     api = User() | 
					
						
							| 
									
										
										
										
											2020-12-16 18:06:41 +08:00
										 |  |  |     is_teardown = TEARDOWN | 
					
						
							|  |  |  |     if _teardown in (True, False): | 
					
						
							|  |  |  |         is_teardown = _teardown | 
					
						
							| 
									
										
										
										
											2020-03-12 11:50:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     user_id, user_name = api.create_user(user_password=password, **ADMIN_CLIENT) | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         yield (user_id, user_name) | 
					
						
							|  |  |  |     finally: | 
					
						
							| 
									
										
										
										
											2020-12-16 18:06:41 +08:00
										 |  |  |         if is_teardown: | 
					
						
							| 
									
										
										
										
											2020-03-12 11:50:30 +08:00
										 |  |  |             api.delete_user(user_id, **ADMIN_CLIENT) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @contextmanager | 
					
						
							| 
									
										
										
										
											2020-12-16 18:06:41 +08:00
										 |  |  | def created_project(name=None, metadata=None, user_id=None, member_role_id=None, _teardown=None): | 
					
						
							| 
									
										
										
										
											2020-03-12 11:50:30 +08:00
										 |  |  |     from library.project import Project | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     api = Project() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 18:06:41 +08:00
										 |  |  |     is_teardown = TEARDOWN | 
					
						
							|  |  |  |     if _teardown in (True, False): | 
					
						
							|  |  |  |         is_teardown = _teardown | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-17 17:55:38 +08:00
										 |  |  |     project_id, project_name = api.create_project(name=name, metadata=metadata, **ADMIN_CLIENT) | 
					
						
							| 
									
										
										
										
											2020-03-12 11:50:30 +08:00
										 |  |  |     if user_id: | 
					
						
							| 
									
										
										
										
											2020-08-17 14:51:18 +08:00
										 |  |  |         api.add_project_members(project_id, user_id=user_id, member_role_id=member_role_id, **ADMIN_CLIENT) | 
					
						
							| 
									
										
										
										
											2020-03-12 11:50:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         yield (project_id, project_name) | 
					
						
							|  |  |  |     finally: | 
					
						
							| 
									
										
										
										
											2020-12-16 18:06:41 +08:00
										 |  |  |         if is_teardown: | 
					
						
							| 
									
										
										
										
											2020-03-12 11:50:30 +08:00
										 |  |  |             api.delete_project(project_id, **ADMIN_CLIENT) |