Replaces uuid.uuid4 with uuidutils.generate_uuid()

Openstack common has a wrapper for generating uuids.
We should only use that function when generating uuids for consistency.

Change-Id: Ie68850e529eee51c66e8d29a9025e1390576bc1a
Closes-bug: #1082248
This commit is contained in:
melissaml 2016-11-12 18:21:43 +08:00 committed by Tom Barron
parent dbab8415ea
commit 34f5274931
11 changed files with 64 additions and 66 deletions

View File

@ -22,7 +22,6 @@ import copy
import datetime
from functools import wraps
import sys
import uuid
import warnings
# NOTE(uglide): Required to override default oslo_db Query class
@ -3532,12 +3531,12 @@ def consistency_group_get_all_by_share_server(context, share_server_id):
def consistency_group_create(context, values):
consistency_group = models.ConsistencyGroup()
if not values.get('id'):
values['id'] = six.text_type(uuid.uuid4())
values['id'] = six.text_type(uuidutils.generate_uuid())
mappings = []
for item in values.get('share_types') or []:
mapping = models.ConsistencyGroupShareTypeMapping()
mapping['id'] = six.text_type(uuid.uuid4())
mapping['id'] = six.text_type(uuidutils.generate_uuid())
mapping['share_type_id'] = item
mapping['consistency_group_id'] = values['id']
mappings.append(mapping)
@ -3684,7 +3683,7 @@ def cgsnapshot_get_all_by_project(context, project_id, detailed=True):
def cgsnapshot_create(context, values):
cgsnapshot = models.CGSnapshot()
if not values.get('id'):
values['id'] = six.text_type(uuid.uuid4())
values['id'] = six.text_type(uuidutils.generate_uuid())
session = get_session()
with session.begin():
@ -3742,7 +3741,7 @@ def cgsnapshot_member_get(context, member_id, session=None):
def cgsnapshot_member_create(context, values):
member = models.CGSnapshotMember()
if not values.get('id'):
values['id'] = six.text_type(uuid.uuid4())
values['id'] = six.text_type(uuidutils.generate_uuid())
session = get_session()
with session.begin():

View File

@ -23,7 +23,6 @@ inline callbacks.
import os
import shutil
import uuid
import fixtures
import mock
@ -32,6 +31,7 @@ from oslo_config import cfg
from oslo_config import fixture as config_fixture
import oslo_i18n
from oslo_messaging import conffixture as messaging_conffixture
from oslo_utils import uuidutils
import oslotest.base as base_test
from manila.db import migration
@ -176,7 +176,7 @@ class TestCase(base_test.BaseTestCase):
CONF.set_override(k, v, enforce_type=True)
def start_service(self, name, host=None, **kwargs):
host = host and host or uuid.uuid4().hex
host = host and host or uuidutils.generate_uuid()
kwargs.setdefault('host', host)
kwargs.setdefault('binary', 'manila-%s' % name)
svc = service.Service.create(**kwargs)

View File

@ -13,9 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import uuid
from oslo_utils import timeutils
from oslo_utils import uuidutils
import routes
import webob
import webob.dec
@ -166,7 +165,7 @@ class FakeRateLimiter(object):
def get_fake_uuid(token=0):
if token not in FAKE_UUIDS:
FAKE_UUIDS[token] = str(uuid.uuid4())
FAKE_UUIDS[token] = uuidutils.generate_uuid()
return FAKE_UUIDS[token]

View File

