diff --git a/TestCase/testAuditingOperating.py b/TestCase/testAuditingOperating.py index e91016b..81cdf35 100644 --- a/TestCase/testAuditingOperating.py +++ b/TestCase/testAuditingOperating.py @@ -113,12 +113,32 @@ def test_get_audits_trend_by_search(self, search_rule, title): # 获取当前时间的10位时间戳 now_timestamp = str(time.time())[0:10] # 按不同条件查询审计 - response = toolbox_steps.step_get_events_trend_by_search(search_rule, now_timestamp) + response = toolbox_steps.step_get_audits_trend_by_search(search_rule, now_timestamp) # 获取查询结果中的总审计条数 log_count = response.json()['histogram']['total'] # 验证查询成功 assert log_count >= 0 + @allure.story('日志查询规则') + @allure.title('{title}') + @pytest.mark.parametrize(('limit', 'interval', 'title'), + [(10, '1m', '按时间范围查询最近10分钟审计趋势'), + (180, '6m', '按容器模糊查询最近3小时审计趋势'), + (1440, '48m', '按容器模糊查询最近一天审计趋势') + ]) + @allure.severity(allure.severity_level.CRITICAL) + def test_get_audits_trend_by_time_limit(self, limit, interval, title): + # 获取当前时间的10位时间戳(结束时间) + now_timestamp = str(time.time())[0:10] + # 获取开始时间 + start_time = commonFunction.get_before_timestamp(limit) + # 按时间范围查询容器日志 + res = toolbox_steps.step_get_audits_trend_by_time(interval, start_time, now_timestamp) + audits_num = res.json()['query']['total'] + print(audits_num) + # 验证查询成功 + assert audits_num >= 0 + @allure.story('审计查询规则') @allure.title('{title}') @pytest.mark.parametrize(('search_rule', 'title'), @@ -147,4 +167,25 @@ def test_get_audits_by_search(self, search_rule, title): # 验证查询成功 assert logs_count >= 0 + @allure.story('日志查询规则') + @allure.title('{title}') + @pytest.mark.parametrize(('limit', 'interval', 'title'), + [(10, '1m', '按时间范围查询最近10分钟审计详情'), + (180, '6m', '按容器模糊查询最近3小时审计详情'), + (1440, '48m', '按容器模糊查询最近一天审计详情') + ]) + @allure.severity(allure.severity_level.CRITICAL) + def test_get_audits_trend_by_time_limit(self, limit, interval, title): + # 获取当前时间的10位时间戳(结束时间) + now_timestamp = str(time.time())[0:10] + # 获取开始时间 + start_time = commonFunction.get_before_timestamp(limit) + # 按时间范围查询容器日志 + res = toolbox_steps.step_get_audits_by_time(interval, start_time, now_timestamp) + audits_num = res.json()['query']['total'] + print(audits_num) + # 验证查询成功 + assert audits_num >= 0 + + diff --git a/TestCase/testClusterManage.py b/TestCase/testClusterManage.py index 1732a5b..d19efbd 100644 --- a/TestCase/testClusterManage.py +++ b/TestCase/testClusterManage.py @@ -223,6 +223,34 @@ def test_precise_non_existent_system_project(self): # 验证查询结果为空 assert items == [] + @allure.story('项目') + @allure.title('按名称精确查询集群中不存在的用户项目') + @allure.severity(allure.severity_level.NORMAL) + def test_precise_non_existent_user_project(self): + project_name = 'non-existent-project' + # 查询指定的集群的用户项目 + response = cluster_steps.step_query_user_system(project_name) + # 获取查询结果 + items = response.json()['items'] + # 验证查询结果为空 + assert items == [] + + @allure.story('项目') + @allure.title('按名称精确查询集群中存在的用户项目') + @allure.severity(allure.severity_level.NORMAL) + def test_precise_query_existent_user_project(self): + # 创建用户项目 + project_name = 'pro-' + str(commonFunction.get_random()) + alias_name = '' + description = '' + cluster_steps.step_create_user_project(project_name, alias_name, description) + # 按名称精确查询用户项目 + re = cluster_steps.step_query_user_system(project_name) + # 获取查询结果 + project_name_actual = re.json()['items'][0]['metadata']['name'] + # 验证查询结果 + assert project_name_actual == project_name + @allure.story('项目') @allure.title('按名称精确查询集群中存在的系统项目') @allure.severity(allure.severity_level.NORMAL) @@ -236,6 +264,8 @@ def test_precise_query_existent_system_project(self): project_name_actual = re.json()['items'][0]['metadata']['name'] # 验证查询结果 assert project_name_actual == project_name + # 删除项目 + cluster_steps.step_delete_user_system(project_name) @allure.story('项目') @allure.title('按名称模糊查询集群中存在的系统项目') @@ -252,6 +282,24 @@ def test_fuzzy_query_existent_system_project(self): # 验证查询结果 assert project_name_actual == project_name + @allure.story('项目') + @allure.title('按名称模糊查询集群中存在的用户项目') + @allure.severity(allure.severity_level.NORMAL) + def test_precise_query_existent_user_project(self): + # 创建用户项目 + project_name = 'pro-' + str(commonFunction.get_random()) + alias_name = '' + description = '' + cluster_steps.step_create_user_project(project_name, alias_name, description) + # 按名称精确查询用户项目 + re = cluster_steps.step_query_user_system('pro') + # 获取查询结果 + project_name_actual = re.json()['items'][0]['metadata']['name'] + # 验证查询结果 + assert project_name_actual == project_name + # 删除项目 + cluster_steps.step_delete_user_system(project_name) + @allure.story('项目') @allure.title('查询集群中所有系统项目的详情信息,并验证其状态为活跃') @allure.severity(allure.severity_level.CRITICAL) @@ -589,6 +637,27 @@ def test_check_app_workload_revision_records(self, type, title): # 验证请求的资源类型为ControllerRevisionList assert kind == 'ControllerRevisionList' + @allure.story('应用负载') + @allure.severity(allure.severity_level.CRITICAL) + @pytest.mark.parametrize('type, title', + [('jobs', '查看集群所有的jobs,并验证运行状态正常'), + ('cronjobs', '查看集群所有的cronjobs,并验证运行状态正常')]) + def test_check_jobs_of_cluster(self, type, title): + # 查询集群中所有的系统项目 + response = cluster_steps.step_get_system_of_cluster() + system_count = response.json()['totalItems'] + # 查询集群所有系统项目的Jobs + for i in range(0, system_count): + system_name = response.json()['items'][i]['metadata']['name'] + re = cluster_steps.step_get_resource_of_cluster_by_project(type, system_name) + # 获取集群Jobs的数量 + count = re.json()['totalItems'] + # 获取集群所有的Jobs的type + for j in range(0, count): + state = re.json()['items'][j]['status']['conditions'][0]['status'] + # 验证运行状态正常 + assert state == 'True' + @allure.story('应用负载') @allure.severity(allure.severity_level.CRITICAL) @allure.title('{title}') @@ -620,6 +689,8 @@ def test_check_app_workload_monitoring(self, type, title): [('应用负载', 'deployments', '查看集群所有的deployments的event'), ('应用负载', 'statefulsets', '查看集群所有的statefulSets的event'), ('应用负载', 'daemonsets', '查看集群所有的daemonSets的event'), + ('应用负载', 'jobs', '查看集群所有jobs的event'), + ('应用负载', 'cronjobs', '查看集群所有cronjobs的event'), ('应用负载', 'pods', '查看集群所有pod的event'), ('应用负载', 'services', '查看集群所有service的event'), ('存储', 'persistentvolumeclaims', '查看集群所有pvc的event') @@ -649,8 +720,10 @@ def test_check_app_workload_event(self, story, type, title): [('deployments', '按名称精确查询存在的deployments'), ('statefulsets', '按名称精确查询存在的statefulSets'), ('daemonsets', '按名称精确查询存在的daemonSets'), - ('pods', '按名称模糊查询存在的pod'), - ('services', '按名称模糊查询存在的service')]) + ('jobs', '按名称精确查询存在的job'), + ('cronjobs', '按名称精确查询存在的cronjob'), + ('pods', '按名称精确查询存在的pod'), + ('services', '按名称精确查询存在的service')]) def test_precise_query_app_workload_by_name(self, type, title): # 获取集群中存在的资源的名称 response = cluster_steps.step_get_resource_of_cluster(type) @@ -669,6 +742,8 @@ def test_precise_query_app_workload_by_name(self, type, title): [('deployments', '按名称模糊查询存在的deployments'), ('statefulsets', '按名称模糊查询存在的statefulSets'), ('daemonsets', '按名称模糊查询存在的daemonSets'), + ('jobs', '按名称模糊查询存在的job'), + ('cronjobs', '按名称模糊查询存在的cronjob'), ('pods', '按名称模糊查询存在的pod'), ('services', '按名称模糊查询存在的service')]) def test_fuzzy_query_app_workload_by_name(self, type, title): @@ -705,6 +780,34 @@ def test_query_app_workload_by_status(self, type, title): # 验证readyReplicas=replicas,从而判断资源的状态为running assert readyReplicas == replicas + @allure.story('应用负载') + @allure.title('按状态查询存在的jobs') + @allure.severity(allure.severity_level.NORMAL) + def test_query_app_jobs_by_status(self): + # 查询状态为completed的jobs + r = cluster_steps.step_get_resource_of_cluster('jobs', 'status=completed') + # 获取资源的数量 + count = r.json()['totalItems'] + # 获取资源的status + for i in range(0, count): + status = r.json()['items'][i]['status'] + # 验证状态里面有完成时间,判断job状态为已完成 + assert 'completionTime' in status + + @allure.story('应用负载') + @allure.title('按状态查询存在的cronjobs') + @allure.severity(allure.severity_level.NORMAL) + def test_query_app_cronjobs_by_status(self): + # 查询状态为completed的cronjobs + r = cluster_steps.step_get_resource_of_cluster('cronjobs', 'status=running') + # 获取资源的数量 + count = r.json()['totalItems'] + # 获取资源的status + for i in range(0, count): + status = r.json()['items'][i]['status'] + # 验证状态里面有lastScheduleTime,判断job状态为运行中 + assert 'lastScheduleTime' in status + @allure.story('应用负载') @allure.title('{title}') @allure.severity(allure.severity_level.NORMAL) @@ -1011,6 +1114,29 @@ def test_get_storage_class_detail(self): # 验证查询结果正确 assert kind == 'StorageClass' + @allure.story('存储') + @allure.title('按名称查询存储类型中存在的存储卷') + @allure.severity(allure.severity_level.CRITICAL) + def test_get_storage_class_pv(self): + # 查询集群存在的存储类型 + response = cluster_steps.step_get_resource_of_cluster('storageclasses') + # 获取任意一个存储类型 + sc_name = response.json()['items'][0]['metadata']['name'] + # 获取存储卷信息 + re = cluster_steps.step_get_resource_of_cluster('persistentvolumeclaims', 'storageClassName='+sc_name) + # 获取存储卷名称 + pv_name = re.json()['items'][0]['metadata']['name'] + # 根据名称精确查询存储卷 + response = cluster_steps.step_get_resource_of_cluster('persistentvolumeclaims', + 'storageClassName='+sc_name+'&name='+pv_name) + # 验证查询结果 + assert response.json()['totalItems'] == 1 + # 根据名称模糊查询 + response = cluster_steps.step_get_resource_of_cluster('persistentvolumeclaims', + 'storageClassName=' + sc_name + '&name=' + pv_name[:1]) + # 验证查询结果 + assert response.json()['totalItems'] != 0 + @allure.story('存储') @allure.title('将存储类型设置为默认的存储类型') @allure.severity(allure.severity_level.CRITICAL) diff --git a/TestCase/testEventSearch.py b/TestCase/testEventSearch.py index 6f675e1..ccdbfa9 100644 --- a/TestCase/testEventSearch.py +++ b/TestCase/testEventSearch.py @@ -28,6 +28,7 @@ def test_get_total_events(self): event_counts = response.json()['statistics']['events'] # 验证事件数量大于0 assert resources_count > 0 +<<<<<<< HEAD # 获取最近12小时的事件趋势图 interval = '30m' # 时间间隔 30分钟 # 获取12小时之前的时间戳 @@ -46,6 +47,20 @@ def test_get_total_events(self): assert event_count >= event_counts else: # 如果当前时间等于12点,则当天的事件总数等于最近12小时的事件总数 assert event_count == event_counts +======= + # 获取当天的事件趋势图 + interval = '1800' # 时间间隔,单位是秒 + re = toolbox_steps.step_get_events_trend(day_timestamp, now_timestamp, interval) + # 获取趋势图的横坐标数量 + count = len(re.json()['histogram']['buckets']) + # 获取每个时间段的事件数量之和 + events_count_actual = 0 + for i in range(0, count): + number = re.json()['histogram']['buckets'][i]['count'] + events_count_actual += number + # 验证接口返回的事件数量和趋势图中的事件之和一致 + assert events_count_actual == event_counts +>>>>>>> 48ff5d13df5d696fd463354e8c691dea7258d438 @allure.story('事件总量') @allure.title('验证最近 12 小时事件总数正确') @@ -87,8 +102,8 @@ def test_get_events_trend(self): time_1 = response.json()['histogram']['buckets'][0]['time'] try: time_2 = response.json()['histogram']['buckets'][1]['time'] - time_interval = (time_2 - time_1)/1000 # 换算成秒 - # 验证时间间隔正确 + time_interval = (time_2 - time_1) / 1000 # 换算成秒 + # 验证时间间隔正确 assert time_interval == int(interval) except Exception as e: print(e) @@ -150,4 +165,22 @@ def test_get_events_by_search(self, search_rule, title): # 验证查询成功 assert logs_count >= 0 - + @allure.story('事件查询规则') + @allure.title('{title}') + @pytest.mark.parametrize(('limit', 'interval', 'title'), + [(10, '1m', '按时间范围查询最近10分钟事件趋势'), + (180, '6m', '按容器模糊查询最近3小时事件趋势'), + (1440, '48m', '按容器模糊查询最近一天事件趋势') + ]) + @allure.severity(allure.severity_level.CRITICAL) + def test_get_events_by_time_limit(self, limit, interval, title): + # 获取当前时间的10位时间戳 + now_timestamp = str(time.time())[0:10] + # 获取开始时间 + start_time = commonFunction.get_before_timestamp(limit) + # 按时间范围查询事件 + res = toolbox_steps.step_get_events_by_time(interval, start_time, now_timestamp) + event_num = res.json()['query']['total'] + print(event_num) + # 验证查询成功 + assert event_num >= 0 diff --git a/TestCase/testIppool.py b/TestCase/testIppool.py index 3550baa..0668a6a 100644 --- a/TestCase/testIppool.py +++ b/TestCase/testIppool.py @@ -59,6 +59,7 @@ def test_create_ippool(self): assert synced is True response = ippool_steps.step_delete_ippool(ippool_name) assert response.status_code == 200 + ippool_steps.step_delete_ippool(ippool_name) @allure.title('给ippool分配企业空间') @allure.severity('critical') @@ -66,10 +67,13 @@ def test_assign_ws(self): ippool_name = 'ippool-' + str(get_random()) cidr = random_ip() + '/24' description = '' + # 创建ippool ippool_steps.step_create_ippool(ippool_name, cidr, description) + # 给ippool分配企业空间 r = ippool_steps.step_assign_ws(ippool_name, self.ws_name) r_new = ippool_steps.step_search_by_name(ippool_name) assert r_new.json()['items'][0]['metadata']['labels']['kubesphere.io/workspace'] == self.ws_name + # 删除ippool ippool_steps.step_delete_ippool(ippool_name) @allure.title('给已分配企业空间的ippool分配企业空间') @@ -87,9 +91,40 @@ def test_assign_ws_ippool(self): ippool_steps.step_assign_ws(ippool, ws_name_new) r_new = ippool_steps.step_search_by_name(ippool) assert r_new.json()['items'][0]['metadata']['labels']['kubesphere.io/workspace'] == ws_name_new + # 删除ippo ippool_steps.step_delete_ippool(ippool) + # 删除企业空间 workspace_steps.step_delete_workspace(ws_name_new) + @allure.title('给已被使用的ippool分配企业空间') + @allure.severity('normal') + def test_assign_ws_ippool_again(self): + ippool_name = 'ippool-' + str(get_random()) + ippool = '[\"' + ippool_name + '\"]' + deploy_name = 'deploy-' + str(get_random()) + container_name = 'test-ippool-' + str(get_random()) + cidr = random_ip() + '/24' + description = '' + # 创建ippool + ippool_steps.step_create_ippool(ippool_name, cidr, description) + # 分配企业空间 + ippool_steps.step_assign_ws(ippool_name, self.ws_name) + # 创建部署 + ippool_steps.step_create_deploy(ippool, deploy_name, container_name, self.pro_name) + sleep(15) + # 创建新的企业空间 + ws_name_new = 'test-ws-' + str(get_random()) + workspace_steps.step_create_workspace(ws_name_new) + # 给ippool分配企业空间 + re = ippool_steps.step_assign_ws(ippool_name, ws_name_new) + project_steps.step_delete_workload(self.pro_name, 'deployments', deploy_name) + sleep(5) + workspace_steps.step_delete_workspace(ws_name_new) + sleep(5) + # 删除ippool + ippool_steps.step_delete_ippool(ippool_name) + + @allure.title('删除ippool') @allure.severity('critical') def test_delete_ippool(self): @@ -121,6 +156,30 @@ def test_delete_ippool_assign_ws(self): res = ippool_steps.step_search_by_name(ippool_name) assert res.json()['totalItems'] == 0 + @allure.title('删除后创建相同的ippool') + @allure.severity('critical') + def test_create_ippool_again(self): + ippool_name = 'ippool-' + str(get_random()) + cidr = random_ip() + '/24' + description = ' ' + # 创建ippool + ippool_steps.step_create_ippool(ippool_name, cidr, description) + # 验证创建成功 + res = ippool_steps.step_search_by_name(ippool_name) + assert res.json()['items'][0]['status']['synced'] is True + # 删除ippool + ippool_steps.step_delete_ippool(ippool_name) + # 验证删除成功 + re = ippool_steps.step_search_by_name(ippool_name) + assert re.json()['totalItems'] == 0 + # 再次创建相同的ippool + ippool_steps.step_create_ippool(ippool_name, cidr, description) + # 验证创建成功 + res = ippool_steps.step_search_by_name(ippool_name) + assert res.json()['items'][0]['status']['synced'] is True + # 删除创建的ippool + ippool_steps.step_delete_ippool(ippool_name) + @allure.title('删除已使用的ippool') @allure.severity('critical') def test_delete_ippool_used(self): @@ -141,8 +200,9 @@ def test_delete_ippool_used(self): r = ippool_steps.step_delete_ippool(ippool_name) assert r.json()['reason'] == 'ippool is in use, please remove the workload before deleting' # 删除部署 - r = project_steps.step_delete_workload(self.pro_name, 'deployments', deploy_name) + project_steps.step_delete_workload(self.pro_name, 'deployments', deploy_name) sleep(15) + # 删除ippool res = ippool_steps.step_delete_ippool(ippool_name) assert res.status_code == 200 @@ -201,6 +261,7 @@ def test_ippool_num(self): ws_num_new = ippool_steps.step_get_used_ws_number(ippool_name) # 验证使用ippool的企业空间数量 assert ws_num_new == 0 + # 删除ippool ippool_steps.step_delete_ippool(ippool_name) @allure.title('查询ippool的容器组') diff --git a/TestCase/testLogSearch.py b/TestCase/testLogSearch.py index d8dab98..9b2994b 100644 --- a/TestCase/testLogSearch.py +++ b/TestCase/testLogSearch.py @@ -195,6 +195,26 @@ def test_get_logs_by_container(self, query_rule, title): # 验证查询成功 assert logs_count >= 0 + @allure.story('日志查询规则') + @allure.title('{title}') + @pytest.mark.parametrize(('limit', 'interval', 'title'), + [(10, '1m', '按时间范围查询最近10分钟日志的详情信息'), + (180, '6m', '按容器模糊查询最近3小时日志的详情信息'), + (1440, '48m', '按容器模糊查询最近一天日志的详情信息') + ]) + @allure.severity(allure.severity_level.CRITICAL) + def test_get_logs_by_time_limit(self, limit, interval, title): + # 获取当前时间的10位时间戳(结束时间) + now_timestamp = str(time.time())[0:10] + # 获取开始时间 + start_time = commonFunction.get_before_timestamp(limit) + # 按时间范围查询容器日志 + res = toolbox_steps.step_get_logs_by_time(interval, start_time, now_timestamp) + log_num = res.json()['query']['total'] + print(log_num) + # 验证查询成功 + assert log_num >= 0 + @allure.story('日志查询规则') @allure.title('查询所有KS自带容器的日志详情') def test_get_all_containers_log(self): diff --git a/TestCase/testRole.py b/TestCase/testRole.py index 9eeba5c..6e691fd 100644 --- a/TestCase/testRole.py +++ b/TestCase/testRole.py @@ -1,3 +1,5 @@ +import time + import pytest import allure import sys @@ -67,6 +69,60 @@ def test_query_not_exist_role(self): # 验证查询结果为空 assert response.json()['totalItems'] == 0 + @allure.story('角色详情') + @allure.severity(allure.severity_level.NORMAL) + @allure.title('查询角色权限列表') + def test_query_role_permission_list(self): + role_name = 'role' + str(commonFunction.get_random()) + authority = '["role-template-manage-clusters","role-template-view-clusters","role-template-view-basic"]' + # 创建角色 + platform_steps.step_create_role(role_name) + # 查询权限列表 + authority_list = platform_steps.step_get_role_authority(role_name) + # 验证权限正确 + assert authority == authority_list + # 删除角色 + platform_steps.step_delete_role(role_name) + + @allure.story('角色详情') + @allure.severity(allure.severity_level.NORMAL) + @allure.title('查询角色授权用户') + def test_query_role_Authorized_user(self): + role_name = 'role' + str(commonFunction.get_random()) + user_name = 'user' + str(commonFunction.get_random()) + # 创建角色 + platform_steps.step_create_role(role_name) + # 使用新创建的角色创建用户 + platform_steps.step_create_user(user_name, role_name) + time.sleep(3) + # 查询角色授权用户 + res = platform_steps.step_get_role_user(role_name) + # 验证用户数量 + assert res.json()['totalItems'] == 1 + # 验证用户名称 + assert res.json()['items'][0]['metadata']['name'] == user_name + # 删除用户 + platform_steps.step_delete_user(user_name) + # 删除角色 + platform_steps.step_delete_role(role_name) + + @allure.story('角色列表') + @allure.severity(allure.severity_level.NORMAL) + @allure.title('删除已关联用户的角色') + def test_delete_role_Authorized(self): + role_name = 'role' + str(commonFunction.get_random()) + user_name = 'user' + str(commonFunction.get_random()) + # 创建角色 + platform_steps.step_create_role(role_name) + # 使用新创建的角色创建用户 + platform_steps.step_create_user(user_name, role_name) + time.sleep(3) + # 删除角色 + res = platform_steps.step_delete_role(role_name) + print(res.json()) + # 删除用户 + platform_steps.step_delete_user(user_name) + if __name__ == "__main__": pytest.main(['-s', 'testRole.py']) # -s参数是为了显示用例的打印信息。 -q参数只显示结果,不显示过程 diff --git a/TestCase/testUser.py b/TestCase/testUser.py index ceb407d..842a667 100644 --- a/TestCase/testUser.py +++ b/TestCase/testUser.py @@ -124,6 +124,33 @@ def test_modify_user_pwd_by_admin(self, type, title): # 删除创建的用户 platform_steps.step_delete_user(user_name) + @allure.story('用户') + @allure.severity('critical') + @allure.title('用户历史登陆时间') + def test_user_login_history(self): + user_name = 'modify' + str(commonFunction.get_random()) + role = 'platform-admin' + platform_steps.step_create_user(user_name, role) + # 等待创建的用户被激活 + time.sleep(3) + # 验证用户还未登陆 + res = platform_steps.step_get_user_info(user_name) + assert 'lastLoginTime' not in res.json()['items'][0]['status'] + # 使用新创建的用户登陆,并获取headers + try: + headers = platform_steps.step_get_headers(user_name, pwd='P@88w0rd') + except Exception as e: + print(e) + print("新创建的用户登陆失败") + # 验证登陆成功 + assert headers + # 查询新用户信息 + res = platform_steps.step_get_user_info(user_name) + # 验证已有登陆时间信息 + assert 'lastLoginTime' in res.json()['items'][0]['status'] + # 删除用户 + platform_steps.step_delete_user(user_name) + if __name__ == "__main__": pytest.main(['-s', 'testUser.py']) # -s参数是为了显示用例的打印信息。 -q参数只显示结果,不显示过程 diff --git a/TestCase/testWorkspace.py b/TestCase/testWorkspace.py index 278eb64..0a16662 100644 --- a/TestCase/testWorkspace.py +++ b/TestCase/testWorkspace.py @@ -8,7 +8,7 @@ from common.getData import DoexcleByPandas from common.logFormat import log_format from common import commonFunction -from step import workspace_steps, platform_steps +from step import workspace_steps, platform_steps, project_steps, devops_steps @allure.feature('企业空间') @@ -60,6 +60,109 @@ def test_ws(self, id, url, params, data, story, title, method, severity, conditi 以下用例由于存在较多的前置条件,不便于从excle中获取信息,故使用一个方法一个用例的方式 ''' + @allure.story('企业空间列表') + @allure.title('删除企业空间') + @allure.severity('critical') + def test_delete_ws(self): + ws_name = 'test-ws' + str(commonFunction.get_random()) + # 创建企业空间 + workspace_steps.step_create_workspace(ws_name) + # 删除创建的企业空间 + res = workspace_steps.step_delete_workspace(ws_name) + mes = res.json()['message'] + # 判断删除成功 + assert mes == 'success' + + @allure.story('企业空间概览') + @allure.title('资源用量-项目数量验证') + @allure.severity('critical') + def test_get_project_num(self): + ws_name = 'test-ws' + str(commonFunction.get_random()) + # 创建企业空间 + workspace_steps.step_create_workspace(ws_name) + # 获取概览信息 + res = workspace_steps.step_get_ws_num_info(ws_name) + pro_num = res.json()['results'][0]['data']['result'][0]['value'][1] + # 验证项目数量正确 + assert pro_num == '0' + # 在企业空间中创建项目 + pro_name = 'pro-' + str(commonFunction.get_random()) + project_steps.step_create_project(ws_name, pro_name) + # 获取项目数量 + res_new = workspace_steps.step_get_ws_num_info(ws_name) + new_pro_num = res_new.json()['results'][0]['data']['result'][0]['value'][1] + assert new_pro_num == '1' + #删除项目 + project_steps.step_delete_project(ws_name,pro_name) + # 删除企业空间 + workspace_steps.step_delete_workspace(ws_name) + + @allure.story('企业空间概览') + @allure.title('资源用量-devops工程数量验证') + @allure.severity('critical') + def test_get_devops_project_num(self): + ws_name = 'test-ws' + str(commonFunction.get_random()) + # 创建企业空间 + workspace_steps.step_create_workspace(ws_name) + # 获取概览信息 + res = workspace_steps.step_get_ws_num_info(ws_name) + devops_num = res.json()['results'][1]['data']['result'][0]['value'][1] + assert devops_num == '0' + # 在企业空间创建devops工程 + devops_name = 'devops-' + str(commonFunction.get_random()) + devops_steps.step_create_devops(ws_name, devops_name) + time.sleep(3) + # 获取概览信息 + res_new = workspace_steps.step_get_ws_num_info(ws_name) + new_devops_num = res_new.json()['results'][1]['data']['result'][0]['value'][1] + assert new_devops_num == '1' + # 删除devops工程 + devops_steps.step_delete_devops(ws_name, devops_name) + # 删除企业空间 + workspace_steps.step_delete_workspace(ws_name) + + @allure.story('企业空间概览') + @allure.title('资源用量-角色数量验证') + @allure.severity('critical') + def test_get_ws_role_num(self): + ws_name = 'test-ws' + str(commonFunction.get_random()) + # 创建企业空间 + workspace_steps.step_create_workspace(ws_name) + # 获取概览信息 + res = workspace_steps.step_get_ws_num_info(ws_name) + role_num = res.json()['results'][2]['data']['result'][0]['value'][1] + assert role_num == '1' + # 在企业空间创建角色 + role_name = 'role-' + str(commonFunction.get_random()) + workspace_steps.step_create_ws_role(ws_name,role_name) + # 获取概览信息 + res_new = workspace_steps.step_get_ws_num_info(ws_name) + new_role_num = res_new.json()['results'][2]['data']['result'][0]['value'][1] + assert new_role_num == '2' + # 删除企业空间 + workspace_steps.step_delete_workspace(ws_name) + + @allure.story('企业空间概览') + @allure.title('资源用量-用户数量验证') + @allure.severity('critical') + def test_get_ws_role_num(self): + ws_name = 'test-ws' + str(commonFunction.get_random()) + # 创建企业空间 + workspace_steps.step_create_workspace(ws_name) + # 获取概览信息 + res = workspace_steps.step_get_ws_num_info(ws_name) + user_num = res.json()['results'][3]['data']['result'][0]['value'][1] + assert user_num == '4' + # 在企业空间创建用户 + user_name = 'user-' + str(commonFunction.get_random()) + workspace_steps.step_create_user(ws_name, user_name) + # 获取概览信息 + res_new = workspace_steps.step_get_ws_num_info(ws_name) + new_user_num = res_new.json()['results'][3]['data']['result'][0]['value'][1] + assert new_user_num == '5' + # 删除企业空间 + workspace_steps.step_delete_workspace(ws_name) + @allure.story('企业空间设置-企业角色') @allure.title('在企业空间编辑角色的权限信息') @allure.severity('critical') @@ -105,6 +208,32 @@ def test_ws_invite_user(self): # 删除创建的用户 platform_steps.step_delete_user(user_name) + @allure.story('企业空间设置-企业角色') + @allure.title('在企业空间创建角色,关联到用户,验证权限正确') + @allure.severity(allure.severity_level.CRITICAL) + def test_ws_role_authorized_user(self): + authority_create = '["role-template-view-basic"]' + role_name = 'role-' + str(commonFunction.get_random()) + # 创建角色 + workspace_steps.step_create_ws_role(self.ws_name, role_name, authority_create) + # 在平台创建用户 + user_name = 'user' + str(commonFunction.get_random()) + user_role = 'platform-regular' + platform_steps.step_create_user(user_name, user_role) + # 邀请用户到企业空间 + workspace_steps.step_invite_user(self.ws_name, user_name, role_name) + # 查询角色授权用户 + res = workspace_steps.step_get_role_user(self.ws_name, role_name) + user = res.json()['items'][0]['metadata']['name'] + user_num = res.json()['totalItems'] + # 验证授权用户正确 + assert user == user_name + assert user_num == 1 + # 删除用户 + workspace_steps.step_delete_user(user_name) + # 删除角色 + workspace_steps.step_delete_role(self.ws_name, role_name) + @allure.story('企业空间设置-企业角色') @allure.title('在企业空间编辑邀请成员的角色') @allure.severity(allure.severity_level.CRITICAL) @@ -412,6 +541,28 @@ def test_enable_network_lsolation(self): # 验证设置成功 assert network_lsolation is True + @allure.story('概览/用量排行') + @allure.title('{title}') + @allure.severity(allure.severity_level.CRITICAL) + @pytest.mark.parametrize('sort, title', + [('namespace_cpu_usage', 'Sort by CPU查看Namespace Usage Ranking'), + ('namespace_memory_usage_wo_cache', 'Sort by Memory查看Namespace Usage Ranking'), + ('namespace_pod_count', 'Sort by Pod Count查看Namespace Usage Ranking'), + ('namespace_net_bytes_received', 'Sort by Received查看Namespace Usage Ranking'), + ('namespace_net_bytes_transmitted', 'Sort by Pod Transmitted查看Namespace Usage Ranking') + ]) + def test_get_namespace_usage_rank(self, sort, title): + # 查询Node Usage Ranking + response = workspace_steps.step_get_namespace_usage_rank(self.ws_name, sort) + # 获取结果中的数据类型 + for i in range(0, 15): + try: + result_type = response.json()['results'][i]['data']['resultType'] + # 验证数据类型为vector + assert result_type == 'vector' + except Exception as e: + print(e) + if __name__ == "__main__": pytest.main(['-s', 'testWorkspace.py']) # -s参数是为了显示用例的打印信息。 -q参数只显示结果,不显示过程 diff --git a/step/cluster_steps.py b/step/cluster_steps.py index fb9753b..bec2de1 100644 --- a/step/cluster_steps.py +++ b/step/cluster_steps.py @@ -207,6 +207,14 @@ def step_get_user_system(project_name): return response +@allure.step('名称查询指定的用户项目') +def step_query_user_system(project_name): + url = env_url + '/kapis/resources.kubesphere.io/v1alpha3/namespaces?name=' + project_name +\ + '&sortBy=createTime&limit=10&labelSelector=kubesphere.io%2Fworkspace%21%3Dsystem-workspace%2C%21kubesphere.io%2Fdevopsproject' + response = requests.get(url=url, headers=get_header()) + return response + + @allure.step('删除用户项目') def step_delete_user_system(project_name): url = env_url + '/api/v1/namespaces/' + project_name diff --git a/step/platform_steps.py b/step/platform_steps.py index 3e16595..8a44d73 100644 --- a/step/platform_steps.py +++ b/step/platform_steps.py @@ -57,6 +57,20 @@ def step_get_role_info(role_name): return response +@allure.step('获取角色权限列表') +def step_get_role_authority(role_name): + url = env_url + '/kapis/iam.kubesphere.io/v1alpha2/globalroles/' + role_name + response = requests.get(url=url, headers=get_header()) + return response.json()['metadata']['annotations']['iam.kubesphere.io/aggregation-roles'] + + +@allure.step('获取角色授权用户') +def step_get_role_user(role_name): + url = env_url + '/kapis/iam.kubesphere.io/v1alpha2/users?globalrole=' + role_name + '&sortBy=createTime&limit=10' + response = requests.get(url=url, headers=get_header()) + return response + + @allure.step('删除角色') def step_delete_role(role_name): """ diff --git a/step/toolbox_steps.py b/step/toolbox_steps.py index dd0102c..4430cd4 100644 --- a/step/toolbox_steps.py +++ b/step/toolbox_steps.py @@ -29,13 +29,21 @@ def step_get_audits_trend(start_time, end_time): @allure.step('按不同条件查询集群审计总数的变化趋势') -def step_get_events_trend_by_search(search_rule, end_time): +def step_get_audits_trend_by_search(search_rule, end_time): url = env_url + '/kapis/tenant.kubesphere.io/v1alpha2/auditing/events?operation=histogram&' \ 'start_time=0&end_time=' + end_time + '&interval=1d&' + search_rule response = requests.get(url=url, headers=get_header()) return response +@allure.step('按时间范围查询集群审计总数的变化趋势') +def step_get_audits_trend_by_time(interval, start_time, end_time): + url = env_url + '/kapis/tenant.kubesphere.io/v1alpha2/auditing/events?operation=histogram&' \ + 'start_time=' + start_time + '&end_time=' + end_time + '&interval=' + interval + response = requests.get(url=url, headers=get_header()) + return response + + @allure.step('按不同条件查询审计的信息') def step_get_audits_by_search(search_rule, end_time): url = env_url + '/kapis/tenant.kubesphere.io/v1alpha2/auditing/events?operation=query&from=0&size=50&' \ @@ -44,6 +52,14 @@ def step_get_audits_by_search(search_rule, end_time): return response +@allure.step('按时间范围查询审计的信息') +def step_get_audits_by_time(interval, start_time, end_time): + url = env_url + '/kapis/tenant.kubesphere.io/v1alpha2/auditing/events?operation=query&from=0&size=50&' \ + + '&start_time=' + start_time + '&end_time=' + end_time + '&interval=' + interval + response = requests.get(url=url, headers=get_header()) + return response + + @allure.step('查询集群的事件总量') def step_get_event(start_time, end_time): url = env_url + '/kapis/tenant.kubesphere.io/v1alpha2/events?operation=statistics&start_time=' + start_time + \ @@ -76,6 +92,13 @@ def step_get_events_by_search(search_rule, end_time): return response +@allure.step('按时间范围查询事件的信息') +def step_get_events_by_time(interval, start_time, end_time): + url = env_url + '/kapis/tenant.kubesphere.io/v1alpha2/events?operation=query&from=0&size=50' + \ + '&start_time=' + start_time + '&end_time=' + end_time + '&interval=' + interval + response = requests.get(url=url, headers=get_header()) + return response + @allure.step('查询集群的日志总量') def step_get_log(start_time, end_time): @@ -145,6 +168,14 @@ def step_get_logs_by_pod(query_rule, pod_name, end_time): return response +@allure.step('按时间范围查询日志的详情信息') +def step_get_logs_by_time(interval, start_time, end_time): + url = env_url + '/kapis/tenant.kubesphere.io/v1alpha2/logs?operation=query&log_query=&pods=&' \ + 'containers=&from=0&size=50&interval=' + interval + '&start_time=' + start_time + '&end_time=' + end_time + response = requests.get(url=url, headers=get_header()) + return response + + @allure.step('按容器查询日志的详情信息') def step_get_logs_by_container(query_rule, container_name, end_time): if query_rule == 'Exact Query': diff --git a/step/workspace_steps.py b/step/workspace_steps.py index 0ff116d..89bd2dd 100644 --- a/step/workspace_steps.py +++ b/step/workspace_steps.py @@ -30,6 +30,13 @@ def step_edit_role_authory(ws_name, role_name, version, authory): return response +@allure.step('企业空间概览信息') +def step_get_ws_num_info(ws_name): + url = env_url + '/kapis/monitoring.kubesphere.io/v1alpha3/workspaces/' + ws_name + '?type=statistics' + response = requests.get(url=url, headers=get_header()) + return response + + @allure.step('创建企业空间的角色') def step_create_ws_role(ws_name, ws_role_name, authory): """ @@ -77,6 +84,13 @@ def step_delete_role(ws_name, role_name): return response +@allure.step('查询角色授权用户') +def step_get_role_user(ws_name, role_name): + url = env_url + '/kapis/iam.kubesphere.io/v1alpha2/workspaces/' + ws_name + '/workspacemembers?workspacerole=' + role_name + '&sortBy=createTime&limit=10' + response = requests.get(url=url, headers=get_header()) + return response + + @allure.step('邀请用户到企业空间') def step_invite_user(ws_name, user_name, role_name): url = env_url + '/kapis/iam.kubesphere.io/v1alpha2/workspaces/' + ws_name + '/workspacemembers' @@ -261,7 +275,8 @@ def step_create_workspace(ws_name): "metadata": {"name": ws_name, "annotations": {"kubesphere.io/creator": "admin"}}, "spec": {"template": {"spec": {"manager": "admin"}}}} - requests.post(url, headers=get_header(), data=json.dumps(data)) + response = requests.post(url, headers=get_header(), data=json.dumps(data)) + return response @allure.step('创建多集群企业空间') @@ -330,7 +345,7 @@ def step_get_ws_info(ws_name): @allure.step('查询企业空间的项目信息') def step_get_project_info(ws_name): url = env_url + '/kapis/tenant.kubesphere.io/v1alpha2/workspaces/' + ws_name + '/namespaces?' \ - 'sortBy=createTime&labelSelector=%21kubesphere.io%2Fkubefed-host-namespace%2C%21kubesphere.io%2Fdevopsproject' + 'sortBy=createTime&labelSelector=%21kubesphere.io%2Fkubefed-host-namespace%2C%21kubesphere.io%2Fdevopsproject' response = requests.get(url=url, headers=get_header()) return response @@ -359,4 +374,8 @@ def step_create_multi_ws(ws_name, alias_name, description, cluster_names): return response - +@allure.step('查询集群的 namespace usage ranking信息') +def step_get_namespace_usage_rank(ws_name, sort): + url = env_url + '/kapis/monitoring.kubesphere.io/v1alpha3/workspaces/' + ws_name + '/namespaces?type=rank&metrics_filter=namespace_memory_usage_wo_cache%7Cnamespace_memory_limit_hard%7Cnamespace_cpu_usage%7Cnamespace_cpu_limit_hard%7Cnamespace_pod_count%7Cnamespace_pod_count_hard%7Cnamespace_net_bytes_received%7Cnamespace_net_bytes_transmitted&page=1&limit=10&sort_type=desc&sort_metric=' + sort + response = requests.get(url=url, headers=get_header()) + return response