From b40b4513e61cd76a11e031d5b77bffbda1d012f6 Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Wed, 29 Jul 2015 19:36:35 +0200 Subject: [PATCH] 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 --- aodh/api/controllers/v2/alarms.py | 35 ++++++++++++++++------------ aodh/tests/gabbi/gabbits/alarms.yaml | 1 + 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/aodh/api/controllers/v2/alarms.py b/aodh/api/controllers/v2/alarms.py index a2cd01ed..3b48f102 100644 --- a/aodh/api/controllers/v2/alarms.py +++ b/aodh/api/controllers/v2/alarms.py @@ -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 diff --git a/aodh/tests/gabbi/gabbits/alarms.yaml b/aodh/tests/gabbi/gabbits/alarms.yaml index 530dca18..642da72b 100644 --- a/aodh/tests/gabbi/gabbits/alarms.yaml +++ b/aodh/tests/gabbi/gabbits/alarms.yaml @@ -34,6 +34,7 @@ tests: request_headers: content-type: application/json data: + ok_actions: null name: added_alarm_defaults type: threshold threshold_rule: