Fix: CLI metric-create using project-id fails

The tenant-id query parameter was being passed as a list instead
of as a string

Added test

Change-Id: Ib8300530a3a17d9cb96962c1ffdf5362ed0553ca
Closes-Bug:#1664415
This commit is contained in:
Craig Bryant 2017-02-13 18:27:08 -07:00
parent 6c91e28edb
commit 3736d114be
2 changed files with 31 additions and 4 deletions

View File

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

View File

@ -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='<CROSS_PROJECT_ID>',
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='<METRIC_VALUE>',
type=float,
help='Metric value.')