api: fix alarm deletion and update

The API allow the actions to be null.

This allow the alarm to be deleted and updated in this case.

Closes bug: #1479274

Change-Id: I0e53c39e9b6c9c80537ac646fb5695177eeb69d1
This commit is contained in:
Mehdi Abaakouk 2015-07-29 19:36:35 +02:00
parent db76887b1d
commit b40b4513e6
2 changed files with 21 additions and 15 deletions

View File

@ -411,24 +411,29 @@ class Alarm(base.Base):
url[1] = netloc
actions[index] = urlparse.urlunsplit(url)
if old_alarm:
for key in ('ok_actions', 'alarm_actions',
'insufficient_data_actions'):
for action in getattr(old_alarm, key):
url = netutils.urlsplit(action)
if (self._is_trust_url(url) and url.password and
action not in getattr(self, key)):
keystone_client.delete_trust_id(
pecan.request.cfg,
url.username, auth_plugin)
new_actions = list(itertools.chain(
self.ok_actions or [],
self.alarm_actions or [],
self.insufficient_data_actions or []))
for action in itertools.chain(
old_alarm.ok_actions or [],
old_alarm.alarm_actions or [],
old_alarm.insufficient_data_actions or []):
if action not in new_actions:
self.delete_trust(action)
def delete_actions(self):
for action in itertools.chain(self.ok_actions or [],
self.alarm_actions or [],
self.insufficient_data_actions or []):
self.delete_trust(action)
def delete_trust(self, action):
auth_plugin = pecan.request.environ.get('keystone.token_auth')
for action in itertools.chain(self.ok_actions, self.alarm_actions,
self.insufficient_data_actions):
url = netutils.urlsplit(action)
if self._is_trust_url(url) and url.password:
keystone_client.delete_trust_id(pecan.request.cfg,
url.username, auth_plugin)
url = netutils.urlsplit(action)
if self._is_trust_url(url) and url.password:
keystone_client.delete_trust_id(pecan.request.cfg,
url.username, auth_plugin)
Alarm.add_attributes(**{"%s_rule" % ext.name: ext.plugin

View File

@ -34,6 +34,7 @@ tests:
request_headers:
content-type: application/json
data:
ok_actions: null
name: added_alarm_defaults
type: threshold
threshold_rule: