Skip to content

Commit

Permalink
Merge pull request #28 from wenxinll/master
Browse files Browse the repository at this point in the history
add new case
  • Loading branch information
wenxinll authored Sep 24, 2023
2 parents 8b06e5a + e0ac43b commit d6eae3e
Show file tree
Hide file tree
Showing 49 changed files with 3,788 additions and 2,591 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# name: Build

# on:
# push:
# branches:
# - master


# jobs:
# build:
# name: Build
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# with:
# fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
# - uses: sonarsource/sonarqube-scan-action@master
# env:
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
# If you wish to fail your job when the Quality Gate is red, uncomment the
# following lines. This would typically be used to fail a deployment.
# - uses: sonarsource/sonarqube-quality-gate-action@master
# timeout-minutes: 5
# env:
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
179 changes: 146 additions & 33 deletions TestCase/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import time
from common import commonFunction
from datetime import datetime
from common.commonFunction import get_random
from step import cluster_steps, multi_project_steps, multi_workspace_steps, project_steps, ippool_steps, platform_steps, \
from step import cluster_steps, multi_project_steps, multi_workspace_steps, project_steps, network_steps, \
platform_steps, \
workspace_steps, app_steps, devops_steps, storage_steps, multi_cluster_steps, multi_cluster_storages_step


Expand All @@ -12,10 +12,22 @@ def create_project(create_ws):
# 创建项目
project_name = 'test-pro' + str(commonFunction.get_random())
project_steps.step_create_project(create_ws, project_name)
time.sleep(3)
# 等待项目创建成功
i = 0
while i < 60:
try:
project_info = project_steps.step_get_project_info_by_name(create_ws, project_name)
if project_info.json()['totalItems'] == 1:
break
else:
time.sleep(1)
i += 1
except KeyError as e:
print(e)
time.sleep(1)
i += 1
yield project_name
# 删除创建的项目
time.sleep(1)
project_steps.step_delete_project(create_ws, project_name)


Expand All @@ -37,12 +49,6 @@ def workload_name():
return workload_name


@pytest.fixture()
def container_name():
container_name = 'container-nginx' + str(commonFunction.get_random()) # 容器名称
return container_name


@pytest.fixture()
def strategy_info():
# 创建deployment的策略信息
Expand Down Expand Up @@ -86,9 +92,16 @@ def create_project_role(create_project):
role_name = 'role' + str(commonFunction.get_random())
# 创建角色
project_steps.step_create_role(create_project, role_name)
time.sleep(1)
# 等待角色创建成功
i = 0
while i < 60:
role_info = project_steps.step_get_role(create_project, role_name)
if role_info.json()['totalItems'] == 1:
break
else:
time.sleep(1)
i += 1
yield role_name
time.sleep(1)
project_steps.step_project_delete_role(create_project, role_name)


Expand All @@ -98,7 +111,6 @@ def create_role():
role_name = 'role' + str(commonFunction.get_random())
# 创建角色
platform_steps.step_create_role(role_name, authority)
time.sleep(1)
yield role_name
# 删除角色
platform_steps.step_delete_role(role_name)
Expand All @@ -111,7 +123,7 @@ def create_multi_workspace():
alias_name = '跨集群'
description = '包含所有的集群的企业空间'
clusters = cluster_steps.step_get_cluster_name()
multi_workspace_steps.step_create_multi_ws(ws_name, alias_name, description, clusters)
multi_workspace_steps.step_create_multi_ws(ws_name, clusters, alias_name, description)
yield ws_name
multi_workspace_steps.step_delete_workspace(ws_name)

Expand All @@ -121,9 +133,9 @@ def create_multi_project(create_multi_workspace):
# 创建一个多集群项目(包含所有集群)
pro_name = 'pro-multi-' + str(commonFunction.get_random())
clusters = cluster_steps.step_get_cluster_name()
multi_project_steps.step_create_multi_project(create_multi_workspace, pro_name, clusters)
multi_project_steps.step_create_fed_project(create_multi_workspace, pro_name, clusters)
yield pro_name
multi_project_steps.step_delete_multi_project(project_name=pro_name)
multi_project_steps.step_delete_fed_project(project_name=pro_name)


@pytest.fixture()
Expand All @@ -145,6 +157,17 @@ def create_user(create_role):
password = 'P@88w0rd'
# 使用新创建的角色创建用户
platform_steps.step_create_user(user_name, create_role, email, password)
# # 等待用户创建成功
i = 0
while i < 10:
try:
user_info = platform_steps.step_get_user_info(user_name)
if user_info.json()['items'][0]['status']['state']:
break
except Exception as e:
print(e)
time.sleep(1)
i += 1
yield user_name
# 删除用户
platform_steps.step_delete_user(user_name)
Expand All @@ -155,10 +178,17 @@ def create_ws():
ws_name = 'test-ws' + str(commonFunction.get_random())
# 创建企业空间
workspace_steps.step_create_workspace(ws_name)
time.sleep(1)
# 等待企业空间创建成功
i = 0
while i < 60:
ws_info = workspace_steps.step_get_ws_info(ws_name)
if ws_info.json()['totalItems'] == 1:
break
else:
time.sleep(1)
i += 1
yield ws_name
# 删除企业空间
time.sleep(1)
workspace_steps.step_delete_workspace(ws_name)


Expand Down Expand Up @@ -196,33 +226,54 @@ def node_name():


