mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-10 12:40:19 +01:00
Merge pull request #10933 from danfengliu/API-test-of-push-helm-chart
Add API test python script - Push chart by Helm3 registry/chart CLI
This commit is contained in:
commit
440a75228a
3
.github/workflows/CI.yml
vendored
3
.github/workflows/CI.yml
vendored
@ -130,6 +130,9 @@ jobs:
|
||||
sudo cp ./tests/harbor_ca.crt /usr/local/share/ca-certificates/
|
||||
sudo update-ca-certificates
|
||||
sudo service docker restart
|
||||
wget https://get.helm.sh/helm-v3.1.1-linux-386.tar.gz && tar zxvf helm-v3.1.1-linux-386.tar.gz && \
|
||||
sudo mv linux-386/helm /usr/local/bin/helm3 && \
|
||||
helm3 plugin install https://github.com/chartmuseum/helm-push
|
||||
- name: install
|
||||
run: |
|
||||
cd src/github.com/goharbor/harbor
|
||||
|
36
tests/apitests/python/library/helm.py
Normal file
36
tests/apitests/python/library/helm.py
Normal file
@ -0,0 +1,36 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import base
|
||||
|
||||
def get_chart_file(file_name):
|
||||
command = ["wget", file_name]
|
||||
ret = base.run_command(command)
|
||||
print "Command Return: ", ret
|
||||
command = ["tar", "xvf", file_name.split('/')[-1]]
|
||||
ret = base.run_command(command)
|
||||
print "Command Return: ", ret
|
||||
|
||||
def helm_login(harbor_server, user, password):
|
||||
os.putenv("HELM_EXPERIMENTAL_OCI", "1")
|
||||
command = ["helm3", "registry", "login", harbor_server, "-u", user, "-p", password]
|
||||
print "Command: ", command
|
||||
ret = base.run_command(command)
|
||||
print "Command return: ", ret
|
||||
|
||||
def helm_save(chart_archive, harbor_server, project, repo_name):
|
||||
command = ["helm3", "chart","save", chart_archive, harbor_server+"/"+project+"/"+repo_name]
|
||||
print "Command: ", command
|
||||
base.run_command(command)
|
||||
|
||||
def helm_push(harbor_server, project, repo_name, version):
|
||||
command = ["helm3", "chart","push", harbor_server+"/"+project+"/"+repo_name+":"+version]
|
||||
print "Command: ", command
|
||||
ret = base.run_command(command)
|
||||
return ret
|
||||
|
||||
def helm_chart_push_to_harbor(chart_file, archive, harbor_server, project, repo_name, version, user, password):
|
||||
get_chart_file(chart_file)
|
||||
helm_login(harbor_server, user, password)
|
||||
helm_save(archive, harbor_server, project, repo_name)
|
||||
return helm_push(harbor_server, project, repo_name, version)
|
82
tests/apitests/python/test_push_chart_by_helm3_chart_cli.py
Normal file
82
tests/apitests/python/test_push_chart_by_helm3_chart_cli.py
Normal file
@ -0,0 +1,82 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
|
||||
import unittest
|
||||
|
||||
import library.repository
|
||||
import library.helm
|
||||
from testutils import ADMIN_CLIENT
|
||||
from testutils import harbor_server
|
||||
|
||||
from testutils import TEARDOWN
|
||||
from library.project import Project
|
||||
from library.user import User
|
||||
from library.repository import Repository
|
||||
from library.artifact import Artifact
|
||||
|
||||
class TestProjects(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(self):
|
||||
self.project= Project()
|
||||
self.user= User()
|
||||
self.artifact = Artifact(api_type='artifact')
|
||||
self.repo= Repository(api_type='repository')
|
||||
self.url = ADMIN_CLIENT["endpoint"]
|
||||
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.repo_name = "harbor_api_test"
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(self):
|
||||
print "Case completed"
|
||||
|
||||
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
|
||||
def test_ClearData(self):
|
||||
#1. Delete repository chart(CA) by user(UA);
|
||||
self.repo.delete_repoitory(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 Helm Chart 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 registry/chart CLI successfully;
|
||||
4. Get chart(CA) from Harbor successfully;
|
||||
5. TO_DO: Verify this chart artifact information, like digest.
|
||||
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 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)
|
||||
print "chart_cli_ret:", chart_cli_ret
|
||||
|
||||
#4. Get chart(CA) from Harbor successfully;
|
||||
artifact = self.artifact.get_reference_info(TestProjects.project_push_chart_name, self.repo_name, self.verion, **TestProjects.USER_CLIENT)
|
||||
print "artifact:", artifact
|
||||
|
||||
#5. TO_DO: Verify this chart artifact information, like digest;
|
||||
self.assertEqual(artifact[0].type, 'CHART')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -70,4 +70,6 @@ Test Case - Health Check
|
||||
Harbor API Test ./tests/apitests/python/test_health_check.py
|
||||
Test Case - Push Index By Docker Manifest
|
||||
Harbor API Test ./tests/apitests/python/test_push_index_by_docker_manifest.py
|
||||
Test Case - Push Index By Docker Manifest
|
||||
Harbor API Test ./tests/apitests/python/test_push_chart_by_helm3_chart_cli.py
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user