Replaces uuid.uuid4 with uuidutils.generate_uuid()

Fixes bug #1082248

Change-Id: I1be4ae129382585cecc4346e1e712ee0ab03bab5
This commit is contained in:
Zhongyue Luo 2012-11-23 11:54:37 +08:00
parent a14a03f4c5
commit e597cbc7ca
9 changed files with 58 additions and 54 deletions

View File

@ -15,11 +15,10 @@
# under the License.
# @author: Rohit Agarwalla, Cisco Systems, Inc.
import uuid
from sqlalchemy import Column, Integer, String, ForeignKey, Boolean
from sqlalchemy.orm import relation, object_mapper
from quantum.openstack.common import uuidutils
from quantum.plugins.cisco.db import models
from quantum.plugins.cisco.db.models import BASE
@ -110,10 +109,10 @@ class PortProfile(BASE, L2NetworkBase):
qos = Column(String(255))
def __init__(self, name, vlan_id, qos=None):
self.uuid = uuid.uuid4()
self.name = name
self.vlan_id = vlan_id
self.qos = qos
self.uuid = uuidutils.generate_uuid()
self.name = name
self.vlan_id = vlan_id
self.qos = qos
def __repr__(self):
return "<PortProfile(%s,%s,%d,%s)>" % (self.uuid,
@ -159,7 +158,7 @@ class QoS(BASE, L2NetworkBase):
qos_desc = Column(String(255))
def __init__(self, tenant_id, qos_name, qos_desc):
self.qos_id = str(uuid.uuid4())
self.qos_id = uuidutils.generate_uuid()
self.tenant_id = tenant_id
self.qos_name = qos_name
self.qos_desc = qos_desc
@ -180,7 +179,7 @@ class Credential(BASE, L2NetworkBase):
password = Column(String(255))
def __init__(self, tenant_id, credential_name, user_name, password):
self.credential_id = str(uuid.uuid4())
self.credential_id = uuidutils.generate_uuid()
self.tenant_id = tenant_id
self.credential_name = credential_name
self.user_name = user_name

View File

@ -1,4 +1,5 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2011 Nicira Networks, Inc.
# All Rights Reserved.
#
@ -17,12 +18,13 @@
# @author: Brad Hall, Nicira Networks, Inc.
# @author: Dan Wendlandt, Nicira Networks, Inc.
import uuid
from sqlalchemy import Column, String, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relation, object_mapper
from quantum.openstack.common import uuidutils
BASE = declarative_base()
@ -74,7 +76,7 @@ class Port(BASE, QuantumBase):
state = Column(String(8))
def __init__(self, network_id):
self.uuid = str(uuid.uuid4())
self.uuid = uuidutils.generate_uuid()
self.network_id = network_id
self.state = "DOWN"
@ -93,7 +95,7 @@ class Network(BASE, QuantumBase):
ports = relation(Port, order_by=Port.uuid, backref="network")
def __init__(self, tenant_id, name):
self.uuid = str(uuid.uuid4())
self.uuid = uuidutils.generate_uuid()
self.tenant_id = tenant_id
self.name = name

View File

@ -1,5 +1,5 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012, Cisco Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -16,13 +16,12 @@
#
# @author: Rohit Agarwalla, Cisco Systems, Inc.
import uuid
from sqlalchemy import Column, Integer, String, ForeignKey, Boolean
from sqlalchemy.orm import relation, object_mapper
from quantum.db import model_base
from quantum.db import models_v2 as models
from quantum.openstack.common import uuidutils
class L2NetworkBase(object):
@ -111,10 +110,10 @@ class PortProfile(model_base.BASEV2, L2NetworkBase):
qos = Column(String(255))
def __init__(self, name, vlan_id, qos=None):
self.uuid = uuid.uuid4()
self.name = name
self.vlan_id = vlan_id
self.qos = qos
self.uuid = uuidutils.generate_uuid()
self.name = name
self.vlan_id = vlan_id
self.qos = qos
def __repr__(self):
return "<PortProfile(%s,%s,%d,%s)>" % (self.uuid,
@ -160,7 +159,7 @@ class QoS(model_base.BASEV2, L2NetworkBase):
qos_desc = Column(String(255))
def __init__(self, tenant_id, qos_name, qos_desc):
self.qos_id = str(uuid.uuid4())
self.qos_id = uuidutils.generate_uuid()
self.tenant_id = tenant_id
self.qos_name = qos_name
self.qos_desc = qos_desc
@ -181,7 +180,7 @@ class Credential(model_base.BASEV2, L2NetworkBase):
password = Column(String(255))
def __init__(self, tenant_id, credential_name, user_name, password):
self.credential_id = str(uuid.uuid4())
self.credential_id = uuidutils.generate_uuid()
self.tenant_id = tenant_id
self.credential_name = credential_name
self.user_name = user_name

View File

@ -1,5 +1,5 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Cisco Systems, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -19,9 +19,9 @@
import logging
import unittest
import uuid
from quantum.common import exceptions as exc
from quantum.openstack.common import uuidutils
from quantum.plugins.cisco.common import cisco_constants as const
from quantum.plugins.cisco.common import cisco_credentials_v2 as creds
from quantum.plugins.cisco.db import network_db_v2 as cdb
@ -71,7 +71,7 @@ class TestUCSInventory(unittest.TestCase):
def _test_with_port_creation(self, cmd, params=None):
"""Tests commands that requires a port to exist"""
LOG.debug("test_%s - START", cmd)
net_uuid = str(uuid.uuid4())
net_uuid = uuidutils.generate_uuid()
device_params = self._ucs_inventory.create_port(tenant, net_uuid,
port_state,
state=port_state)

View File

@ -1,5 +1,5 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 NEC Corporation. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -15,8 +15,7 @@
# under the License.
# @author: Ryota MIBU
import uuid
from quantum.openstack.common import uuidutils
from quantum.plugins.nec.common import ofc_client
from quantum.plugins.nec import ofc_driver_base
@ -32,7 +31,7 @@ class TremaDriverBase(ofc_driver_base.OFCDriverBase):
port=conf_ofc.port)
def create_tenant(self, description, tenant_id=None):
return tenant_id or str(uuid.uuid4())
return tenant_id or uuidutils.generate_uuid()
def update_tenant(self, ofc_tenant_id, description):
pass
@ -41,7 +40,7 @@ class TremaDriverBase(ofc_driver_base.OFCDriverBase):
pass
def create_network(self, ofc_tenant_id, description, network_id=None):
ofc_network_id = network_id or str(uuid.uuid4())
ofc_network_id = network_id or uuidutils.generate_uuid()
body = {'id': ofc_network_id, 'description': description}
self.client.post(self.networks_path, body=body)
return ofc_network_id
@ -142,7 +141,7 @@ class TremaFilterDriver(object):
else:
ofp_wildcards.append("tp_dst")
ofc_filter_id = filter_id or str(uuid.uuid4())
ofc_filter_id = filter_id or uuidutils.generate_uuid()
body['id'] = ofc_filter_id
body['ofp_wildcards'] = ','.join(ofp_wildcards)
@ -166,7 +165,7 @@ class TremaPortBaseDriver(TremaDriverBase, TremaFilterDriver):
def create_port(self, ofc_tenant_id, ofc_network_id, portinfo,
port_id=None):
ofc_port_id = port_id or str(uuid.uuid4())
ofc_port_id = port_id or uuidutils.generate_uuid()
path = self.ports_path % ofc_network_id
body = {'id': ofc_port_id,
'datapath_id': portinfo.datapath_id,
@ -196,7 +195,7 @@ class TremaPortMACBaseDriver(TremaDriverBase, TremaFilterDriver):
#NOTE: This Driver create slices with Port-MAC Based bindings on Trema
# Sliceable. It's REST API requires Port Based binding before you
# define Port-MAC Based binding.
ofc_port_id = port_id or str(uuid.uuid4())
ofc_port_id = port_id or uuidutils.generate_uuid()
dummy_port_id = "dummy-%s" % ofc_port_id
path = self.ports_path % ofc_network_id
@ -237,7 +236,7 @@ class TremaMACBaseDriver(TremaDriverBase):
def create_port(self, ofc_tenant_id, ofc_network_id, portinfo,
port_id=None):
ofc_port_id = port_id or str(uuid.uuid4())
ofc_port_id = port_id or uuidutils.generate_uuid()
path = self.attachments_path % ofc_network_id
body = {'id': ofc_port_id, 'mac': portinfo.mac}
self.client.post(path, body=body)

View File

@ -1,5 +1,5 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012, Nachi Ueno, NTT MCL, Inc.
# All Rights Reserved.
#
@ -16,7 +16,6 @@
# under the License.
import os
import uuid
import mock
import mox
@ -31,6 +30,7 @@ from quantum.db import models_v2
from quantum.extensions.flavor import (FLAVOR_NETWORK, FLAVOR_ROUTER)
from quantum.extensions import l3
from quantum.openstack.common import cfg
from quantum.openstack.common import uuidutils
from quantum.plugins.metaplugin.meta_quantum_plugin import MetaPluginV2
from quantum.plugins.metaplugin.proxy_quantum_plugin import ProxyPluginV2
from quantum.tests.unit.metaplugin import fake_plugin
@ -76,7 +76,7 @@ class MetaQuantumPluginV2Test(unittest.TestCase):
super(MetaQuantumPluginV2Test, self).setUp()
db._ENGINE = None
db._MAKER = None
self.fake_tenant_id = str(uuid.uuid4())
self.fake_tenant_id = uuidutils.generate_uuid()
self.context = context.get_admin_context()
sql_connection = 'sqlite:///:memory:'

View File

@ -1,3 +1,5 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 Nicira Networks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -11,12 +13,13 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
import json
import logging
import urlparse
import uuid
from quantum.openstack.common import uuidutils
LOG = logging.getLogger("fake_nvpapiclient")
LOG.setLevel(logging.DEBUG)
@ -67,7 +70,7 @@ class FakeClient:
def _add_lswitch(self, body):
fake_lswitch = json.loads(body)
fake_lswitch['uuid'] = str(uuid.uuid4())
fake_lswitch['uuid'] = uuidutils.generate_uuid()
self._fake_lswitch_dict[fake_lswitch['uuid']] = fake_lswitch
# put the tenant_id and the zone_uuid in the main dict
# for simplyfying templating
@ -78,7 +81,7 @@ class FakeClient:
def _add_lport(self, body, ls_uuid):
fake_lport = json.loads(body)
fake_lport['uuid'] = str(uuid.uuid4())
fake_lport['uuid'] = uuidutils.generate_uuid()
# put the tenant_id and the ls_uuid in the main dict
# for simplyfying templating
fake_lport['ls_uuid'] = ls_uuid

View File

@ -15,12 +15,11 @@
# under the License.
# @author: Dan Wendlandt, Nicira, Inc.
import uuid
import mox
import unittest2 as unittest
from quantum.agent.linux import ovs_lib, utils
from quantum.openstack.common import uuidutils
class OVS_Lib_Test(unittest.TestCase):
@ -48,7 +47,7 @@ class OVS_Lib_Test(unittest.TestCase):
pname = "vif1.0"
ofport = 5
vif_id = str(uuid.uuid4())
vif_id = uuidutils.generate_uuid()
mac = "ca:fe:de:ad:be:ef"
# test __init__
@ -230,7 +229,7 @@ class OVS_Lib_Test(unittest.TestCase):
def _test_get_vif_ports(self, is_xen=False):
pname = "tap99"
ofport = "6"
vif_id = str(uuid.uuid4())
vif_id = uuidutils.generate_uuid()
mac = "ca:fe:de:ad:be:ef"
utils.execute(["ovs-vsctl", self.TO, "list-ports", self.BR_NAME],

View File

@ -1,3 +1,5 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 OpenStack LLC.
# All Rights Reserved.
#
@ -15,12 +17,10 @@
import logging
import os
import unittest
import uuid
import mock
import webtest
from webob import exc
import webtest
from quantum.api.extensions import PluginAwareExtensionManager
from quantum.api.v2 import attributes
@ -33,13 +33,14 @@ from quantum import context
from quantum.manager import QuantumManager
from quantum.openstack.common import cfg
from quantum.openstack.common.notifier import api as notifer_api
from quantum.openstack.common import uuidutils
LOG = logging.getLogger(__name__)
def _uuid():
return str(uuid.uuid4())
return uuidutils.generate_uuid()
ROOTDIR = os.path.dirname(os.path.dirname(__file__))
ETCDIR = os.path.join(ROOTDIR, 'etc')
@ -323,7 +324,7 @@ class JSONV2TestCase(APIv2TestBase):
env = {}
if req_tenant_id:
env = {'quantum.context': context.Context('', req_tenant_id)}
input_dict = {'id': str(uuid.uuid4()),
input_dict = {'id': uuidutils.generate_uuid(),
'name': 'net1',
'admin_state_up': True,
'status': "ACTIVE",
@ -568,7 +569,7 @@ class JSONV2TestCase(APIv2TestBase):
instance = self.plugin.return_value
instance.get_network.return_value = return_value
self.api.get(_get_path('networks', id=str(uuid.uuid4())))
self.api.get(_get_path('networks', id=uuidutils.generate_uuid()))
def _test_delete(self, req_tenant_id, real_tenant_id, expected_code,
expect_errors=False):
@ -580,8 +581,10 @@ class JSONV2TestCase(APIv2TestBase):
'shared': False}
instance.delete_network.return_value = None
res = self.api.delete(_get_path('networks', id=str(uuid.uuid4())),
extra_environ=env, expect_errors=expect_errors)
res = self.api.delete(_get_path('networks',
id=uuidutils.generate_uuid()),
extra_environ=env,
expect_errors=expect_errors)
self.assertEqual(res.status_int, expected_code)
def test_delete_noauth(self):
@ -611,7 +614,7 @@ class JSONV2TestCase(APIv2TestBase):
instance.get_network.return_value = data
res = self.api.get(_get_path('networks',
id=str(uuid.uuid4())),
id=uuidutils.generate_uuid()),
extra_environ=env,
expect_errors=expect_errors)
self.assertEqual(res.status_int, expected_code)
@ -648,7 +651,7 @@ class JSONV2TestCase(APIv2TestBase):
instance.update_network.return_value = return_value
res = self.api.put_json(_get_path('networks',
id=str(uuid.uuid4())),
id=uuidutils.generate_uuid()),
data,
extra_environ=env,
expect_errors=expect_errors)