]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Replaces uuid.uuid4 with uuidutils.generate_uuid()
authorZhongyue Luo <zhongyue.nah@intel.com>
Fri, 23 Nov 2012 03:54:37 +0000 (11:54 +0800)
committerZhongyue Luo <zhongyue.nah@intel.com>
Mon, 26 Nov 2012 01:55:46 +0000 (09:55 +0800)
Fixes bug #1082248

Change-Id: I1be4ae129382585cecc4346e1e712ee0ab03bab5

quantum/plugins/cisco/db/l2network_models.py
quantum/plugins/cisco/db/models.py
quantum/plugins/cisco/db/network_models_v2.py
quantum/plugins/cisco/tests/unit/v2/ucs/test_ucs_inventory_v2.py
quantum/plugins/nec/drivers/trema.py
quantum/tests/unit/metaplugin/test_metaplugin.py
quantum/tests/unit/nicira/fake_nvpapiclient.py
quantum/tests/unit/openvswitch/test_ovs_lib.py
quantum/tests/unit/test_api_v2.py

index cd5adfe10e16cc024041823113619ce8f0d9eb2b..d43def91541554a09a9349519ae0a5fdd85e1e97 100644 (file)
 #    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
index 1dca18d81afd3ae27dd1e9e4d547084bac36eb68..99ae98c5c63a3aa996b3c6ea4bafa44acd5cce3f 100644 (file)
@@ -1,4 +1,5 @@
 # vim: tabstop=4 shiftwidth=4 softtabstop=4
+
 # Copyright 2011 Nicira Networks, Inc.
 # All Rights Reserved.
 #
 # @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
 
index 84cd2081fba3f131d2cdcc65d727c5e68b9e727d..bd73c2fbe417df5ae7c35b417c8bd6c8b53e6434 100644 (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
 #
 # @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
index b2f1dd034d762df7ca55beefa2399159a8846153..1d16a190b23a30d625059027810c5b498b97fc8f 100644 (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)
index 845b380708d77b374469a4752f805d00c14ff0b8..38c7e395008993ccb4bb458a9322235a18306773 100644 (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)
index 27ae49bcb0aa6480d1a02d34d3799039f102b9ac..3d42923177542510b66d343804b5689f13cd1f61 100644 (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:'
index 4a5853382abe0c0ebf597eca14a5b85915fd2cd0..962949639fd86d0602859548614f07a1e3fbe0e0 100644 (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
 #    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
index e67eb9ba26575aa2da8477ff0886d10a6a99e377..52d8fbc73cc025228b81edec2d7d826b547d18f4 100644 (file)
 #    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],
index 654dbdd4f4003e19907b5853061201a4d242d9d7..4557fc0a890d67828b5ce76e0a3b758094aaca0f 100644 (file)
@@ -1,3 +1,5 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
 # Copyright 2012 OpenStack LLC.
 # All Rights Reserved.
 #
 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)