Avoid discarding alarm-threshold-create --query option
Fixes bug 1271913 The query is crucial to the alarm evaluator statistics query being well-formed, so must not be discarded. Change-Id: I5ff8dcb420b932fc58dfef3dadfcbc4a4dc5cf66
This commit is contained in:
@@ -227,7 +227,7 @@ class CeilometerShell(object):
|
||||
else:
|
||||
logging.basicConfig(format=format, level=logging.WARN)
|
||||
|
||||
def main(self, argv):
|
||||
def parse_args(self, argv):
|
||||
# Parse args once to find version
|
||||
parser = self.get_base_parser()
|
||||
(options, args) = parser.parse_known_args(argv)
|
||||
@@ -244,8 +244,14 @@ class CeilometerShell(object):
|
||||
self.do_help(options)
|
||||
return 0
|
||||
|
||||
# Parse args again and call whatever callback was selected
|
||||
args = subcommand_parser.parse_args(argv)
|
||||
# Return parsed args
|
||||
return api_version, subcommand_parser.parse_args(argv)
|
||||
|
||||
def main(self, argv):
|
||||
parsed = self.parse_args(argv)
|
||||
if parsed == 0:
|
||||
return 0
|
||||
api_version, args = parsed
|
||||
|
||||
# Short-circuit and deal with help command right away.
|
||||
if args.func == self.do_help:
|
||||
@@ -278,6 +284,7 @@ class CeilometerShell(object):
|
||||
|
||||
client = ceiloclient.get_client(api_version, **(args.__dict__))
|
||||
|
||||
# call whatever callback was selected
|
||||
try:
|
||||
args.func(client, args)
|
||||
except exc.Unauthorized:
|
||||
|
||||
@@ -17,6 +17,7 @@ import sys
|
||||
|
||||
from testtools import matchers
|
||||
|
||||
from ceilometerclient import shell as base_shell
|
||||
from ceilometerclient.tests import utils
|
||||
from ceilometerclient.v2 import alarms
|
||||
from ceilometerclient.v2 import samples
|
||||
@@ -232,6 +233,49 @@ class ShellAlarmCommandTest(utils.BaseTestCase):
|
||||
method = ceilometer_shell.do_alarm_threshold_update
|
||||
self._do_test_alarm_update_repeat_actions(method, False)
|
||||
|
||||
def test_alarm_threshold_create_args(self):
|
||||
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)
|
||||
|
||||
orig = sys.stdout
|
||||
sys.stdout = six.StringIO()
|
||||
alarm = alarms.Alarm(mock.Mock(), self.ALARM)
|
||||
self.cc.alarms.create.return_value = alarm
|
||||
|
||||
try:
|
||||
ceilometer_shell.do_alarm_threshold_create(self.cc, args)
|
||||
_, kwargs = self.cc.alarms.create.call_args
|
||||
self.assertEqual('cpu_high', kwargs.get('name'))
|
||||
self.assertEqual('instance running hot', kwargs.get('description'))
|
||||
actions = ['log://', 'http://example.com/alarm/state']
|
||||
self.assertEqual(actions, kwargs.get('alarm_actions'))
|
||||
self.assertTrue('threshold_rule' in kwargs)
|
||||
rule = kwargs['threshold_rule']
|
||||
self.assertEqual('cpu_util', rule.get('meter_name'))
|
||||
self.assertEqual(70.0, rule.get('threshold'))
|
||||
self.assertEqual('gt', rule.get('comparison_operator'))
|
||||
self.assertEqual('avg', rule.get('statistic'))
|
||||
self.assertEqual(600, rule.get('period'))
|
||||
self.assertEqual(3, rule.get('evaluation_periods'))
|
||||
query = dict(field='resource_id', type='',
|
||||
value='INSTANCE_ID', op='eq')
|
||||
self.assertEqual([query], rule['query'])
|
||||
finally:
|
||||
sys.stdout.close()
|
||||
sys.stdout = orig
|
||||
|
||||
|
||||
class ShellSampleListCommandTest(utils.BaseTestCase):
|
||||
|
||||
|
||||
@@ -330,6 +330,7 @@ def do_alarm_create(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',
|
||||
|
||||
Reference in New Issue
Block a user