@ -15,12 +15,12 @@
import copy
import datetime
import uuid
import ddt
import mock
from oslo_config import cfg
from oslo_serialization import jsonutils
from oslo_utils import uuidutils
import six
import webob
@ -125,7 +125,7 @@ class CGSnapshotApiTest(test.TestCase):
def test_create(self):
fake_snap, expected_snap = self._get_fake_cgsnapshot()
fake_id = six.text_type(uuid.uuid4())
fake_id = six.text_type(uuidutils.generate_uuid())
self.mock_object(self.controller.cg_api, 'create_cgsnapshot',
mock.Mock(return_value=fake_snap))
@ -140,12 +140,12 @@ class CGSnapshotApiTest(test.TestCase):
self.assertEqual(expected_snap, res_dict['cgsnapshot'])
def test_create_cg_does_not_exist(self):
fake_id = six.text_type(uuid.uuid4())
fake_id = six.text_type(uuidutils.generate_uuid())
self.mock_object(self.controller.cg_api, 'create_cgsnapshot',
mock.Mock(
side_effect=exception.ConsistencyGroupNotFound(
consistency_group_id=six.text_type(
uuid.uuid4())
uuidutils.generate_uuid())
)))
body = {"cgsnapshot": {"consistency_group_id": fake_id}}
@ -168,7 +168,7 @@ class CGSnapshotApiTest(test.TestCase):
self.context, self.resource_name, 'create')
def test_create_invalid_cg(self):
fake_id = six.text_type(uuid.uuid4())
fake_id = six.text_type(uuidutils.generate_uuid())
self.mock_object(self.controller.cg_api, 'create_cgsnapshot',
mock.Mock(
side_effect=exception.InvalidConsistencyGroup(
@ -184,7 +184,7 @@ class CGSnapshotApiTest(test.TestCase):
def test_create_with_name(self):
fake_name = 'fake_name'
fake_snap, expected_snap = self._get_fake_cgsnapshot(name=fake_name)
fake_id = six.text_type(uuid.uuid4())
fake_id = six.text_type(uuidutils.generate_uuid())
self.mock_object(self.controller.cg_api, 'create_cgsnapshot',
mock.Mock(return_value=fake_snap))
@ -202,7 +202,7 @@ class CGSnapshotApiTest(test.TestCase):
fake_description = 'fake_description'
fake_snap, expected_snap = self._get_fake_cgsnapshot(
description=fake_description)
fake_id = six.text_type(uuid.uuid4())
fake_id = six.text_type(uuidutils.generate_uuid())
self.mock_object(self.controller.cg_api, 'create_cgsnapshot',
mock.Mock(return_value=fake_snap))
@ -220,7 +220,7 @@ class CGSnapshotApiTest(test.TestCase):
def test_create_with_name_and_description(self):
fake_name = 'fake_name'
fake_description = 'fake_description'
fake_id = six.text_type(uuid.uuid4())
fake_id = six.text_type(uuidutils.generate_uuid())
fake_snap, expected_snap = self._get_fake_cgsnapshot(
description=fake_description, name=fake_name)
self.mock_object(self.controller.cg_api, 'create_cgsnapshot',
@ -241,7 +241,7 @@ class CGSnapshotApiTest(test.TestCase):
def test_update_with_name_and_description(self):
fake_name = 'fake_name'
fake_description = 'fake_description'
fake_id = six.text_type(uuid.uuid4())
fake_id = six.text_type(uuidutils.generate_uuid())
fake_snap, expected_snap = self._get_fake_cgsnapshot(
description=fake_description, name=fake_name)
self.mock_object(self.controller.cg_api, 'get_cgsnapshot',

View File

@ -15,12 +15,12 @@
import copy
import datetime
import uuid
import ddt
import mock
from oslo_config import cfg
from oslo_serialization import jsonutils
from oslo_utils import uuidutils
import six
import webob
@ -49,7 +49,7 @@ class CGApiTest(test.TestCase):
super(self.__class__, self).setUp()
self.controller = cgs.CGController()
self.resource_name = self.controller.resource_name
self.fake_share_type = {'id': six.text_type(uuid.uuid4())}
self.fake_share_type = {'id': six.text_type(uuidutils.generate_uuid())}
self.api_version = '2.4'
self.request = fakes.HTTPRequest.blank('/consistency-groups',
version=self.api_version,
@ -89,8 +89,8 @@ class CGApiTest(test.TestCase):
'description': None,
'host': None,
'source_cgsnapshot_id': None,
'share_network_id': uuid.uuid4(),
'share_server_id': uuid.uuid4(),
'share_network_id': uuidutils.generate_uuid(),
'share_server_id': uuidutils.generate_uuid(),
'share_types': [],
'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
}
@ -134,7 +134,7 @@ class CGApiTest(test.TestCase):
self.context, self.resource_name, 'create')
def test_cg_create_invalid_cgsnapshot_state(self):
fake_snap_id = six.text_type(uuid.uuid4())
fake_snap_id = six.text_type(uuidutils.generate_uuid())
self.mock_object(self.controller.cg_api, 'create',
mock.Mock(side_effect=exception.InvalidCGSnapshot(
reason='bad status'
@ -214,8 +214,8 @@ class CGApiTest(test.TestCase):
self.context, self.resource_name, 'create')
def test_cg_create_with_source_cgsnapshot_id_and_share_network(self):
fake_snap_id = six.text_type(uuid.uuid4())
fake_net_id = six.text_type(uuid.uuid4())
fake_snap_id = six.text_type(uuidutils.generate_uuid())
fake_net_id = six.text_type(uuidutils.generate_uuid())
self.mock_object(share_types, 'get_default_share_type',
mock.Mock(return_value=self.fake_share_type))
mock_api_call = self.mock_object(self.controller.cg_api, 'create')
@ -235,7 +235,7 @@ class CGApiTest(test.TestCase):
self.context, self.resource_name, 'create')
def test_cg_create_with_source_cgsnapshot_id(self):
fake_snap_id = six.text_type(uuid.uuid4())
fake_snap_id = six.text_type(uuidutils.generate_uuid())
fake_cg, expected_cg = self._get_fake_cg(
source_cgsnapshot_id=fake_snap_id)
@ -256,7 +256,7 @@ class CGApiTest(test.TestCase):
self.context, self.resource_name, 'create')
def test_cg_create_with_share_network_id(self):
fake_net_id = six.text_type(uuid.uuid4())
fake_net_id = six.text_type(uuidutils.generate_uuid())
fake_cg, expected_cg = self._get_fake_cg(
share_network_id=fake_net_id)
@ -278,7 +278,7 @@ class CGApiTest(test.TestCase):
self.context, self.resource_name, 'create')
def test_cg_create_no_default_share_type_with_cgsnapshot(self):
fake_snap_id = six.text_type(uuid.uuid4())
fake_snap_id = six.text_type(uuidutils.generate_uuid())
fake_cg, expected_cg = self._get_fake_cg()
self.mock_object(share_types, 'get_default_share_type',
mock.Mock(return_value=None))
@ -334,7 +334,7 @@ class CGApiTest(test.TestCase):
self.context, self.resource_name, 'create')
def test_cg_create_source_cgsnapshot_not_in_available(self):
fake_snap_id = six.text_type(uuid.uuid4())
fake_snap_id = six.text_type(uuidutils.generate_uuid())
body = {"consistency_group": {"source_cgsnapshot_id": fake_snap_id}}
self.mock_object(self.controller.cg_api, 'create', mock.Mock(
side_effect=exception.InvalidCGSnapshot(reason='blah')))
@ -345,7 +345,7 @@ class CGApiTest(test.TestCase):
self.context, self.resource_name, 'create')
def test_cg_create_source_cgsnapshot_does_not_exist(self):
fake_snap_id = six.text_type(uuid.uuid4())
fake_snap_id = six.text_type(uuidutils.generate_uuid())
body = {"consistency_group": {"source_cgsnapshot_id": fake_snap_id}}
self.mock_object(self.controller.cg_api, 'create', mock.Mock(
side_effect=exception.CGSnapshotNotFound(

View File

@ -13,9 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import uuid
from oslo_config import cfg
from oslo_utils import uuidutils
CONF = cfg.CONF
@ -124,11 +123,11 @@ class API(object):
def get_all_admin_project_networks(self):
net1 = self.network.copy()
net1['tenant_id'] = self.admin_project_id
net1['id'] = str(uuid.uuid4())
net1['id'] = uuidutils.generate_uuid()
net2 = self.network.copy()
net2['tenant_id'] = self.admin_project_id
net2['id'] = str(uuid.uuid4())
net2['id'] = uuidutils.generate_uuid()
return [net1, net2]
def create_port(self, tenant_id, network_id, subnet_id=None,
@ -154,7 +153,7 @@ class API(object):
for i in range(2):
ports.append(self.port.copy())
for port in ports:
port['id'] = str(uuid.uuid4())
port['id'] = uuidutils.generate_uuid()
for key, val in search_opts.items():
port[key] = val
if 'id' in search_opts:
@ -195,8 +194,8 @@ class API(object):
"""Get all networks for client."""
net1 = self.network.copy()
net2 = self.network.copy()
net1['id'] = str(uuid.uuid4())
net2['id'] = str(uuid.uuid4())
net1['id'] = uuidutils.generate_uuid()
net2['id'] = uuidutils.generate_uuid()
return [net1, net2]
def get_network(self, network_uuid):

View File

@ -14,12 +14,12 @@
# License for the specific language governing permissions and limitations
# under the License.
import datetime
import uuid
from manila.api.openstack import api_version_request as api_version
from manila.common import constants
from manila.db.sqlalchemy import models
from manila.tests.db import fakes as db_fakes
from oslo_utils import uuidutils
def fake_share(**kwargs):
@ -230,7 +230,7 @@ def fake_access(**kwargs):
def fake_replica(id=None, as_primitive=True, for_manager=False, **kwargs):
replica = {
'id': id or str(uuid.uuid4()),
'id': id or uuidutils.generate_uuid(),
'share_id': 'f0e4bb5e-65f0-11e5-9d70-feff819cdc9f',
'deleted': False,
'host': 'openstack@BackendZ#PoolA',

View File

@ -19,7 +19,6 @@ Provides common functionality for integrated unit tests
import random
import string
import uuid
from oslo_log import log
@ -28,6 +27,7 @@ from manila import test # For the flags
from manila.tests.integrated.api import client
from oslo_config import cfg
from oslo_utils import uuidutils
CONF = cfg.CONF
LOG = log.getLogger(__name__)
@ -103,7 +103,7 @@ class _IntegratedTestBase(test.TestCase):
return generate_new_element(server_names, 'server')
def get_invalid_image(self):
return str(uuid.uuid4())
return uuidutils.generate_uuid()
def _build_minimal_create_server_request(self):
server = {}

View File

@ -21,7 +21,6 @@ import json
import math
import socket
import time
import uuid
import ddt
import mock
@ -29,6 +28,7 @@ from oslo_log import log
from oslo_service import loopingcall
from oslo_utils import timeutils
from oslo_utils import units
from oslo_utils import uuidutils
from manila.common import constants
from manila import exception
@ -3043,10 +3043,10 @@ class NetAppFileStorageLibraryTestCase(test.TestCase):
fake_snapshot = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot['share_id'] = self.fake_replica['id']
fake_snapshot_2 = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot_2['id'] = str(uuid.uuid4())
fake_snapshot_2['id'] = uuidutils.generate_uuid()
fake_snapshot_2['share_id'] = self.fake_replica_2['id']
fake_snapshot_3 = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot_3['id'] = str(uuid.uuid4())
fake_snapshot_3['id'] = uuidutils.generate_uuid()
fake_snapshot_3['share_id'] = fake_replica_3['id']
snapshot_list = [fake_snapshot, fake_snapshot_2, fake_snapshot_3]
@ -3091,10 +3091,10 @@ class NetAppFileStorageLibraryTestCase(test.TestCase):
fake_snapshot = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot['share_id'] = self.fake_replica['id']
fake_snapshot_2 = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot_2['id'] = str(uuid.uuid4())
fake_snapshot_2['id'] = uuidutils.generate_uuid()
fake_snapshot_2['share_id'] = self.fake_replica_2['id']
fake_snapshot_3 = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot_3['id'] = str(uuid.uuid4())
fake_snapshot_3['id'] = uuidutils.generate_uuid()
fake_snapshot_3['share_id'] = fake_replica_3['id']
snapshot_list = [fake_snapshot, fake_snapshot_2, fake_snapshot_3]
@ -3141,10 +3141,10 @@ class NetAppFileStorageLibraryTestCase(test.TestCase):
fake_snapshot = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot['share_id'] = self.fake_replica['id']
fake_snapshot_2 = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot_2['id'] = str(uuid.uuid4())
fake_snapshot_2['id'] = uuidutils.generate_uuid()
fake_snapshot_2['share_id'] = self.fake_replica_2['id']
fake_snapshot_3 = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot_3['id'] = str(uuid.uuid4())
fake_snapshot_3['id'] = uuidutils.generate_uuid()
fake_snapshot_3['share_id'] = fake_replica_3['id']
snapshot_list = [fake_snapshot, fake_snapshot_2, fake_snapshot_3]
@ -3192,10 +3192,10 @@ class NetAppFileStorageLibraryTestCase(test.TestCase):
fake_snapshot = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot['share_id'] = self.fake_replica['id']
fake_snapshot_2 = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot_2['id'] = str(uuid.uuid4())
fake_snapshot_2['id'] = uuidutils.generate_uuid()
fake_snapshot_2['share_id'] = self.fake_replica_2['id']
fake_snapshot_3 = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot_3['id'] = str(uuid.uuid4())
fake_snapshot_3['id'] = uuidutils.generate_uuid()
fake_snapshot_3['share_id'] = fake_replica_3['id']
snapshot_list = [fake_snapshot, fake_snapshot_2, fake_snapshot_3]
@ -3222,11 +3222,11 @@ class NetAppFileStorageLibraryTestCase(test.TestCase):
fake_snapshot['id'])
fake_snapshot['provider_location'] = snapshot_name
fake_snapshot_2 = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot_2['id'] = str(uuid.uuid4())
fake_snapshot_2['id'] = uuidutils.generate_uuid()
fake_snapshot_2['share_id'] = self.fake_replica_2['id']
fake_snapshot_2['provider_location'] = snapshot_name
fake_snapshot_3 = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot_3['id'] = str(uuid.uuid4())
fake_snapshot_3['id'] = uuidutils.generate_uuid()
fake_snapshot_3['share_id'] = fake_replica_3['id']
fake_snapshot_3['provider_location'] = snapshot_name
@ -3265,11 +3265,11 @@ class NetAppFileStorageLibraryTestCase(test.TestCase):
fake_snapshot['id'])
fake_snapshot['provider_location'] = snapshot_name
fake_snapshot_2 = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot_2['id'] = str(uuid.uuid4())
fake_snapshot_2['id'] = uuidutils.generate_uuid()
fake_snapshot_2['share_id'] = self.fake_replica_2['id']
fake_snapshot_2['provider_location'] = snapshot_name
fake_snapshot_3 = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot_3['id'] = str(uuid.uuid4())
fake_snapshot_3['id'] = uuidutils.generate_uuid()
fake_snapshot_3['share_id'] = fake_replica_3['id']
fake_snapshot_3['provider_location'] = snapshot_name
@ -3312,11 +3312,11 @@ class NetAppFileStorageLibraryTestCase(test.TestCase):
fake_snapshot['busy'] = False
fake_snapshot_2 = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot_2['id'] = str(uuid.uuid4())
fake_snapshot_2['id'] = uuidutils.generate_uuid()
fake_snapshot_2['share_id'] = self.fake_replica_2['id']
fake_snapshot_2['provider_location'] = snapshot_name
fake_snapshot_3 = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot_3['id'] = str(uuid.uuid4())
fake_snapshot_3['id'] = uuidutils.generate_uuid()
fake_snapshot_3['share_id'] = fake_replica_3['id']
fake_snapshot_3['provider_location'] = snapshot_name
@ -3358,11 +3358,11 @@ class NetAppFileStorageLibraryTestCase(test.TestCase):
fake_snapshot['busy'] = False
fake_snapshot_2 = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot_2['id'] = str(uuid.uuid4())
fake_snapshot_2['id'] = uuidutils.generate_uuid()
fake_snapshot_2['share_id'] = self.fake_replica_2['id']
fake_snapshot_2['provider_location'] = snapshot_name
fake_snapshot_3 = copy.deepcopy(fake.SNAPSHOT)
fake_snapshot_3['id'] = str(uuid.uuid4())
fake_snapshot_3['id'] = uuidutils.generate_uuid()
fake_snapshot_3['share_id'] = fake_replica_3['id']
fake_snapshot_3['provider_location'] = snapshot_name

View File

@ -16,12 +16,12 @@
import copy
import datetime
import uuid
import ddt
import mock
from oslo_config import cfg
from oslo_utils import timeutils
from oslo_utils import uuidutils
from manila.common import constants
from manila import context
@ -1204,7 +1204,8 @@ class ShareAPITestCase(test.TestCase):
@ddt.data(constants.STATUS_MANAGING, constants.STATUS_ERROR_DELETING,
constants.STATUS_CREATING, constants.STATUS_AVAILABLE)
def test_delete_snapshot_force_delete(self, status):
share = fakes.fake_share(id=uuid.uuid4(), has_replicas=False)
share = fakes.fake_share(id=uuidutils.generate_uuid(),
has_replicas=False)
snapshot = fakes.fake_snapshot(aggregate_status=status, share=share)
snapshot_instance = fakes.fake_snapshot_instance(
base_snapshot=snapshot)
@ -1872,7 +1873,7 @@ class ShareAPITestCase(test.TestCase):
def test_share_metadata_get(self):
metadata = {'a': 'b', 'c': 'd'}
share_id = str(uuid.uuid4())
share_id = uuidutils.generate_uuid()
db_api.share_create(self.context,
{'id': share_id, 'metadata': metadata})
self.assertEqual(metadata,
@ -1882,7 +1883,7 @@ class ShareAPITestCase(test.TestCase):
metadata1 = {'a': '1', 'c': '2'}
metadata2 = {'a': '3', 'd': '5'}
should_be = {'a': '3', 'c': '2', 'd': '5'}
share_id = str(uuid.uuid4())
share_id = uuidutils.generate_uuid()
db_api.share_create(self.context,
{'id': share_id, 'metadata': metadata1})
db_api.share_metadata_update(self.context, share_id, metadata2, False)
@ -1893,7 +1894,7 @@ class ShareAPITestCase(test.TestCase):
metadata1 = {'a': '1', 'c': '2'}
metadata2 = {'a': '3', 'd': '4'}
should_be = metadata2
share_id = str(uuid.uuid4())
share_id = uuidutils.generate_uuid()
db_api.share_create(self.context,
{'id': share_id, 'metadata': metadata1})
db_api.share_metadata_update(self.context, share_id, metadata2, True)

View File

@ -18,12 +18,12 @@ import datetime
import errno
import socket
import time
import uuid
import ddt
import mock
from oslo_config import cfg
from oslo_utils import timeutils
from oslo_utils import uuidutils
import paramiko
from webob import exc
@ -202,7 +202,7 @@ class MonkeyPatchTestCase(test.TestCase):
class FakeSSHClient(object):
def __init__(self):
self.id = uuid.uuid4()
self.id = uuidutils.generate_uuid()
self.transport = FakeTransport()
def set_missing_host_key_policy(self, policy):