Merge pull request #15879 from YangJiao0817/add-helm3.7-case2python

Add test cases helm3.7 CLI push in python test
This commit is contained in:
Yang Jiao 2021-11-02 16:51:04 +08:00 committed by GitHub
commit b3c959a7ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 142 additions and 13 deletions

View File

@ -56,3 +56,15 @@ def helm2_fetch_chart_file(helm_repo_name, harbor_url, project, username, passwo
command = ["helm2", "fetch", "{}/{}".format(helm_repo_name, chart_file)]
base.run_command(command)
base.run_command(command_ls)
def helm3_7_registry_login(ip, user, password):
command = ["helm3.7", "registry", "login", ip, "-u", user, "-p", password]
base.run_command(command)
def helm3_7_package(file_path):
command = ["helm3.7", "package", file_path]
base.run_command(command)
def helm3_7_push(file_path, ip, project_name):
command = ["helm3.7", "push", file_path, "oci://{}/{}".format(ip, project_name)]
base.run_command(command)

View File

@ -0,0 +1,110 @@
from __future__ import absolute_import
import unittest
from testutils import ADMIN_CLIENT, suppress_urllib3_warning, harbor_server, files_directory
from testutils import TEARDOWN
from library import base
from library import helm
from library.project import Project
from library.user import User
from library.repository import Repository
from library.artifact import Artifact
class TestProjects(unittest.TestCase):
user_id = None
project_push_chart_id = None
USER_CLIENT = None
project_push_chart_name = None
@suppress_urllib3_warning
def setUp(self):
self.project = Project()
self.user = User()
self.artifact = Artifact()
self.repo = Repository()
self.url = ADMIN_CLIENT["endpoint"]
self.user_push_chart_password = "Aa123456"
self.chart_file_name = "harbor-helm-1.7.3"
self.chart_file_package_name = "harbor-1.7.3.tgz"
self.chart_file_path = files_directory + "harbor-helm-1.7.3.tar.gz"
self.version = "1.7.3"
self.repo_name = "harbor"
@unittest.skipIf(TEARDOWN is False, "Test data won't be erased.")
def tearDown(self):
# 1. Delete repository chart(CA) by user(UA);
self.repo.delete_repository(TestProjects.project_push_chart_name, self.repo_name, **TestProjects.USER_CLIENT)
# 2. Delete project(PA);
self.project.delete_project(TestProjects.project_push_chart_id, **TestProjects.USER_CLIENT)
# 3. Delete user(UA).
self.user.delete_user(TestProjects.user_id, **ADMIN_CLIENT)
def testPushChartByHelmChartCLI(self):
"""
Test case:
Push Chart File By Helm3.7 CLI
Test step and expected result:
1. Create a new user(UA);
2. Create a new project(PA) by user(UA);
3. Push an chart(CA) to Harbor by helm3.7 CLI successfully;
4. List artifacts successfully;
5. Get chart(CA) by reference successfully;
6. Get addition successfully;
7. Delete chart by reference successfully.
Tear down:
1. Delete repository chart(CA) by user(UA);
2. Delete project(PA);
3. Delete user(UA).
"""
# 1. Create a new user(UA);
TestProjects.user_id, user_name = self.user.create_user(user_password=self.user_push_chart_password,
**ADMIN_CLIENT)
TestProjects.USER_CLIENT = dict(endpoint=self.url, username=user_name, password=self.user_push_chart_password)
# 2. Create a new project(PA) by user(UA);
TestProjects.project_push_chart_id, TestProjects.project_push_chart_name = self.project.create_project(
metadata={"public": "false"}, **TestProjects.USER_CLIENT)
# 3 Push an chart(CA) to Harbor by helm3.7 CLI successfully;
command = ["tar", "zxf", self.chart_file_path]
base.run_command(command)
# 3.1 helm3_7_registry_login;
helm.helm3_7_registry_login(ip=harbor_server, user=user_name, password=self.user_push_chart_password)
# 3.2 helm3_7_package;
helm.helm3_7_package(file_path=self.chart_file_name)
# 3.2 helm3_7_push;
helm.helm3_7_push(file_path=self.chart_file_package_name, ip=harbor_server,
project_name=TestProjects.project_push_chart_name)
# 4. List artifacts successfully;
artifacts = self.artifact.list_artifacts(TestProjects.project_push_chart_name, self.repo_name,
**TestProjects.USER_CLIENT)
self.assertEqual(artifacts[0].type, 'CHART')
self.assertEqual(artifacts[0].tags[0].name, self.version)
# 5.1 Get chart(CA) by reference successfully;
artifact = self.artifact.get_reference_info(TestProjects.project_push_chart_name, self.repo_name, self.version,
**TestProjects.USER_CLIENT)
self.assertEqual(artifact.type, 'CHART')
self.assertEqual(artifact.tags[0].name, self.version)
# 6. Get addition successfully;
addition_r = self.artifact.get_addition(TestProjects.project_push_chart_name, self.repo_name, self.version,
"readme.md", **TestProjects.USER_CLIENT)
self.assertIn("Helm Chart for Harbor", addition_r[0])
addition_v = self.artifact.get_addition(TestProjects.project_push_chart_name, self.repo_name, self.version,
"values.yaml", **TestProjects.USER_CLIENT)
self.assertIn("expose", addition_v[0])
# 7. Delete chart by reference successfully.
self.artifact.delete_artifact(TestProjects.project_push_chart_name, self.repo_name, self.version,
**TestProjects.USER_CLIENT)
if __name__ == '__main__':
unittest.main()

View File

@ -24,7 +24,7 @@ class TestProjects(unittest.TestCase):
self.user_push_chart_password = "Aa123456"
self.chart_file = "https://storage.googleapis.com/harbor-builds/helm-chart-test-files/harbor-0.2.0.tgz"
self.archive = "harbor/"
self.verion = "0.2.0"
self.version = "0.2.0"
self.repo_name = "harbor_api_test"
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
@ -63,33 +63,33 @@ class TestProjects(unittest.TestCase):
TestProjects.project_push_chart_id, TestProjects.project_push_chart_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_CLIENT)
#3. Push an chart(CA) to Harbor by helm3 registry/chart CLI successfully;
chart_cli_ret = library.helm.helm_chart_push_to_harbor(self.chart_file, self.archive, harbor_server, TestProjects.project_push_chart_name, self.repo_name, self.verion, user_name, self.user_push_chart_password)
chart_cli_ret = library.helm.helm_chart_push_to_harbor(self.chart_file, self.archive, harbor_server, TestProjects.project_push_chart_name, self.repo_name, self.version, user_name, self.user_push_chart_password)
#4. List artifacts successfully;
artifacts = self.artifact.list_artifacts(TestProjects.project_push_chart_name, self.repo_name, **TestProjects.USER_CLIENT)
self.assertEqual(artifacts[0].type, 'CHART')
self.assertEqual(artifacts[0].tags[0].name, self.verion)
self.assertEqual(artifacts[0].tags[0].name, self.version)
#5.1 Get chart(CA) by reference successfully;
artifact = self.artifact.get_reference_info(TestProjects.project_push_chart_name, self.repo_name, self.verion, **TestProjects.USER_CLIENT)
artifact = self.artifact.get_reference_info(TestProjects.project_push_chart_name, self.repo_name, self.version, **TestProjects.USER_CLIENT)
self.assertEqual(artifact.type, 'CHART')
self.assertEqual(artifact.tags[0].name, self.verion)
self.assertEqual(artifact.tags[0].name, self.version)
#5.2 Chart bundle can be pulled by ctr successfully;
#oci_ref = harbor_server+"/"+TestProjects.project_push_chart_name+"/"+self.repo_name+":"+self.verion
#oci_ref = harbor_server+"/"+TestProjects.project_push_chart_name+"/"+self.repo_name+":"+self.version
#library.containerd.ctr_images_pull(user_name, self.user_push_chart_password, oci_ref)
#library.containerd.ctr_images_list(oci_ref = oci_ref)
#6. Get addtion successfully;
addition_r = self.artifact.get_addition(TestProjects.project_push_chart_name, self.repo_name, self.verion, "readme.md", **TestProjects.USER_CLIENT)
addition_r = self.artifact.get_addition(TestProjects.project_push_chart_name, self.repo_name, self.version, "readme.md", **TestProjects.USER_CLIENT)
self.assertIn("Helm Chart for Harbor", addition_r[0])
addition_d = self.artifact.get_addition(TestProjects.project_push_chart_name, self.repo_name, self.verion, "dependencies", **TestProjects.USER_CLIENT)
addition_d = self.artifact.get_addition(TestProjects.project_push_chart_name, self.repo_name, self.version, "dependencies", **TestProjects.USER_CLIENT)
self.assertIn("https://kubernetes-charts.storage.googleapis.com", addition_d[0])
addition_v = self.artifact.get_addition(TestProjects.project_push_chart_name, self.repo_name, self.verion, "values.yaml", **TestProjects.USER_CLIENT)
addition_v = self.artifact.get_addition(TestProjects.project_push_chart_name, self.repo_name, self.version, "values.yaml", **TestProjects.USER_CLIENT)
self.assertIn("adminserver", addition_v[0])
#7. Delete chart by reference successfully.
self.artifact.delete_artifact(TestProjects.project_push_chart_name, self.repo_name, self.verion, **TestProjects.USER_CLIENT)
self.artifact.delete_artifact(TestProjects.project_push_chart_name, self.repo_name, self.version, **TestProjects.USER_CLIENT)
if __name__ == '__main__':

