From 83d5d2767410b60b21765215979ccdf471dc8bdc Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Fri, 22 Nov 2013 08:37:21 +0800 Subject: Remove uuidutils imports in oslo modules The only use of uuidutils in oslo-incubator is generate_uuid which could be replaced with uuid.uuid4(). Droping the dependency would help deprecating/removing uuidutils in the future. Partial-bug: #1253497 Change-Id: Ie0bc94e0b4aea6563f138c0f09c54c323ba23279 --- openstack/common/middleware/correlation_id.py | 5 +++-- tests/unit/middleware/test_correlation_id.py | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/openstack/common/middleware/correlation_id.py b/openstack/common/middleware/correlation_id.py index bffa0d7..d594c51 100644 --- a/openstack/common/middleware/correlation_id.py +++ b/openstack/common/middleware/correlation_id.py @@ -17,13 +17,14 @@ """Middleware that attaches a correlation id to WSGI request""" +import uuid + from openstack.common.middleware import base -from openstack.common import uuidutils class CorrelationIdMiddleware(base.Middleware): def process_request(self, req): correlation_id = (req.headers.get("X_CORRELATION_ID") or - uuidutils.generate_uuid()) + str(uuid.uuid4())) req.headers['X_CORRELATION_ID'] = correlation_id diff --git a/tests/unit/middleware/test_correlation_id.py b/tests/unit/middleware/test_correlation_id.py index f330ada..9a0d128 100644 --- a/tests/unit/middleware/test_correlation_id.py +++ b/tests/unit/middleware/test_correlation_id.py @@ -15,12 +15,13 @@ # License for the specific language governing permissions and limitations # under the License. +import uuid + import mock from openstack.common.fixture import moxstubout from openstack.common.middleware import correlation_id from openstack.common import test -from openstack.common import uuidutils class CorrelationIdMiddlewareTest(test.BaseTestCase): @@ -34,9 +35,9 @@ class CorrelationIdMiddlewareTest(test.BaseTestCase): req = mock.Mock() req.headers = {} - mock_generate_uuid = mock.Mock() - mock_generate_uuid.return_value = "fake_uuid" - self.stubs.Set(uuidutils, 'generate_uuid', mock_generate_uuid) + mock_uuid4 = mock.Mock() + mock_uuid4.return_value = "fake_uuid" + self.stubs.Set(uuid, 'uuid4', mock_uuid4) middleware = correlation_id.CorrelationIdMiddleware(app) middleware(req) -- cgit v1.2.1