Replaces uuid.uuid4 with uuidutils.generate_uuid()

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

Change-Id: Id13e01ba59f37a5be90db1fe778e9735f0e8b9b6
Closes-Bug: #1082248
This commit is contained in:
Luong Anh Tuan 2016-12-05 15:49:14 +07:00 committed by garyk
parent bcd6fddb12
commit 4f3be300b2
9 changed files with 55 additions and 58 deletions

View File

@ -19,6 +19,7 @@ import uuid
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import excutils
from oslo_utils import uuidutils
import six
from neutron._i18n import _LE
@ -154,7 +155,7 @@ class DbCreateCommand(BaseCommand):
def __init__(self, context, opts=None, args=None):
super(DbCreateCommand, self).__init__(context, "create", opts, args)
# NOTE(twilson) pre-commit result used for intra-transaction reference
self.record_id = "@%s" % uuid.uuid4()
self.record_id = "@%s" % uuidutils.generate_uuid()
self.opts.append("--id=%s" % self.record_id)
@property

View File

@ -14,8 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import uuid
from oslo_utils import uuidutils
from tempest.lib.common.utils import data_utils
from tempest.lib import exceptions as lib_exc
from tempest import test
@ -382,7 +381,7 @@ class RBACSharedNetworksTest(base.BaseAdminNetworkTest):
self.admin_client.create_rbac_policy(
object_type='network', object_id=net['id'],
action='access_as_shared',
target_tenant=str(uuid.uuid4()).replace('-', ''))
target_tenant=uuidutils.generate_uuid().replace('-', ''))
@test.idempotent_id('86c3529b-1231-40de-803c-afffffff7fff')
def test_regular_client_blocked_from_sharing_with_wildcard(self):

View File

@ -13,9 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import uuid
import netaddr
from oslo_utils import uuidutils
from tempest.lib.common.utils import data_utils
from tempest.lib import exceptions as lib_exc
from tempest import test
@ -115,7 +114,7 @@ class SubnetPoolsNegativeTestJSON(test_subnetpools.SubnetPoolsTestBase):
@test.requires_ext(extension='address-scope', service='network')
def test_create_subnetpool_associate_non_exist_address_scope(self):
self.assertRaises(lib_exc.NotFound, self._create_subnetpool,
address_scope_id=str(uuid.uuid4()))
address_scope_id=uuidutils.generate_uuid())
@test.attr(type='negative')
@test.idempotent_id('2dfb4269-8657-485a-a053-b022e911456e')

View File

@ -14,10 +14,10 @@
# under the License.
#
import uuid
import mock
from oslo_utils import uuidutils
from neutron.agent.l3 import l3_agent_extension_api as l3_agent_api
from neutron.agent.l3 import router_info
from neutron.agent.linux import ip_lib
@ -27,8 +27,8 @@ from neutron.tests import base
class TestL3AgentExtensionApi(base.BaseTestCase):
def _prepare_router_data(self, ports=None):
self.router_id = str(uuid.uuid4())
self.project_id = str(uuid.uuid4())
self.router_id = uuidutils.generate_uuid()
self.project_id = uuidutils.generate_uuid()
ri_kwargs = {'router': {'id': self.router_id,
'project_id': self.project_id},
'agent_conf': mock.ANY,
@ -90,7 +90,7 @@ class TestL3AgentExtensionApi(base.BaseTestCase):
with mock.patch.object(ip_lib.IPWrapper,
'get_namespaces') as mock_get_namespaces:
mock_get_namespaces.return_value = [str(uuid.uuid4())]
mock_get_namespaces.return_value = [uuidutils.generate_uuid()]
api_object = l3_agent_api.L3AgentExtensionAPI(router_info)
router_in_ns = api_object.is_router_in_namespace(ri.router_id)
self.assertFalse(router_in_ns)

View File

@ -16,10 +16,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import uuid
import mock
from oslo_config import cfg
from oslo_utils import uuidutils
from webob import exc
import webtest
@ -109,7 +108,7 @@ class ExtensionTestCase(testlib_api.WebTestCase):
def _test_entity_delete(self, entity):
"""Does the entity deletion based on naming convention."""
entity_id = str(uuid.uuid4())
entity_id = uuidutils.generate_uuid()
path = self._resource_prefix + '/' if self._resource_prefix else ''
path += self._plural_mappings.get(entity, entity + 's')
if self._translate_resource_name:

View File

@ -10,10 +10,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import uuid
import mock
from neutron_lib.plugins import directory
from oslo_utils import uuidutils
from neutron import context
from neutron.plugins.ml2 import config
@ -34,7 +33,7 @@ class ExtensionDriverTestCase(test_plugin.Ml2PluginV2TestCase):
self._ctxt = context.get_admin_context()
def _verify_network_create(self, code, exc_reason):
tenant_id = str(uuid.uuid4())
tenant_id = uuidutils.generate_uuid()
data = {'network': {'name': 'net1',
'tenant_id': tenant_id}}
req = self.new_create_request('networks', data)

View File

@ -14,7 +14,6 @@
# under the License.
import functools
import uuid
import fixtures
import mock
@ -2162,7 +2161,7 @@ class TestFaultyMechansimDriver(Ml2PluginV2FaultyDriverTestCase):
'create_network_postcommit',
side_effect=(exc.InvalidInput(
error_message=err_msg))):
tenant_id = str(uuid.uuid4())
tenant_id = uuidutils.generate_uuid()
data = {'network': {'name': 'net1',
'tenant_id': tenant_id}}
req = self.new_create_request('networks', data)

