Skip to content

Commit

Permalink
Merge pull request #26 from wenxinll/master
Browse files Browse the repository at this point in the history
增加whizard开启与否的判断和用例优化
  • Loading branch information
wenxinll authored Apr 14, 2023
2 parents e61df51 + fd2f6f3 commit 57be10c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
7 changes: 5 additions & 2 deletions TestCase/test_multiClusterAlerting.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

@allure.feature('多集群告警')
@pytest.mark.skipif(commonFunction.get_components_status_of_cluster('alerting') is False, reason='集群未开启alerting功能')
@pytest.mark.skipif(commonFunction.get_components_status_of_cluster('whizard') is True, reason='集群已开启whizard功能')
class TestMultiClusterAlerting(object):
# 如果为单集群环境,则不会collect该class的所有用例。 __test__ = False
__test__ = commonFunction.check_multi_cluster()
Expand Down Expand Up @@ -62,14 +63,16 @@ def test_create_alert_policy(self):
time.sleep(180)
re = multi_cluster_steps.step_get_alert_custom_policy(self.cluster_host_name, alert_name)
state = re.json()['items'][0]['state']
pytest.assume(state == 'firing')
with pytest.assume:
assert state == 'firing'
# 查看告警消息,并验证告警消息正确
r = multi_cluster_steps.step_get_alert_message(self.cluster_host_name, '', 'label_filters=severity%3Dwarning')
message_count = r.json()['total']
policy_names = []
for i in range(0, message_count):
policy_names.append(r.json()['items'][i]['ruleName'])
pytest.assume(alert_name in policy_names)
with pytest.assume:
assert alert_name in policy_names
# 删除告警策略
multi_cluster_steps.step_delete_alert_custom_policy(self.cluster_host_name, alert_name)

Expand Down
22 changes: 14 additions & 8 deletions TestCase/test_multiClusterLogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def test_get_total_logs(self):
# 获取收集到的日志数量
log_counts = response.json()['statistics']['logs']
# 验证容器数量大于0
pytest.assume(pod_count > 0)
with pytest.assume:
assert pod_count > 0
# 查询最近12小时的日志变化趋势
interval = '30m' # 时间间隔 30分钟
# 获取12小时之前的时间戳
Expand Down Expand Up @@ -98,9 +99,9 @@ def test_get_logs_trend(self):
# 获取查询结果数据中的时间间隔
time_1 = response.json()['histogram']['histograms'][0]['time']
time_2 = response.json()['histogram']['histograms'][1]['time']
time_interval = (time_2 - time_1) / 1000 # 换算成秒
time_interval = (time_2 - time_1) / 1000 / 60 # 换算成分钟
# 验证时间间隔正确
assert time_interval == int(interval)
assert time_interval == int(interval[:2])

@allure.story('日志查询规则')
@allure.title('{title}')
Expand Down Expand Up @@ -237,7 +238,8 @@ def test_get_log_receiver_log(self):
component = response.json()['items'][0]['metadata']['labels']['logging.kubesphere.io/component']
enabled = response.json()['items'][0]['metadata']['labels']['logging.kubesphere.io/enabled']
# 校验接收器类型和启用状态,启用状态默认为开启
pytest.assume(component == 'logging')
with pytest.assume:
assert component == 'logging'
assert enabled == 'true'

@allure.story('集群设置/日志接收器')
Expand All @@ -254,7 +256,8 @@ def test_add_log_receiver_logging(self, type, log_type, title):
response = multi_cluster_steps.step_get_log_receiver(self.cluster_host_name, log_type)
log_receiver_name = response.json()['items'][1]['metadata']['name']
# 验证日志接收器添加成功
pytest.assume(log_receiver_name == 'forward-' + log_type)
with pytest.assume:
assert log_receiver_name == 'forward-' + log_type
# 删除创建的日志接收器
multi_cluster_steps.step_delete_log_receiver(self.cluster_host_name, log_receiver_name)

Expand All @@ -277,7 +280,8 @@ def test_modify_log_receiver_logging_status(self, log_type, title):
# 查看日志接受器详情并验证更改成功
re = multi_cluster_steps.step_get_log_receiver_detail(self.cluster_host_name, log_receiver_name)
status = re.json()['metadata']['labels']['logging.kubesphere.io/enabled']
pytest.assume(status == 'false')
with pytest.assume:
assert status == 'false'
# 删除创建的日志接收器
multi_cluster_steps.step_delete_log_receiver(self.cluster_host_name, log_receiver_name)

Expand All @@ -304,7 +308,9 @@ def test_modify_log_receiver_logging_address(self, log_type, title):
re = multi_cluster_steps.step_get_log_receiver_detail(self.cluster_host_name, log_receiver_name)
host_actual = re.json()['spec']['forward']['host']
port_actual = re.json()['spec']['forward']['port']
pytest.assume(host_actual == host)
pytest.assume(port_actual == port)
with pytest.assume:
assert host_actual == host
with pytest.assume:
assert port_actual == port
# 删除创建的日志接收器
multi_cluster_steps.step_delete_log_receiver(self.cluster_host_name, log_receiver_name)
2 changes: 2 additions & 0 deletions common/commonFunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ def get_components_status_of_cluster(component):
component_status = spec[component]['store']['enabled']
elif component == 'network':
component_status = spec[component]['networkpolicy']['enabled']
elif component == 'whizard':
component_status = spec['monitoring']['whizard']['enabled']
else:
component_status = spec[component]['enabled']
return component_status
Expand Down
3 changes: 2 additions & 1 deletion step/toolbox_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,13 @@ def step_get_log(start_time, end_time, *cluster_name):

@allure.step('查询集群日志总数的变化趋势')
def step_get_logs_trend(start_time, end_time, interval, *cluster_name):
path = ''
if cluster_name:
for i in cluster_name:
path = '/kapis/clusters/' + str(i) + '/tenant.kubesphere.io/v1alpha2/logs'
else:
path = '/kapis/tenant.kubesphere.io/v1alpha2/logs'
url = env_url + path + '?operation=histogram&interval=' + interval + 's&start_time=' + start_time + '&end_time=' + end_time
url = env_url + path + '?operation=histogram&interval=' + interval + '&start_time=' + start_time + '&end_time=' + end_time
response = requests.get(url=url, headers=get_header())
return response

Expand Down

0 comments on commit 57be10c

Please sign in to comment.