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:
parent
db76887b1d
commit
b40b4513e6
@ -411,20 +411,25 @@ class Alarm(base.Base):
|
|||||||
url[1] = netloc
|
url[1] = netloc
|
||||||
actions[index] = urlparse.urlunsplit(url)
|
actions[index] = urlparse.urlunsplit(url)
|
||||||
if old_alarm:
|
if old_alarm:
|
||||||
for key in ('ok_actions', 'alarm_actions',
|
new_actions = list(itertools.chain(
|
||||||
'insufficient_data_actions'):
|
self.ok_actions or [],
|
||||||
for action in getattr(old_alarm, key):
|
self.alarm_actions or [],
|
||||||
url = netutils.urlsplit(action)
|
self.insufficient_data_actions or []))
|
||||||
if (self._is_trust_url(url) and url.password and
|
for action in itertools.chain(
|
||||||
action not in getattr(self, key)):
|
old_alarm.ok_actions or [],
|
||||||
keystone_client.delete_trust_id(
|
old_alarm.alarm_actions or [],
|
||||||
pecan.request.cfg,
|
old_alarm.insufficient_data_actions or []):
|
||||||
url.username, auth_plugin)
|
if action not in new_actions:
|
||||||
|
self.delete_trust(action)
|
||||||
|
|
||||||
def delete_actions(self):
|
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')
|
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)
|
url = netutils.urlsplit(action)
|
||||||
if self._is_trust_url(url) and url.password:
|
if self._is_trust_url(url) and url.password:
|
||||||
keystone_client.delete_trust_id(pecan.request.cfg,
|
keystone_client.delete_trust_id(pecan.request.cfg,
|
||||||
|
@ -34,6 +34,7 @@ tests:
|
|||||||
request_headers:
|
request_headers:
|
||||||
content-type: application/json
|
content-type: application/json
|
||||||
data:
|
data:
|
||||||
|
ok_actions: null
|
||||||
name: added_alarm_defaults
|
name: added_alarm_defaults
|
||||||
type: threshold
|
type: threshold
|
||||||
threshold_rule:
|
threshold_rule:
|
||||||
|
Loading…
Reference in New Issue
Block a user