cli: replace metrics by metric

All cli endpoint takes --metric, expect one. To avoid confusion
allow --metric everywhere.

Change-Id: I443ffaedc53508604a3895819f5dc1b443905bf2
This commit is contained in:
Mehdi Abaakouk 2018-05-19 08:49:26 +02:00
parent c96b2c335d
commit 6002b08818
5 changed files with 21 additions and 17 deletions

View File

@ -74,8 +74,8 @@ class AodhShell(app.App):
:param version: version number for the application :param version: version number for the application
:paramtype version: str :paramtype version: str
""" """
parser = super(AodhShell, self).build_option_parser(description, parser = super(AodhShell, self).build_option_parser(
version) description, version, argparse_kwargs={'allow_abbrev': False})
# Global arguments, one day this should go to keystoneauth1 # Global arguments, one day this should go to keystoneauth1
parser.add_argument( parser.add_argument(
'--os-region-name', '--os-region-name',

View File

@ -627,7 +627,7 @@ class AodhClientGnocchiRulesTest(base.ClientTestBase):
"--type gnocchi_aggregation_by_metrics_threshold " "--type gnocchi_aggregation_by_metrics_threshold "
"--name alarm1 " "--name alarm1 "
"--metrics %s " "--metrics %s "
"--metrics %s " "--metric %s "
"--threshold 80 " "--threshold 80 "
"--aggregation-method last " "--aggregation-method last "
"--project-id %s" "--project-id %s"

View File

@ -95,7 +95,7 @@ class CliAlarmCreateTest(testtools.TestCase):
self.cli_alarm_create._validate_args(test_parsed_args) self.cli_alarm_create._validate_args(test_parsed_args)
mock_arg.assert_called_once_with( mock_arg.assert_called_once_with(
'gnocchi_aggregation_by_metrics_threshold requires ' 'gnocchi_aggregation_by_metrics_threshold requires '
'--metrics, --threshold and --aggregation-method') '--metric, --threshold and --aggregation-method')
def test_alarm_from_args(self): def test_alarm_from_args(self):
# The test case to cover the method _alarm_from_args # The test case to cover the method _alarm_from_args
@ -168,7 +168,8 @@ class CliAlarmCreateTest(testtools.TestCase):
'aggregation_method': 'last', 'aggregation_method': 'last',
'evaluation_periods': 60, 'evaluation_periods': 60,
'comparison_operator': 'le', 'comparison_operator': 'le',
'threshold': 80.0 'threshold': 80.0,
'metrics': ['cpu'],
}, },
'gnocchi_aggregation_by_resources_threshold_rule': { 'gnocchi_aggregation_by_resources_threshold_rule': {
'granularity': '60', 'granularity': '60',

View File

@ -123,7 +123,13 @@ def format_archive_policy(ap):
def dict_from_parsed_args(parsed_args, attrs): def dict_from_parsed_args(parsed_args, attrs):
d = {} d = {}
for attr in attrs: for attr in attrs:
value = getattr(parsed_args, attr) if attr == "metric":
if parsed_args.metrics:
value = parsed_args.metrics[0]
else:
value = None
else:
value = getattr(parsed_args, attr)
if value is not None: if value is not None:
d[attr] = value d[attr] = value
return d return d

View File

@ -282,9 +282,6 @@ class CliAlarmCreate(show.ShowOne):
common_group.add_argument( common_group.add_argument(
'--threshold', type=float, metavar='<THRESHOLD>', '--threshold', type=float, metavar='<THRESHOLD>',
dest='threshold', help='Threshold to evaluate against.') dest='threshold', help='Threshold to evaluate against.')
common_group.add_argument(
'--metric', metavar='<METRIC>',
dest='metric', help='Metric to evaluate against.')
event_group = parser.add_argument_group('event alarm') event_group = parser.add_argument_group('event alarm')
event_group.add_argument( event_group.add_argument(
@ -301,6 +298,10 @@ class CliAlarmCreate(show.ShowOne):
'--aggregation-method', metavar='<AGGR_METHOD>', '--aggregation-method', metavar='<AGGR_METHOD>',
dest='aggregation_method', dest='aggregation_method',
help='The aggregation_method to compare to the threshold.') help='The aggregation_method to compare to the threshold.')
gnocchi_common_group.add_argument(
'--metric', '--metrics', metavar='<METRIC>', action='append',
dest='metrics', help='The metric id or name '
'depending of the alarm type')
gnocchi_resource_threshold_group = parser.add_argument_group( gnocchi_resource_threshold_group = parser.add_argument_group(
'gnocchi resource threshold alarm') 'gnocchi resource threshold alarm')
@ -311,11 +312,6 @@ class CliAlarmCreate(show.ShowOne):
'--resource-id', metavar='<RESOURCE_ID>', '--resource-id', metavar='<RESOURCE_ID>',
dest='resource_id', help='The id of a resource.') dest='resource_id', help='The id of a resource.')
gnocchi_aggr_metrics_group = parser.add_argument_group(
'gnocchi aggregation by metrics alarm')
gnocchi_aggr_metrics_group.add_argument(
'--metrics', metavar='<METRICS>', action='append',
dest='metrics', help='The list of metric ids.')
composite_group = parser.add_argument_group('composite alarm') composite_group = parser.add_argument_group('composite alarm')
composite_group.add_argument( composite_group.add_argument(
'--composite-rule', metavar='<COMPOSITE_RULE>', '--composite-rule', metavar='<COMPOSITE_RULE>',
@ -344,7 +340,7 @@ class CliAlarmCreate(show.ShowOne):
def _validate_args(self, parsed_args): def _validate_args(self, parsed_args):
if (parsed_args.type == 'gnocchi_resources_threshold' and if (parsed_args.type == 'gnocchi_resources_threshold' and
not (parsed_args.metric and parsed_args.threshold is not None not (parsed_args.metrics and parsed_args.threshold is not None
and parsed_args.resource_id and parsed_args.resource_type and parsed_args.resource_id and parsed_args.resource_type
and parsed_args.aggregation_method)): and parsed_args.aggregation_method)):
self.parser.error('gnocchi_resources_threshold requires --metric, ' self.parser.error('gnocchi_resources_threshold requires --metric, '
@ -355,10 +351,11 @@ class CliAlarmCreate(show.ShowOne):
and parsed_args.threshold is not None and parsed_args.threshold is not None
and parsed_args.aggregation_method)): and parsed_args.aggregation_method)):
self.parser.error('gnocchi_aggregation_by_metrics_threshold ' self.parser.error('gnocchi_aggregation_by_metrics_threshold '
'requires --metrics, --threshold and ' 'requires --metric, --threshold and '
'--aggregation-method') '--aggregation-method')
elif (parsed_args.type == 'gnocchi_aggregation_by_resources_threshold' elif (parsed_args.type == 'gnocchi_aggregation_by_resources_threshold'
and not (parsed_args.metric and parsed_args.threshold is not None and not (parsed_args.metrics
and parsed_args.threshold is not None
and parsed_args.query and parsed_args.resource_type and and parsed_args.query and parsed_args.resource_type and
parsed_args.aggregation_method)): parsed_args.aggregation_method)):
self.parser.error('gnocchi_aggregation_by_resources_threshold ' self.parser.error('gnocchi_aggregation_by_resources_threshold '