Merge "Fix monascaclient in tempest for updates"

This commit is contained in:
Jenkins 2016-07-08 19:55:33 +00:00 committed by Gerrit Code Review
commit 08b279bb99
5 changed files with 123 additions and 51 deletions

View File

@ -1,5 +1,6 @@
# Copyright 2015 Cray
# 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
# 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,
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.repo.update_or_patch_alarm_definition,
'bob', '234',
@ -445,6 +454,15 @@ class TestAlarmDefinitionRepoDB(testtools.TestCase, fixtures.TestWithFixtures):
None, None,
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.assertRaises(exceptions.DoesNotExistException,

View File

@ -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
# not use this file except in compliance with the License. You may obtain

View File

@ -107,20 +107,12 @@ class MonascaClient(rest_client.RestClient):
resp, response_body = self.get(uri)
return resp, json.loads(response_body)
def update_notification_method(self,
id,
name=None,
type=None,
address=None,
period=None):
def update_notification_method(self, id, name, type, address, period=None):
uri = 'notification-methods/' + id
request_body = {}
if name is not None:
request_body['name'] = name
if type is not None:
request_body['type'] = type
if address is not None:
request_body['address'] = address
request_body['name'] = name
request_body['type'] = type
request_body['address'] = address
if period is not None:
request_body['period'] = period
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)
return resp, response_body
def update_alarm_definition(self, id, name, expression, description=None,
actions_enabled=None, match_by=None,
severity=None, alarm_actions=None,
ok_actions=None, undetermined_actions=None,
def update_alarm_definition(self, id, name, expression, description,
actions_enabled, match_by,
severity, alarm_actions,
ok_actions, undetermined_actions,
**kwargs):
uri = 'alarm-definitions/' + id
request_body = {}
request_body['name'] = name
request_body['expression'] = expression
if description is not None:
request_body['description'] = description
if actions_enabled is not None:
request_body['actions_enabled'] = actions_enabled
if match_by is not None:
request_body['match_by'] = match_by
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
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['ok_actions'] = ok_actions
request_body['undetermined_actions'] = undetermined_actions
for key, value in kwargs.iteritems():
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)
def patch_alarm_definition(self,
@ -305,3 +289,38 @@ class MonascaClient(rest_client.RestClient):
uri = uri + query_params
resp, response_body = self.get(uri)
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)

View File

@ -702,19 +702,26 @@ class TestAlarmDefinitions(base.BaseMonascaTest):
@test.attr(type="gate")
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(
expression=None, number_of_definitions=1)
# Update alarm definition
updated_name = data_utils.rand_name('updated_name')
updated_description = 'updated description'
updated_expression = "max(cpu.system_perc) < 0"
resp, response_body = self.monasca_client.update_alarm_definition(
id=str(response_body_list[0]['id']),
name=updated_name,
expression=updated_expression,
description=updated_description,
actions_enabled='true'
)
str(response_body_list[0]['id']), updated_name, updated_expression,
updated_description, True, response_body_list[0]['match_by'],
'LOW', [notification_id], [notification_id], [notification_id])
self.assertEqual(200, resp.status)
self._verify_update_patch_alarm_definition(response_body, updated_name,
updated_expression,
@ -739,10 +746,24 @@ class TestAlarmDefinitions(base.BaseMonascaTest):
updated_match_by = ['hostname']
self.assertRaises(exceptions.UnprocessableEntity,
self.monasca_client.update_alarm_definition,
id=response_body_list[0]['id'], name=name,
expression=expression,
description=description, actions_enabled='true',
match_by=updated_match_by)
response_body_list[0]['id'], name, expression,
description, 'true', updated_match_by, 'LOW', None,
None, None)
@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")
def test_update_notification_in_alarm_definition(self):
@ -763,13 +784,9 @@ class TestAlarmDefinitions(base.BaseMonascaTest):
# Update alarm definition
update_alarm_def_name = data_utils.rand_name('monitoring_alarm_update')
resp, response_body = self.monasca_client.update_alarm_definition(
response_body_list[0]['id'],
name=update_alarm_def_name,
expression=expression,
actions_enabled='true',
alarm_actions=[notification_id],
ok_actions=[notification_id],
undetermined_actions=[notification_id])
response_body_list[0]['id'], update_alarm_def_name, expression,
'description', True, response_body_list[0]['match_by'], 'LOW',
[notification_id], [notification_id], [notification_id])
self.assertEqual(200, resp.status)
self._verify_update_patch_alarm_definition(response_body,
update_alarm_def_name,

View File

@ -570,6 +570,24 @@ class TestNotificationMethods(base.BaseMonascaTest):
self.monasca_client.delete_notification_method(id)
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")
def test_create_and_delete_notification_method(self):
notification = helpers.create_notification()