@pytest.fixture()
def create_ippool():
ippool_name = 'ippool-' + str(commonFunction.get_random())
cidr = commonFunction.random_ip()
description = ' '
# 在单集群环境创建ippool
def create_ippool(ip_pool_name, ip_address):
# 创建ippool
ippool_steps.step_create_ippool(ippool_name, cidr, description)
time.sleep(1)
yield ippool_name
network_steps.step_create_ippool(ip_pool_name, ip_address)
yield ip_pool_name
# 删除ippool
time.sleep(1)
ippool_steps.step_delete_ippool(ippool_name)
network_steps.step_delete_ippool(ip_pool_name)


@pytest.fixture()
# 在多集群环境创建ippool
def create_multi_ippool(request, ip_pool_name, ip_address):
# 获取参数
# 创建ippool
network_steps.step_create_ippool(ip_pool_name, ip_address, cluster_name=request.param)
yield ip_pool_name
# 删除ippool
i = 0
while i < 60:
r = network_steps.step_delete_ippool(ip_pool_name, request.param)
if r.status_code == 200:
break
i += 1
time.sleep(1)


@pytest.fixture()
def create_devops(create_ws):
dev_name = 'test-dev' + str(commonFunction.get_random())
devops_steps.step_create_devops(create_ws, dev_name) # 创建一个devops工程
response = devops_steps.step_get_devopinfo(create_ws, dev_name)
devops_name_new = response.json()['items'][0]['metadata']['name']
i = 0
devops_name_new = ''
while i < 10:
response = devops_steps.step_get_devopinfo(create_ws, dev_name)
devops_name_new = response.json()['items'][0]['metadata']['name']
status = response.json()['items'][0]['metadata']['annotations']['devopsproject.devops.kubesphere.io/syncstatus']
if status == 'successful':
break
time.sleep(1)
i += 1
yield devops_name_new
# 删除devops工程
devops_steps.step_delete_devops(create_ws, devops_name_new)


@pytest.fixture()
def create_sc():
sc_name = 'sc-' + str(get_random())
sc_name = 'sc-' + str(commonFunction.get_random())
ex = True
# 创建存储类
storage_steps.create_sc(sc_name, ex)
Expand All @@ -233,7 +284,7 @@ def create_sc():

@pytest.fixture()
def create_multi_cluster_sc():
sc_name = 'sc-' + str(get_random())
sc_name = 'sc-' + str(commonFunction.get_random())
ex = True
cluster_name = multi_cluster_steps.step_get_host_cluster_name()
# 创建存储类
Expand All @@ -250,5 +301,67 @@ def create_code_repository(create_devops):
provider = 'git'
url = 'https://gitee.com/linuxsuren/demo-go-http'
devops_steps.step_import_code_repository(create_devops, name, provider, url)
time.sleep(5)
yield url
yield url


@pytest.fixture()
# 创建网络策略
def create_network_policy(create_project):
# 创建网络策略
policy_name = 'network-policy-' + str(commonFunction.get_random())
network_steps.step_create_network_policy(create_project, policy_name)
yield policy_name
# 删除网络策略
network_steps.step_delete_network_policy(create_project, policy_name)


@pytest.fixture()
def ip_pool_name():
return 'ip-pool-' + str(commonFunction.get_random())


@pytest.fixture()
def ip_address():
return commonFunction.random_ip()


@pytest.fixture()
# 返回企业空间名称
def ws_name():
ws_name = 'ws-test' + str(commonFunction.get_random())
return ws_name


@pytest.fixture()
# 返回项目名称
def pro_name():
pro_name = 'pro-test' + str(commonFunction.get_random())
return pro_name


@pytest.fixture()
# 返回deploy名称
def deploy_name():
deploy_name = 'deploy-test' + str(commonFunction.get_random())
return deploy_name


@pytest.fixture()
# 返回container名称
def container_name():
container_name = 'container-test' + str(commonFunction.get_random())
return container_name


@pytest.fixture()
# 在多集群环境创建卷快照类
def create_multi_volume_snapshot_class(request):
cluster_name = request.param
vsc_name = 'vsc-' + str(commonFunction.get_random())
diver = 'disk.csi.qingcloud.com'
policy = 'Delete'
# 创建卷快照类
multi_cluster_storages_step.step_create_vsc(cluster_name, vsc_name, diver, policy)
yield vsc_name
# 删除卷快照类
multi_cluster_storages_step.delete_vsc(cluster_name, vsc_name)
3 changes: 2 additions & 1 deletion TestCase/test_appManage.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,12 @@ def test_add_version(self, create_app_template):
app_steps.step_add_version(self.ws_name, app_id)
# 等待应用版本添加成功
i = 0
versions = []
while i < 60:
try:
# 获取应用模版中所有的版本version
versions = app_steps.step_get_app_versions(self.ws_name, app_id)
if versions:
if len(versions) > 0:
break
except Exception as e:
print(e)
Expand Down
11 changes: 6 additions & 5 deletions TestCase/test_appStore.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
@pytest.mark.skipif(commonFunction.get_components_status_of_cluster('openpitrix') is False, reason='集群未开启openpitrix功能')
@pytest.mark.skipif(commonFunction.check_multi_cluster() is True, reason='多集群环境下不执行')
class TestAppStore(object):
if commonFunction.check_multi_cluster() is True:
# 如果为多集群环境,则不会collect该class的所有用例。 __test__ = False
__test__ = False
else:
__test__ = True
__test__ = False
# if commonFunction.check_multi_cluster() is True:
# # 如果为多集群环境,则不会collect该class的所有用例。 __test__ = False
# __test__ = False
# else:
# __test__ = True

ws_name = 'test-deploy-from-appstore' + str(commonFunction.get_random()) # 在excle中读取的用例此名称,不能修改。
# 在excle中读取的用例此名称,不能修改。
Expand Down
Loading

0 comments on commit d6eae3e

Please sign in to comment.