Skip to content

Commit

Permalink
fix e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
airycanon committed Dec 19, 2024
1 parent a4dc372 commit 08dfd72
Show file tree
Hide file tree
Showing 32 changed files with 525 additions and 135 deletions.
52 changes: 52 additions & 0 deletions .build/build-e2e.yaml
Original file line number Diff line number Diff line change
@@ -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)
85 changes: 85 additions & 0 deletions .build/e2e.yaml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 19 additions & 12 deletions tests/apitests/python/library/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import v2_swagger_client

import logging


try:
from urllib import getproxies
except ImportError:
Expand All @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion tests/apitests/python/library/containerd.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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"]
20 changes: 10 additions & 10 deletions tests/apitests/python/library/docker_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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=[]
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions tests/apitests/python/library/helm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-

import os
import base


Expand All @@ -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"]
8 changes: 7 additions & 1 deletion tests/apitests/python/library/notation.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# -*- coding: utf-8 -*-
import os
import base

def generate_cert():
command = ["notation", "cert", "generate-test", "--default", "wabbit-networks.io"]
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)
13 changes: 10 additions & 3 deletions tests/apitests/python/library/oras.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"] )
Expand All @@ -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:
Expand All @@ -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"]
6 changes: 3 additions & 3 deletions tests/apitests/python/library/podman.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
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):
command = ["podman", "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)
Loading

0 comments on commit 08dfd72

Please sign in to comment.