Tolerate alarm actions set to None
This change avoids a crash when an alarm action list is set to None by the client, as Heat does in some of its tests. Change-Id: I6feaf639e198a5af7ce970552ce7633a26629024 Closes-Bug: #1472891
This commit is contained in:
parent
6dd4a93905
commit
c40e790548
@ -396,11 +396,13 @@ class Alarm(base.Base):
|
||||
auth_plugin = pecan.request.environ.get('keystone.token_auth')
|
||||
for actions in (self.ok_actions, self.alarm_actions,
|
||||
self.insufficient_data_actions):
|
||||
if actions is not None:
|
||||
for index, action in enumerate(actions[:]):
|
||||
url = netutils.urlsplit(action)
|
||||
if self._is_trust_url(url):
|
||||
if '@' not in url.netloc:
|
||||
# We have a trust action without a trust ID, create it
|
||||
# We have a trust action without a trust ID,
|
||||
# create it
|
||||
trust_id = keystone_client.create_trust_id(
|
||||
trustor_user_id, trustor_project_id, roles,
|
||||
auth_plugin)
|
||||
|
@ -1782,6 +1782,30 @@ class TestAlarms(v2.FunctionalTest,
|
||||
self.assertEqual(['test://', 'log://'],
|
||||
alarms[0].alarm_actions)
|
||||
|
||||
def test_post_alarm_without_actions(self):
|
||||
body = {
|
||||
'name': 'alarm_actions_none',
|
||||
'type': 'combination',
|
||||
'combination_rule': {
|
||||
'alarm_ids': ['a', 'b'],
|
||||
},
|
||||
'alarm_actions': None
|
||||
}
|
||||
headers = self.auth_headers
|
||||
headers['X-Roles'] = 'admin'
|
||||
self.post_json('/alarms', params=body, status=201,
|
||||
headers=headers)
|
||||
alarms = list(self.alarm_conn.get_alarms(name='alarm_actions_none'))
|
||||
self.assertEqual(1, len(alarms))
|
||||
|
||||
# FIXME(sileht): This should really returns [] not None
|
||||
# but the mongodb and sql just store the json dict as is...
|
||||
# migration script for sql will be a mess because we have
|
||||
# to parse all JSON :(
|
||||
# I guess we assume that wsme convert the None input to []
|
||||
# because of the array type, but it won't...
|
||||
self.assertIsNone(alarms[0].alarm_actions)
|
||||
|
||||
def test_post_alarm_trust(self):
|
||||
json = {
|
||||
'name': 'added_alarm_defaults',
|
||||
|
Loading…
x
Reference in New Issue
Block a user