mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-25 03:35:21 +01:00
Merge pull request #12234 from danfengliu/fix-keyword-go-into-repo
Add helm and helm3 CLI py-test
This commit is contained in:
commit
c5e5e9ec9f
4
.github/workflows/CI.yml
vendored
4
.github/workflows/CI.yml
vendored
@ -135,6 +135,10 @@ 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-v2.14.1-linux-386.tar.gz && tar zxvf helm-v2.14.1-linux-386.tar.gz
|
||||
sudo mv linux-386/helm /usr/local/bin/helm2
|
||||
helm2 init --client-only
|
||||
helm2 plugin install https://github.com/chartmuseum/helm-push
|
||||
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
|
||||
|
@ -33,4 +33,16 @@ def helm_chart_push_to_harbor(chart_file, archive, harbor_server, project, repo_
|
||||
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)
|
||||
return helm_push(harbor_server, project, repo_name, version)
|
||||
|
||||
# helm repo add --ca-file /ca/server.crt --username=${user} --password=${pwd} ${helm_repo_name} ${harbor_url}/chartrepo/${project_name}
|
||||
def helm2_add_repo(helm_repo_name, harbor_url, project, username, password):
|
||||
command = ["helm2", "repo", "add", "--username=" + username, "--password=" + password, helm_repo_name, harbor_url + "/chartrepo/" + project]
|
||||
print "Command: ", command
|
||||
base.run_command(command)
|
||||
|
||||
def helm2_push(helm_repo_name, chart_file, project, username, password):
|
||||
get_chart_file(chart_file)
|
||||
command = ["helm2", "push", "--username=" + username, "--password=" + password, chart_file.split('/')[-1], helm_repo_name]
|
||||
print "Command: ", command
|
||||
base.run_command(command)
|
@ -173,7 +173,7 @@ class Project(base.Base):
|
||||
base._assert_status_code(expect_status_code, status_code)
|
||||
return base._get_id_from_header(header)
|
||||
|
||||
def add_project_robot_account(self, project_id, project_name, expires_at, robot_name = None, robot_desc = None, has_pull_right = True, has_push_right = True, expect_status_code = 201, **kwargs):
|
||||
def add_project_robot_account(self, project_id, project_name, expires_at, robot_name = None, robot_desc = None, has_pull_right = True, has_push_right = True, has_chart_read_right = True, has_chart_create_right = True, expect_status_code = 201, **kwargs):
|
||||
if robot_name is None:
|
||||
robot_name = base._random_name("robot")
|
||||
if robot_desc is None:
|
||||
@ -182,14 +182,25 @@ class Project(base.Base):
|
||||
has_pull_right = True
|
||||
access_list = []
|
||||
resource_by_project_id = "/project/"+str(project_id)+"/repository"
|
||||
resource_helm_by_project_id = "/project/"+str(project_id)+"/helm-chart"
|
||||
resource_helm__create_by_project_id = "/project/"+str(project_id)+"/helm-chart-version"
|
||||
action_pull = "pull"
|
||||
action_push = "push"
|
||||
action_read = "read"
|
||||
action_create = "create"
|
||||
if has_pull_right is True:
|
||||
robotAccountAccess = swagger_client.RobotAccountAccess(resource = resource_by_project_id, action = action_pull)
|
||||
access_list.append(robotAccountAccess)
|
||||
if has_push_right is True:
|
||||
robotAccountAccess = swagger_client.RobotAccountAccess(resource = resource_by_project_id, action = action_push)
|
||||
access_list.append(robotAccountAccess)
|
||||
if has_chart_read_right is True:
|
||||
robotAccountAccess = swagger_client.RobotAccountAccess(resource = resource_helm_by_project_id, action = action_read)
|
||||
access_list.append(robotAccountAccess)
|
||||
if has_chart_create_right is True:
|
||||
robotAccountAccess = swagger_client.RobotAccountAccess(resource = resource_helm__create_by_project_id, action = action_create)
|
||||
access_list.append(robotAccountAccess)
|
||||
|
||||
robotAccountCreate = swagger_client.RobotAccountCreate(robot_name, robot_desc, expires_at, access_list)
|
||||
client = self._get_client(**kwargs)
|
||||
data = []
|
||||
|
@ -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()
|
||||
self.repo= 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.chart_repo_name = "chart_local"
|
||||
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 user(UA).
|
||||
self.user.delete_user(TestProjects.user_id, **ADMIN_CLIENT)
|
||||
|
||||
def testPushChartToChartRepoByHelm2WithRobotAccount(self):
|
||||
"""
|
||||
Test case:
|
||||
Push Chart File To Chart Repository By Helm V2 With Robot Account
|
||||
Test step and expected result:
|
||||
1. Create a new user(UA);
|
||||
2. Create private project(PA) with user(UA);
|
||||
3. Create a new robot account(RA) with full priviliges in project(PA) with user(UA);
|
||||
4. Push chart to project(PA) by Helm2 CLI with robot account(RA);
|
||||
5. Get chart repositry from project(PA) successfully;
|
||||
Tear down:
|
||||
1. Delete user(UA).
|
||||
"""
|
||||
|
||||
print "#1. Create user(UA);"
|
||||
TestProjects.user_id, user_name = self.user.create_user(user_password = self.user_push_chart_password, **ADMIN_CLIENT)
|
||||
TestProjects.USER_RA_CLIENT=dict(endpoint = self.url, username = user_name, password = self.user_push_chart_password)
|
||||
|
||||
print "#2. Create private project(PA) with user(UA);"
|
||||
TestProjects.project_id, TestProjects.project_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_RA_CLIENT)
|
||||
|
||||
|
||||
print "#3. Create a new robot account(RA) with full priviliges in project(PA) with user(UA);"
|
||||
robot_id, robot_account = self.project.add_project_robot_account(TestProjects.project_id, TestProjects.project_name,
|
||||
2441000531 ,**TestProjects.USER_RA_CLIENT)
|
||||
print robot_account.name
|
||||
print robot_account.token
|
||||
|
||||
print "#4. Push chart to project(PA) by Helm2 CLI with robot account(RA);"
|
||||
library.helm.helm2_add_repo(self.chart_repo_name, "https://"+harbor_server, TestProjects.project_name, robot_account.name, robot_account.token)
|
||||
library.helm.helm2_push(self.chart_repo_name, self.chart_file, TestProjects.project_name, robot_account.name, robot_account.token)
|
||||
|
||||
print "#5. Get chart repositry from project(PA) successfully;"
|
||||
# Depend on issue #12252
|
||||
|
||||
print "#6. Push chart to project(PA) by Helm3 CLI with robot account(RA);"
|
||||
chart_cli_ret = library.helm.helm_chart_push_to_harbor(self.chart_file, self.archive, harbor_server, TestProjects.project_name, self.repo_name, self.verion, robot_account.name, robot_account.token)
|
||||
print "chart_cli_ret:", chart_cli_ret
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -104,3 +104,6 @@ Test Case - Push Artifact With ORAS CLI
|
||||
Test Case - Push Singularity file With Singularity CLI
|
||||
[Tags] singularity
|
||||
Harbor API Test ./tests/apitests/python/test_push_sif_by_singularity.py
|
||||
Test Case - Push Chart File To Chart Repository By Helm V2 With Robot Account
|
||||
[Tags] helm2
|
||||
Harbor API Test ./tests/apitests/python/test_push_chart_by_helm2_helm3_with_robot_Account.py
|
||||
|
@ -20,4 +20,8 @@ Default Tags Nightly
|
||||
*** Test Cases ***
|
||||
Test Suites Setup
|
||||
Nightly Test Setup ${ip} ${HARBOR_PASSWORD} ${ip1}
|
||||
Setup API Test
|
||||
Setup API Test
|
||||
|
||||
Test Case - Get Harbor Version
|
||||
#Just get harbor version and log it
|
||||
Get Harbor Version
|
Loading…
Reference in New Issue
Block a user