From: Zhongyue Luo Date: Wed, 14 Nov 2012 13:49:07 +0000 (+0900) Subject: Remove gen_uuid() X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f51e4af121b9289fa6ab4c634cb525d7c3d840e4;p=openstack-build%2Fcinder-build.git Remove gen_uuid() Removed gen_uuid and uuid related unittests Replaced utils.gen_uuid() with uuid.uuid4() Change-Id: If34096f47fdea719e2dc180b448654519ede9bc9 --- diff --git a/bin/cinder-manage b/bin/cinder-manage index 9d1321742..19bb1d6ea 100755 --- a/bin/cinder-manage +++ b/bin/cinder-manage @@ -58,6 +58,7 @@ import gettext import optparse import os import sys +import uuid from sqlalchemy import create_engine, MetaData, Table from sqlalchemy.orm import sessionmaker @@ -502,7 +503,7 @@ class StorageManagerCommands(object): # TODO(renukaapte) Add backend_introduce. ctxt = context.get_admin_context() params = dict(map(self._splitfun, args)) - sr_uuid = utils.gen_uuid() + sr_uuid = uuid.uuid4() if flavor_label is None: print "error: backend needs to be associated with flavor" diff --git a/cinder/context.py b/cinder/context.py index fc80f53ed..f8ca839f4 100644 --- a/cinder/context.py +++ b/cinder/context.py @@ -20,19 +20,19 @@ """RequestContext: context for requests that persist through all of cinder.""" import copy +import uuid from cinder.openstack.common import local from cinder.openstack.common import log as logging from cinder.openstack.common import timeutils from cinder import policy -from cinder import utils LOG = logging.getLogger(__name__) def generate_request_id(): - return 'req-' + str(utils.gen_uuid()) + return 'req-' + str(uuid.uuid4()) class RequestContext(object): diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 8dd3abc28..589ef2909 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -21,6 +21,7 @@ import datetime import functools +import uuid import warnings from sqlalchemy.exc import IntegrityError @@ -41,7 +42,6 @@ from cinder import flags from cinder.openstack.common import log as logging from cinder.openstack.common import timeutils from cinder.openstack.common import uuidutils -from cinder import utils FLAGS = flags.FLAGS @@ -736,7 +736,7 @@ def quota_reserve(context, resources, quotas, deltas, expire, reservations = [] for resource, delta in deltas.items(): reservation = reservation_create(elevated, - str(utils.gen_uuid()), + str(uuid.uuid4()), usages[resource], context.project_id, resource, delta, expire, @@ -915,7 +915,7 @@ def volume_create(context, values): models.VolumeMetadata) volume_ref = models.Volume() if not values.get('id'): - values['id'] = str(utils.gen_uuid()) + values['id'] = str(uuid.uuid4()) volume_ref.update(values) session = get_session() @@ -1133,7 +1133,7 @@ def volume_metadata_update(context, volume_id, metadata, delete): def snapshot_create(context, values): snapshot_ref = models.Snapshot() if not values.get('id'): - values['id'] = str(utils.gen_uuid()) + values['id'] = str(uuid.uuid4()) snapshot_ref.update(values) session = get_session() diff --git a/cinder/tests/api/openstack/fakes.py b/cinder/tests/api/openstack/fakes.py index 81d6148a4..695322f08 100644 --- a/cinder/tests/api/openstack/fakes.py +++ b/cinder/tests/api/openstack/fakes.py @@ -16,6 +16,7 @@ # under the License. import datetime +import uuid import routes import webob @@ -33,7 +34,6 @@ from cinder.api.openstack import wsgi as os_wsgi from cinder import context from cinder import exception as exc from cinder.openstack.common import timeutils -from cinder import utils from cinder import wsgi @@ -172,7 +172,7 @@ class FakeRateLimiter(object): def get_fake_uuid(token=0): if not token in FAKE_UUIDS: - FAKE_UUIDS[token] = str(utils.gen_uuid()) + FAKE_UUIDS[token] = str(uuid.uuid4()) return FAKE_UUIDS[token] diff --git a/cinder/tests/api/openstack/volume/contrib/test_volume_actions.py b/cinder/tests/api/openstack/volume/contrib/test_volume_actions.py index 227680dab..afb87b494 100644 --- a/cinder/tests/api/openstack/volume/contrib/test_volume_actions.py +++ b/cinder/tests/api/openstack/volume/contrib/test_volume_actions.py @@ -1,3 +1,5 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + # Copyright 2012 OpenStack LLC. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -13,6 +15,7 @@ # under the License. import datetime +import uuid import webob from cinder.api.openstack.volume.contrib import volume_actions @@ -22,7 +25,6 @@ from cinder.openstack.common import jsonutils from cinder.openstack.common.rpc import common as rpc_common from cinder import test from cinder.tests.api.openstack import fakes -from cinder import utils from cinder import volume from cinder.volume import api as volume_api @@ -47,7 +49,7 @@ class VolumeActionsTest(test.TestCase): def setUp(self): super(VolumeActionsTest, self).setUp() self.stubs.Set(volume.API, 'get', fake_volume_api) - self.UUID = utils.gen_uuid() + self.UUID = uuid.uuid4() for _method in self._methods: self.stubs.Set(volume.API, _method, fake_volume_api) diff --git a/cinder/tests/api/openstack/volume/contrib/test_volume_host_attribute.py b/cinder/tests/api/openstack/volume/contrib/test_volume_host_attribute.py index 2ce957b44..d32076ecc 100644 --- a/cinder/tests/api/openstack/volume/contrib/test_volume_host_attribute.py +++ b/cinder/tests/api/openstack/volume/contrib/test_volume_host_attribute.py @@ -1,3 +1,5 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + # Copyright 2012 OpenStack LLC. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,6 +16,7 @@ import datetime import json +import uuid from lxml import etree import webob @@ -21,7 +24,6 @@ import webob from cinder import context from cinder import test from cinder.tests.api.openstack import fakes -from cinder import utils from cinder import volume @@ -60,7 +62,7 @@ class VolumeHostAttributeTest(test.TestCase): super(VolumeHostAttributeTest, self).setUp() self.stubs.Set(volume.API, 'get', fake_volume_get) self.stubs.Set(volume.API, 'get_all', fake_volume_get_all) - self.UUID = utils.gen_uuid() + self.UUID = uuid.uuid4() def test_get_volume_allowed(self): ctx = context.RequestContext('admin', 'fake', True) diff --git a/cinder/tests/api/openstack/volume/contrib/test_volume_tenant_attribute.py b/cinder/tests/api/openstack/volume/contrib/test_volume_tenant_attribute.py index f34288880..65a17d73d 100644 --- a/cinder/tests/api/openstack/volume/contrib/test_volume_tenant_attribute.py +++ b/cinder/tests/api/openstack/volume/contrib/test_volume_tenant_attribute.py @@ -1,3 +1,5 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + # Copyright 2012 OpenStack LLC. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,6 +16,7 @@ import datetime import json +import uuid from lxml import etree import webob @@ -21,9 +24,9 @@ import webob from cinder import context from cinder import test from cinder.tests.api.openstack import fakes -from cinder import utils from cinder import volume + PROJECT_ID = '88fd1da4-f464-4a87-9ce5-26f2f40743b9' @@ -62,7 +65,7 @@ class VolumeTenantAttributeTest(test.TestCase): super(VolumeTenantAttributeTest, self).setUp() self.stubs.Set(volume.API, 'get', fake_volume_get) self.stubs.Set(volume.API, 'get_all', fake_volume_get_all) - self.UUID = utils.gen_uuid() + self.UUID = uuid.uuid4() def test_get_volume_allowed(self): ctx = context.RequestContext('admin', 'fake', True) diff --git a/cinder/tests/image/fake.py b/cinder/tests/image/fake.py index 16c600e57..b6b5eb5bb 100644 --- a/cinder/tests/image/fake.py +++ b/cinder/tests/image/fake.py @@ -20,12 +20,12 @@ import copy import datetime +import uuid from cinder import exception from cinder import flags import cinder.image.glance from cinder.openstack.common import log as logging -from cinder import utils LOG = logging.getLogger(__name__) @@ -178,7 +178,7 @@ class _FakeImageService(object): :raises: Duplicate if the image already exist. """ - image_id = str(metadata.get('id', utils.gen_uuid())) + image_id = str(metadata.get('id', uuid.uuid4())) metadata['id'] = image_id if image_id in self.images: raise exception.Duplicate() diff --git a/cinder/tests/integrated/integrated_helpers.py b/cinder/tests/integrated/integrated_helpers.py index 72f4e690d..f7ed84eea 100644 --- a/cinder/tests/integrated/integrated_helpers.py +++ b/cinder/tests/integrated/integrated_helpers.py @@ -21,12 +21,12 @@ Provides common functionality for integrated unit tests import random import string +import uuid from cinder.openstack.common import log as logging from cinder import service from cinder import test # For the flags from cinder.tests.integrated.api import client -from cinder import utils LOG = logging.getLogger(__name__) @@ -102,7 +102,7 @@ class _IntegratedTestBase(test.TestCase): return generate_new_element(server_names, 'server') def get_invalid_image(self): - return str(utils.gen_uuid()) + return str(uuid.uuid4()) def _build_minimal_create_server_request(self): server = {} diff --git a/cinder/tests/test_utils.py b/cinder/tests/test_utils.py index 4e542e533..52c5ec7a3 100644 --- a/cinder/tests/test_utils.py +++ b/cinder/tests/test_utils.py @@ -22,6 +22,7 @@ import os.path import paramiko import StringIO import tempfile +import uuid import mox @@ -29,7 +30,6 @@ import cinder from cinder import exception from cinder import flags from cinder.openstack.common import timeutils -from cinder.openstack.common import uuidutils from cinder import test from cinder import utils @@ -437,11 +437,6 @@ class GenericUtilsTestCase(test.TestCase): self.assertEquals(h1, h2) -class GenUUIDTestCase(test.TestCase): - def test_gen_valid_uuid(self): - self.assertTrue(uuidutils.is_uuid_like(str(utils.gen_uuid()))) - - class MonkeyPatchTestCase(test.TestCase): """Unit test for utils.monkey_patch().""" def setUp(self): @@ -654,7 +649,7 @@ class AuditPeriodTest(test.TestCase): class FakeSSHClient(object): def __init__(self): - self.id = utils.gen_uuid() + self.id = uuid.uuid4() self.transport = FakeTransport() def set_missing_host_key_policy(self, policy): diff --git a/cinder/utils.py b/cinder/utils.py index df2894d5e..40be4ff96 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -1,5 +1,4 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2010 United States Government as represented by the # Administrator of the National Aeronautics and Space Administration. @@ -41,7 +40,6 @@ import sys import tempfile import time import types -import uuid import warnings from xml.sax import saxutils @@ -754,10 +752,6 @@ def check_isinstance(obj, cls): return cls() # Ugly PyLint hack -def gen_uuid(): - return uuid.uuid4() - - def bool_from_str(val): """Convert a string representation of a bool into a bool value"""