Merge "Modify monasca-webhook test"

This commit is contained in:
Zuul 2019-01-15 23:11:39 +00:00 committed by Gerrit Code Review
commit e144f17bf7
1 changed files with 171 additions and 85 deletions

View File

@ -1,4 +1,4 @@
# Copyright 2018 VMware Corporation. All rights reserved. # Copyright 2018 VMware Corporation. NEC, Inc. All rights reserved.
# All Rights Reserved. # All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -13,12 +13,14 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import testtools
from tempest import config from tempest import config
from tempest.lib.common.utils import test_utils from tempest.lib.common.utils import test_utils
from tempest.lib import decorators from tempest.lib import decorators
from tempest.lib import exceptions from tempest.lib import exceptions
# from congress_tempest_plugin.tests.scenario import helper from congress_tempest_plugin.tests.scenario import helper
from congress_tempest_plugin.tests.scenario import manager_congress from congress_tempest_plugin.tests.scenario import manager_congress
@ -47,86 +49,170 @@ class TestMonascaDriver(manager_congress.ScenarioPolicyBase):
'without error.') 'without error.')
# class TestMonascaWebhookDriver(manager_congress.ScenarioPolicyBase): class TestMonascaWebhookDriver(manager_congress.ScenarioPolicyBase):
#
# @classmethod @classmethod
# def skip_checks(cls): def skip_checks(cls):
# super(TestMonascaWebhookDriver, cls).skip_checks() super(TestMonascaWebhookDriver, cls).skip_checks()
# if not CONF.congress_feature_enabled.monasca_webhook: if not CONF.congress_feature_enabled.monasca_webhook:
# msg = ("feature not available in this congress version") msg = ("feature not available in this congress version")
# raise cls.skipException(msg) raise cls.skipException(msg)
#
# def setUp(self): def setUp(self):
# super(TestMonascaWebhookDriver, self).setUp() super(TestMonascaWebhookDriver, self).setUp()
# monasca_setting = { monasca_setting = {
# 'name': 'monasca_webhook', 'name': 'monasca_webhook',
# 'driver': 'monasca_webhook', 'driver': 'monasca_webhook',
# 'config': None, 'config': None,
# } }
# self.client = self.os_admin.congress_client self.client = self.os_admin.congress_client
#
# response = self.client.create_datasource(monasca_setting) response = self.client.create_datasource(monasca_setting)
# self.datasource_id = response['id'] self.datasource_id = response['id']
#
# def tearDown(self): def tearDown(self):
# super(TestMonascaWebhookDriver, self).tearDown() super(TestMonascaWebhookDriver, self).tearDown()
# self.client.delete_datasource(self.datasource_id) self.client.delete_datasource(self.datasource_id)
#
# def _list_datasource_rows(self, datasource, table): def _list_datasource_rows(self, datasource, table):
# return self.client.list_datasource_rows(datasource, table) return self.client.list_datasource_rows(datasource, table)
#
# @decorators.attr(type='smoke') @decorators.attr(type='smoke')
# def test_monasca_alarm_notification_table(self): @testtools.skipIf(CONF.congress_feature_enabled.monasca_webhook_rocky,
# test_alarm = { 'Test expects new (post-Rocky) monasca webhook schema.')
# 'metrics': [ def test_monasca_alarm_notification_table(self):
# {u'dimensions': {u'hostname': u'openstack-13.local.lan', test_alarm = {
# u'service': u'monitoring'}, 'metrics': [
# u'id': None, {u'dimensions': {u'hostname': u'openstack-13.local.lan',
# u'name': u'load.avg_1_min'}], u'service': u'monitoring'},
# 'alarm_id': u'3beb4934-053d-4f8f-9704-273bffc2441b', u'id': None,
# 'state': u'ALARM', u'name': u'load.avg_1_min'}],
# 'alarm_timestamp': 1531821822, 'alarm_id': u'3beb4934-053d-4f8f-9704-273bffc244',
# 'tenant_id': u'3661888238874df098988deab07c599d', 'state': u'ALARM',
# 'old_state': u'UNDETERMINED', 'alarm_timestamp': 1531821822,
# 'alarm_description': u'', 'tenant_id': u'3661888238874df098988deab07c599d',
# 'message': u'Thresholds were exceeded for the sub-alarms', 'old_state': u'UNDETERMINED',
# 'alarm_definition_id': u'8e5d033f-28cc-459f-91d4-813307e4ca8a', 'alarm_description': u'',
# 'alarm_name': u'alarmPerHost23'} 'message': u'Thresholds were exceeded for alarm',
# 'alarm_definition_id': u'8e5d033f-28cc-459f-91d4-813307e4ca',
# # Check if service is up 'alarm_name': u'alarmPerHost23'}
# @helper.retry_on_exception
# def _check_service(): # Check if service is up
# self.client.list_datasource_status(self.datasource_id) @helper.retry_on_exception
# return True def _check_service():
# self.client.list_datasource_status(self.datasource_id)
# if not test_utils.call_until_true(func=_check_service, return True
# duration=60, sleep_for=1):
# raise exceptions.TimeoutException( if not test_utils.call_until_true(func=_check_service,
# "Monasca-Webhook data source service is not up") duration=60, sleep_for=1):
# raise exceptions.TimeoutException(
# self.client.send_datasource_webhook(self.datasource_id, test_alarm) "Monasca-Webhook data source service is not up")
# results = self._list_datasource_rows(self.datasource_id,
# 'alarm_notification') def _check_result_for_exception(result, expected_result,
# if len(results['results']) != 1: result_length=1):
# error_msg = ('Unexpected additional rows are ' if len(result['results']) != result_length:
# 'inserted. row details: %s' % results['results']) error_msg = ('Unexpected number of rows are '
# raise exceptions.InvalidStructure(error_msg) 'inserted. Row details: %s' % result['results'])
# raise exceptions.InvalidStructure(error_msg)
# expected_row = [u'3beb4934-053d-4f8f-9704-273bffc2441b',
# u'8e5d033f-28cc-459f-91d4-813307e4ca8a', output = []
# u'alarmPerHost23', for data in result['results']:
# u'', output.append(data['data'])
# 1531821822, output = sorted(output)
# u'ALARM', expected_result = sorted(expected_result)
# u'UNDETERMINED', for index in range(result_length):
# u'Thresholds were exceeded for the sub-alarms', if output[index] != expected_result[index]:
# u'3661888238874df098988deab07c599d', msg = ('inserted row %s is not expected row %s'
# u'None', % (output[index], expected_result[index]))
# u'load.avg_1_min', raise exceptions.InvalidStructure(msg)
# u'openstack-13.local.lan',
# u'monitoring'] self.client.send_datasource_webhook(self.datasource_id, test_alarm)
# alarm_notification = self._list_datasource_rows(self.datasource_id,
# if results['results'][0]['data'] != expected_row: 'alarm_notification')
# msg = ('inserted row %s is not expected row %s'
# % (results['results'][0]['data'], expected_row)) expected_alarm_notification = [[u'3beb4934-053d-4f8f-9704-273bffc244',
# raise exceptions.InvalidStructure(msg) u'8e5d033f-28cc-459f-91d4-813307e4ca',
u'alarmPerHost23',
u'',
1531821822,
u'ALARM',
u'UNDETERMINED',
u'Thresholds were exceeded for alarm',
u'3661888238874df098988deab07c599d']]
_check_result_for_exception(alarm_notification,
expected_alarm_notification)
metrics_result = self._list_datasource_rows(self.datasource_id,
'alarms.metrics')
dimension_id = metrics_result['results'][0]['data'][3]
expected_metrics = [[u'3beb4934-053d-4f8f-9704-273bffc244',
u'None',
u'load.avg_1_min',
dimension_id]]
_check_result_for_exception(metrics_result, expected_metrics)
dimension_result = self._list_datasource_rows(
self.datasource_id, 'alarms.metrics.dimensions')
expected_dimensions = [
[dimension_id, u'hostname', u'openstack-13.local.lan'],
[dimension_id, u'service', u'monitoring']]
_check_result_for_exception(dimension_result, expected_dimensions, 2)
@decorators.attr(type='smoke')
@testtools.skipUnless(CONF.congress_feature_enabled.monasca_webhook_rocky,
'Test expects monasca webhook rocky schema.')
def test_monasca_alarm_notification_table_rocky(self):
test_alarm = {
'metrics': [
{u'dimensions': {u'hostname': u'openstack-13.local.lan',
u'service': u'monitoring'},
u'id': None,
u'name': u'load.avg_1_min'}],
'alarm_id': u'3beb4934-053d-4f8f-9704-273bffc2441b',
'state': u'ALARM',
'alarm_timestamp': 1531821822,
'tenant_id': u'3661888238874df098988deab07c599d',
'old_state': u'UNDETERMINED',
'alarm_description': u'',
'message': u'Thresholds were exceeded for the sub-alarms',
'alarm_definition_id': u'8e5d033f-28cc-459f-91d4-813307e4ca8a',
'alarm_name': u'alarmPerHost23'}
# Check if service is up
@helper.retry_on_exception
def _check_service():
self.client.list_datasource_status(self.datasource_id)
return True
if not test_utils.call_until_true(func=_check_service,
duration=60, sleep_for=1):
raise exceptions.TimeoutException(
"Monasca-Webhook data source service is not up")
self.client.send_datasource_webhook(self.datasource_id, test_alarm)
results = self._list_datasource_rows(self.datasource_id,
'alarm_notification')
if len(results['results']) != 1:
error_msg = ('Unexpected additional rows are '
'inserted. row details: %s' % results['results'])
raise exceptions.InvalidStructure(error_msg)
expected_row = [u'3beb4934-053d-4f8f-9704-273bffc2441b',
u'8e5d033f-28cc-459f-91d4-813307e4ca8a',
u'alarmPerHost23',
u'',
1531821822,
u'ALARM',
u'UNDETERMINED',
u'Thresholds were exceeded for the sub-alarms',
u'3661888238874df098988deab07c599d',
u'None',
u'load.avg_1_min',
u'openstack-13.local.lan',
u'monitoring']
if results['results'][0]['data'] != expected_row:
msg = ('inserted row %s is not expected row %s'
% (results['results'][0]['data'], expected_row))
raise exceptions.InvalidStructure(msg)