diff options
author | ZhiQiang Fan <zhiqiang.fan@huawei.com> | 2014-04-29 11:44:04 +0800 |
---|---|---|
committer | ZhiQiang Fan <zhiqiang.fan@huawei.com> | 2014-06-11 10:56:38 +0800 |
commit | 18342a412f2557199dc3d7b1d16f50baf92eac1b (patch) | |
tree | 269d25fc992688820310c563acafc41002500224 | |
parent | 339b55c319f0f7cbd2a8025d4eff47351d66a997 (diff) | |
download | python-ceilometerclient-18342a412f2557199dc3d7b1d16f50baf92eac1b.tar.gz |
Fix alarm-threshold-update --query option
Currently, alarm-threshold-update command can not update its query
field, because the dest value is removed accidently so the query is
not put under threshold_rule dict. This patch simply adds it back.
Change-Id: I2eeaf8cbb26f506e097dafdcb6d0eae4ad7fec3e
Closes-Bug: #1313676
-rw-r--r-- | ceilometerclient/tests/v2/test_shell.py | 46 | ||||
-rw-r--r-- | ceilometerclient/v2/shell.py | 1 |
2 files changed, 32 insertions, 15 deletions
diff --git a/ceilometerclient/tests/v2/test_shell.py b/ceilometerclient/tests/v2/test_shell.py index ebb9129..730382b 100644 --- a/ceilometerclient/tests/v2/test_shell.py +++ b/ceilometerclient/tests/v2/test_shell.py @@ -178,6 +178,20 @@ class ShellAlarmCommandTest(utils.BaseTestCase): "type": "threshold", "name": "cpu_high"} + THRESHOLD_ALARM_CLI_ARGS = [ + '--name', 'cpu_high', + '--description', 'instance running hot', + '--meter-name', 'cpu_util', + '--threshold', '70.0', + '--comparison-operator', 'gt', + '--statistic', 'avg', + '--period', '600', + '--evaluation-periods', '3', + '--alarm-action', 'log://', + '--alarm-action', 'http://example.com/alarm/state', + '--query', 'resource_id=INSTANCE_ID' + ] + def setUp(self): super(ShellAlarmCommandTest, self).setUp() self.cc = mock.Mock() @@ -241,26 +255,28 @@ class ShellAlarmCommandTest(utils.BaseTestCase): @mock.patch('sys.stdout', new=six.StringIO()) def test_alarm_threshold_create_args(self): + argv = ['alarm-threshold-create'] + self.THRESHOLD_ALARM_CLI_ARGS + self._test_alarm_threshold_action_args('create', argv) + + def test_alarm_threshold_update_args(self): + argv = ['alarm-threshold-update', + '--alarm_id', 'x'] + self.THRESHOLD_ALARM_CLI_ARGS + self._test_alarm_threshold_action_args('update', argv) + + @mock.patch('sys.stdout', new=six.StringIO()) + def _test_alarm_threshold_action_args(self, action, argv): shell = base_shell.CeilometerShell() - argv = ['alarm-threshold-create', - '--name', 'cpu_high', - '--description', 'instance running hot', - '--meter-name', 'cpu_util', - '--threshold', '70.0', - '--comparison-operator', 'gt', - '--statistic', 'avg', - '--period', '600', - '--evaluation-periods', '3', - '--alarm-action', 'log://', - '--alarm-action', 'http://example.com/alarm/state', - '--query', 'resource_id=INSTANCE_ID'] _, args = shell.parse_args(argv) alarm = alarms.Alarm(mock.Mock(), self.ALARM) - self.cc.alarms.create.return_value = alarm + getattr(self.cc.alarms, action).return_value = alarm - ceilometer_shell.do_alarm_threshold_create(self.cc, args) - _, kwargs = self.cc.alarms.create.call_args + func = getattr(ceilometer_shell, 'do_alarm_threshold_' + action) + func(self.cc, args) + _, kwargs = getattr(self.cc.alarms, action).call_args + self._check_alarm_threshold_args(kwargs) + + def _check_alarm_threshold_args(self, kwargs): self.assertEqual('cpu_high', kwargs.get('name')) self.assertEqual('instance running hot', kwargs.get('description')) actions = ['log://', 'http://example.com/alarm/state'] diff --git a/ceilometerclient/v2/shell.py b/ceilometerclient/v2/shell.py index c603814..3807c7b 100644 --- a/ceilometerclient/v2/shell.py +++ b/ceilometerclient/v2/shell.py @@ -544,6 +544,7 @@ def do_alarm_update(cc, args={}): dest='threshold_rule/threshold', help='Threshold to evaluate against.') @utils.arg('-q', '--query', metavar='<QUERY>', + dest='threshold_rule/query', help='key[op]data_type::value; list. data_type is optional, ' 'but if supplied must be string, integer, float, or boolean.') @utils.arg('--repeat-actions', dest='repeat_actions', |