Fix list metric for other tenants
1. Use get_x_tenant_or_tenant_id instead of get_tenant_id in list metrics api. 2. Add missing delegateAuthorizedRole config to devstack api-config.yml Change-Id: I18c0dd340a4ac8b016e761d648d9f03923b070bc Closes-bug: #1613997
This commit is contained in:
parent
2016ec57c8
commit
c1f0bdaea9
|
@ -32,8 +32,10 @@ class MonascaClient(rest_client.RestClient):
|
|||
resp, response_body = self.get('')
|
||||
return resp, response_body
|
||||
|
||||
def create_metrics(self, metrics):
|
||||
def create_metrics(self, metrics, tenant_id=None):
|
||||
uri = 'metrics'
|
||||
if tenant_id:
|
||||
uri = uri + '?tenant_id=%s' % tenant_id
|
||||
request_body = json.dumps(metrics)
|
||||
resp, response_body = self.post(uri, request_body)
|
||||
return resp, response_body
|
||||
|
|
|
@ -39,9 +39,10 @@ class BaseMonascaTest(tempest.test.BaseTestCase):
|
|||
force_tenant_isolation=True,
|
||||
identity_version=auth_version)
|
||||
credentials = cls.cred_provider.get_creds_by_roles(
|
||||
['monasca-user', 'anotherrole']).credentials
|
||||
['monasca-user', 'anotherrole', 'admin']).credentials
|
||||
cls.os = clients.Manager(credentials=credentials)
|
||||
cls.monasca_client = cls.os.monasca_client
|
||||
cls.tenants_client = cls.os.tenants_client
|
||||
|
||||
@staticmethod
|
||||
def cleanup_resources(method, list_of_ids):
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
# TODO(RMH): Check if ' should be added in the list of INVALID_CHARS.
|
||||
# TODO(RMH): test_create_metric_no_value, should return 422 if value not sent
|
||||
import time
|
||||
from six.moves import range as xrange
|
||||
|
||||
from monasca_tempest_tests.tests.api import base
|
||||
from monasca_tempest_tests.tests.api import constants
|
||||
|
@ -413,6 +414,38 @@ class TestMetrics(base.BaseMonascaTest):
|
|||
"metrics = 0"
|
||||
self.fail(error_msg)
|
||||
|
||||
@test.attr(type='gate')
|
||||
def test_list_metrics_with_tenant(self):
|
||||
name = data_utils.rand_name('name')
|
||||
key = data_utils.rand_name('key')
|
||||
value = data_utils.rand_name('value')
|
||||
tenant = self.tenants_client.create_tenant(
|
||||
name=data_utils.rand_name('test_tenant'))['tenant']
|
||||
# Delete the tenant at the end of the test
|
||||
self.addCleanup(self.tenants_client.delete_tenant, tenant['id'])
|
||||
metric = helpers.create_metric(name=name,
|
||||
dimensions={key: value})
|
||||
resp, response_body = self.monasca_client.create_metrics(
|
||||
metric, tenant_id=tenant['id'])
|
||||
self.assertEqual(204, resp.status)
|
||||
query_param = '?tenant_id=' + str(tenant['id'])
|
||||
for i in xrange(constants.MAX_RETRIES):
|
||||
resp, response_body = self.monasca_client.list_metrics(query_param)
|
||||
self.assertEqual(200, resp.status)
|
||||
elements = response_body['elements']
|
||||
for element in elements:
|
||||
if str(element['name']) == name:
|
||||
self._verify_list_metrics_element(element, test_key=key,
|
||||
test_value=value)
|
||||
return
|
||||
time.sleep(constants.RETRY_WAIT_SECS)
|
||||
if i == constants.MAX_RETRIES - 1:
|
||||
error_msg = "Failed test_list_metrics_with_tenant: " \
|
||||
"timeout on waiting for metrics: at least " \
|
||||
"one metric is needed. Current number of " \
|
||||
"metrics = 0"
|
||||
self.fail(error_msg)
|
||||
|
||||
@test.attr(type='gate')
|
||||
def test_list_metrics_with_offset_limit(self):
|
||||
name = data_utils.rand_name()
|
||||
|
|
Loading…
Reference in New Issue