Skip to content

Commit

Permalink
Merge branch 'jioce-master'
Browse files Browse the repository at this point in the history
the commit.
  • Loading branch information
wenxinll committed Apr 2, 2022
2 parents 3daa53a + b63fae2 commit 6180905
Show file tree
Hide file tree
Showing 12 changed files with 599 additions and 12 deletions.
43 changes: 42 additions & 1 deletion TestCase/testAuditingOperating.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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



130 changes: 128 additions & 2 deletions TestCase/testClusterManage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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('按名称模糊查询集群中存在的系统项目')
Expand All @@ -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)
Expand Down Expand Up @@ -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}')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
39 changes: 36 additions & 3 deletions TestCase/testEventSearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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小时之前的时间戳
Expand All @@ -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 小时事件总数正确')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Loading

0 comments on commit 6180905

Please sign in to comment.