From 5beeed884753c3fb196cb66684d761dfc424b0db Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Wed, 14 Nov 2012 18:25:59 +0800 Subject: [PATCH] Remove gen_uuid() Removed gen_uuid and uuid related unittests Replaced utils.gen_uuid() with uuid.uuid4() Change-Id: I3020a0d67525eb73cfb8873d2570c93e2022bb76 --- nova/compute/api.py | 3 +- nova/compute/instance_types.py | 3 +- nova/compute/manager.py | 3 +- nova/context.py | 4 +-- nova/db/sqlalchemy/api.py | 8 ++--- .../versions/089_add_volume_id_mappings.py | 8 +++-- nova/network/manager.py | 3 +- .../compute/contrib/test_admin_actions.py | 9 +++--- .../compute/contrib/test_floating_ips.py | 6 ++-- .../api/openstack/compute/test_consoles.py | 7 +++-- .../openstack/compute/test_server_actions.py | 5 +-- .../openstack/compute/test_server_metadata.py | 6 ++-- .../api/openstack/compute/test_servers.py | 31 ++++++++++--------- .../api/openstack/compute/test_versions.py | 5 +-- nova/tests/api/openstack/fakes.py | 4 +-- nova/tests/compute/test_compute.py | 11 ++++--- nova/tests/fake_volume.py | 8 +++-- nova/tests/hyperv/db_fakes.py | 5 +-- nova/tests/image/fake.py | 5 +-- nova/tests/integrated/integrated_helpers.py | 4 +-- nova/tests/network/test_quantumv2.py | 6 ++-- nova/tests/test_db_api.py | 7 +++-- nova/tests/test_utils.py | 26 ---------------- nova/tests/vmwareapi/db_fakes.py | 3 +- nova/utils.py | 5 --- 25 files changed, 89 insertions(+), 96 deletions(-) diff --git a/nova/compute/api.py b/nova/compute/api.py index 092ea6b39a28..5a8bcad2f37b 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -27,6 +27,7 @@ import re import string import time import urllib +import uuid from nova import block_device from nova.compute import instance_types @@ -678,7 +679,7 @@ class API(base.Base): if not instance.get('uuid'): # Generate the instance_uuid here so we can use it # for additional setup before creating the DB entry. - instance['uuid'] = str(utils.gen_uuid()) + instance['uuid'] = str(uuid.uuid4()) instance['launch_index'] = 0 instance['vm_state'] = vm_states.BUILDING diff --git a/nova/compute/instance_types.py b/nova/compute/instance_types.py index 5efa3d97c393..4be4ab71d8a9 100644 --- a/nova/compute/instance_types.py +++ b/nova/compute/instance_types.py @@ -21,6 +21,7 @@ """Built-in instance properties.""" import re +import uuid from nova import config from nova import context @@ -41,7 +42,7 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb=None, flavorid=None, """Creates instance types.""" if flavorid is None: - flavorid = utils.gen_uuid() + flavorid = uuid.uuid4() if swap is None: swap = 0 if rxtx_factor is None: diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 9011196b2887..be20c7a4001e 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -40,6 +40,7 @@ import socket import sys import time import traceback +import uuid from eventlet import greenthread @@ -2180,7 +2181,7 @@ class ComputeManager(manager.SchedulerDependentManager): """Return connection information for a vnc console.""" context = context.elevated() LOG.debug(_("Getting vnc console"), instance=instance) - token = str(utils.gen_uuid()) + token = str(uuid.uuid4()) if console_type == 'novnc': # For essex, novncproxy_base_url must include the full path diff --git a/nova/context.py b/nova/context.py index 74f7a3c23d18..094e2bffbc33 100644 --- a/nova/context.py +++ b/nova/context.py @@ -20,19 +20,19 @@ """RequestContext: context for requests that persist through all of nova.""" import copy +import uuid from nova.openstack.common import local from nova.openstack.common import log as logging from nova.openstack.common import timeutils from nova import policy -from nova 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/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 42cedc4b2ea1..007e83cbef44 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -23,6 +23,7 @@ import collections import copy import datetime import functools +import uuid from sqlalchemy import and_ from sqlalchemy.exc import IntegrityError @@ -46,7 +47,6 @@ from nova import flags from nova.openstack.common import log as logging from nova.openstack.common import timeutils from nova.openstack.common import uuidutils -from nova import utils CONF = config.CONF @@ -1344,7 +1344,7 @@ def instance_create(context, values): instance_ref = models.Instance() if not values.get('uuid'): - values['uuid'] = str(utils.gen_uuid()) + values['uuid'] = str(uuid.uuid4()) instance_ref['info_cache'] = models.InstanceInfoCache() info_cache = values.pop('info_cache', None) if info_cache is not None: @@ -2042,7 +2042,7 @@ def network_create_safe(context, values): raise exception.DuplicateVlan(vlan=values['vlan']) network_ref = models.Network() - network_ref['uuid'] = str(utils.gen_uuid()) + network_ref['uuid'] = str(uuid.uuid4()) network_ref.update(values) try: @@ -2643,7 +2643,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, diff --git a/nova/db/sqlalchemy/migrate_repo/versions/089_add_volume_id_mappings.py b/nova/db/sqlalchemy/migrate_repo/versions/089_add_volume_id_mappings.py index d878e250b91a..a4cd06704dd7 100644 --- a/nova/db/sqlalchemy/migrate_repo/versions/089_add_volume_id_mappings.py +++ b/nova/db/sqlalchemy/migrate_repo/versions/089_add_volume_id_mappings.py @@ -15,11 +15,13 @@ # License for the specific language governing permissions and limitations # under the License. +import uuid + from sqlalchemy import Boolean, Column, DateTime, Integer from sqlalchemy import MetaData, String, Table from nova.openstack.common import log as logging -from nova import utils + LOG = logging.getLogger(__name__) @@ -93,7 +95,7 @@ def upgrade(migrate_engine): volume_list = list(volumes.select().execute()) for v in volume_list: old_id = v['id'] - new_id = utils.gen_uuid() + new_id = uuid.uuid4() row = volume_id_mappings.insert() row.execute({'id': old_id, 'uuid': str(new_id)}) @@ -101,7 +103,7 @@ def upgrade(migrate_engine): snapshot_list = list(snapshots.select().execute()) for s in snapshot_list: old_id = s['id'] - new_id = utils.gen_uuid() + new_id = uuid.uuid4() row = snapshot_id_mappings.insert() row.execute({'id': old_id, 'uuid': str(new_id)}) diff --git a/nova/network/manager.py b/nova/network/manager.py index cf7b6109d4c6..dbd82a6b2b91 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -49,6 +49,7 @@ import itertools import math import re import socket +import uuid from eventlet import greenpool import netaddr @@ -1263,7 +1264,7 @@ class NetworkManager(manager.SchedulerDependentManager): vif = {'address': utils.generate_mac_address(), 'instance_uuid': instance_uuid, 'network_id': network_id, - 'uuid': str(utils.gen_uuid())} + 'uuid': str(uuid.uuid4())} # try FLAG times to create a vif record with a unique mac_address for i in xrange(CONF.create_unique_mac_address_attempts): try: diff --git a/nova/tests/api/openstack/compute/contrib/test_admin_actions.py b/nova/tests/api/openstack/compute/contrib/test_admin_actions.py index 337e1e4e7638..f6337f035ea1 100644 --- a/nova/tests/api/openstack/compute/contrib/test_admin_actions.py +++ b/nova/tests/api/openstack/compute/contrib/test_admin_actions.py @@ -13,6 +13,7 @@ # under the License. import datetime +import uuid import webob @@ -28,7 +29,7 @@ from nova.openstack.common import jsonutils from nova.scheduler import rpcapi as scheduler_rpcapi from nova import test from nova.tests.api.openstack import fakes -from nova import utils + CONF = config.CONF @@ -88,7 +89,7 @@ class AdminActionsTest(test.TestCase): def setUp(self): super(AdminActionsTest, self).setUp() self.stubs.Set(compute_api.API, 'get', fake_compute_api_get) - self.UUID = utils.gen_uuid() + self.UUID = uuid.uuid4() for _method in self._methods: self.stubs.Set(compute_api.API, _method, fake_compute_api) self.stubs.Set(scheduler_rpcapi.SchedulerAPI, @@ -181,7 +182,7 @@ class CreateBackupTests(test.TestCase): self.stubs.Set(compute_api.API, 'get', fake_compute_api_get) self.backup_stubs = fakes.stub_out_compute_api_backup(self.stubs) self.app = compute.APIRouter(init_only=('servers',)) - self.uuid = utils.gen_uuid() + self.uuid = uuid.uuid4() def _get_request(self, body): url = '/fake/servers/%s/action' % self.uuid @@ -307,7 +308,7 @@ class ResetStateTests(test.TestCase): self.exists = True self.kwargs = None - self.uuid = utils.gen_uuid() + self.uuid = uuid.uuid4() def fake_get(inst, context, instance_id): if self.exists: diff --git a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py index 171b0900ec02..d67682a4fb20 100644 --- a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py +++ b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py @@ -14,6 +14,8 @@ # License for the specific language governing permissions and limitations # under the License. +import uuid + from lxml import etree import webob @@ -29,7 +31,7 @@ from nova.openstack.common import rpc from nova import test from nova.tests.api.openstack import fakes from nova.tests import fake_network -from nova import utils + FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' @@ -88,7 +90,7 @@ def network_api_disassociate(self, context, instance, floating_address): def fake_instance_get(context, instance_id): return { "id": 1, - "uuid": utils.gen_uuid(), + "uuid": uuid.uuid4(), "name": 'fake', "user_id": 'fakeuser', "project_id": '123'} diff --git a/nova/tests/api/openstack/compute/test_consoles.py b/nova/tests/api/openstack/compute/test_consoles.py index 8a701588c606..413015a4d252 100644 --- a/nova/tests/api/openstack/compute/test_consoles.py +++ b/nova/tests/api/openstack/compute/test_consoles.py @@ -17,6 +17,7 @@ # under the License. import datetime +import uuid as uuidutils from lxml import etree import webob @@ -31,7 +32,7 @@ from nova.openstack.common import timeutils from nova import test from nova.tests.api.openstack import fakes from nova.tests import matchers -from nova import utils + FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' @@ -57,7 +58,7 @@ class FakeInstanceDB(object): if id is None: id = self.max_id + 1 if uuid is None: - uuid = str(utils.gen_uuid()) + uuid = str(uuidutils.uuid4()) instance = stub_instance(id, uuid=uuid) self.instances_by_id[id] = instance self.ids_by_uuid[uuid] = id @@ -133,7 +134,7 @@ class ConsolesControllerTest(test.TestCase): self.instance_db.return_server_by_id) self.stubs.Set(db, 'instance_get_by_uuid', self.instance_db.return_server_by_uuid) - self.uuid = str(utils.gen_uuid()) + self.uuid = str(uuidutils.uuid4()) self.url = '/v2/fake/servers/%s/consoles' % self.uuid self.controller = consoles.Controller() diff --git a/nova/tests/api/openstack/compute/test_server_actions.py b/nova/tests/api/openstack/compute/test_server_actions.py index ae2fde791dfc..415313d9aa45 100644 --- a/nova/tests/api/openstack/compute/test_server_actions.py +++ b/nova/tests/api/openstack/compute/test_server_actions.py @@ -14,6 +14,7 @@ # under the License. import base64 +import uuid import mox import webob @@ -32,7 +33,7 @@ from nova import test from nova.tests.api.openstack import fakes from nova.tests.image import fake from nova.tests import matchers -from nova import utils + CONF = config.CONF FAKE_UUID = fakes.FAKE_UUID @@ -177,7 +178,7 @@ class ServerActionsControllerTest(test.TestCase): req = fakes.HTTPRequest.blank(self.url) self.assertRaises(webob.exc.HTTPNotFound, self.controller._action_reboot, - req, str(utils.gen_uuid()), body) + req, str(uuid.uuid4()), body) def test_reboot_raises_conflict_on_invalid_state(self): body = dict(reboot=dict(type="HARD")) diff --git a/nova/tests/api/openstack/compute/test_server_metadata.py b/nova/tests/api/openstack/compute/test_server_metadata.py index 093c1efdac11..82b7df74c32f 100644 --- a/nova/tests/api/openstack/compute/test_server_metadata.py +++ b/nova/tests/api/openstack/compute/test_server_metadata.py @@ -15,6 +15,8 @@ # License for the specific language governing permissions and limitations # under the License. +import uuid + import webob from nova.api.openstack.compute import server_metadata @@ -26,7 +28,7 @@ from nova import flags from nova.openstack.common import jsonutils from nova import test from nova.tests.api.openstack import fakes -from nova import utils + CONF = config.CONF @@ -108,7 +110,7 @@ class ServerMetaDataTest(test.TestCase): fake_change_instance_metadata) self.controller = server_metadata.Controller() - self.uuid = str(utils.gen_uuid()) + self.uuid = str(uuid.uuid4()) self.url = '/v1.1/fake/servers/%s/metadata' % self.uuid def test_index(self): diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index e329a5f7bfbd..06f6e9ba7da8 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -19,6 +19,7 @@ import base64 import datetime import urlparse +import uuid import iso8601 from lxml import etree @@ -49,7 +50,7 @@ from nova.tests.api.openstack import fakes from nova.tests import fake_network from nova.tests.image import fake from nova.tests import matchers -from nova import utils + CONF = config.CONF @@ -238,7 +239,7 @@ class ServersControllerTest(test.TestCase): """Create two servers with the same host and different project_ids and check that the hostId's are unique""" def return_instance_with_host(self, *args): - project_id = str(utils.gen_uuid()) + project_id = str(uuid.uuid4()) return fakes.stub_instance(id=1, uuid=FAKE_UUID, project_id=project_id, host='fake_host') @@ -517,7 +518,7 @@ class ServersControllerTest(test.TestCase): self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get) - server_id = str(utils.gen_uuid()) + server_id = str(uuid.uuid4()) req = fakes.HTTPRequest.blank('/v2/fake/servers/%s/ips' % server_id) self.assertRaises(webob.exc.HTTPNotFound, self.ips_controller.index, req, server_id) @@ -674,7 +675,7 @@ class ServersControllerTest(test.TestCase): self.controller.index, req) def test_get_servers_with_bad_option(self): - server_uuid = str(utils.gen_uuid()) + server_uuid = str(uuid.uuid4()) def fake_get_all(compute_self, context, search_opts=None, sort_key=None, sort_dir='desc', @@ -690,7 +691,7 @@ class ServersControllerTest(test.TestCase): self.assertEqual(servers[0]['id'], server_uuid) def test_get_servers_allows_image(self): - server_uuid = str(utils.gen_uuid()) + server_uuid = str(uuid.uuid4()) def fake_get_all(compute_self, context, search_opts=None, sort_key=None, sort_dir='desc', @@ -773,7 +774,7 @@ class ServersControllerTest(test.TestCase): self.assertTrue('servers' in res) def test_get_servers_allows_flavor(self): - server_uuid = str(utils.gen_uuid()) + server_uuid = str(uuid.uuid4()) def fake_get_all(compute_self, context, search_opts=None, sort_key=None, sort_dir='desc', @@ -793,7 +794,7 @@ class ServersControllerTest(test.TestCase): self.assertEqual(servers[0]['id'], server_uuid) def test_get_servers_allows_status(self): - server_uuid = str(utils.gen_uuid()) + server_uuid = str(uuid.uuid4()) def fake_get_all(compute_self, context, search_opts=None, sort_key=None, sort_dir='desc', @@ -825,7 +826,7 @@ class ServersControllerTest(test.TestCase): self.controller.detail, req) def test_get_servers_deleted_status_as_admin(self): - server_uuid = str(utils.gen_uuid()) + server_uuid = str(uuid.uuid4()) def fake_get_all(compute_self, context, search_opts=None, sort_key=None, sort_dir='desc', @@ -845,7 +846,7 @@ class ServersControllerTest(test.TestCase): self.assertEqual(servers[0]['id'], server_uuid) def test_get_servers_allows_name(self): - server_uuid = str(utils.gen_uuid()) + server_uuid = str(uuid.uuid4()) def fake_get_all(compute_self, context, search_opts=None, sort_key=None, sort_dir='desc', @@ -864,7 +865,7 @@ class ServersControllerTest(test.TestCase): self.assertEqual(servers[0]['id'], server_uuid) def test_get_servers_allows_changes_since(self): - server_uuid = str(utils.gen_uuid()) + server_uuid = str(uuid.uuid4()) def fake_get_all(compute_self, context, search_opts=None, sort_key=None, sort_dir='desc', @@ -896,7 +897,7 @@ class ServersControllerTest(test.TestCase): context is not admin. Make sure the admin and unknown options are stripped before they get to compute_api.get_all() """ - server_uuid = str(utils.gen_uuid()) + server_uuid = str(uuid.uuid4()) def fake_get_all(compute_self, context, search_opts=None, sort_key=None, sort_dir='desc', @@ -925,7 +926,7 @@ class ServersControllerTest(test.TestCase): """Test getting servers by admin-only or unknown options when context is admin. All options should be passed """ - server_uuid = str(utils.gen_uuid()) + server_uuid = str(uuid.uuid4()) def fake_get_all(compute_self, context, search_opts=None, sort_key=None, sort_dir='desc', @@ -954,7 +955,7 @@ class ServersControllerTest(test.TestCase): """Test getting servers by ip with admin_api enabled and admin context """ - server_uuid = str(utils.gen_uuid()) + server_uuid = str(uuid.uuid4()) def fake_get_all(compute_self, context, search_opts=None, sort_key=None, sort_dir='desc', @@ -977,7 +978,7 @@ class ServersControllerTest(test.TestCase): """Test getting servers by ip6 with admin_api enabled and admin context """ - server_uuid = str(utils.gen_uuid()) + server_uuid = str(uuid.uuid4()) def fake_get_all(compute_self, context, search_opts=None, sort_key=None, sort_dir='desc', @@ -1700,7 +1701,7 @@ class ServersControllerCreateTest(test.TestCase): fakes.stub_out_key_pair_funcs(self.stubs) fake.stub_out_image_service(self.stubs) fakes.stub_out_nw_api(self.stubs) - self.stubs.Set(utils, 'gen_uuid', fake_gen_uuid) + self.stubs.Set(uuid, 'uuid4', fake_gen_uuid) self.stubs.Set(db, 'instance_add_security_group', return_security_group) self.stubs.Set(db, 'project_get_networks', diff --git a/nova/tests/api/openstack/compute/test_versions.py b/nova/tests/api/openstack/compute/test_versions.py index d59270bd6fcc..2c05d6d8ab85 100644 --- a/nova/tests/api/openstack/compute/test_versions.py +++ b/nova/tests/api/openstack/compute/test_versions.py @@ -15,6 +15,8 @@ # License for the specific language governing permissions and limitations # under the License. +import uuid as uuidutils + import feedparser from lxml import etree import webob @@ -27,7 +29,6 @@ from nova import test from nova.tests.api.openstack import common from nova.tests.api.openstack import fakes from nova.tests import matchers -from nova import utils NS = { @@ -385,7 +386,7 @@ class VersionsTest(test.TestCase): self.assertEqual(res.content_type, "application/json") def test_multi_choice_server(self): - uuid = str(utils.gen_uuid()) + uuid = str(uuidutils.uuid4()) req = webob.Request.blank('/servers/' + uuid) req.accept = "application/json" res = req.get_response(fakes.wsgi_app()) diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py index 4f39e569ed7c..89a78deaa652 100644 --- a/nova/tests/api/openstack/fakes.py +++ b/nova/tests/api/openstack/fakes.py @@ -16,6 +16,7 @@ # under the License. import datetime +import uuid import glanceclient.v1.images import routes @@ -44,7 +45,6 @@ from nova.openstack.common import timeutils from nova import quota from nova.tests import fake_network from nova.tests.glance import stubs as glance_stubs -from nova import utils from nova import wsgi @@ -373,7 +373,7 @@ def create_info_cache(nw_cache): 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/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 3b2c00b324bf..e84fc917558a 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -23,6 +23,7 @@ import copy import datetime import sys import time +import uuid import mox @@ -2397,7 +2398,7 @@ class ComputeTestCase(BaseTestCase): def test_add_instance_fault(self): exc_info = None - instance_uuid = str(utils.gen_uuid()) + instance_uuid = str(uuid.uuid4()) def fake_db_fault_create(ctxt, values): self.assertTrue(values['details'].startswith('test')) @@ -2425,7 +2426,7 @@ class ComputeTestCase(BaseTestCase): def test_add_instance_fault_with_remote_error(self): exc_info = None - instance_uuid = str(utils.gen_uuid()) + instance_uuid = str(uuid.uuid4()) def fake_db_fault_create(ctxt, values): self.assertTrue(values['details'].startswith('Remote error')) @@ -2454,7 +2455,7 @@ class ComputeTestCase(BaseTestCase): def test_add_instance_fault_user_error(self): exc_info = None - instance_uuid = str(utils.gen_uuid()) + instance_uuid = str(uuid.uuid4()) def fake_db_fault_create(ctxt, values): @@ -2480,7 +2481,7 @@ class ComputeTestCase(BaseTestCase): user_exc, exc_info) def test_add_instance_fault_no_exc_info(self): - instance_uuid = str(utils.gen_uuid()) + instance_uuid = str(uuid.uuid4()) def fake_db_fault_create(ctxt, values): expected = { @@ -3036,7 +3037,7 @@ class ComputeAPITestCase(BaseTestCase): db.instance_destroy(self.context, refs[0]['uuid']) def test_default_hostname_generator(self): - fake_uuids = [str(utils.gen_uuid()) for x in xrange(4)] + fake_uuids = [str(uuid.uuid4()) for x in xrange(4)] orig_populate = self.compute_api._populate_instance_for_create diff --git a/nova/tests/fake_volume.py b/nova/tests/fake_volume.py index 54fd85fe54c3..f490b6705e5f 100644 --- a/nova/tests/fake_volume.py +++ b/nova/tests/fake_volume.py @@ -14,10 +14,12 @@ """Implementation of a fake volume API""" +import uuid + from nova import exception from nova.openstack.common import log as logging from nova.openstack.common import timeutils -from nova import utils + LOG = logging.getLogger(__name__) @@ -34,7 +36,7 @@ class fake_volume(): if snapshot is not None: snapshot_id = snapshot['id'] if volume_id is None: - volume_id = str(utils.gen_uuid()) + volume_id = str(uuid.uuid4()) self.vol = { 'created_at': timeutils.utcnow(), 'deleted_at': None, @@ -79,7 +81,7 @@ class fake_snapshot(): def __init__(self, volume_id, size, name, desc, id=None): if id is None: - id = str(utils.gen_uuid()) + id = str(uuid.uuid4()) self.snap = { 'created_at': timeutils.utcnow(), 'deleted_at': None, diff --git a/nova/tests/hyperv/db_fakes.py b/nova/tests/hyperv/db_fakes.py index 9f5572fd1879..e240483eaf76 100644 --- a/nova/tests/hyperv/db_fakes.py +++ b/nova/tests/hyperv/db_fakes.py @@ -19,6 +19,7 @@ Stubouts, mocks and fixtures for the test suite """ import time +import uuid from nova.compute import task_states from nova.compute import vm_states @@ -29,7 +30,7 @@ from nova import utils def get_fake_instance_data(name, project_id, user_id): return {'name': name, 'id': 1, - 'uuid': utils.gen_uuid(), + 'uuid': uuid.uuid4(), 'project_id': project_id, 'user_id': user_id, 'image_ref': "1", @@ -124,7 +125,7 @@ def stub_out_db_instance_api(stubs): base_options = { 'name': values['name'], 'id': values['id'], - 'uuid': utils.gen_uuid(), + 'uuid': uuid.uuid4(), 'reservation_id': utils.generate_uid('r'), 'image_ref': values['image_ref'], 'kernel_id': values['kernel_id'], diff --git a/nova/tests/image/fake.py b/nova/tests/image/fake.py index 1c61bee359e9..b2953526f1f0 100644 --- a/nova/tests/image/fake.py +++ b/nova/tests/image/fake.py @@ -20,13 +20,14 @@ import copy import datetime +import uuid from nova import config from nova import exception from nova import flags import nova.image.glance from nova.openstack.common import log as logging -from nova import utils + CONF = config.CONF LOG = logging.getLogger(__name__) @@ -176,7 +177,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/nova/tests/integrated/integrated_helpers.py b/nova/tests/integrated/integrated_helpers.py index b1b2c076ea69..825881137daa 100644 --- a/nova/tests/integrated/integrated_helpers.py +++ b/nova/tests/integrated/integrated_helpers.py @@ -21,6 +21,7 @@ Provides common functionality for integrated unit tests import random import string +import uuid import nova.image.glance from nova.openstack.common.log import logging @@ -29,7 +30,6 @@ from nova import test # For the flags from nova.tests import fake_crypto import nova.tests.image.fake from nova.tests.integrated.api import client -from nova import utils LOG = logging.getLogger(__name__) @@ -116,7 +116,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/nova/tests/network/test_quantumv2.py b/nova/tests/network/test_quantumv2.py index e69058cc0b00..7c19698fba31 100644 --- a/nova/tests/network/test_quantumv2.py +++ b/nova/tests/network/test_quantumv2.py @@ -15,6 +15,8 @@ # # vim: tabstop=4 shiftwidth=4 softtabstop=4 +import uuid + import mox from nova import config @@ -24,9 +26,9 @@ from nova.network import model from nova.network import quantumv2 from nova.network.quantumv2 import api as quantumapi from nova import test -from nova import utils from quantumclient.v2_0 import client + CONF = config.CONF #NOTE: Quantum client raises Exception which is discouraged by HACKING. @@ -133,7 +135,7 @@ class TestQuantumv2(test.TestCase): 'auth_token', 'bff4a5a6b9eb4ea2a6efec6eefb77936') self.instance = {'project_id': '9d049e4b60b64716978ab415e6fbd5c0', - 'uuid': str(utils.gen_uuid()), + 'uuid': str(uuid.uuid4()), 'display_name': 'test_instance', 'security_groups': []} self.nets1 = [{'id': 'my_netid1', diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index 00188048314a..39d3e1b1fb41 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -20,6 +20,7 @@ """Unit tests for the DB API""" import datetime +import uuid as uuidutils from nova import config from nova import context @@ -29,7 +30,7 @@ from nova import flags from nova.openstack.common import timeutils from nova import test from nova.tests import matchers -from nova import utils + CONF = config.CONF CONF.import_opt('reserved_host_memory_mb', 'nova.compute.resource_tracker') @@ -145,7 +146,7 @@ class DbApiTestCase(test.TestCase): self.assertRaises(exception.MarkerNotFound, db.instance_get_all_by_filters, self.context, {'display_name': '%test%'}, - marker=str(utils.gen_uuid())) + marker=str(uuidutils.uuid4())) def test_migration_get_unconfirmed_by_dest_compute(self): ctxt = context.get_admin_context() @@ -286,7 +287,7 @@ class DbApiTestCase(test.TestCase): def test_instance_fault_create(self): """Ensure we can create an instance fault""" ctxt = context.get_admin_context() - uuid = str(utils.gen_uuid()) + uuid = str(uuidutils.uuid4()) # Create a fault fault_values = { diff --git a/nova/tests/test_utils.py b/nova/tests/test_utils.py index 0fc14c1c71e4..68e6a6a76ca9 100644 --- a/nova/tests/test_utils.py +++ b/nova/tests/test_utils.py @@ -31,7 +31,6 @@ from nova import config from nova import exception from nova import flags from nova.openstack.common import timeutils -from nova.openstack.common import uuidutils from nova import test from nova import utils @@ -509,31 +508,6 @@ class GenericUtilsTestCase(test.TestCase): self.assertEquals(h1, h2) -class IsUUIDLikeTestCase(test.TestCase): - def assertUUIDLike(self, val, expected): - result = uuidutils.is_uuid_like(val) - self.assertEqual(result, expected) - - def test_good_uuid(self): - val = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' - self.assertUUIDLike(val, True) - - def test_integer_passed(self): - val = 1 - self.assertUUIDLike(val, False) - - def test_non_uuid_string_passed(self): - val = 'foo-fooo' - self.assertUUIDLike(val, False) - - def test_non_uuid_string_passed2(self): - val = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' - self.assertUUIDLike(val, False) - - def test_gen_valid_uuid(self): - self.assertUUIDLike(str(utils.gen_uuid()), True) - - class MonkeyPatchTestCase(test.TestCase): """Unit test for utils.monkey_patch().""" def setUp(self): diff --git a/nova/tests/vmwareapi/db_fakes.py b/nova/tests/vmwareapi/db_fakes.py index a469c47066bf..dd19f49290e8 100644 --- a/nova/tests/vmwareapi/db_fakes.py +++ b/nova/tests/vmwareapi/db_fakes.py @@ -20,6 +20,7 @@ Stubouts, mocks and fixtures for the test suite """ import time +import uuid from nova.compute import task_states from nova.compute import vm_states @@ -62,7 +63,7 @@ def stub_out_db_instance_api(stubs): base_options = { 'name': values['name'], 'id': values['id'], - 'uuid': utils.gen_uuid(), + 'uuid': uuid.uuid4(), 'reservation_id': utils.generate_uid('r'), 'image_ref': values['image_ref'], 'kernel_id': values['kernel_id'], diff --git a/nova/utils.py b/nova/utils.py index 5f78b93da3bd..7ee58bdd8651 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -37,7 +37,6 @@ import struct import sys import tempfile import time -import uuid import weakref from xml.sax import saxutils @@ -776,10 +775,6 @@ def parse_server_string(server_str): return ('', '') -def gen_uuid(): - return uuid.uuid4() - - def bool_from_str(val): """Convert a string representation of a bool into a bool value"""