Add Tempest tests for invalid IDs and fix potential 500 errors

Add tests that an invalid ID returns 404 for update, patch and delete
methods for alarms, alarm definitions and notification methods.  Some
of these tests already existed but this ensures a complete set of
tests exists for these cases.

Move the resource try catch block wrapper to the correct layer
so that it catches all potential Internal Server Errors and throws
the proper exception.

Change-Id: I07159d0eaed995518bb0c0e2fbf446dff65ec632
This commit is contained in:
Craig Bryant 2017-01-18 18:34:05 -07:00 committed by Andrea Adams
parent b50f4d8215
commit 295e54af7c
3 changed files with 78 additions and 1 deletions

View File

@ -911,6 +911,43 @@ class TestAlarmDefinitions(base.BaseMonascaTest):
self.fail("Failed test_create_and_delete_alarm_definition: "
"cannot find the alarm definition just created.")
@test.attr(type="gate")
@test.attr(type=['negative'])
def test_get_alarm_defintion_with_invalid_id(self):
def_id = data_utils.rand_name()
self.assertRaises(exceptions.NotFound,
self.monasca_client.get_alarm_definition, def_id)
@test.attr(type="gate")
@test.attr(type=['negative'])
def test_delete_alarm_defintion_with_invalid_id(self):
def_id = data_utils.rand_name()
self.assertRaises(exceptions.NotFound,
self.monasca_client.delete_alarm_definition, def_id)
@test.attr(type="gate")
@test.attr(type=['negative'])
def test_patch_alarm_defintion_with_invalid_id(self):
def_id = data_utils.rand_name()
self.assertRaises(exceptions.NotFound,
self.monasca_client.patch_alarm_definition,
id=def_id, name='Test')
@test.attr(type="gate")
@test.attr(type=['negative'])
def test_update_alarm_defintion_with_invalid_id(self):
def_id = data_utils.rand_name()
updated_name = data_utils.rand_name('updated_name')
updated_description = 'updated description'
updated_expression = "max(cpu.system_perc) < 0"
self.assertRaises(exceptions.NotFound,
self.monasca_client.update_alarm_definition,
def_id, updated_name, updated_expression,
updated_description, True, ['device'],
'LOW', [], [],
[])
def _create_alarm_definitions(self, expression, number_of_definitions):
self.rule = {'expression': 'mem_total_mb > 0'}
if expression is None:

View File

@ -722,6 +722,27 @@ class TestAlarms(base.BaseMonascaTest):
self.assertRaises(exceptions.NotFound,
self.monasca_client.delete_alarm, id)
@test.attr(type="gate")
@test.attr(type=['negative'])
def test_patch_alarm_with_invalid_id(self):
id = data_utils.rand_name()
self.assertRaises(exceptions.NotFound,
self.monasca_client.patch_alarm, id=id,
lifecycle_state="OPEN")
@test.attr(type="gate")
@test.attr(type=['negative'])
def test_update_alarm_with_invalid_id(self):
alarm_id = data_utils.rand_name()
updated_state = "ALARM"
updated_lifecycle_state = "OPEN"
updated_link = "http://somesite.com"
self.assertRaises(exceptions.NotFound,
self.monasca_client.update_alarm,
id=alarm_id, state=updated_state,
lifecycle_state=updated_lifecycle_state,
link=updated_link)
@test.attr(type="gate")
def test_create_alarms_with_match_by(self):
# Create an alarm definition with no match_by

View File

@ -1,4 +1,4 @@
# (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
# (C) Copyright 2015-2017 Hewlett Packard Enterprise Development 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
@ -733,6 +733,25 @@ class TestNotificationMethods(base.BaseMonascaTest):
delete_notification_method(response_body['id'])
self.assertEqual(204, resp.status)
@test.attr(type="gate")
@test.attr(type=['negative'])
def test_patch_notification_method_with_invalid_id(self):
id = data_utils.rand_name()
name = data_utils.rand_name('notification-')
self.assertRaises(exceptions.NotFound,
self.monasca_client.patch_notification_method,
id, name)
@test.attr(type="gate")
@test.attr(type=['negative'])
def test_update_notification_method_with_invalid_id(self):
id = data_utils.rand_name()
name = data_utils.rand_name('notification-')
self.assertRaises(exceptions.NotFound,
self.monasca_client.update_notification_method, id,
name=name, type='EMAIL',
address='bob@thebridge.org', period=0)
@test.attr(type="gate")
@test.attr(type=['negative'])
def test_update_email_notification_method_with_nonzero_period(self):