Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 08b476d

Browse files
author
Eoghan Glynn
committed
Allow alarm-threshold-update to upate generic attributes
Fixes bug 1253989 Previously, generic (i.e. non-threshold-related) alarm attributes could not be updated with the alarm-threshold-update command. An attempt to do so failed semi-silently when a non-existent dict key was referenced. Now, all alarm attributes can be updated with this command. Change-Id: Iba3f21de879fb853575dcec1730de7873eab8afd
1 parent 936faeb commit 08b476d

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

ceilometerclient/tests/v2/test_shell.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def setUp(self):
172172
self.args = mock.Mock()
173173
self.args.alarm_id = self.ALARM_ID
174174

175-
def _do_test_alarm_update_repeat_actions(self, repeat_actions):
175+
def _do_test_alarm_update_repeat_actions(self, method, repeat_actions):
176176
self.args.threshold = 42.0
177177
if repeat_actions is not None:
178178
self.args.repeat_actions = repeat_actions
@@ -183,7 +183,7 @@ def _do_test_alarm_update_repeat_actions(self, repeat_actions):
183183
self.cc.alarms.update.return_value = alarm[0]
184184

185185
try:
186-
ceilometer_shell.do_alarm_update(self.cc, self.args)
186+
method(self.cc, self.args)
187187
args, kwargs = self.cc.alarms.update.call_args
188188
self.assertEqual(self.ALARM_ID, args[0])
189189
self.assertEqual(42.0, kwargs.get('threshold'))
@@ -196,13 +196,40 @@ def _do_test_alarm_update_repeat_actions(self, repeat_actions):
196196
sys.stdout = orig
197197

198198
def test_alarm_update_repeat_actions_untouched(self):
199-
self._do_test_alarm_update_repeat_actions(None)
199+
method = ceilometer_shell.do_alarm_update
200+
self._do_test_alarm_update_repeat_actions(method, None)
200201

201202
def test_alarm_update_repeat_actions_set(self):
202-
self._do_test_alarm_update_repeat_actions(True)
203+
method = ceilometer_shell.do_alarm_update
204+
self._do_test_alarm_update_repeat_actions(method, True)
203205

204206
def test_alarm_update_repeat_actions_clear(self):
205-
self._do_test_alarm_update_repeat_actions(False)
207+
method = ceilometer_shell.do_alarm_update
208+
self._do_test_alarm_update_repeat_actions(method, False)
209+
210+
def test_alarm_combination_update_repeat_actions_untouched(self):
211+
method = ceilometer_shell.do_alarm_combination_update
212+
self._do_test_alarm_update_repeat_actions(method, None)
213+
214+
def test_alarm_combination_update_repeat_actions_set(self):
215+
method = ceilometer_shell.do_alarm_combination_update
216+
self._do_test_alarm_update_repeat_actions(method, True)
217+
218+
def test_alarm_combination_update_repeat_actions_clear(self):
219+
method = ceilometer_shell.do_alarm_combination_update
220+
self._do_test_alarm_update_repeat_actions(method, False)
221+
222+
def test_alarm_threshold_update_repeat_actions_untouched(self):
223+
method = ceilometer_shell.do_alarm_threshold_update
224+
self._do_test_alarm_update_repeat_actions(method, None)
225+
226+
def test_alarm_threshold_update_repeat_actions_set(self):
227+
method = ceilometer_shell.do_alarm_threshold_update
228+
self._do_test_alarm_update_repeat_actions(method, True)
229+
230+
def test_alarm_threshold_update_repeat_actions_clear(self):
231+
method = ceilometer_shell.do_alarm_threshold_update
232+
self._do_test_alarm_update_repeat_actions(method, False)
206233

207234

208235
class ShellSampleListCommandTest(utils.BaseTestCase):

ceilometerclient/v2/shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def do_alarm_threshold_update(cc, args={}):
436436
fields = utils.key_with_slash_to_nested_dict(fields)
437437
fields.pop('alarm_id')
438438
fields['type'] = 'threshold'
439-
if 'query' in fields['threshold_rule']:
439+
if 'threshold_rule' in fields and 'query' in fields['threshold_rule']:
440440
fields['threshold_rule']['query'] = options.cli_to_array(
441441
fields['threshold_rule']['query'])
442442
try:

0 commit comments

Comments
 (0)