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
This commit is contained in:
ZhiQiang Fan
2014-04-29 11:44:04 +08:00
parent 339b55c319
commit 18342a412f
2 changed files with 32 additions and 15 deletions

View File

@@ -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']

View File

@@ -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',