diff --git a/aodhclient/shell.py b/aodhclient/shell.py index d7a60bc..0307657 100644 --- a/aodhclient/shell.py +++ b/aodhclient/shell.py @@ -74,8 +74,8 @@ class AodhShell(app.App): :param version: version number for the application :paramtype version: str """ - parser = super(AodhShell, self).build_option_parser(description, - version) + parser = super(AodhShell, self).build_option_parser( + description, version, argparse_kwargs={'allow_abbrev': False}) # Global arguments, one day this should go to keystoneauth1 parser.add_argument( '--os-region-name', diff --git a/aodhclient/tests/functional/test_alarm.py b/aodhclient/tests/functional/test_alarm.py index 4b1349c..a8f8753 100644 --- a/aodhclient/tests/functional/test_alarm.py +++ b/aodhclient/tests/functional/test_alarm.py @@ -627,7 +627,7 @@ class AodhClientGnocchiRulesTest(base.ClientTestBase): "--type gnocchi_aggregation_by_metrics_threshold " "--name alarm1 " "--metrics %s " - "--metrics %s " + "--metric %s " "--threshold 80 " "--aggregation-method last " "--project-id %s" diff --git a/aodhclient/tests/unit/test_alarm_cli.py b/aodhclient/tests/unit/test_alarm_cli.py index e480d9a..68d01f4 100644 --- a/aodhclient/tests/unit/test_alarm_cli.py +++ b/aodhclient/tests/unit/test_alarm_cli.py @@ -95,7 +95,7 @@ class CliAlarmCreateTest(testtools.TestCase): self.cli_alarm_create._validate_args(test_parsed_args) mock_arg.assert_called_once_with( 'gnocchi_aggregation_by_metrics_threshold requires ' - '--metrics, --threshold and --aggregation-method') + '--metric, --threshold and --aggregation-method') def test_alarm_from_args(self): # The test case to cover the method _alarm_from_args @@ -168,7 +168,8 @@ class CliAlarmCreateTest(testtools.TestCase): 'aggregation_method': 'last', 'evaluation_periods': 60, 'comparison_operator': 'le', - 'threshold': 80.0 + 'threshold': 80.0, + 'metrics': ['cpu'], }, 'gnocchi_aggregation_by_resources_threshold_rule': { 'granularity': '60', diff --git a/aodhclient/utils.py b/aodhclient/utils.py index ef67d50..11609ec 100644 --- a/aodhclient/utils.py +++ b/aodhclient/utils.py @@ -123,7 +123,13 @@ def format_archive_policy(ap): def dict_from_parsed_args(parsed_args, attrs): d = {} 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: d[attr] = value return d diff --git a/aodhclient/v2/alarm_cli.py b/aodhclient/v2/alarm_cli.py index d94fb81..f85a5a5 100644 --- a/aodhclient/v2/alarm_cli.py +++ b/aodhclient/v2/alarm_cli.py @@ -282,9 +282,6 @@ class CliAlarmCreate(show.ShowOne): common_group.add_argument( '--threshold', type=float, metavar='', dest='threshold', help='Threshold to evaluate against.') - common_group.add_argument( - '--metric', metavar='', - dest='metric', help='Metric to evaluate against.') event_group = parser.add_argument_group('event alarm') event_group.add_argument( @@ -301,6 +298,10 @@ class CliAlarmCreate(show.ShowOne): '--aggregation-method', metavar='', dest='aggregation_method', help='The aggregation_method to compare to the threshold.') + gnocchi_common_group.add_argument( + '--metric', '--metrics', metavar='', 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 alarm') @@ -311,11 +312,6 @@ class CliAlarmCreate(show.ShowOne): '--resource-id', metavar='', 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='', action='append', - dest='metrics', help='The list of metric ids.') composite_group = parser.add_argument_group('composite alarm') composite_group.add_argument( '--composite-rule', metavar='', @@ -344,7 +340,7 @@ class CliAlarmCreate(show.ShowOne): def _validate_args(self, parsed_args): 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.aggregation_method)): 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.aggregation_method)): self.parser.error('gnocchi_aggregation_by_metrics_threshold ' - 'requires --metrics, --threshold and ' + 'requires --metric, --threshold and ' '--aggregation-method') 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 parsed_args.aggregation_method)): self.parser.error('gnocchi_aggregation_by_resources_threshold '