diff --git a/ceilometer/dispatcher/gnocchi_client.py b/ceilometer/dispatcher/gnocchi_client.py index f3335080..a298e4e2 100644 --- a/ceilometer/dispatcher/gnocchi_client.py +++ b/ceilometer/dispatcher/gnocchi_client.py @@ -19,6 +19,7 @@ import json from oslo_log import log import requests import retrying +from six.moves.urllib import parse as urlparse from ceilometer.i18n import _ from ceilometer import keystone_client @@ -104,7 +105,8 @@ class Client(object): measure_attributes): r = self._session.post("%s/v1/resource/%s/%s/metric/%s/measures" % (self._gnocchi_url, resource_type, - resource_id, metric_name), + urlparse.quote(resource_id, safe=""), + metric_name), headers=self._get_headers(), data=json.dumps(measure_attributes)) @@ -155,7 +157,8 @@ class Client(object): resource_extra): r = self._session.patch( "%s/v1/resource/%s/%s" - % (self._gnocchi_url, resource_type, resource_id), + % (self._gnocchi_url, resource_type, + urlparse.quote(resource_id, safe="")), headers=self._get_headers(), data=json.dumps(resource_extra)) @@ -175,7 +178,7 @@ class Client(object): params = {metric_name: archive_policy} r = self._session.post("%s/v1/resource/%s/%s/metric" % (self._gnocchi_url, resource_type, - resource_id), + urlparse.quote(resource_id, safe="")), headers=self._get_headers(), data=json.dumps(params)) if r.status_code == 409: diff --git a/ceilometer/tests/unit/dispatcher/test_gnocchi.py b/ceilometer/tests/unit/dispatcher/test_gnocchi.py index 7c10f168..22b68415 100644 --- a/ceilometer/tests/unit/dispatcher/test_gnocchi.py +++ b/ceilometer/tests/unit/dispatcher/test_gnocchi.py @@ -337,7 +337,7 @@ class DispatcherWorkflowTest(base.BaseTestCase, group="dispatcher_gnocchi" ) - self.sample['resource_id'] = str(uuid.uuid4()) + self.sample['resource_id'] = str(uuid.uuid4()) + "/foobar" @mock.patch('ceilometer.dispatcher.gnocchi.LOG') @mock.patch('ceilometer.dispatcher.gnocchi_client.LOG') @@ -348,7 +348,9 @@ class DispatcherWorkflowTest(base.BaseTestCase, base_url = self.dispatcher.conf.dispatcher_gnocchi.url url_params = { 'url': urlparse.urljoin(base_url, '/v1/resource'), - 'resource_id': self.sample['resource_id'], + # NOTE(sileht): we don't use urlparse.quote here + # to ensure / is converted in %2F + 'resource_id': self.sample['resource_id'].replace("/", "%2F"), 'resource_type': self.resource_type, 'metric_name': self.sample['counter_name'] }