View File

@ -12,10 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import uuid
import mock
from oslo_config import cfg
from oslo_utils import uuidutils
from neutron import context
from neutron.db import api as db_api
@ -63,10 +62,12 @@ class TestTrackedResource(testlib_api.SqlTestCaseLight):
session = db_api.get_session()
with session.begin():
tenant_id = tenant_id or self.tenant_id
session.add(test_quota.MehModel(meh='meh_%s' % uuid.uuid4(),
tenant_id=tenant_id))
session.add(test_quota.MehModel(meh='meh_%s' % uuid.uuid4(),
tenant_id=tenant_id))
session.add(test_quota.MehModel(
meh='meh_%s' % uuidutils.generate_uuid(),
tenant_id=tenant_id))
session.add(test_quota.MehModel(
meh='meh_%s' % uuidutils.generate_uuid(),
tenant_id=tenant_id))
def _delete_data(self):
session = db_api.get_session()

View File

@ -16,7 +16,6 @@
import collections
import contextlib
import datetime
import uuid
import mock
from neutron_lib import constants
@ -24,6 +23,7 @@ from neutron_lib.plugins import directory
from oslo_config import cfg
from oslo_utils import importutils
from oslo_utils import timeutils
from oslo_utils import uuidutils
from sqlalchemy import orm
import testscenarios
import testtools
@ -298,7 +298,7 @@ class L3SchedulerBaseTestCase(base.BaseTestCase):
plugin = mock.MagicMock()
# distributed router already hosted
plugin.get_l3_agents_hosting_routers.return_value = [{'id': 'a1'}]
router = {'distributed': True, 'id': str(uuid.uuid4())}
router = {'distributed': True, 'id': uuidutils.generate_uuid()}
plugin.get_l3_agents.return_value = ['a1']
self.scheduler._get_candidates(plugin, mock.MagicMock(), router)
self.assertFalse(plugin.get_l3_agent_candidates.called)
@ -335,7 +335,7 @@ class L3SchedulerBaseMixin(object):
@contextlib.contextmanager
def router_with_ext_gw(self, name='router1', admin_state_up=True,
fmt=None, tenant_id=str(uuid.uuid4()),
fmt=None, tenant_id=uuidutils.generate_uuid(),
external_gateway_info=None,
subnet=None, set_context=False,
**kwargs):
@ -366,7 +366,7 @@ class L3SchedulerTestBaseMixin(object):
agent_id = self.l3_dvr_snat_id
agent = self.l3_dvr_snat_agent
router = self._make_router(self.fmt,
tenant_id=str(uuid.uuid4()),
tenant_id=uuidutils.generate_uuid(),
name='r1')
router['router']['distributed'] = distributed
router['router']['external_gateway_info'] = external_gw
@ -386,7 +386,7 @@ class L3SchedulerTestBaseMixin(object):
agent_id = self.agent_id1
agent = self.agent1
router = self._make_router(self.fmt,
tenant_id=str(uuid.uuid4()),
tenant_id=uuidutils.generate_uuid(),
name='r1')
self._test_schedule_bind_router(agent, router)
self.plugin._unbind_router(self.adminContext,
@ -400,7 +400,7 @@ class L3SchedulerTestBaseMixin(object):
distributed=False,
external_gw=None):
router = self._make_router(self.fmt,
tenant_id=str(uuid.uuid4()),
tenant_id=uuidutils.generate_uuid(),
name='r1')
router['router']['distributed'] = distributed
router['router']['external_gateway_info'] = external_gw
@ -451,7 +451,7 @@ class L3SchedulerTestBaseMixin(object):
def test_add_router_to_l3_agent_dvr_to_snat(self):
external_gw_info = {
"network_id": str(uuid.uuid4()),
"network_id": uuidutils.generate_uuid(),
"enable_snat": True
}
self._register_l3_dvr_agents()
@ -477,7 +477,7 @@ class L3SchedulerTestBaseMixin(object):
def test_add_distributed_router_to_l3_agent(self):
external_gw_info = {
"network_id": str(uuid.uuid4()),
"network_id": uuidutils.generate_uuid(),
"enable_snat": True
}
self._test_add_router_to_l3_agent(distributed=True,
@ -488,7 +488,7 @@ class L3SchedulerTestBaseMixin(object):
def test_add_distributed_router_to_l3_agent_already_scheduled(self):
external_gw_info = {
"network_id": str(uuid.uuid4()),
"network_id": uuidutils.generate_uuid(),
"enable_snat": True
}
self._test_add_router_to_l3_agent(distributed=True,
@ -556,7 +556,7 @@ class L3SchedulerTestBaseMixin(object):
'id': 'foo_router_id',
'distributed': True,
'external_gateway_info': {
'network_id': str(uuid.uuid4()),
'network_id': uuidutils.generate_uuid(),
'enable_snat': True
}
}
@ -588,7 +588,7 @@ class L3SchedulerTestBaseMixin(object):
def test_bind_new_router(self):
router = self._make_router(self.fmt,
tenant_id=str(uuid.uuid4()),
tenant_id=uuidutils.generate_uuid(),
name='r1')
with mock.patch.object(l3_agent_scheduler.LOG, 'debug') as flog:
self._test_schedule_bind_router(self.agent1, router)
@ -605,7 +605,7 @@ class L3SchedulerTestBaseMixin(object):
def test_bind_existing_router(self):
router = self._make_router(self.fmt,
tenant_id=str(uuid.uuid4()),
tenant_id=uuidutils.generate_uuid(),
name='r2')
self._test_schedule_bind_router(self.agent1, router)
with mock.patch.object(l3_agent_scheduler.LOG, 'debug') as flog:
@ -625,10 +625,10 @@ class L3SchedulerTestBaseMixin(object):
def test_get_l3_agent_candidates_legacy(self):
self._register_l3_dvr_agents()
router = self._make_router(self.fmt,
tenant_id=str(uuid.uuid4()),
tenant_id=uuidutils.generate_uuid(),
name='r2')
router['external_gateway_info'] = None
router['id'] = str(uuid.uuid4())
router['id'] = uuidutils.generate_uuid()
agent_list = [self.agent1, self.l3_dvr_agent]
# test legacy agent_mode case: only legacy agent should be candidate
@ -639,10 +639,10 @@ class L3SchedulerTestBaseMixin(object):
def test_get_l3_agent_candidates_dvr(self):
self._register_l3_dvr_agents()
router = self._make_router(self.fmt,
tenant_id=str(uuid.uuid4()),
tenant_id=uuidutils.generate_uuid(),
name='r2')
router['external_gateway_info'] = None
router['id'] = str(uuid.uuid4())
router['id'] = uuidutils.generate_uuid()
agent_list = [self.agent1, self.l3_dvr_agent]
# test dvr agent_mode case no candidates
router['distributed'] = True
@ -654,10 +654,10 @@ class L3SchedulerTestBaseMixin(object):
def test_get_l3_agent_candidates_dvr_no_vms(self):
self._register_l3_dvr_agents()
router = self._make_router(self.fmt,
tenant_id=str(uuid.uuid4()),
tenant_id=uuidutils.generate_uuid(),
name='r2')
router['external_gateway_info'] = None
router['id'] = str(uuid.uuid4())
router['id'] = uuidutils.generate_uuid()
agent_list = [self.agent1, self.l3_dvr_agent]
router['distributed'] = True
# Test no VMs present case
@ -670,10 +670,10 @@ class L3SchedulerTestBaseMixin(object):
def test_get_l3_agent_candidates_dvr_snat(self):
self._register_l3_dvr_agents()
router = self._make_router(self.fmt,
tenant_id=str(uuid.uuid4()),
tenant_id=uuidutils.generate_uuid(),
name='r2')
router['external_gateway_info'] = None
router['id'] = str(uuid.uuid4())
router['id'] = uuidutils.generate_uuid()
router['distributed'] = True
agent_list = [self.l3_dvr_snat_agent]
@ -685,10 +685,10 @@ class L3SchedulerTestBaseMixin(object):
def test_get_l3_agent_candidates_dvr_snat_no_vms(self):
self._register_l3_dvr_agents()
router = self._make_router(self.fmt,
tenant_id=str(uuid.uuid4()),
tenant_id=uuidutils.generate_uuid(),
name='r2')
router['external_gateway_info'] = None
router['id'] = str(uuid.uuid4())
router['id'] = uuidutils.generate_uuid()
router['distributed'] = True
agent_list = [self.l3_dvr_snat_agent]
@ -703,10 +703,10 @@ class L3SchedulerTestBaseMixin(object):
def test_get_l3_agent_candidates_dvr_ha_snat_no_vms(self):
self._register_l3_dvr_agents()
router = self._make_router(self.fmt,
tenant_id=str(uuid.uuid4()),
tenant_id=uuidutils.generate_uuid(),
name='r2')
router['external_gateway_info'] = None
router['id'] = str(uuid.uuid4())
router['id'] = uuidutils.generate_uuid()
router['distributed'] = True
router['ha'] = True
@ -721,10 +721,10 @@ class L3SchedulerTestBaseMixin(object):
def test_get_l3_agent_candidates_centralized(self):
self._register_l3_dvr_agents()
router = self._make_router(self.fmt,
tenant_id=str(uuid.uuid4()),
tenant_id=uuidutils.generate_uuid(),
name='r2')
router['external_gateway_info'] = None
router['id'] = str(uuid.uuid4())
router['id'] = uuidutils.generate_uuid()
# check centralized test case
router['distributed'] = False
agent_list = [self.l3_dvr_snat_agent]
@ -733,7 +733,7 @@ class L3SchedulerTestBaseMixin(object):
def test_get_l3_agents_hosting_routers(self):
agent = helpers.register_l3_agent('host_6')
router = self._make_router(self.fmt,
tenant_id=str(uuid.uuid4()),
tenant_id=uuidutils.generate_uuid(),
name='r1')
ctx = self.adminContext
router_id = router['router']['id']
@ -902,7 +902,7 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
def test__notify_l3_agent_update_port_with_allowed_address_pairs_revert(
self):
port_id = str(uuid.uuid4())
port_id = uuidutils.generate_uuid()
kwargs = {
'context': self.adminContext,
'port': {
@ -952,7 +952,7 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
self.assertFalse(l3plugin.dvr_handle_new_service_port.called)
def test__notify_l3_agent_update_port_with_allowed_address_pairs(self):
port_id = str(uuid.uuid4())
port_id = uuidutils.generate_uuid()
kwargs = {
'context': self.adminContext,
'port': {
@ -1154,7 +1154,7 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
kwargs = {
'context': self.adminContext,
'original_port': {
'id': str(uuid.uuid4()),
'id': uuidutils.generate_uuid(),
portbindings.HOST_ID: source_host,
'device_owner': DEVICE_OWNER_COMPUTE,
},
@ -1241,7 +1241,7 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
]
directory.add_plugin(constants.L3, l3plugin)
port = {
'id': str(uuid.uuid4()),
'id': uuidutils.generate_uuid(),
'device_id': 'abcd',
'device_owner': DEVICE_OWNER_COMPUTE_NOVA,
portbindings.HOST_ID: 'host1',
@ -1401,7 +1401,7 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
'id': 'foo_router_id',
'distributed': True,
'external_gateway_info': {
'network_id': str(uuid.uuid4()),
'network_id': uuidutils.generate_uuid(),
'enable_snat': True
}
}