2020-06-15 08:20:23 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
2020-11-04 03:13:12 +01:00
|
|
|
from testutils import ADMIN_CLIENT, CHART_API_CLIENT, suppress_urllib3_warning
|
2020-06-15 08:20:23 +02:00
|
|
|
from testutils import harbor_server
|
|
|
|
from testutils import TEARDOWN
|
2020-08-07 08:56:18 +02:00
|
|
|
import library.repository
|
|
|
|
import library.helm
|
2020-06-15 08:20:23 +02:00
|
|
|
from library.project import Project
|
|
|
|
from library.user import User
|
2020-06-16 11:34:30 +02:00
|
|
|
from library.chart import Chart
|
2020-06-15 08:20:23 +02:00
|
|
|
|
|
|
|
class TestProjects(unittest.TestCase):
|
2020-11-04 03:13:12 +01:00
|
|
|
@suppress_urllib3_warning
|
|
|
|
def setUp(self):
|
2020-06-15 08:20:23 +02:00
|
|
|
self.project= Project()
|
|
|
|
self.user= User()
|
2020-06-16 11:34:30 +02:00
|
|
|
self.chart= Chart()
|
2020-06-15 08:20:23 +02:00
|
|
|
self.url = ADMIN_CLIENT["endpoint"]
|
2020-06-16 11:34:30 +02:00
|
|
|
self.chart_api_url = CHART_API_CLIENT['endpoint']
|
2020-06-15 08:20:23 +02:00
|
|
|
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/"
|
2020-06-16 11:34:30 +02:00
|
|
|
self.CHART_NAME=self.archive.replace("/", "")
|
2020-06-15 08:20:23 +02:00
|
|
|
self.verion = "0.2.0"
|
|
|
|
self.chart_repo_name = "chart_local"
|
|
|
|
self.repo_name = "harbor_api_test"
|
|
|
|
|
|
|
|
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
|
2020-11-04 03:13:12 +01:00
|
|
|
def tearDown(self):
|
2020-06-15 08:20:23 +02:00
|
|
|
#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).
|
|
|
|
"""
|
|
|
|
|
2020-07-30 10:04:14 +02:00
|
|
|
#1. Create user(UA);
|
2020-06-15 08:20:23 +02:00
|
|
|
TestProjects.user_id, user_name = self.user.create_user(user_password = self.user_push_chart_password, **ADMIN_CLIENT)
|
2020-06-16 11:34:30 +02:00
|
|
|
TestProjects.USER_CLIENT=dict(endpoint = self.url, username = user_name, password = self.user_push_chart_password)
|
|
|
|
TestProjects.API_CHART_CLIENT=dict(endpoint = self.chart_api_url, username = user_name, password = self.user_push_chart_password)
|
2020-07-30 10:04:14 +02:00
|
|
|
#2. Create private project(PA) with user(UA);
|
2020-06-16 11:34:30 +02:00
|
|
|
TestProjects.project_id, TestProjects.project_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_CLIENT)
|
2020-06-15 08:20:23 +02:00
|
|
|
|
|
|
|
|
2020-07-30 10:04:14 +02:00
|
|
|
#3. Create a new robot account(RA) with full priviliges in project(PA) with user(UA);
|
2020-06-15 08:20:23 +02:00
|
|
|
robot_id, robot_account = self.project.add_project_robot_account(TestProjects.project_id, TestProjects.project_name,
|
2020-06-16 11:34:30 +02:00
|
|
|
2441000531 ,**TestProjects.USER_CLIENT)
|
2020-07-30 10:04:14 +02:00
|
|
|
#4. Push chart to project(PA) by Helm2 CLI with robot account(RA);"
|
2020-06-15 08:20:23 +02:00
|
|
|
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)
|
|
|
|
|
2020-07-30 10:04:14 +02:00
|
|
|
#5. Get chart repositry from project(PA) successfully;
|
2020-06-16 11:34:30 +02:00
|
|
|
self.chart.chart_should_exist(TestProjects.project_name, self.CHART_NAME, **TestProjects.API_CHART_CLIENT)
|
2020-06-15 08:20:23 +02:00
|
|
|
|
2020-07-30 10:04:14 +02:00
|
|
|
#6. Push chart to project(PA) by Helm3 CLI with robot account(RA);
|
2020-06-15 08:20:23 +02:00
|
|
|
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)
|
2020-07-30 10:04:14 +02:00
|
|
|
|
2020-06-15 08:20:23 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|