diff --git a/ceilometer/api/controllers/v2/alarms.py b/ceilometer/api/controllers/v2/alarms.py index 5fdbd00b2d..be015ffa2b 100644 --- a/ceilometer/api/controllers/v2/alarms.py +++ b/ceilometer/api/controllers/v2/alarms.py @@ -396,18 +396,20 @@ 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): - 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 - trust_id = keystone_client.create_trust_id( - trustor_user_id, trustor_project_id, roles, - auth_plugin) - netloc = '%s:delete@%s' % (trust_id, url.netloc) - url = list(url) - url[1] = netloc - actions[index] = urlparse.urlunsplit(url) + 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 + trust_id = keystone_client.create_trust_id( + trustor_user_id, trustor_project_id, roles, + auth_plugin) + netloc = '%s:delete@%s' % (trust_id, url.netloc) + url = list(url) + url[1] = netloc + actions[index] = urlparse.urlunsplit(url) if old_alarm: for key in ('ok_actions', 'alarm_actions', 'insufficient_data_actions'): diff --git a/ceilometer/tests/api/v2/test_alarm_scenarios.py b/ceilometer/tests/api/v2/test_alarm_scenarios.py index eb0c396397..47993508ee 100644 --- a/ceilometer/tests/api/v2/test_alarm_scenarios.py +++ b/ceilometer/tests/api/v2/test_alarm_scenarios.py @@ -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',