View File

@ -13,6 +13,8 @@ path=os.getcwd() + "/tests/apitests/python/"
sys.path.insert(0, path)
print(sys.path)
files_directory = os.getcwd() + "/tests/files/"
import v2_swagger_client
import swagger_client.models

View File

@ -18,7 +18,7 @@ harbor_logs_bucket="harbor-ci-logs"
#echo "content_language = en" >> $botofile
#echo "default_project_id = $GS_PROJECT_ID" >> $botofile
DIR="$(cd "$(dirname "$0")" && pwd)"
E2E_IMAGE="goharbor/harbor-e2e-engine:3.0.0-api"
E2E_IMAGE="goharbor/harbor-e2e-engine:4.1.0-api"
# GS util
function uploader {

View File

@ -97,6 +97,10 @@ Test Case - Push Chart By Helm3 Chart CLI
[Tags] push_chart
Harbor API Test ./tests/apitests/python/test_push_chart_by_helm3_chart_cli.py
Test Case - Push Chart By Helm3.7 Chart CLI
[Tags] push_chart_by_Helm3.7
Harbor API Test ./tests/apitests/python/test_push_chart_by_helm3.7_chart_cli.py
Test Case - Push Cnab Bundle
[Tags] push_cnab
Harbor API Test ./tests/apitests/python/test_push_cnab_bundle.py

View File

@ -2,6 +2,7 @@
# photon based image
FROM photon:4.0
ENV LANG C.UTF-8
ENV HELM_EXPERIMENTAL_OCI=1
COPY --from=tool_builder /tool/tools.tar.gz /usr/local/bin

View File

@ -65,8 +65,8 @@ RUN pwd && mkdir /tool/binary && \
pwd
#ubuntu
RUN wget https://github.com/sylabs/singularity/releases/download/v3.7.4/singularity-3.7.4.tar.gz && \
tar -xzf singularity-3.7.4.tar.gz && \
RUN wget https://github.com/hpcng/singularity/releases/download/v3.3.0/singularity-3.3.0.tar.gz && \
tar -xzf singularity-3.3.0.tar.gz && \
cd singularity && \
./mconfig && \
make -C builddir && \