diff --git a/monascaclient/tests/test_shell.py b/monascaclient/tests/test_shell.py index 5980847..3692a5b 100644 --- a/monascaclient/tests/test_shell.py +++ b/monascaclient/tests/test_shell.py @@ -1,4 +1,4 @@ -# (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP +# (C) Copyright 2014-2017 Hewlett Packard Enterprise Development LP # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -205,6 +205,34 @@ class ShellTestMonascaCommands(ShellBase): self.assertHeaders() self.assertEqual(data, self.requests_mock.last_request.json()) + def test_good_metrics_create_subcommand_with_tenant_id(self): + self._script_keystone_client() + self.m.ReplayAll() + + headers = {'location': 'http://no.where/v2.0/metrics'} + self.requests_mock.post('http://192.168.1.5:8004/v1/f14b41234/metrics', + status_code=204, + headers=headers) + + proj = 'd48e63e76a5c4e05ba26a1185f31d4aa' + argstrings = [ + 'metric-create metric1 123 --time 1395691090 --project-id ' + proj, + ] + for argstr in argstrings: + retvalue = self.shell(argstr) + self.assertRegexpMatches(retvalue, "^Success") + + data = {'timestamp': 1395691090, + 'name': 'metric1', + 'value': 123.0} + + self.assertHeaders() + self.assertEqual(data, self.requests_mock.last_request.json()) + + request_url = self.requests_mock.last_request.url + query_arg = request_url[request_url.index('?') + 1:] + self.assertEqual('tenant_id=' + proj, query_arg) + def test_bad_notifications_create_missing_args_subcommand(self): argstrings = [ 'notification-create email1 metric1@hp.com', diff --git a/monascaclient/v2_0/shell.py b/monascaclient/v2_0/shell.py index 411e9b1..44a5c41 100644 --- a/monascaclient/v2_0/shell.py +++ b/monascaclient/v2_0/shell.py @@ -1,4 +1,4 @@ -# (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP +# (C) Copyright 2014-2017 Hewlett Packard Enterprise Development LP # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -65,8 +65,7 @@ notification_types = ['EMAIL', 'WEBHOOK', 'PAGERDUTY'] help='Metric timestamp in milliseconds. Default: current timestamp.') @utils.arg('--project-id', metavar='', help='The Project ID to create metric on behalf of. ' - 'Requires monitoring-delegate role in keystone.', - action='append') + 'Requires monitoring-delegate role in keystone.') @utils.arg('value', metavar='', type=float, help='Metric value.')