Merge "Fix monascaclient in tempest for updates"
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
# Copyright 2015 Cray
|
# Copyright 2015 Cray
|
||||||
# Copyright 2016 FUJITSU LIMITED
|
# Copyright 2016 FUJITSU LIMITED
|
||||||
|
# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
@@ -433,8 +434,16 @@ class TestAlarmDefinitionRepoDB(testtools.TestCase, fixtures.TestWithFixtures):
|
|||||||
[], [],
|
[], [],
|
||||||
None, None,
|
None, None,
|
||||||
True)
|
True)
|
||||||
from monasca_api.common.repositories import exceptions
|
|
||||||
|
|
||||||
|
self.repo.update_or_patch_alarm_definition('bob', '234',
|
||||||
|
None, None,
|
||||||
|
None, False,
|
||||||
|
None, None,
|
||||||
|
None, None,
|
||||||
|
match_by, None,
|
||||||
|
False)
|
||||||
|
|
||||||
|
from monasca_api.common.repositories import exceptions
|
||||||
self.assertRaises(exceptions.InvalidUpdateException,
|
self.assertRaises(exceptions.InvalidUpdateException,
|
||||||
self.repo.update_or_patch_alarm_definition,
|
self.repo.update_or_patch_alarm_definition,
|
||||||
'bob', '234',
|
'bob', '234',
|
||||||
@@ -445,6 +454,15 @@ class TestAlarmDefinitionRepoDB(testtools.TestCase, fixtures.TestWithFixtures):
|
|||||||
None, None,
|
None, None,
|
||||||
False)
|
False)
|
||||||
|
|
||||||
|
self.assertRaises(exceptions.InvalidUpdateException,
|
||||||
|
self.repo.update_or_patch_alarm_definition,
|
||||||
|
'bob', '234',
|
||||||
|
'90% CPU', None,
|
||||||
|
sub_expr_list, False,
|
||||||
|
description, alarm_actions,
|
||||||
|
None, None,
|
||||||
|
'update_match_by', 'LOW')
|
||||||
|
|
||||||
self.repo.delete_alarm_definition('bob', '234')
|
self.repo.delete_alarm_definition('bob', '234')
|
||||||
|
|
||||||
self.assertRaises(exceptions.DoesNotExistException,
|
self.assertRaises(exceptions.DoesNotExistException,
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# Copyright 2014,2016 Hewlett Packard Enterprise Development Company, L.P.
|
# (C) Copyright 2014,2016 Hewlett Packard Enterprise Development Company LP
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@@ -107,20 +107,12 @@ class MonascaClient(rest_client.RestClient):
|
|||||||
resp, response_body = self.get(uri)
|
resp, response_body = self.get(uri)
|
||||||
return resp, json.loads(response_body)
|
return resp, json.loads(response_body)
|
||||||
|
|
||||||
def update_notification_method(self,
|
def update_notification_method(self, id, name, type, address, period=None):
|
||||||
id,
|
|
||||||
name=None,
|
|
||||||
type=None,
|
|
||||||
address=None,
|
|
||||||
period=None):
|
|
||||||
uri = 'notification-methods/' + id
|
uri = 'notification-methods/' + id
|
||||||
request_body = {}
|
request_body = {}
|
||||||
if name is not None:
|
request_body['name'] = name
|
||||||
request_body['name'] = name
|
request_body['type'] = type
|
||||||
if type is not None:
|
request_body['address'] = address
|
||||||
request_body['type'] = type
|
|
||||||
if address is not None:
|
|
||||||
request_body['address'] = address
|
|
||||||
if period is not None:
|
if period is not None:
|
||||||
request_body['period'] = period
|
request_body['period'] = period
|
||||||
resp, response_body = self.put(uri, json.dumps(request_body))
|
resp, response_body = self.put(uri, json.dumps(request_body))
|
||||||
@@ -168,35 +160,27 @@ class MonascaClient(rest_client.RestClient):
|
|||||||
resp, response_body = self.delete(uri)
|
resp, response_body = self.delete(uri)
|
||||||
return resp, response_body
|
return resp, response_body
|
||||||
|
|
||||||
def update_alarm_definition(self, id, name, expression, description=None,
|
def update_alarm_definition(self, id, name, expression, description,
|
||||||
actions_enabled=None, match_by=None,
|
actions_enabled, match_by,
|
||||||
severity=None, alarm_actions=None,
|
severity, alarm_actions,
|
||||||
ok_actions=None, undetermined_actions=None,
|
ok_actions, undetermined_actions,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
uri = 'alarm-definitions/' + id
|
uri = 'alarm-definitions/' + id
|
||||||
request_body = {}
|
request_body = {}
|
||||||
request_body['name'] = name
|
request_body['name'] = name
|
||||||
request_body['expression'] = expression
|
request_body['expression'] = expression
|
||||||
|
request_body['description'] = description
|
||||||
if description is not None:
|
request_body['actions_enabled'] = actions_enabled
|
||||||
request_body['description'] = description
|
request_body['match_by'] = match_by
|
||||||
if actions_enabled is not None:
|
request_body['severity'] = severity
|
||||||
request_body['actions_enabled'] = actions_enabled
|
request_body['alarm_actions'] = alarm_actions
|
||||||
if match_by is not None:
|
request_body['ok_actions'] = ok_actions
|
||||||
request_body['match_by'] = match_by
|
request_body['undetermined_actions'] = undetermined_actions
|
||||||
if severity is not None:
|
|
||||||
request_body['severity'] = severity
|
|
||||||
if alarm_actions is not None:
|
|
||||||
request_body['alarm_actions'] = alarm_actions
|
|
||||||
if ok_actions is not None:
|
|
||||||
request_body['ok_actions'] = ok_actions
|
|
||||||
if undetermined_actions is not None:
|
|
||||||
request_body['undetermined_actions'] = undetermined_actions
|
|
||||||
|
|
||||||
for key, value in kwargs.iteritems():
|
for key, value in kwargs.iteritems():
|
||||||
request_body[key] = value
|
request_body[key] = value
|
||||||
|
|
||||||
resp, response_body = self.patch(uri, json.dumps(request_body))
|
resp, response_body = self.put(uri, json.dumps(request_body))
|
||||||
return resp, json.loads(response_body)
|
return resp, json.loads(response_body)
|
||||||
|
|
||||||
def patch_alarm_definition(self,
|
def patch_alarm_definition(self,
|
||||||
@@ -305,3 +289,38 @@ class MonascaClient(rest_client.RestClient):
|
|||||||
uri = uri + query_params
|
uri = uri + query_params
|
||||||
resp, response_body = self.get(uri)
|
resp, response_body = self.get(uri)
|
||||||
return resp, json.loads(response_body)
|
return resp, json.loads(response_body)
|
||||||
|
|
||||||
|
# For Negative Tests
|
||||||
|
def update_alarm_definition_with_no_ok_actions(self, id, name,
|
||||||
|
expression, description,
|
||||||
|
actions_enabled, match_by,
|
||||||
|
severity, alarm_actions,
|
||||||
|
undetermined_actions,
|
||||||
|
**kwargs):
|
||||||
|
uri = 'alarm-definitions/' + id
|
||||||
|
request_body = {}
|
||||||
|
request_body['name'] = name
|
||||||
|
request_body['expression'] = expression
|
||||||
|
request_body['description'] = description
|
||||||
|
request_body['actions_enabled'] = actions_enabled
|
||||||
|
request_body['match_by'] = match_by
|
||||||
|
request_body['severity'] = severity
|
||||||
|
request_body['alarm_actions'] = alarm_actions
|
||||||
|
request_body['undetermined_actions'] = undetermined_actions
|
||||||
|
|
||||||
|
for key, value in kwargs.iteritems():
|
||||||
|
request_body[key] = value
|
||||||
|
|
||||||
|
resp, response_body = self.put(uri, json.dumps(request_body))
|
||||||
|
return resp, json.loads(response_body)
|
||||||
|
|
||||||
|
def update_notification_method_with_no_address(self, id, name, type,
|
||||||
|
period=None):
|
||||||
|
uri = 'notification-methods/' + id
|
||||||
|
request_body = {}
|
||||||
|
request_body['name'] = name
|
||||||
|
request_body['type'] = type
|
||||||
|
if period is not None:
|
||||||
|
request_body['period'] = period
|
||||||
|
resp, response_body = self.put(uri, json.dumps(request_body))
|
||||||
|
return resp, json.loads(response_body)
|
||||||
|
@@ -702,19 +702,26 @@ class TestAlarmDefinitions(base.BaseMonascaTest):
|
|||||||
|
|
||||||
@test.attr(type="gate")
|
@test.attr(type="gate")
|
||||||
def test_update_alarm_definition(self):
|
def test_update_alarm_definition(self):
|
||||||
|
notification_name = data_utils.rand_name('notification-')
|
||||||
|
notification_type = 'EMAIL'
|
||||||
|
address = 'root@localhost'
|
||||||
|
|
||||||
|
resp, response_body = self.monasca_client.create_notification_method(
|
||||||
|
notification_name, type=notification_type, address=address)
|
||||||
|
notification_id = self._verify_create_notification_method(
|
||||||
|
resp, response_body, notification_name, notification_type, address)
|
||||||
|
|
||||||
response_body_list = self._create_alarm_definitions(
|
response_body_list = self._create_alarm_definitions(
|
||||||
expression=None, number_of_definitions=1)
|
expression=None, number_of_definitions=1)
|
||||||
# Update alarm definition
|
# Update alarm definition
|
||||||
updated_name = data_utils.rand_name('updated_name')
|
updated_name = data_utils.rand_name('updated_name')
|
||||||
updated_description = 'updated description'
|
updated_description = 'updated description'
|
||||||
updated_expression = "max(cpu.system_perc) < 0"
|
updated_expression = "max(cpu.system_perc) < 0"
|
||||||
|
|
||||||
resp, response_body = self.monasca_client.update_alarm_definition(
|
resp, response_body = self.monasca_client.update_alarm_definition(
|
||||||
id=str(response_body_list[0]['id']),
|
str(response_body_list[0]['id']), updated_name, updated_expression,
|
||||||
name=updated_name,
|
updated_description, True, response_body_list[0]['match_by'],
|
||||||
expression=updated_expression,
|
'LOW', [notification_id], [notification_id], [notification_id])
|
||||||
description=updated_description,
|
|
||||||
actions_enabled='true'
|
|
||||||
)
|
|
||||||
self.assertEqual(200, resp.status)
|
self.assertEqual(200, resp.status)
|
||||||
self._verify_update_patch_alarm_definition(response_body, updated_name,
|
self._verify_update_patch_alarm_definition(response_body, updated_name,
|
||||||
updated_expression,
|
updated_expression,
|
||||||
@@ -739,10 +746,24 @@ class TestAlarmDefinitions(base.BaseMonascaTest):
|
|||||||
updated_match_by = ['hostname']
|
updated_match_by = ['hostname']
|
||||||
self.assertRaises(exceptions.UnprocessableEntity,
|
self.assertRaises(exceptions.UnprocessableEntity,
|
||||||
self.monasca_client.update_alarm_definition,
|
self.monasca_client.update_alarm_definition,
|
||||||
id=response_body_list[0]['id'], name=name,
|
response_body_list[0]['id'], name, expression,
|
||||||
expression=expression,
|
description, 'true', updated_match_by, 'LOW', None,
|
||||||
description=description, actions_enabled='true',
|
None, None)
|
||||||
match_by=updated_match_by)
|
|
||||||
|
@test.attr(type="gate")
|
||||||
|
@test.attr(type=['negative'])
|
||||||
|
def test_update_alarm_definition_with_no_ok_actions(self):
|
||||||
|
response_body_list = self._create_alarm_definitions(
|
||||||
|
expression=None, number_of_definitions=1)
|
||||||
|
name = response_body_list[0]['name']
|
||||||
|
expression = response_body_list[0]['expression']
|
||||||
|
description = response_body_list[0]['description']
|
||||||
|
updated_match_by = ['hostname']
|
||||||
|
self.assertRaises(
|
||||||
|
exceptions.UnprocessableEntity,
|
||||||
|
self.monasca_client.update_alarm_definition_with_no_ok_actions,
|
||||||
|
response_body_list[0]['id'], name, expression, description,
|
||||||
|
'true', updated_match_by, 'LOW', None, None)
|
||||||
|
|
||||||
@test.attr(type="gate")
|
@test.attr(type="gate")
|
||||||
def test_update_notification_in_alarm_definition(self):
|
def test_update_notification_in_alarm_definition(self):
|
||||||
@@ -763,13 +784,9 @@ class TestAlarmDefinitions(base.BaseMonascaTest):
|
|||||||
# Update alarm definition
|
# Update alarm definition
|
||||||
update_alarm_def_name = data_utils.rand_name('monitoring_alarm_update')
|
update_alarm_def_name = data_utils.rand_name('monitoring_alarm_update')
|
||||||
resp, response_body = self.monasca_client.update_alarm_definition(
|
resp, response_body = self.monasca_client.update_alarm_definition(
|
||||||
response_body_list[0]['id'],
|
response_body_list[0]['id'], update_alarm_def_name, expression,
|
||||||
name=update_alarm_def_name,
|
'description', True, response_body_list[0]['match_by'], 'LOW',
|
||||||
expression=expression,
|
[notification_id], [notification_id], [notification_id])
|
||||||
actions_enabled='true',
|
|
||||||
alarm_actions=[notification_id],
|
|
||||||
ok_actions=[notification_id],
|
|
||||||
undetermined_actions=[notification_id])
|
|
||||||
self.assertEqual(200, resp.status)
|
self.assertEqual(200, resp.status)
|
||||||
self._verify_update_patch_alarm_definition(response_body,
|
self._verify_update_patch_alarm_definition(response_body,
|
||||||
update_alarm_def_name,
|
update_alarm_def_name,
|
||||||
|
@@ -570,6 +570,24 @@ class TestNotificationMethods(base.BaseMonascaTest):
|
|||||||
self.monasca_client.delete_notification_method(id)
|
self.monasca_client.delete_notification_method(id)
|
||||||
self.assertEqual(204, resp.status)
|
self.assertEqual(204, resp.status)
|
||||||
|
|
||||||
|
@test.attr(type="gate")
|
||||||
|
@test.attr(type=['negative'])
|
||||||
|
def test_update_notification_method_with_no_address(self):
|
||||||
|
name = data_utils.rand_name('notification-')
|
||||||
|
notification = helpers.create_notification(name=name)
|
||||||
|
resp, response_body = self.monasca_client.create_notifications(
|
||||||
|
notification)
|
||||||
|
id = response_body['id']
|
||||||
|
self.assertEqual(201, resp.status)
|
||||||
|
self.assertRaises(
|
||||||
|
(exceptions.BadRequest, exceptions.UnprocessableEntity),
|
||||||
|
self.monasca_client.update_notification_method_with_no_address, id,
|
||||||
|
name="test_update_notification_method_name",
|
||||||
|
type=response_body['type'])
|
||||||
|
resp, response_body = \
|
||||||
|
self.monasca_client.delete_notification_method(id)
|
||||||
|
self.assertEqual(204, resp.status)
|
||||||
|
|
||||||
@test.attr(type="gate")
|
@test.attr(type="gate")
|
||||||
def test_create_and_delete_notification_method(self):
|
def test_create_and_delete_notification_method(self):
|
||||||
notification = helpers.create_notification()
|
notification = helpers.create_notification()
|
||||||
|
Reference in New Issue
Block a user