remove alarm name unique constraint in each project
alarm_id can be the unique key to identify each other. The unique constraint for alarm name can benefit end user because literal name is more human friendly than UUID, but now it limits downstream like Vitrage. If end user does want this constraint, it can apply in portal like Horizon, Aodh should be more open to satisfy different use cases. Change-Id: I4abf2654135aa9d45c25d0284c2cf18fe31166be
This commit is contained in:
parent
b72a247b4f
commit
413f83d795
@ -592,15 +592,6 @@ class AlarmController(rest.RestController):
|
||||
else:
|
||||
data.state_timestamp = alarm_in.state_timestamp
|
||||
|
||||
# make sure alarms are unique by name per project.
|
||||
if alarm_in.name != data.name:
|
||||
alarms = list(pecan.request.storage.get_alarms(
|
||||
name=data.name, project=data.project_id))
|
||||
if alarms:
|
||||
raise base.ClientSideError(
|
||||
_("Alarm with name='%s' exists") % data.name,
|
||||
status_code=409)
|
||||
|
||||
ALARMS_RULES[data.type].plugin.update_hook(data)
|
||||
|
||||
old_data = Alarm.from_db_model(alarm_in)
|
||||
@ -763,13 +754,6 @@ class AlarmsController(rest.RestController):
|
||||
change = data.as_dict(models.Alarm)
|
||||
|
||||
data.update_actions()
|
||||
# make sure alarms are unique by name per project.
|
||||
alarms = list(conn.get_alarms(name=data.name,
|
||||
project=data.project_id))
|
||||
if alarms:
|
||||
raise base.ClientSideError(
|
||||
_("Alarm with name='%s' exists") % data.name,
|
||||
status_code=409)
|
||||
|
||||
try:
|
||||
alarm_in = models.Alarm(**change)
|
||||
|
@ -816,10 +816,10 @@ class TestAlarms(TestAlarmsBase):
|
||||
else:
|
||||
self.fail("Alarm not found")
|
||||
|
||||
def test_post_conflict(self):
|
||||
def test_post_alarm_with_same_name(self):
|
||||
json = {
|
||||
'enabled': False,
|
||||
'name': 'added_alarm',
|
||||
'name': 'dup_alarm_name',
|
||||
'state': 'ok',
|
||||
'type': 'threshold',
|
||||
'ok_actions': ['http://something/ok'],
|
||||
@ -840,10 +840,17 @@ class TestAlarms(TestAlarmsBase):
|
||||
}
|
||||
}
|
||||
|
||||
self.post_json('/alarms', params=json, status=201,
|
||||
headers=self.auth_headers)
|
||||
self.post_json('/alarms', params=json, status=409,
|
||||
headers=self.auth_headers)
|
||||
resp1 = self.post_json('/alarms', params=json, status=201,
|
||||
headers=self.auth_headers)
|
||||
resp2 = self.post_json('/alarms', params=json, status=201,
|
||||
headers=self.auth_headers)
|
||||
self.assertEqual(resp1.json['name'], resp2.json['name'])
|
||||
self.assertNotEqual(resp1.json['alarm_id'], resp2.json['alarm_id'])
|
||||
alarms = self.get_json('/alarms',
|
||||
headers=self.auth_headers,
|
||||
q=[{'field': 'name',
|
||||
'value': 'dup_alarm_name'}])
|
||||
self.assertEqual(2, len(alarms))
|
||||
|
||||
def _do_test_post_alarm(self, exclude_outliers=None):
|
||||
json = {
|
||||
@ -1521,12 +1528,9 @@ class TestAlarms(TestAlarmsBase):
|
||||
alarm_id = data[0]['alarm_id']
|
||||
|
||||
resp = self.put_json('/alarms/%s' % alarm_id,
|
||||
expect_errors=True, status=409,
|
||||
params=json,
|
||||
headers=self.auth_headers)
|
||||
self.assertEqual(
|
||||
"Alarm with name='name1' exists",
|
||||
resp.json['error_message']['faultstring'])
|
||||
self.assertEqual(200, resp.status_code)
|
||||
|
||||
def test_put_invalid_alarm_actions(self):
|
||||
json = {
|
||||
|
@ -0,0 +1,3 @@
|
||||
---
|
||||
other:
|
||||
- Alarm name unique constraint for each project has been removed.
|
Loading…
Reference in New Issue
Block a user