From 08dfd72052d834b94551a84de52bbc0a398e59d5 Mon Sep 17 00:00:00 2001 From: airycanon Date: Thu, 19 Dec 2024 10:04:32 +0800 Subject: [PATCH] fix e2e --- .build/build-e2e.yaml | 52 +++++ .build/e2e.yaml | 85 ++++++++ Makefile | 2 +- tests/apitests/python/library/base.py | 31 ++- tests/apitests/python/library/containerd.py | 8 +- tests/apitests/python/library/docker_api.py | 20 +- tests/apitests/python/library/helm.py | 10 +- tests/apitests/python/library/notation.py | 8 +- tests/apitests/python/library/oras.py | 13 +- tests/apitests/python/library/podman.py | 6 +- .../apitests/python/library/referrers_api.py | 6 +- .../python/test_add_replication_rule.py | 4 +- .../test_copy_artifact_outside_project.py | 4 +- tests/apitests/python/test_del_repo.py | 4 +- .../python/test_job_service_dashboard.py | 4 +- ...test_project_level_policy_content_trust.py | 3 - .../test_push_index_by_docker_manifest.py | 6 +- tests/apitests/python/test_referrers_api.py | 10 +- tests/apitests/python/test_registry_api.py | 19 +- tests/apitests/python/test_retention.py | 6 +- tests/apitests/python/test_tag_crud.py | 4 +- tests/apitests/python/test_user_group.py | 5 +- tests/apitests/python/testutils.py | 14 +- tests/ci/api_run.sh | 58 ++--- tests/resources/Docker-Util.robot | 15 +- tests/resources/Harbor-Util.robot | 2 +- tests/resources/Nightly-Util.robot | 6 +- tests/robot-cases/Group0-BAT/API_DB.robot | 19 -- .../Group0-BAT/API_DB_SUCCESS.robot | 205 ++++++++++++++++++ tests/test-engine-image/Dockerfile.api_test | 2 +- tests/test-engine-image/Dockerfile.common | 2 +- tests/test-engine-image/generate.sh | 27 +++ 32 files changed, 525 insertions(+), 135 deletions(-) create mode 100644 .build/build-e2e.yaml create mode 100644 .build/e2e.yaml create mode 100644 tests/robot-cases/Group0-BAT/API_DB_SUCCESS.robot create mode 100755 tests/test-engine-image/generate.sh diff --git a/.build/build-e2e.yaml b/.build/build-e2e.yaml new file mode 100644 index 00000000000..0005f2c8ba9 --- /dev/null +++ b/.build/build-e2e.yaml @@ -0,0 +1,52 @@ +apiVersion: builds.katanomi.dev/v1alpha1 +kind: Build +spec: + workspaces: + - description: | + This workspace is shared among all the pipeline tasks to read/write common resources + name: source + tasks: + - name: prepare-dockerfile + timeout: 30m + retries: 0 + taskRef: + kind: ClusterTask + name: alauda-script + workspaces: + - name: source + workspace: source + params: + - name: tool-image + value: registry.alauda.cn:60080/fundamentals/katanomi-ci-builder:master + - name: script + value: | + cd tests/test-engine-image && ./generate.sh api + - name: build-image-amd + timeout: 60m + retries: 0 + runAfter: + - prepare-dockerfile + taskRef: + kind: ClusterTask + name: build-image-buildkit + workspaces: + - name: source + workspace: source + - name: cache + - name: config + when: [] + params: + - name: reuse-image + value: "false" + - name: dockerfile + value: tests/test-engine-image/Dockerfile + - name: context + value: tests/test-engine-image + - name: container-images + value: + - build-harbor.alauda.cn/fundamentals/harbor-e2e-engine:5.3.0-api + - name: labels + value: + - branch=$(build.git.branch.name) + - commit=$(build.git.lastCommit.id) + - commit_id=$(build.git.lastCommit.id) diff --git a/.build/e2e.yaml b/.build/e2e.yaml new file mode 100644 index 00000000000..65325abfcde --- /dev/null +++ b/.build/e2e.yaml @@ -0,0 +1,85 @@ +apiVersion: builds.katanomi.dev/v1alpha1 +kind: Build +spec: + git: + options: + depth: 3 + resources: + limits: + cpu: 200m + memory: 200Mi + requests: + cpu: 200m + memory: 200Mi + workspaces: + - name: source + params: + - name: HARBOR_PASSWORD + description: 密码 + type: string + default: Harbor12345 + - name: HARBOR_HOST + description: harbor 地址,访问地址去掉协议的部分,如 harbor.test、127.0.0.1:8080 + type: string + default: "" + - name: HARBOR_HOST_SCHEMA + description: harbor 地址的协议,http 或者 https + type: string + default: "http" + - name: TEST_IMAGE + description: 测试镜像的地址 + type: string + default: "build-harbor.alauda.cn/fundamentals/harbor-e2e-engine:5.3.0-api" + tasks: + - name: api-test + timeout: 2.5h + retries: 0 + taskRef: + resolver: katanomi.dev.gitsource + params: + - name: url + value: https://gitlab-ce.alauda.cn/devops/edge + - name: revision + value: refs/heads/master + - name: pathInRepo + value: tasks/docker-in-docker/0.1/docker-in-docker.yaml + workspaces: + - name: source + workspace: source + params: + - name: command + value: | + export HARBOR_HOST=$(params.HARBOR_HOST) + export HARBOR_HOST_SCHEMA=$(params.HARBOR_HOST_SCHEMA) + export HARBOR_PASSWORD=$(params.HARBOR_PASSWORD) + export E2E_IMAGE=$(params.TEST_IMAGE) + + ./tests/ci/api_run.sh DB $(params.HARBOR_HOST) + + - name: upload-report + timeout: 30m + retries: 0 + runAfter: + - api-test + taskRef: + resolver: katanomi.hub + params: + - name: kind + value: task + - name: name + value: upload-files + workspaces: + - name: source + workspace: source + params: + - name: artifacts-path + value: + - $(workspaces.source.path)/log.html + - name: artifact-repository + value: https://build-nexus.alauda.cn/repository/alauda/ + - name: target-path + value: ./devops/pipeline-report/harbor-e2e/$(build.git.branch)/ + - name: checksum + value: "false" + - name: upload-pack + value: "false" diff --git a/Makefile b/Makefile index cbad61ca698..110c23eb48c 100644 --- a/Makefile +++ b/Makefile @@ -533,7 +533,7 @@ restart: down prepare start swagger_client: @echo "Generate swagger client" - wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/4.3.1/openapi-generator-cli-4.3.1.jar -O openapi-generator-cli.jar + wget https://build-nexus.alauda.cn/repository/maven-central/org/openapitools/openapi-generator-cli/4.3.1/openapi-generator-cli-4.3.1.jar -O openapi-generator-cli.jar rm -rf harborclient mkdir -p harborclient/harbor_v2_swagger_client java -jar openapi-generator-cli.jar generate -i api/v2.0/swagger.yaml -g python -o harborclient/harbor_v2_swagger_client --package-name v2_swagger_client diff --git a/tests/apitests/python/library/base.py b/tests/apitests/python/library/base.py index 4b73b9feffb..5622f2285f2 100644 --- a/tests/apitests/python/library/base.py +++ b/tests/apitests/python/library/base.py @@ -5,6 +5,9 @@ import v2_swagger_client +import logging + + try: from urllib import getproxies except ImportError: @@ -23,7 +26,8 @@ def __init__(self, type, username, password): def get_endpoint(): harbor_server = os.environ.get("HARBOR_HOST", "localhost:8080") - return os.environ.get("HARBOR_HOST_SCHEMA", "https")+ "://"+harbor_server+"/api/v2.0" + harbor_schema = os.environ.get("HARBOR_HOST_SCHEMA", "https") + return harbor_schema+"://"+harbor_server+"/api/v2.0" def _create_client(server, credential, debug, api_type): cfg = v2_swagger_client.Configuration() @@ -108,22 +112,22 @@ def restart_process(process): full_process_name = "/usr/local/bin/containerd" else: raise Exception("Please input dockerd or containerd for process retarting.") - run_command_with_popen("ps aux |grep " + full_process_name) - for i in range(10): - pid = run_command_with_popen(["pidof " + full_process_name]) - if pid in [None, ""]: - break - run_command_with_popen(["kill " + str(pid)]) + + pid = run_command_with_popen(f"ps aux | grep -v grep | grep {full_process_name} | awk '{{print $2}}'") + if pid: + run_command_with_popen("kill " + str(pid)) time.sleep(3) - run_command_with_popen("ps aux |grep " + full_process_name) run_command_with_popen("rm -rf /var/lib/" + process + "/*") run_command_with_popen(full_process_name + " > ./daemon-local.log 2>&1 &") - time.sleep(3) - pid = run_command_with_popen(["pidof " + full_process_name]) + for i in range(10): + pid = run_command_with_popen(f"ps aux | grep -v grep | grep {full_process_name} | awk '{{print $2}}'") + if pid: + break + time.sleep(3) + if pid in [None, ""]: raise Exception("Failed to start process {}.".format(full_process_name)) - run_command_with_popen("ps aux |grep " + full_process_name) def run_command_with_popen(command): try: @@ -158,13 +162,16 @@ def __init__(self, server=None, credential=None, debug=True, api_type=""): server.verify_ssl = server.verify_ssl == "True" if credential is None: - credential = Credential(type="basic_auth", username="admin", password="Harbor12345") + password = os.environ.get("HARBOR_PASSWORD","Harbor12345") + credential = Credential(type="basic_auth", username="admin", password=password) self.server = server self.credential = credential self.debug = debug self.api_type = api_type self.client = _create_client(server, credential, debug, api_type=api_type) + self.logger = logging.getLogger(__name__) + def _get_client(self, **kwargs): if len(kwargs) == 0: diff --git a/tests/apitests/python/library/containerd.py b/tests/apitests/python/library/containerd.py index f8d5c82c60f..97d2ca568df 100644 --- a/tests/apitests/python/library/containerd.py +++ b/tests/apitests/python/library/containerd.py @@ -1,11 +1,12 @@ # -*- coding: utf-8 -*- +import os import base import json import docker_api def ctr_images_pull(username, password, oci): - command = ["ctr", "images", "pull","--snapshotter", "native", "-u", username+":"+password, oci] + command = ["ctr", "images", "pull", *insecure_opt(), "--snapshotter", "native", "-u", username+":"+password, oci] ret = base.run_command(command) def ctr_images_list(oci_ref = None): @@ -15,3 +16,8 @@ def ctr_images_list(oci_ref = None): raise Exception(r" Get OCI ref failed, expected ref is [{}], but return ref list is [{}]".format (ret)) +def insecure_opt(): + schema = os.environ.get("HARBOR_HOST_SCHEMA", "https") + if schema == "http": + return ["--plain-http"] + return ["--skip-verify"] diff --git a/tests/apitests/python/library/docker_api.py b/tests/apitests/python/library/docker_api.py index e18b18173e7..69a6ac45dfc 100644 --- a/tests/apitests/python/library/docker_api.py +++ b/tests/apitests/python/library/docker_api.py @@ -31,7 +31,7 @@ def docker_login_cmd(harbor_host, username, password, cfg_file = "./tests/apites raise Exception("Failed to update docker config.") def docker_manifest_create(index, manifests): - command = ["docker","manifest","create", "--amend", index] + command = ["docker","manifest","create","--insecure","--amend", index] command.extend(manifests) base.run_command(command) @@ -52,7 +52,7 @@ def docker_image_clean_all(): docker_images_all_list() def docker_manifest_push(index): - command = ["docker","manifest","push",index] + command = ["docker","manifest","push","--insecure", index] ret = base.run_command(command) index_sha256="" manifest_list=[] @@ -68,24 +68,24 @@ def docker_manifest_push_to_harbor(index, manifests, harbor_server, username, pa docker_manifest_create(index, manifests) return docker_manifest_push(index) -def list_repositories(harbor_host, username, password, n = None, last = None): +def list_repositories(harbor_url, username, password, n = None, last = None): if n is not None and last is not None: - command = ["curl", "-s", "-u", username+":"+password, "https://"+harbor_host+"/v2/_catalog"+"?n=%d"%n+"&last="+last, "--insecure"] + command = ["curl", "-s", "-u", username+":"+password, harbor_url+"/v2/_catalog"+"?n=%d"%n+"&last="+last, "--insecure"] elif n is not None: - command = ["curl", "-s", "-u", username+":"+password, "https://"+harbor_host+"/v2/_catalog"+"?n=%d"%n, "--insecure"] + command = ["curl", "-s", "-u", username+":"+password, harbor_url+"/v2/_catalog"+"?n=%d"%n, "--insecure"] else: - command = ["curl", "-s", "-u", username+":"+password, "https://"+harbor_host+"/v2/_catalog", "--insecure"] + command = ["curl", "-s", "-u", username+":"+password, harbor_url+"/v2/_catalog", "--insecure"] ret = base.run_command(command) repos = json.loads(ret).get("repositories","") return repos -def list_image_tags(harbor_host, repository, username, password, n = None, last = None): +def list_image_tags(harbor_url, repository, username, password, n = None, last = None): if n is not None and last is not None: - command = ["curl", "-s", "-u", username+":"+password, "https://"+harbor_host+"/v2/"+repository+"/tags/list"+"?n=%d"%n+"&last="+last, "--insecure"] + command = ["curl", "-s", "-u", username+":"+password, harbor_url+"/v2/"+repository+"/tags/list"+"?n=%d"%n+"&last="+last, "--insecure"] elif n is not None: - command = ["curl", "-s", "-u", username+":"+password, "https://"+harbor_host+"/v2/"+repository+"/tags/list"+"?n=%d"%n, "--insecure"] + command = ["curl", "-s", "-u", username+":"+password, harbor_url+"/v2/"+repository+"/tags/list"+"?n=%d"%n, "--insecure"] else: - command = ["curl", "-s", "-u", username+":"+password, "https://"+harbor_host+"/v2/"+repository+"/tags/list", "--insecure"] + command = ["curl", "-s", "-u", username+":"+password, harbor_url+"/v2/"+repository+"/tags/list", "--insecure"] ret = base.run_command(command) tags = json.loads(ret).get("tags","") return tags diff --git a/tests/apitests/python/library/helm.py b/tests/apitests/python/library/helm.py index d475a71aeab..e316d81379b 100644 --- a/tests/apitests/python/library/helm.py +++ b/tests/apitests/python/library/helm.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- - +import os import base @@ -12,5 +12,11 @@ def helm_package(file_path): base.run_command(command) def helm_push(file_path, ip, project_name): - command = ["helm", "push", file_path, "oci://{}/{}".format(ip, project_name), "--insecure-skip-tls-verify"] + command = ["helm", "push", file_path, "oci://{}/{}".format(ip, project_name), *insecure_opt()] base.run_command(command) + +def insecure_opt(): + schema = os.environ.get("HARBOR_HOST_SCHEMA", "https") + if schema == "http": + return ["--plain-http"] + return ["--insecure-skip-tls-verify"] diff --git a/tests/apitests/python/library/notation.py b/tests/apitests/python/library/notation.py index 7a7c7333048..5ea944b81db 100644 --- a/tests/apitests/python/library/notation.py +++ b/tests/apitests/python/library/notation.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import os import base def generate_cert(): @@ -6,5 +7,10 @@ def generate_cert(): base.run_command(command) def sign_artifact(artifact): - command = ["notation", "sign", "-d", "--allow-referrers-api", artifact] + if os.environ.get("HARBOR_HOST_SCHEMA") == "http": + insecure = ["--insecure-registry"] + else: + insecure = [] + + command = ["notation", "sign", *insecure, "-d", "--allow-referrers-api", artifact] base.run_command(command) diff --git a/tests/apitests/python/library/oras.py b/tests/apitests/python/library/oras.py index e862a54efb5..b492be0e5cd 100644 --- a/tests/apitests/python/library/oras.py +++ b/tests/apitests/python/library/oras.py @@ -34,7 +34,7 @@ def oras_push(harbor_server, user, password, project, repo, tag): def oras_push_cmd(harbor_server, project, repo, tag): try: - ret = base.run_command( [oras_cmd, "push", harbor_server + "/" + project + "/" + repo+":"+ tag, + ret = base.run_command( [oras_cmd, "push", *insecure_opt(), harbor_server + "/" + project + "/" + repo+":"+ tag, "--config", "config.json:application/vnd.acme.rocket.config.v1+json", \ file_artifact+":application/vnd.acme.rocket.layer.v1+txt", \ file_readme +":application/vnd.acme.rocket.docs.layer.v1+json"] ) @@ -44,7 +44,7 @@ def oras_push_cmd(harbor_server, project, repo, tag): return e def oras_login(harbor_server, user, password): - ret = base.run_command([oras_cmd, "login", "-u", user, "-p", password, harbor_server]) + ret = base.run_command([oras_cmd, "login", *insecure_opt(), "-u", user, "-p", password, harbor_server]) def oras_pull(harbor_server, user, password, project, repo, tag): try: @@ -56,7 +56,14 @@ def oras_pull(harbor_server, user, password, project, repo, tag): os.chdir(cwd) except Exception as e: raise Exception('Error: Exited with error {}',format(e)) - ret = base.run_command([oras_cmd, "pull", harbor_server + "/" + project + "/" + repo+":"+ tag]) + ret = base.run_command([oras_cmd, "pull", *insecure_opt(), harbor_server + "/" + project + "/" + repo+":"+ tag]) assert os.path.exists(file_artifact) assert os.path.exists(file_readme) return base.run_command( ["md5sum", file_artifact] ).split(' ')[0], base.run_command( [ "md5sum", file_readme] ).split(' ')[0] + +def insecure_opt(): + schema = os.environ.get("HARBOR_HOST_SCHEMA", "https") + if schema == "http": + return ["--plain-http"] + + return ["--insecure"] diff --git a/tests/apitests/python/library/podman.py b/tests/apitests/python/library/podman.py index c8d54dcdc7b..25e34c9fe1b 100644 --- a/tests/apitests/python/library/podman.py +++ b/tests/apitests/python/library/podman.py @@ -2,7 +2,7 @@ import base def login(registry, username, password): - command = ["podman", "login", "-u", username, "-p", password, registry] + command = ["podman", "login", "--tls-verify=false", "-u", username, "-p", password, registry] base.run_command(command) def logout(registry): @@ -10,9 +10,9 @@ def logout(registry): base.run_command(command) def pull(artifact): - command = ["podman", "pull", artifact] + command = ["podman", "pull", "--tls-verify=false", artifact] base.run_command(command) def push(source_artifact, target_artifact): - command = ["podman", "push", source_artifact, target_artifact] + command = ["podman", "push", "--tls-verify=false", source_artifact, target_artifact] base.run_command(command) diff --git a/tests/apitests/python/library/referrers_api.py b/tests/apitests/python/library/referrers_api.py index 5d51a6d5309..74e3d55498a 100644 --- a/tests/apitests/python/library/referrers_api.py +++ b/tests/apitests/python/library/referrers_api.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- import requests -def call(server, project_name, repo_name, digest, artifactType=None, **kwargs): +def call(harbor_url, project_name, repo_name, digest, artifactType=None, **kwargs): url=None auth = (kwargs.get("username"), kwargs.get("password")) if artifactType: artifactType = artifactType.replace("+", "%2B") - url="https://{}/v2/{}/{}/referrers/{}?artifactType={}".format(server, project_name, repo_name, digest, artifactType) + url="{}/v2/{}/{}/referrers/{}?artifactType={}".format(harbor_url, project_name, repo_name, digest, artifactType) else: - url="https://{}/v2/{}/{}/referrers/{}".format(server, project_name, repo_name, digest) + url="{}/v2/{}/{}/referrers/{}".format(harbor_url, project_name, repo_name, digest) return requests.get(url, auth=auth, verify=False) diff --git a/tests/apitests/python/test_add_replication_rule.py b/tests/apitests/python/test_add_replication_rule.py index cca2f8045ae..5d7686d9547 100644 --- a/tests/apitests/python/test_add_replication_rule.py +++ b/tests/apitests/python/test_add_replication_rule.py @@ -2,7 +2,7 @@ import unittest from testutils import ADMIN_CLIENT, suppress_urllib3_warning -from testutils import harbor_server +from testutils import harbor_url, admin_user, admin_pwd from testutils import TEARDOWN from library.project import Project from library.user import User @@ -64,7 +64,7 @@ def testAddReplicationRule(self): expected_project_id = TestProjects.project_add_rule_id, **TestProjects.USER_add_rule_CLIENT) #3. Create a new registry - TestProjects.registry_id, _ = self.registry.create_registry("https://" + harbor_server,**ADMIN_CLIENT) + TestProjects.registry_id, _ = self.registry.create_registry(harbor_url, access_key= admin_user, access_secret = admin_pwd, **ADMIN_CLIENT) #4. Create a new rule for this registry; TestProjects.rule_id, rule_name = self.replication.create_replication_policy(dest_registry=v2_swagger_client.Registry(id=int(TestProjects.registry_id)), **ADMIN_CLIENT) diff --git a/tests/apitests/python/test_copy_artifact_outside_project.py b/tests/apitests/python/test_copy_artifact_outside_project.py index 085943a508f..c6c4df7ccaf 100644 --- a/tests/apitests/python/test_copy_artifact_outside_project.py +++ b/tests/apitests/python/test_copy_artifact_outside_project.py @@ -4,7 +4,7 @@ import unittest from testutils import ADMIN_CLIENT, suppress_urllib3_warning -from testutils import harbor_server +from testutils import harbor_server, admin_user, admin_pwd from testutils import TEARDOWN from library.base import _assert_status_code from library.artifact import Artifact @@ -83,7 +83,7 @@ def testRetag(self): self.project.update_project_member_role(TestProjects.project_dst_repo_id, retag_member_id, 3, **ADMIN_CLIENT) #5. Create a new repository(RA) in project(PA) by user(UA); - TestProjects.src_repo_name, tag_name = push_self_build_image_to_project(TestProjects.project_src_repo_name, harbor_server, 'admin', 'Harbor12345', "test_copy", pull_tag_name) + TestProjects.src_repo_name, tag_name = push_self_build_image_to_project(TestProjects.project_src_repo_name, harbor_server, admin_user, admin_pwd, "test_copy", pull_tag_name) #6. Get repository in project(PA), there should be one repository which was created by user(UA); src_repo_data = self.repo.list_repositories(TestProjects.project_src_repo_name, **TestProjects.USER_RETAG_CLIENT) diff --git a/tests/apitests/python/test_del_repo.py b/tests/apitests/python/test_del_repo.py index ccde66da5e0..d797f8b12c2 100644 --- a/tests/apitests/python/test_del_repo.py +++ b/tests/apitests/python/test_del_repo.py @@ -4,7 +4,7 @@ import unittest from testutils import ADMIN_CLIENT, suppress_urllib3_warning -from testutils import harbor_server +from testutils import harbor_server, admin_user, admin_pwd from testutils import TEARDOWN from library.base import _assert_status_code from library.project import Project @@ -54,7 +54,7 @@ def testDelRepo(self): TestProjects.project_del_repo_id, TestProjects.project_del_repo_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_del_repo_CLIENT) #3. Create a new repository(RA) in project(PA) by user(UA); - repo_name, _ = push_self_build_image_to_project(TestProjects.project_del_repo_name, harbor_server, 'admin', 'Harbor12345', "test_del_repo", "latest", size=512) + repo_name, _ = push_self_build_image_to_project(TestProjects.project_del_repo_name, harbor_server, admin_user, admin_pwd, "test_del_repo", "latest", size=512) #4. Get repository in project(PA), there should be one repository which was created by user(UA); repo_data = self.repo.list_repositories(TestProjects.project_del_repo_name, **TestProjects.USER_del_repo_CLIENT) diff --git a/tests/apitests/python/test_job_service_dashboard.py b/tests/apitests/python/test_job_service_dashboard.py index fd71c4c5a1a..f4560fd0378 100644 --- a/tests/apitests/python/test_job_service_dashboard.py +++ b/tests/apitests/python/test_job_service_dashboard.py @@ -4,7 +4,7 @@ import unittest import v2_swagger_client from library import base -from testutils import harbor_server, ADMIN_CLIENT, suppress_urllib3_warning +from testutils import harbor_url, admin_pwd, ADMIN_CLIENT, suppress_urllib3_warning from library.jobservice import Jobservice from library.gc import GC from library.purge import Purge @@ -197,7 +197,7 @@ def testSchedules(self): preheat_policy = self.preheat.get_policy(project_name, preheat_policy_name) # 5. Create a new registry - registry_id, _ = self.registry.create_registry("https://" + harbor_server) + registry_id, _ = self.registry.create_registry(url = harbor_url, access_secret = admin_pwd) # 6. Create a replication policy triggered by schedule replication_id, _ = self.replication.create_replication_policy(dest_registry=v2_swagger_client.Registry(id=int(registry_id)), trigger=v2_swagger_client.ReplicationTrigger(type="scheduled",trigger_settings=v2_swagger_client.ReplicationTriggerSettings(cron=self.cron))) diff --git a/tests/apitests/python/test_project_level_policy_content_trust.py b/tests/apitests/python/test_project_level_policy_content_trust.py index 5e174de5ba5..aa1083cc5ed 100644 --- a/tests/apitests/python/test_project_level_policy_content_trust.py +++ b/tests/apitests/python/test_project_level_policy_content_trust.py @@ -81,9 +81,6 @@ def testProjectLevelPolicyContentTrust(self): #7. Pull image(IA) failed and the reason is "The image is not signed". docker_image_clean_all() - restart_process("containerd") - restart_process("dockerd") - time.sleep(30) pull_harbor_image(harbor_server, ADMIN_CLIENT["username"], ADMIN_CLIENT["password"], TestProjects.repo_name, tag, expected_error_message = "The image is not signed by cosign") if __name__ == '__main__': diff --git a/tests/apitests/python/test_push_index_by_docker_manifest.py b/tests/apitests/python/test_push_index_by_docker_manifest.py index b9bc7f0fb8f..a04623a6b0d 100644 --- a/tests/apitests/python/test_push_index_by_docker_manifest.py +++ b/tests/apitests/python/test_push_index_by_docker_manifest.py @@ -4,7 +4,7 @@ import unittest from testutils import ADMIN_CLIENT, suppress_urllib3_warning -from testutils import harbor_server +from testutils import harbor_server, admin_user, admin_pwd from testutils import TEARDOWN import library.repository import library.docker_api @@ -85,8 +85,8 @@ def test_01_AddIndexByDockerManifest(self): TestManifest.project_id, TestManifest.project_name = TestManifest.project.create_project(metadata = {"public": "false"}, **TestManifest.USER_CLIENT) #3. Create 2 new repositorys(RA,RB) in project(PA) by user(UA); - repo_name_a, tag_a = push_self_build_image_to_project(TestManifest.project_name, harbor_server, 'admin', 'Harbor12345', TestManifest.image_a, "latest") - repo_name_b, tag_b = push_self_build_image_to_project(TestManifest.project_name, harbor_server, 'admin', 'Harbor12345', TestManifest.image_b, "latest") + repo_name_a, tag_a = push_self_build_image_to_project(TestManifest.project_name, harbor_server, admin_user, admin_pwd, TestManifest.image_a, "latest") + repo_name_b, tag_b = push_self_build_image_to_project(TestManifest.project_name, harbor_server, admin_user, admin_pwd, TestManifest.image_b, "latest") #4. Push an index(IA) to Harbor by docker manifest CLI successfully; manifests = [harbor_server+"/"+repo_name_a+":"+tag_a, harbor_server+"/"+repo_name_b+":"+tag_b] diff --git a/tests/apitests/python/test_referrers_api.py b/tests/apitests/python/test_referrers_api.py index a62f1dbfc6d..79e129b3e26 100644 --- a/tests/apitests/python/test_referrers_api.py +++ b/tests/apitests/python/test_referrers_api.py @@ -3,7 +3,7 @@ from __future__ import absolute_import import unittest -from testutils import harbor_server, files_directory, ADMIN_CLIENT, suppress_urllib3_warning +from testutils import harbor_server, harbor_url, files_directory, ADMIN_CLIENT, suppress_urllib3_warning from library import cosign, referrers_api from library.project import Project from library.user import User @@ -73,7 +73,7 @@ def testReferrersApi(self): cosign.sign_artifact("{}/{}/{}@{}".format(harbor_server, project_name, self.image, sbom_digest)) # 7. Call the referrers api successfully - res_json = referrers_api.call(harbor_server, project_name, self.image, artifact_digest, **user_client).json() + res_json = referrers_api.call(harbor_url, project_name, self.image, artifact_digest, **user_client).json() self.assertEqual(len(res_json["manifests"]), 2) for manifest in res_json["manifests"]: self.assertIn(manifest["digest"], [signature_digest, sbom_digest]) @@ -81,7 +81,7 @@ def testReferrersApi(self): self.assertIsNotNone(manifest["mediaType"]) self.assertIsNotNone(manifest["size"]) - res_json = referrers_api.call(harbor_server, project_name, self.image, sbom_digest, **user_client).json() + res_json = referrers_api.call(harbor_url, project_name, self.image, sbom_digest, **user_client).json() self.assertEqual(len(res_json["manifests"]), 1) manifest = res_json["manifests"][0] self.assertIsNotNone(manifest["digest"]) @@ -90,7 +90,7 @@ def testReferrersApi(self): self.assertIsNotNone(manifest["size"]) # 8. Call the referrers api and filter artifact_type - res = referrers_api.call(harbor_server, project_name, self.image, artifact_digest, self.sbom_artifact_type, **user_client) + res = referrers_api.call(harbor_url, project_name, self.image, artifact_digest, self.sbom_artifact_type, **user_client) self.assertEqual(res.headers["Oci-Filters-Applied"], "artifactType") res_json = res.json() self.assertEqual(len(res_json["manifests"]), 1) @@ -100,7 +100,7 @@ def testReferrersApi(self): self.assertIsNotNone(manifest["mediaType"]) self.assertIsNotNone(manifest["size"]) - res = referrers_api.call(harbor_server, project_name, self.image, artifact_digest, self.signature_artifact_type, **user_client) + res = referrers_api.call(harbor_url, project_name, self.image, artifact_digest, self.signature_artifact_type, **user_client) self.assertEqual(res.headers["Oci-Filters-Applied"], "artifactType") res_json = res.json() self.assertEqual(len(res_json["manifests"]), 1) diff --git a/tests/apitests/python/test_registry_api.py b/tests/apitests/python/test_registry_api.py index 179ad758085..77bc745a4c9 100644 --- a/tests/apitests/python/test_registry_api.py +++ b/tests/apitests/python/test_registry_api.py @@ -1,9 +1,8 @@ from __future__ import absolute_import import unittest -from testutils import harbor_server, suppress_urllib3_warning -from testutils import admin_user -from testutils import admin_pwd +from testutils import harbor_server, harbor_url, suppress_urllib3_warning +from testutils import admin_user, admin_pwd from testutils import TEARDOWN from testutils import ADMIN_CLIENT from library.system import System @@ -80,24 +79,24 @@ def testRegistryAPI(self): for tag in create_tags: self.artifact.create_tag(TestProjects.project_Alice_name, image_c, tag_c, tag, **USER_ALICE_CLIENT) #4. Call the image_list_tags API - tags = list_image_tags(harbor_server,TestProjects.repo_c,user_Alice_name,user_common_password) + tags = list_image_tags(harbor_url,TestProjects.repo_c,user_Alice_name,user_common_password) for tag in create_tags: self.assertTrue(tags.count(tag)>0, "Expect tag: %s is not listed"%tag) - page_tags = list_image_tags(harbor_server,TestProjects.repo_c,user_Alice_name,user_common_password,len(tags)/2+1) - page_tags += list_image_tags(harbor_server,TestProjects.repo_c,user_Alice_name,user_common_password,len(tags)/2+1,tags[int(len(tags)/2)]) + page_tags = list_image_tags(harbor_url,TestProjects.repo_c,user_Alice_name,user_common_password,len(tags)/2+1) + page_tags += list_image_tags(harbor_url,TestProjects.repo_c,user_Alice_name,user_common_password,len(tags)/2+1,tags[int(len(tags)/2)]) for tag in create_tags: self.assertTrue(page_tags.count(tag)>0, "Expect tag: %s is not listed by the pagination query"%tag) #5. Call the catalog API; - repos = list_repositories(harbor_server,admin_user,admin_pwd) + repos = list_repositories(harbor_url,admin_user,admin_pwd) self.assertTrue(repos.count(TestProjects.repo_a)>0 and repos.count(TestProjects.repo_b)>0 and repos.count(TestProjects.repo_c)>0, "Expected repo not found") for repo in [TestProjects.repo_a,TestProjects.repo_b,TestProjects.repo_c]: self.assertTrue(repos.count(repo)>0,"Expected repo: %s is not listed"%repo) - page_repos = list_repositories(harbor_server,admin_user,admin_pwd,len(repos)/2+1) - page_repos += list_repositories(harbor_server,admin_user,admin_pwd,len(repos)/2+1,repos[int(len(repos)/2)]) + page_repos = list_repositories(harbor_url,admin_user,admin_pwd,len(repos)/2+1) + page_repos += list_repositories(harbor_url,admin_user,admin_pwd,len(repos)/2+1,repos[int(len(repos)/2)]) for repo in [TestProjects.repo_a,TestProjects.repo_b,TestProjects.repo_c]: self.assertTrue(page_repos.count(repo)>0,"Expected repo: %s is not listed by the pagination query"%repo) - null_repos = list_repositories(harbor_server,user_Alice_name,user_common_password) + null_repos = list_repositories(harbor_url,user_Alice_name,user_common_password) self.assertEqual(null_repos, "") if __name__ == '__main__': diff --git a/tests/apitests/python/test_retention.py b/tests/apitests/python/test_retention.py index dd53ee33a43..51f8af23a1e 100644 --- a/tests/apitests/python/test_retention.py +++ b/tests/apitests/python/test_retention.py @@ -5,7 +5,7 @@ from testutils import ADMIN_CLIENT, suppress_urllib3_warning from testutils import TEARDOWN -from testutils import harbor_server +from testutils import harbor_url, harbor_server from library.repository import push_special_image_to_project from library.docker_api import list_image_tags from library.retention import Retention @@ -76,11 +76,11 @@ def testTagRetention(self): tag_data_artifact2_image2 = self.artifact.get_reference_info(TestProjects.project_src_repo_name, self.repo_name_2, "latest", **TestProjects.USER_RA_CLIENT) - tags = list_image_tags(harbor_server, TestProjects.project_src_repo_name+"/"+self.repo_name_1, user_ra_name, user_ra_password) + tags = list_image_tags(harbor_url, TestProjects.project_src_repo_name+"/"+self.repo_name_1, user_ra_name, user_ra_password) #Delete all 2 tags of "artifact3" in repostory "image1"; self.artifact.delete_tag(TestProjects.project_src_repo_name, self.repo_name_1, "3.0", "latest", **TestProjects.USER_RA_CLIENT) self.artifact.delete_tag(TestProjects.project_src_repo_name, self.repo_name_1, "3.0", "3.0", **TestProjects.USER_RA_CLIENT) - tags = list_image_tags(harbor_server, TestProjects.project_src_repo_name+"/"+self.repo_name_1, user_ra_name, user_ra_password) + tags = list_image_tags(harbor_url, TestProjects.project_src_repo_name+"/"+self.repo_name_1, user_ra_name, user_ra_password) resp=self.repo.list_repositories(TestProjects.project_src_repo_name, **TestProjects.USER_RA_CLIENT) self.assertEqual(len(resp), 4) diff --git a/tests/apitests/python/test_tag_crud.py b/tests/apitests/python/test_tag_crud.py index d06c65caeba..1d171197191 100644 --- a/tests/apitests/python/test_tag_crud.py +++ b/tests/apitests/python/test_tag_crud.py @@ -4,7 +4,7 @@ import unittest from testutils import ADMIN_CLIENT, suppress_urllib3_warning -from testutils import harbor_server +from testutils import harbor_server, admin_user, admin_pwd from testutils import TEARDOWN import library.repository import library.docker_api @@ -67,7 +67,7 @@ def testCreateDeleteTag(self): TestProjects.project_id, TestProjects.project_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_CLIENT) #3. Push an image(IA) to Harbor by docker successfully; - repo_name, tag = push_self_build_image_to_project(TestProjects.project_name, harbor_server, 'admin', 'Harbor12345', self.repo_name, "latest") + repo_name, tag = push_self_build_image_to_project(TestProjects.project_name, harbor_server, admin_user, admin_pwd, self.repo_name, "latest") #4. Create a tag(1.0) for the image(IA) self.artifact.create_tag(TestProjects.project_name, self.repo_name, tag, "1.0",**TestProjects.USER_CLIENT) diff --git a/tests/apitests/python/test_user_group.py b/tests/apitests/python/test_user_group.py index 3eecc444c1f..d497b3146b9 100644 --- a/tests/apitests/python/test_user_group.py +++ b/tests/apitests/python/test_user_group.py @@ -21,7 +21,8 @@ import unittest import testutils -from testutils import ADMIN_CLIENT +from testutils import ADMIN_CLIENT, harbor_url, admin_user, admin_pwd + from v2_swagger_client.models.user_group import UserGroup from library.configurations import Configurations @@ -34,7 +35,7 @@ class TestUserGroup(unittest.TestCase): """UserGroup unit test stubs""" - usergroup_api = testutils.GetUserGroupApi("admin", "Harbor12345") + usergroup_api = testutils.GetUserGroupApi(admin_user, admin_pwd, harbor_url) groupId = 0 def setUp(self): self.conf= Configurations() diff --git a/tests/apitests/python/testutils.py b/tests/apitests/python/testutils.py index 8ec925b42bc..a940e699f4b 100644 --- a/tests/apitests/python/testutils.py +++ b/tests/apitests/python/testutils.py @@ -18,10 +18,12 @@ import v2_swagger_client admin_user = "admin" -admin_pwd = "Harbor12345" +admin_pwd = os.environ.get("HARBOR_PASSWORD", "Harbor12345") harbor_server = os.environ.get("HARBOR_HOST", '') -harbor_url = "https://{}".format(harbor_server) +harbor_schema = os.environ.get("HARBOR_HOST_SCHEMA", "https") +harbor_url = "{}://{}".format(harbor_schema, harbor_server) + #CLIENT=dict(endpoint="https://"+harbor_server+"/api") ADMIN_CLIENT=dict(endpoint = os.environ.get("HARBOR_HOST_SCHEMA", "https")+ "://"+harbor_server+"/api/v2.0", username = admin_user, password = admin_pwd) CHART_API_CLIENT=dict(endpoint = os.environ.get("HARBOR_HOST_SCHEMA", "https")+ "://"+harbor_server+"/api", username = admin_user, password = admin_pwd) @@ -36,10 +38,10 @@ BASE_IMAGE_ABS_PATH_NAME = '/' + BASE_IMAGE['name'] + '.tar' -def GetRepositoryApi(username, password, harbor_server= os.environ.get("HARBOR_HOST", '')): +def GetRepositoryApi(username, password, harbor_url): cfg = v2_swagger_client.Configuration() - cfg.host = "https://"+harbor_server+"/api/v2.0" + cfg.host = harbor_url+"/api/v2.0" cfg.username = username cfg.password = password cfg.verify_ssl = False @@ -48,9 +50,9 @@ def GetRepositoryApi(username, password, harbor_server= os.environ.get("HARBOR_H api_instance = v2_swagger_client.RepositoryApi(api_client) return api_instance -def GetUserGroupApi(username, password, harbor_server= os.environ.get("HARBOR_HOST", '')): +def GetUserGroupApi(username, password, harbor_url): cfg = v2_swagger_client.Configuration() - cfg.host = "https://"+harbor_server+"/api/v2.0" + cfg.host = harbor_url+"/api/v2.0" cfg.username = username cfg.password = password cfg.verify_ssl = False diff --git a/tests/ci/api_run.sh b/tests/ci/api_run.sh index 83f60ffd8bd..c0f62fdb02f 100755 --- a/tests/ci/api_run.sh +++ b/tests/ci/api_run.sh @@ -1,27 +1,39 @@ #!/bin/bash set -x -#source gskey.sh - -sudo gsutil version -l - -harbor_logs_bucket="harbor-ci-logs" - DIR="$(cd "$(dirname "$0")" && pwd)" -E2E_IMAGE="goharbor/harbor-e2e-engine:latest-api" - -# GS util -function uploader { - sudo gsutil cp $1 gs://$2/$1 - sudo gsutil acl ch -u AllUsers:R gs://$2/$1 -} +E2E_IMAGE="${E2E_IMAGE:-goharbor/harbor-e2e-engine:4.2.1-api}" +HARBOR_PASSWORD="${HARBOR_PASSWORD:-Harbor12345}" +HARBOR_HOST="${HARBOR_HOST:-}" +HARBOR_HOST_SCHEMA="${HARBOR_HOST_SCHEMA:-https}" +DOCKER_USER="${DOCKER_USER:-}" +DOCKER_PWD="${DOCKER_PWD:-}" set +e docker ps # run db auth api cases if [ "$1" = 'DB' ]; then - docker run -i --privileged -v $DIR/../../:/drone -v $DIR/../:/ca -w /drone $E2E_IMAGE robot --exclude proxy_cache -v DOCKER_USER:${DOCKER_USER} -v DOCKER_PWD:${DOCKER_PWD} -v ip:$2 -v ip1: -v http_get_ca:false -v HARBOR_PASSWORD:Harbor12345 /drone/tests/robot-cases/Group1-Nightly/Setup.robot /drone/tests/robot-cases/Group0-BAT/API_DB.robot + docker run -i --privileged \ + -e HARBOR_PASSWORD="$HARBOR_PASSWORD" \ + -e HARBOR_HOST_SCHEMA="$HARBOR_HOST_SCHEMA" \ + -e HARBOR_HOST="$HARBOR_HOST" \ + -e COSIGN_EXPERIMENTAL=1 \ + -e CONTAINERD_ADDRESS=/var/run/docker/containerd/containerd.sock \ + -v $DIR/../../:/drone \ + -v $DIR/../:/ca \ + -v /var/log/harbor/:/var/log/harbor/ \ + -w /drone \ + "$E2E_IMAGE" \ + robot --exclude proxy_cache \ + -v DOCKER_USER:"${DOCKER_USER}" \ + -v DOCKER_PWD:"${DOCKER_PWD}" \ + -v ip:$2 -v ip1: \ + -v http_get_ca:false \ + -v protocol:http \ + -v HARBOR_PASSWORD:"$HARBOR_PASSWORD" \ + /drone/tests/robot-cases/Group1-Nightly/Setup.robot \ + /drone/tests/robot-cases/Group0-BAT/API_DB_SUCCESS.robot elif [ "$1" = 'PROXY_CACHE' ]; then docker run -i --privileged -v $DIR/../../:/drone -v $DIR/../:/ca -w /drone $E2E_IMAGE robot --include setup --include proxy_cache -v DOCKER_USER:${DOCKER_USER} -v DOCKER_PWD:${DOCKER_PWD} -v ip:$2 -v ip1: -v http_get_ca:false -v HARBOR_PASSWORD:Harbor12345 /drone/tests/robot-cases/Group1-Nightly/Setup.robot /drone/tests/robot-cases/Group0-BAT/API_DB.robot elif [ "$1" = 'LDAP' ]; then @@ -38,18 +50,10 @@ else fi rc=$? ## --------------------------------------------- Upload Harbor CI Logs ------------------------------------------- -timestamp=$(date +%s) GIT_COMMIT=$(git rev-parse --short "$GITHUB_SHA") -outfile="integration_logs_$timestamp$GIT_COMMIT.tar.gz" -sudo tar -zcvf $outfile output.xml log.html /var/log/harbor/* -if [ -f "$outfile" ]; then - uploader $outfile $harbor_logs_bucket - echo "----------------------------------------------" - echo "Download test logs:" - echo "https://storage.googleapis.com/harbor-ci-logs/$outfile" - echo "----------------------------------------------" -else - echo "No log output file to upload" -fi +outfile="integration-logs-$GIT_COMMIT.tar.gz" +tar -zcvf $outfile output.xml log.html -exit $rc +if [ $rc -gt 0 ]; then + echo "Failed test count $rc" >&2 +fi \ No newline at end of file diff --git a/tests/resources/Docker-Util.robot b/tests/resources/Docker-Util.robot index 76fb89d8b18..917355525ab 100644 --- a/tests/resources/Docker-Util.robot +++ b/tests/resources/Docker-Util.robot @@ -115,16 +115,18 @@ Get Container IP # docker:1.13-dind # If you are running this keyword in a container, make sure it is run with --privileged turned on Start Docker Daemon Locally - ${pid}= Run pidof dockerd + ${pid}= Run ps aux | grep -v grep | grep /usr/local/bin/dockerd | awk '{print $2}' #${rc} ${output}= Run And Return Rc And Output ./tests/robot-cases/Group0-Util/docker_config.sh #Log ${output} #Should Be Equal As Integers ${rc} 0 + Log To Console pid: ${pid} Return From Keyword If '${pid}' != '${EMPTY}' OperatingSystem.File Should Exist /usr/local/bin/dockerd-entrypoint.sh ${handle}= Start Process /usr/local/bin/dockerd-entrypoint.sh dockerd>./daemon-local.log 2>&1 shell=True Process Should Be Running ${handle} - FOR ${IDX} IN RANGE 5 - ${pid}= Run pidof dockerd + FOR ${IDX} IN RANGE 20 + ${pid}= Run ps aux | grep -v grep | grep -v sh | grep dockerd | awk '{print $2}' + Log To Console pid: ${pid} Exit For Loop If '${pid}' != '${EMPTY}' Sleep 2s END @@ -132,9 +134,12 @@ Start Docker Daemon Locally [Return] ${handle} Start Containerd Daemon Locally + ${pid}= Run ps aux | grep -v grep | grep /usr/local/bin/containerd | awk '{print $2}' + Log To Console pid: ${pid} + Return From Keyword If '${pid}' != '${EMPTY}' ${handle}= Start Process /usr/local/bin/containerd > ./daemon-local.log 2>&1 & shell=True - FOR ${IDX} IN RANGE 5 - ${pid}= Run pidof /usr/local/bin/containerd + FOR ${IDX} IN RANGE 20 + ${pid}= Run ps aux | grep -v grep | grep /usr/local/bin/containerd | awk '{print $2}' Log To Console pid: ${pid} Exit For Loop If '${pid}' != '${EMPTY}' Sleep 2s diff --git a/tests/resources/Harbor-Util.robot b/tests/resources/Harbor-Util.robot index 4d466255adc..73ad0ad6411 100644 --- a/tests/resources/Harbor-Util.robot +++ b/tests/resources/Harbor-Util.robot @@ -159,5 +159,5 @@ Wait for Harbor Ready Fail Harbor failed to come up properly! Get Harbor Version - ${rc} ${output}= Run And Return Rc And Output curl -k -X GET --header 'Accept: application/json' 'https://${ip}/api/v2.0/systeminfo'|grep -i harbor_version + ${rc} ${output}= Run And Return Rc And Output curl -k -X GET --header 'Accept: application/json' '${protocol}://${ip}/api/v2.0/systeminfo'|grep -i harbor_version Log To Console ${output} diff --git a/tests/resources/Nightly-Util.robot b/tests/resources/Nightly-Util.robot index be670846acc..06a4d2d34c7 100644 --- a/tests/resources/Nightly-Util.robot +++ b/tests/resources/Nightly-Util.robot @@ -34,7 +34,7 @@ Get And Setup Harbor CA Nightly Test Setup In Photon [Arguments] ${ip} ${HARBOR_PASSWORD} ${ip1}==${EMPTY} - Get And Setup Harbor CA ${ip} ${HARBOR_PASSWORD} CA Setup In Photon ip1=${ip1} + # Get And Setup Harbor CA ${ip} ${HARBOR_PASSWORD} CA Setup In Photon ip1=${ip1} Prepare Test Tools Log To Console Start Docker Daemon Locally ... Start Docker Daemon Locally @@ -43,14 +43,14 @@ Nightly Test Setup In Photon Nightly Test Setup In Ubuntu [Arguments] ${ip} ${HARBOR_PASSWORD} ${ip1}==${EMPTY} - Get And Setup Harbor CA ${ip} ${HARBOR_PASSWORD} CA Setup In ubuntu ip1=${ip1} + # Get And Setup Harbor CA ${ip} ${HARBOR_PASSWORD} CA Setup In ubuntu ip1=${ip1} Prepare Test Tools Log To Console Start Docker Daemon Locally ... Run Keyword Start Docker Daemon Locally Nightly Test Setup In Ubuntu For Upgrade [Arguments] ${ip} ${HARBOR_PASSWORD} ${ip1}==${EMPTY} - Get And Setup Harbor CA ${ip} ${HARBOR_PASSWORD} CA Setup In ubuntu ip1=${ip1} + # Get And Setup Harbor CA ${ip} ${HARBOR_PASSWORD} CA Setup In ubuntu ip1=${ip1} Prepare Test Tools Log To Console Start Docker Daemon Locally ... Run Keyword Start Docker Daemon Locally diff --git a/tests/robot-cases/Group0-BAT/API_DB.robot b/tests/robot-cases/Group0-BAT/API_DB.robot index 7e5bae3c238..58fcc329211 100644 --- a/tests/robot-cases/Group0-BAT/API_DB.robot +++ b/tests/robot-cases/Group0-BAT/API_DB.robot @@ -92,10 +92,6 @@ Test Case - Push Chart By Helm Chart CLI [Tags] push_chart_by_helm Harbor API Test ./tests/apitests/python/test_push_chart_by_helm_chart_cli.py -Test Case - Push Cnab Bundle - [Tags] push_cnab - Harbor API Test ./tests/apitests/python/test_push_cnab_bundle.py - Test Case - Tag CRUD [Tags] tag_crud Harbor API Test ./tests/apitests/python/test_tag_crud.py @@ -140,10 +136,6 @@ Test Case - Push Artifact With ORAS CLI [Tags] oras Harbor API Test ./tests/apitests/python/test_push_files_by_oras.py -Test Case - Replication From Dockerhub - [Tags] replic_dockerhub - Harbor API Test ./tests/apitests/python/test_replication_from_dockerhub.py - Test Case - Proxy Cache [Tags] proxy_cache Harbor API Test ./tests/apitests/python/test_proxy_cache.py @@ -156,10 +148,6 @@ Test Case - P2P [Tags] p2p Harbor API Test ./tests/apitests/python/test_p2p.py -Test Case - Metrics - [Tags] metrics - Harbor API Test ./tests/apitests/python/test_verify_metrics_enabled.py - Test Case - Project Level Policy Content Trust [Tags] content_trust Harbor API Test ./tests/apitests/python/test_project_level_policy_content_trust.py @@ -180,13 +168,6 @@ Test Case - Log Rotation [Tags] log_rotation Harbor API Test ./tests/apitests/python/test_log_rotation.py -Test Case - Log Forward - [Tags] log_forward - ${SYSLOG_ENDPOINT_VALUE}= Get Variable Value ${SYSLOG_ENDPOINT} ${EMPTY} - ${ES_ENDPOINT_VALUE}= Get Variable Value ${ES_ENDPOINT} ${EMPTY} - Skip If '${SYSLOG_ENDPOINT_VALUE}' == '${EMPTY}' or '${ES_ENDPOINT_VALUE}' == '${EMPTY}' - Harbor API Test ./tests/apitests/python/test_audit_log_forward.py SYSLOG_ENDPOINT=${SYSLOG_ENDPOINT_VALUE} ES_ENDPOINT=${ES_ENDPOINT_VALUE} - Test Case - Scan Data Export [Tags] scan_data_export Harbor API Test ./tests/apitests/python/test_scan_data_export.py diff --git a/tests/robot-cases/Group0-BAT/API_DB_SUCCESS.robot b/tests/robot-cases/Group0-BAT/API_DB_SUCCESS.robot new file mode 100644 index 00000000000..58fcc329211 --- /dev/null +++ b/tests/robot-cases/Group0-BAT/API_DB_SUCCESS.robot @@ -0,0 +1,205 @@ +*** Settings *** +Documentation Harbor BATs +Resource ../../resources/APITest-Util.robot +Resource ../../resources/Docker-Util.robot +Library OperatingSystem +Library String +Library Collections +Library requests +Library Process +Default Tags APIDB + +*** Variables *** +${SERVER} ${ip} +${SERVER_URL} https://${SERVER} +${SERVER_API_ENDPOINT} ${SERVER_URL}/api +&{SERVER_CONFIG} endpoint=${SERVER_API_ENDPOINT} verify_ssl=False + +*** Test Cases *** +Test Case - Garbage Collection + [Tags] gc + Harbor API Test ./tests/apitests/python/test_garbage_collection.py + +Test Case - Quota Sorting + [Tags] quota_sorting + Harbor API Test ./tests/apitests/python/test_quota_sorting.py + +Test Case - Add Private Project Member and Check User Can See It + [Tags] private_member + Harbor API Test ./tests/apitests/python/test_add_member_to_private_project.py + +Test Case - Delete a Repository of a Certain Project Created by Normal User + [Tags] del_repo + Harbor API Test ./tests/apitests/python/test_del_repo.py + +Test Case - Add a System Global Label to a Certain Tag + [Tags] global_lbl + Harbor API Test ./tests/apitests/python/test_add_sys_label_to_tag.py + +Test Case - Add Replication Rule + [Tags] replic_rule + Harbor API Test ./tests/apitests/python/test_add_replication_rule.py + +Test Case - Edit Project Creation + [Tags] pro_creation + Harbor API Test ./tests/apitests/python/test_edit_project_creation.py + +Test Case - Manage Project Member + [Tags] member + Harbor API Test ./tests/apitests/python/test_manage_project_member.py + +Test Case - User View Logs + [Tags] view_logs + Harbor API Test ./tests/apitests/python/test_user_view_logs.py + +Test Case - Assign Sys Admin + [Tags] assign_adin + Harbor API Test ./tests/apitests/python/test_assign_sys_admin.py + +Test Case - Copy Artifact Outside Project + [Tags] copy_artifact + Harbor API Test ./tests/apitests/python/test_copy_artifact_outside_project.py + +Test Case - Robot Account + [Tags] robot_account + Harbor API Test ./tests/apitests/python/test_robot_account.py + +Test Case - Project Quota + [Tags] quota + Harbor API Test ./tests/apitests/python/test_project_quota.py + +Test Case - System Level CVE Allowlist + [Tags] sys_cve + Harbor API Test ./tests/apitests/python/test_sys_cve_allowlists.py + +Test Case - Project Level CVE Allowlist + [Tags] pro_cve + Harbor API Test ./tests/apitests/python/test_project_level_cve_allowlist.py + +Test Case - Tag Retention + [Tags] tag_retention + Harbor API Test ./tests/apitests/python/test_retention.py + +Test Case - Health Check + [Tags] health + Harbor API Test ./tests/apitests/python/test_health_check.py + +Test Case - Push Index By Docker Manifest + [Tags] push_index + Harbor API Test ./tests/apitests/python/test_push_index_by_docker_manifest.py + +Test Case - Push Chart By Helm Chart CLI + [Tags] push_chart_by_helm + Harbor API Test ./tests/apitests/python/test_push_chart_by_helm_chart_cli.py + +Test Case - Tag CRUD + [Tags] tag_crud + Harbor API Test ./tests/apitests/python/test_tag_crud.py + +Test Case - Scan Image + [Tags] scan + Harbor API Test ./tests/apitests/python/test_scan_image_artifact.py + +Test Case - Scan Image In Public Project + [Tags] scan_public_project + Harbor API Test ./tests/apitests/python/test_scan_image_artifact_in_public_project.py + +Test Case - Scan All Images + [Tags] scan_all + Harbor API Test ./tests/apitests/python/test_system_level_scan_all.py + +Test Case - Stop Scan Image + [Tags] stop_scan + Harbor API Test ./tests/apitests/python/test_stop_scan_image_artifact.py + +Test Case - Stop Scan All Images + [Tags] stop_scan_all + Harbor API Test ./tests/apitests/python/test_system_level_stop_scan_all.py + +Test Case - Generate SBOM Of An Image + [Tags] generate_sbom + Harbor API Test ./tests/apitests/python/test_sbom_generation_of_image_artifact.py + +Test Case - Stop Generating SBOM Of An Image + [Tags] stop_generating_sbom + Harbor API Test ./tests/apitests/python/test_stop_sbom_generation_of_image_artifact.py + +Test Case - Registry API + [Tags] reg_api + Harbor API Test ./tests/apitests/python/test_registry_api.py + +Test Case - Push Image With Special Name + [Tags] special_repo_name + Harbor API Test ./tests/apitests/python/test_push_image_with_special_name.py + +Test Case - Push Artifact With ORAS CLI + [Tags] oras + Harbor API Test ./tests/apitests/python/test_push_files_by_oras.py + +Test Case - Proxy Cache + [Tags] proxy_cache + Harbor API Test ./tests/apitests/python/test_proxy_cache.py + +Test Case - Tag Immutability + [Tags] tag_immutability + Harbor API Test ./tests/apitests/python/test_tag_immutability.py + +Test Case - P2P + [Tags] p2p + Harbor API Test ./tests/apitests/python/test_p2p.py + +Test Case - Project Level Policy Content Trust + [Tags] content_trust + Harbor API Test ./tests/apitests/python/test_project_level_policy_content_trust.py + +Test Case - Webhook CRUD + [Tags] webhook + Harbor API Test ./tests/apitests/python/test_webhook_crud.py + +Test Case - Cosign Sign Artifact + [Tags] cosign + Harbor API Test ./tests/apitests/python/test_cosign_sign_artifact.py + +Test Case - Notation Sign Artifact + [Tags] notation + Harbor API Test ./tests/apitests/python/test_notation_sign_artifact.py + +Test Case - Log Rotation + [Tags] log_rotation + Harbor API Test ./tests/apitests/python/test_log_rotation.py + +Test Case - Scan Data Export + [Tags] scan_data_export + Harbor API Test ./tests/apitests/python/test_scan_data_export.py + +Test Case - Job Service Dashboard + [Tags] job_service_dashboard + Harbor API Test ./tests/apitests/python/test_job_service_dashboard.py + +Test Case - Retain Image Last Pull Time + [Tags] retain_image_last_pull_time + Harbor API Test ./tests/apitests/python/test_retain_image_last_pull_time.py + +Test Case - Referrers API + [Tags] referrers + Harbor API Test ./tests/apitests/python/test_referrers_api.py + +Test Case - Podman Pull And Push To Harbor + [Tags] podman_pull_push + Harbor API Test ./tests/apitests/python/test_podman_pull_push.py + +Test Case - Security Hub + [Tags] security_hub + Harbor API Test ./tests/apitests/python/test_security_hub.py + +Test Case - Banner Message + [Tags] banner_message + Harbor API Test ./tests/apitests/python/test_banner_message.py + +Test Case - User CRUD + [Tags] user_crud + Harbor API Test ./tests/apitests/python/test_user_crud.py + +Test Case - Limited Guest GetRepository + [Tags] limited_guest_getrepository + Harbor API Test ./tests/apitests/python/test_user_limited_guest_get_repository.py diff --git a/tests/test-engine-image/Dockerfile.api_test b/tests/test-engine-image/Dockerfile.api_test index ab2835164dc..e7435a91433 100644 --- a/tests/test-engine-image/Dockerfile.api_test +++ b/tests/test-engine-image/Dockerfile.api_test @@ -1,5 +1,5 @@ # photon based image -FROM photon:4.0 +FROM build-harbor.alauda.cn/ops/photon:4.0 ENV LANG C.UTF-8 ENV HELM_EXPERIMENTAL_OCI=1 ENV COSIGN_PASSWORD=Harbor12345 diff --git a/tests/test-engine-image/Dockerfile.common b/tests/test-engine-image/Dockerfile.common index 40826655fbd..607c107ddd4 100644 --- a/tests/test-engine-image/Dockerfile.common +++ b/tests/test-engine-image/Dockerfile.common @@ -1,4 +1,4 @@ -FROM ubuntu:20.04 as tool_builder +FROM build-harbor.alauda.cn/ops/ubuntu:22.04 as tool_builder ENV TZ=Asia/Shanghai \ DEBIAN_FRONTEND=noninteractive ENV LANG C.UTF-8 diff --git a/tests/test-engine-image/generate.sh b/tests/test-engine-image/generate.sh new file mode 100755 index 00000000000..f152a4c90f8 --- /dev/null +++ b/tests/test-engine-image/generate.sh @@ -0,0 +1,27 @@ +#!/bin/bash +set -x +set -e + +IMAGE_FOR=$1 +VERSION=$2 + +CMD_BASE="cat Dockerfile.common" +SRC_FILE="" +DST_FILE=Dockerfile + +echo "Starting to prepare Dockerfile for $IMAGE_FOR ..." +if [ "$IMAGE_FOR" == "api" ]; then + SRC_FILE=Dockerfile.api_test +else + SRC_FILE=Dockerfile.ui_test +fi + +if [ ! -r $SRC_FILE ]; then + echo "File $SRC_FILE does not exists at all!" + exit -1 +fi + +if [ -f $DST_FILE ]; then + rm $DST_FILE +fi +$CMD_BASE $SRC_FILE >> $DST_FILE