Merge "Replace uuid4() with uuidsentinel"
This commit is contained in:
commit
55db69f2c0
|
@ -13,11 +13,12 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import uuid
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from nova.objects import keypair as keypair_obj
|
||||
from nova.tests.functional.api_sample_tests import api_sample_base
|
||||
from nova.tests.unit import fake_crypto
|
||||
from nova.tests import uuidsentinel as uuids
|
||||
|
||||
|
||||
class KeyPairsSampleJsonTest(api_sample_base.ApiSampleTestBaseV21):
|
||||
|
@ -43,7 +44,7 @@ class KeyPairsSampleJsonTest(api_sample_base.ApiSampleTestBaseV21):
|
|||
"""Get api sample of key pairs post request."""
|
||||
key_name = kwargs.pop('kp_name', None)
|
||||
if not key_name:
|
||||
key_name = 'keypair-' + str(uuid.uuid4())
|
||||
key_name = 'keypair-' + uuids.fake
|
||||
|
||||
subs = dict(keypair_name=key_name, **kwargs)
|
||||
response = self._do_post('os-keypairs', 'keypairs-post-req', subs)
|
||||
|
@ -62,7 +63,7 @@ class KeyPairsSampleJsonTest(api_sample_base.ApiSampleTestBaseV21):
|
|||
|
||||
def _check_keypairs_import_key_post(self, public_key, **kwargs):
|
||||
# Get api sample of key pairs post to import user's key.
|
||||
key_name = 'keypair-' + str(uuid.uuid4())
|
||||
key_name = 'keypair-' + uuids.fake
|
||||
subs = {
|
||||
'keypair_name': key_name,
|
||||
}
|
||||
|
@ -116,7 +117,7 @@ class KeyPairsV22SampleJsonTest(KeyPairsSampleJsonTest):
|
|||
keypair_type=keypair_obj.KEYPAIR_TYPE_X509)
|
||||
|
||||
def test_keypairs_post_invalid(self):
|
||||
key_name = 'keypair-' + str(uuid.uuid4())
|
||||
key_name = 'keypair-' + uuids.fake
|
||||
subs = dict(keypair_name=key_name, keypair_type='fakey_type')
|
||||
response = self._do_post('os-keypairs', 'keypairs-post-req', subs)
|
||||
|
||||
|
@ -136,7 +137,7 @@ class KeyPairsV22SampleJsonTest(KeyPairsSampleJsonTest):
|
|||
public_key, keypair_type=keypair_obj.KEYPAIR_TYPE_X509)
|
||||
|
||||
def _check_keypairs_import_key_post_invalid(self, keypair_type):
|
||||
key_name = 'keypair-' + str(uuid.uuid4())
|
||||
key_name = 'keypair-' + uuids.fake
|
||||
subs = {
|
||||
'keypair_name': key_name,
|
||||
'keypair_type': keypair_type,
|
||||
|
@ -200,7 +201,7 @@ class KeyPairsV210SampleJsonTest(KeyPairsSampleJsonTest):
|
|||
# Get api sample of key pairs list request.
|
||||
|
||||
# create common kp_name for two users
|
||||
kp_name = 'keypair-' + str(uuid.uuid4())
|
||||
kp_name = 'keypair-' + uuids.fake
|
||||
|
||||
keypair_user1 = self._check_keypairs_post(
|
||||
keypair_type=keypair_obj.KEYPAIR_TYPE_SSH,
|
||||
|
@ -229,7 +230,7 @@ class KeyPairsV210SampleJsonTestNotAdmin(KeyPairsV210SampleJsonTest):
|
|||
user_id="fake")
|
||||
|
||||
def test_keypairs_post_for_other_user(self):
|
||||
key_name = 'keypair-' + str(uuid.uuid4())
|
||||
key_name = 'keypair-' + uuids.fake
|
||||
subs = dict(keypair_name=key_name,
|
||||
keypair_type=keypair_obj.KEYPAIR_TYPE_SSH,
|
||||
user_id='fake1')
|
||||
|
@ -269,7 +270,7 @@ class KeyPairsV235SampleJsonTest(api_sample_base.ApiSampleTestBaseV21):
|
|||
"""Get api sample of key pairs post request."""
|
||||
key_name = kwargs.pop('kp_name', None)
|
||||
if not key_name:
|
||||
key_name = 'keypair-' + str(uuid.uuid4())
|
||||
key_name = 'keypair-' + uuidutils.generate_uuid()
|
||||
|
||||
subs = dict(keypair_name=key_name, **kwargs)
|
||||
response = self._do_post('os-keypairs', 'keypairs-post-req', subs)
|
||||
|
@ -293,7 +294,7 @@ class KeyPairsV235SampleJsonTest(api_sample_base.ApiSampleTestBaseV21):
|
|||
# Get api sample of key pairs list request.
|
||||
|
||||
# create common kp_names for two users
|
||||
kp_names = ['keypair-' + str(uuid.uuid4()) for i in range(3)]
|
||||
kp_names = ['keypair-' + uuidutils.generate_uuid() for i in range(3)]
|
||||
|
||||
# sort key_pairs by name before paging
|
||||
keypairs_user1 = sorted([self.test_keypairs_post(
|
||||
|
|
|
@ -20,7 +20,6 @@ Provides common functionality for integrated unit tests
|
|||
import random
|
||||
import string
|
||||
import time
|
||||
import uuid
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
||||
|
@ -30,6 +29,7 @@ from nova import test
|
|||
from nova.tests import fixtures as nova_fixtures
|
||||
from nova.tests.unit import cast_as_call
|
||||
import nova.tests.unit.image.fake
|
||||
from nova.tests import uuidsentinel as uuids
|
||||
|
||||
|
||||
CONF = nova.conf.CONF
|
||||
|
@ -118,7 +118,7 @@ class _IntegratedTestBase(test.TestCase):
|
|||
int(generate_new_element(flavor_ids, '', True)))
|
||||
|
||||
def get_invalid_image(self):
|
||||
return str(uuid.uuid4())
|
||||
return uuids.fake
|
||||
|
||||
def _build_minimal_create_server_request(self):
|
||||
server = {}
|
||||
|
|
|
@ -17,14 +17,11 @@
|
|||
Tests For Cells Messaging module
|
||||
"""
|
||||
|
||||
import uuid
|
||||
|
||||
import mock
|
||||
from mox3 import mox
|
||||
import oslo_messaging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from nova.cells import messaging
|
||||
from nova.cells import rpcapi as cells_rpcapi
|
||||
|
@ -86,7 +83,7 @@ class CellsMessageClassesTestCase(test.NoDBTestCase):
|
|||
neighbor_only=True))
|
||||
|
||||
def test_response_to_json_and_from_json(self):
|
||||
fake_uuid = str(uuid.uuid4())
|
||||
fake_uuid = uuids.fake
|
||||
response = messaging.Response(self.ctxt, 'child-cell!api-cell',
|
||||
objects.Instance(id=1, uuid=fake_uuid),
|
||||
False)
|
||||
|
@ -1068,7 +1065,7 @@ class CellsTargetedMethodsTestCase(test.NoDBTestCase):
|
|||
|
||||
def test_call_compute_api_with_obj(self):
|
||||
instance = objects.Instance()
|
||||
instance.uuid = uuidutils.generate_uuid()
|
||||
instance.uuid = uuids.fake
|
||||
self.mox.StubOutWithMock(instance, 'refresh')
|
||||
# Using 'snapshot' for this test, because it
|
||||
# takes args and kwargs.
|
||||
|
@ -1086,7 +1083,7 @@ class CellsTargetedMethodsTestCase(test.NoDBTestCase):
|
|||
|
||||
def test_call_compute_api_with_obj_no_cache(self):
|
||||
instance = objects.Instance()
|
||||
instance.uuid = uuidutils.generate_uuid()
|
||||
instance.uuid = uuids.fake
|
||||
error = exception.InstanceInfoCacheNotFound(
|
||||
instance_uuid=instance.uuid)
|
||||
with mock.patch.object(instance, 'refresh', side_effect=error):
|
||||
|
@ -1096,7 +1093,7 @@ class CellsTargetedMethodsTestCase(test.NoDBTestCase):
|
|||
|
||||
def test_call_delete_compute_api_with_obj_no_cache(self):
|
||||
instance = objects.Instance()
|
||||
instance.uuid = uuidutils.generate_uuid()
|
||||
instance.uuid = uuids.fake
|
||||
error = exception.InstanceInfoCacheNotFound(
|
||||
instance_uuid=instance.uuid)
|
||||
with test.nested(
|
||||
|
@ -1111,7 +1108,7 @@ class CellsTargetedMethodsTestCase(test.NoDBTestCase):
|
|||
|
||||
def test_call_compute_with_obj_unknown_instance(self):
|
||||
instance = objects.Instance()
|
||||
instance.uuid = uuidutils.generate_uuid()
|
||||
instance.uuid = uuids.fake
|
||||
instance.vm_state = vm_states.ACTIVE
|
||||
instance.task_state = None
|
||||
self.mox.StubOutWithMock(instance, 'refresh')
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
"""Tests for the conductor service."""
|
||||
|
||||
import copy
|
||||
import uuid
|
||||
|
||||
import mock
|
||||
from mox3 import mox
|
||||
|
@ -427,7 +426,7 @@ class _BaseTaskTestCase(object):
|
|||
instance_type.created_at = None
|
||||
instances = [objects.Instance(context=self.context,
|
||||
id=i,
|
||||
uuid=uuid.uuid4(),
|
||||
uuid=uuids.fake,
|
||||
flavor=instance_type) for i in range(2)]
|
||||
instance_type_p = obj_base.obj_to_primitive(instance_type)
|
||||
instance_properties = obj_base.obj_to_primitive(instances[0])
|
||||
|
|
|
@ -13,12 +13,11 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import uuid
|
||||
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from nova import block_device
|
||||
from nova import objects
|
||||
from nova.tests import uuidsentinel as uuids
|
||||
|
||||
|
||||
def fake_bdm_object(context, bdm_dict):
|
||||
|
@ -40,7 +39,7 @@ class FakeDbBlockDeviceDict(block_device.BlockDeviceDict):
|
|||
def __init__(self, bdm_dict=None, anon=False, **kwargs):
|
||||
bdm_dict = bdm_dict or {}
|
||||
db_id = bdm_dict.pop('id', 1)
|
||||
instance_uuid = bdm_dict.pop('instance_uuid', str(uuid.uuid4()))
|
||||
instance_uuid = bdm_dict.pop('instance_uuid', uuids.fake)
|
||||
|
||||
super(FakeDbBlockDeviceDict, self).__init__(bdm_dict=bdm_dict,
|
||||
**kwargs)
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
|
||||
import copy
|
||||
import datetime
|
||||
import uuid
|
||||
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from nova.compute import arch
|
||||
import nova.conf
|
||||
|
@ -188,7 +188,7 @@ class _FakeImageService(object):
|
|||
:raises: Duplicate if the image already exist.
|
||||
|
||||
"""
|
||||
image_id = str(metadata.get('id', uuid.uuid4()))
|
||||
image_id = str(metadata.get('id', uuidutils.generate_uuid()))
|
||||
metadata['id'] = image_id
|
||||
if image_id in self.images:
|
||||
raise exception.CouldNotUploadImage(image_id=image_id)
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import uuid
|
||||
|
||||
import mock
|
||||
|
||||
from nova import objects
|
||||
|
@ -151,7 +149,7 @@ class TestGroupAffinityFilter(test.NoDBTestCase):
|
|||
policies=['affinity']))
|
||||
self.assertTrue(filt_cls.host_passes(host, spec_obj))
|
||||
spec_obj = objects.RequestSpec(instance_group=objects.InstanceGroup(
|
||||
policies=[policy]), instance_uuid=str(uuid.uuid4()))
|
||||
policies=[policy]), instance_uuid=uuids.fake)
|
||||
spec_obj.instance_group.hosts = []
|
||||
self.assertTrue(filt_cls.host_passes(host, spec_obj))
|
||||
spec_obj.instance_group.hosts = ['host2']
|
||||
|
@ -167,7 +165,7 @@ class TestGroupAffinityFilter(test.NoDBTestCase):
|
|||
spec_obj = objects.RequestSpec(
|
||||
instance_group=objects.InstanceGroup(policies=[policy],
|
||||
hosts=['host1']),
|
||||
instance_uuid=str(uuid.uuid4()))
|
||||
instance_uuid=uuids.fake)
|
||||
self.assertFalse(filt_cls.host_passes(host, spec_obj))
|
||||
|
||||
def test_group_anti_affinity_filter_fails(self):
|
||||
|
@ -176,7 +174,7 @@ class TestGroupAffinityFilter(test.NoDBTestCase):
|
|||
'anti-affinity')
|
||||
|
||||
def test_group_anti_affinity_filter_allows_instance_to_same_host(self):
|
||||
fake_uuid = str(uuid.uuid4())
|
||||
fake_uuid = uuids.fake
|
||||
mock_instance = objects.Instance(uuid=fake_uuid)
|
||||
host_state = fakes.FakeHostState('host1', 'node1',
|
||||
{}, instances=[mock_instance])
|
||||
|
|
|
@ -11,13 +11,13 @@
|
|||
# under the License.
|
||||
|
||||
import itertools
|
||||
import uuid
|
||||
|
||||
from nova import objects
|
||||
from nova.objects import fields
|
||||
from nova.scheduler.filters import numa_topology_filter
|
||||
from nova import test
|
||||
from nova.tests.unit.scheduler import fakes
|
||||
from nova.tests import uuidsentinel as uuids
|
||||
|
||||
|
||||
class TestNUMATopologyFilter(test.NoDBTestCase):
|
||||
|
@ -30,7 +30,7 @@ class TestNUMATopologyFilter(test.NoDBTestCase):
|
|||
image_meta = objects.ImageMeta(properties=objects.ImageMetaProps())
|
||||
spec_obj = objects.RequestSpec(numa_topology=numa_topology,
|
||||
pci_requests=None,
|
||||
instance_uuid=str(uuid.uuid4()),
|
||||
instance_uuid=uuids.fake,
|
||||
flavor=objects.Flavor(extra_specs={}),
|
||||
image=image_meta)
|
||||
return spec_obj
|
||||
|
@ -129,7 +129,7 @@ class TestNUMATopologyFilter(test.NoDBTestCase):
|
|||
])
|
||||
spec_obj = objects.RequestSpec(numa_topology=instance_topology,
|
||||
pci_requests=None,
|
||||
instance_uuid=str(uuid.uuid4()))
|
||||
instance_uuid=uuids.fake)
|
||||
|
||||
extra_specs = [
|
||||
{},
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
"""
|
||||
Tests For Scheduler Utils
|
||||
"""
|
||||
import uuid
|
||||
|
||||
import mock
|
||||
import six
|
||||
|
@ -271,7 +270,7 @@ class SchedulerUtilsTestCase(test.NoDBTestCase):
|
|||
|
||||
group = objects.InstanceGroup()
|
||||
group.name = 'pele'
|
||||
group.uuid = str(uuid.uuid4())
|
||||
group.uuid = uuids.fake
|
||||
group.members = [instance.uuid]
|
||||
group.policies = [policy]
|
||||
return group
|
||||
|
@ -311,7 +310,7 @@ class SchedulerUtilsTestCase(test.NoDBTestCase):
|
|||
params={'host': 'hostA'})
|
||||
|
||||
group = objects.InstanceGroup()
|
||||
group.uuid = str(uuid.uuid4())
|
||||
group.uuid = uuids.fake
|
||||
group.members = [instance.uuid]
|
||||
group.policies = [policy]
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
# under the License.
|
||||
|
||||
import os
|
||||
import uuid
|
||||
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
|
@ -25,6 +24,7 @@ from nova import objects
|
|||
from nova.tests.unit import fake_instance
|
||||
from nova.tests.unit.objects import test_flavor
|
||||
from nova.tests.unit.virt.hyperv import test_base
|
||||
from nova.tests import uuidsentinel as uuids
|
||||
from nova.virt.hyperv import constants
|
||||
from nova.virt.hyperv import imagecache
|
||||
|
||||
|
@ -271,7 +271,7 @@ class ImageCacheTestCase(test_base.HyperVBaseTestCase):
|
|||
|
||||
@mock.patch.object(imagecache.os, 'listdir')
|
||||
def test_list_base_images(self, mock_listdir):
|
||||
original_image = str(uuid.uuid4())
|
||||
original_image = uuids.fake
|
||||
unexplained_image = 'just-an-image'
|
||||
ignored_file = 'foo.bar'
|
||||
mock_listdir.return_value = ['%s.VHD' % original_image,
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
# under the License.
|
||||
|
||||
import collections
|
||||
import uuid
|
||||
|
||||
import mock
|
||||
from oslo_serialization import jsonutils
|
||||
|
@ -1851,7 +1850,7 @@ class HelperMethodsTestCase(test.NoDBTestCase):
|
|||
|
||||
def test_instance_with_fetch(self):
|
||||
host = objects.ComputeNode(numa_topology=self.hosttopo._to_json())
|
||||
fake_uuid = str(uuid.uuid4())
|
||||
fake_uuid = uuids.fake
|
||||
instance = {'uuid': fake_uuid}
|
||||
|
||||
with mock.patch.object(objects.InstanceNUMATopology,
|
||||
|
@ -1862,7 +1861,7 @@ class HelperMethodsTestCase(test.NoDBTestCase):
|
|||
|
||||
def test_object_instance_with_load(self):
|
||||
host = objects.ComputeNode(numa_topology=self.hosttopo._to_json())
|
||||
fake_uuid = str(uuid.uuid4())
|
||||
fake_uuid = uuids.fake
|
||||
instance = objects.Instance(context=self.context, uuid=fake_uuid)
|
||||
|
||||
with mock.patch.object(objects.InstanceNUMATopology,
|
||||
|
@ -1873,7 +1872,7 @@ class HelperMethodsTestCase(test.NoDBTestCase):
|
|||
|
||||
def test_instance_serialized_by_build_request_spec(self):
|
||||
host = objects.ComputeNode(numa_topology=self.hosttopo._to_json())
|
||||
fake_uuid = str(uuid.uuid4())
|
||||
fake_uuid = uuids.fake
|
||||
instance = objects.Instance(context=self.context, id=1, uuid=fake_uuid,
|
||||
numa_topology=self.instancetopo)
|
||||
# NOTE (ndipanov): This emulates scheduler.utils.build_request_spec
|
||||
|
@ -1906,7 +1905,7 @@ class HelperMethodsTestCase(test.NoDBTestCase):
|
|||
self._check_usage(res)
|
||||
|
||||
def test_dict_numa_topology_to_obj(self):
|
||||
fake_uuid = str(uuid.uuid4())
|
||||
fake_uuid = uuids.fake
|
||||
instance = objects.Instance(context=self.context, id=1, uuid=fake_uuid,
|
||||
numa_topology=self.instancetopo)
|
||||
instance_dict = base_obj.obj_to_primitive(instance)
|
||||
|
|
Loading…
Reference in New Issue