]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Removes quantum.common.utils.str_uuid()
authorZhongyue Luo <zhongyue.nah@intel.com>
Thu, 15 Nov 2012 01:02:20 +0000 (09:02 +0800)
committerZhongyue Luo <zhongyue.nah@intel.com>
Fri, 23 Nov 2012 03:00:54 +0000 (11:00 +0800)
Replaced str_uuid() with openstack.common.uuidutils.generate_uuid()

Fixes bug #1082236

Change-Id: Ib09b070bfa1de4435c831d1d3c0fb0b0d12011bd

quantum/common/utils.py
quantum/db/db_base_plugin_v2.py
quantum/db/l3_db.py
quantum/db/models_v2.py
quantum/db/securitygroups_db.py
quantum/plugins/nec/db/nec_plugin_base.py
quantum/tests/unit/nec/test_db.py
quantum/tests/unit/nec/test_ofc_manager.py
quantum/tests/unit/nec/test_pfc_driver.py
quantum/tests/unit/nec/test_trema_driver.py
quantum/tests/unit/test_l3_plugin.py

index 8df274ade2f30b42cdc769ba3bb4eed536e79e38..7cb6639bdc0b6d6793216ede4b1e8c9ace1bc0fa 100644 (file)
 
 """Utilities and helper functions."""
 
-
 import os
 import signal
-import uuid
 
 from eventlet.green import subprocess
 
 from quantum.openstack.common import cfg
 from quantum.openstack.common import log as logging
 
+
 TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
 LOG = logging.getLogger(__name__)
 
@@ -118,11 +117,6 @@ def find_config_file(options, config_file):
             return cfg_file
 
 
-def str_uuid():
-    """Return a uuid as a string"""
-    return str(uuid.uuid4())
-
-
 def _subprocess_setup():
     # Python installs a SIGPIPE handler by default. This is usually not what
     # non-Python subprocesses expect.
index 6eb95e721106d6a7e017516ea004a3a6e4a1bdb2..b21ef593e70f977fd05e2d4d3c284884f7a4d465 100644 (file)
@@ -1,17 +1,19 @@
-# Copyright (c) 2012 OpenStack, LLC.
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright (c) 2012 OpenStack LLC.
+# All Rights Reserved.
 #
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
 #
-#    http://www.apache.org/licenses/LICENSE-2.0
+#         http://www.apache.org/licenses/LICENSE-2.0
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    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 datetime
 import random
@@ -23,12 +25,12 @@ from sqlalchemy.orm import exc
 from quantum.api.v2 import attributes
 from quantum.common import constants
 from quantum.common import exceptions as q_exc
-from quantum.common import utils
 from quantum.db import api as db
 from quantum.db import models_v2
 from quantum.openstack.common import cfg
 from quantum.openstack.common import log as logging
 from quantum.openstack.common import timeutils
+from quantum.openstack.common import uuidutils
 from quantum import quantum_plugin_base_v2
 
 
@@ -906,12 +908,13 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
         #                unneeded db action if the operation raises
         tenant_id = self._get_tenant_id_for_create(context, n)
         with context.session.begin(subtransactions=True):
-            network = models_v2.Network(tenant_id=tenant_id,
-                                        id=n.get('id') or utils.str_uuid(),
-                                        name=n['name'],
-                                        admin_state_up=n['admin_state_up'],
-                                        shared=n['shared'],
-                                        status=constants.NET_STATUS_ACTIVE)
+            args = {'tenant_id': tenant_id,
+                    'id': n.get('id') or uuidutils.generate_uuid(),
+                    'name': n['name'],
+                    'admin_state_up': n['admin_state_up'],
+                    'shared': n['shared'],
+                    'status': constants.NET_STATUS_ACTIVE}
+            network = models_v2.Network(**args)
             context.session.add(network)
         return self._make_network_dict(network)
 
@@ -1030,15 +1033,16 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
             self._validate_subnet_cidr(context, network, s['cidr'])
             # The 'shared' attribute for subnets is for internal plugin
             # use only. It is not exposed through the API
-            subnet = models_v2.Subnet(tenant_id=tenant_id,
-                                      id=s.get('id') or utils.str_uuid(),
-                                      name=s['name'],
-                                      network_id=s['network_id'],
-                                      ip_version=s['ip_version'],
-                                      cidr=s['cidr'],
-                                      enable_dhcp=s['enable_dhcp'],
-                                      gateway_ip=s['gateway_ip'],
-                                      shared=network.shared)
+            args = {'tenant_id': tenant_id,
+                    'id': s.get('id') or uuidutils.generate_uuid(),
+                    'name': s['name'],
+                    'network_id': s['network_id'],
+                    'ip_version': s['ip_version'],
+                    'cidr': s['cidr'],
+                    'enable_dhcp': s['enable_dhcp'],
+                    'gateway_ip': s['gateway_ip'],
+                    'shared': network.shared}
+            subnet = models_v2.Subnet(**args)
 
             # perform allocate pools first, since it might raise an error
             pools = self._allocate_pools_for_subnet(context, s)
@@ -1165,7 +1169,7 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
 
     def create_port(self, context, port):
         p = port['port']
-        port_id = p.get('id') or utils.str_uuid()
+        port_id = p.get('id') or uuidutils.generate_uuid()
         network_id = p['network_id']
         mac_address = p['mac_address']
         # NOTE(jkoelker) Get the tenant_id outside of the session to avoid
index ffa3f8f9e414af9134a9504b0c1ec0533f28d293..d4ac563a5fec939aaaefa6c3f140afa378f99e12 100644 (file)
@@ -1,6 +1,5 @@
-"""
 # vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
+
 # Copyright 2012 Nicira Networks, Inc.  All rights reserved.
 #
 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -17,7 +16,6 @@
 #
 # @author: Dan Wendlandt, Nicira, Inc
 #
-"""
 
 import netaddr
 import sqlalchemy as sa
@@ -28,14 +26,13 @@ import webob.exc as w_exc
 
 from quantum.api.v2 import attributes
 from quantum.common import exceptions as q_exc
-from quantum.common import utils
 from quantum.db import db_base_plugin_v2
 from quantum.db import model_base
 from quantum.db import models_v2
 from quantum.extensions import l3
 from quantum.openstack.common import cfg
 from quantum.openstack.common import log as logging
-
+from quantum.openstack.common import uuidutils
 from quantum import policy
 
 
@@ -143,7 +140,7 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
         with context.session.begin(subtransactions=True):
             # pre-generate id so it will be available when
             # configuring external gw port
-            router_db = Router(id=utils.str_uuid(),
+            router_db = Router(id=uuidutils.generate_uuid(),
                                tenant_id=tenant_id,
                                name=r['name'],
                                admin_state_up=r['admin_state_up'],
@@ -553,7 +550,7 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
     def create_floatingip(self, context, floatingip):
         fip = floatingip['floatingip']
         tenant_id = self._get_tenant_id_for_create(context, fip)
-        fip_id = utils.str_uuid()
+        fip_id = uuidutils.generate_uuid()
 
         f_net_id = fip['floating_network_id']
         if not self._network_is_external(context, f_net_id):
index 2239573ac552e6cd01f06586cedf01d60a3a331b..557dcc5fc73ab32e28398ca43abb45d1c2483ee3 100644 (file)
@@ -1,23 +1,25 @@
-# Copyright (c) 2012 OpenStack, LLC.
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright (c) 2012 OpenStack LLC.
+# All Rights Reserved.
 #
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
 #
-#    http://www.apache.org/licenses/LICENSE-2.0
+#         http://www.apache.org/licenses/LICENSE-2.0
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    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 sqlalchemy as sa
 from sqlalchemy import orm
 
-from quantum.common import utils
 from quantum.db import model_base
+from quantum.openstack.common import uuidutils
 
 
 class HasTenant(object):
@@ -28,7 +30,9 @@ class HasTenant(object):
 
 class HasId(object):
     """id mixin, add to subclasses that have an id."""
-    id = sa.Column(sa.String(36), primary_key=True, default=utils.str_uuid)
+    id = sa.Column(sa.String(36),
+                   primary_key=True,
+                   default=uuidutils.generate_uuid)
 
 
 class IPAvailabilityRange(model_base.BASEV2):
index 6e2eb5d29632a4e44997d8fc58c71eaccd344cc8..94bef9adb974970b3d42175b29decebc2bc34a24 100644 (file)
@@ -1,5 +1,5 @@
 # vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
+
 # Copyright 2012 Nicira Networks, Inc.  All rights reserved.
 #
 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -22,7 +22,6 @@ from sqlalchemy import orm
 from sqlalchemy.orm import exc
 from sqlalchemy.orm import scoped_session
 
-from quantum.common import utils
 from quantum.db import model_base
 from quantum.db import models_v2
 from quantum.extensions import securitygroup as ext_sg
@@ -119,7 +118,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
 
         with context.session.begin(subtransactions=True):
             security_group_db = SecurityGroup(id=s.get('id') or (
-                                              utils.str_uuid()),
+                                              uuidutils.generate_uuid()),
                                               description=s['description'],
                                               tenant_id=tenant_id,
                                               name=s['name'],
@@ -129,7 +128,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
                 for ethertype in self.sg_supported_ethertypes:
                     # Allow intercommunication
                     db = SecurityGroupRule(
-                        id=utils.str_uuid(), tenant_id=tenant_id,
+                        id=uuidutils.generate_uuid(), tenant_id=tenant_id,
                         security_group=security_group_db,
                         direction='ingress',
                         ethertype=ethertype,
@@ -249,7 +248,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
                 rule = rule_dict['security_group_rule']
                 tenant_id = self._get_tenant_id_for_create(context, rule)
                 db = SecurityGroupRule(
-                    id=utils.str_uuid(), tenant_id=tenant_id,
+                    id=uuidutils.generate_uuid(), tenant_id=tenant_id,
                     security_group_id=rule['security_group_id'],
                     direction=rule['direction'],
                     external_id=rule.get('external_id'),
index 65e59c657f9c2c6c7897bd13bea3137827328ccd..8e86f3d14d49d43482bd6a8a3a338e84f0559430 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
@@ -20,8 +20,8 @@ import logging
 from sqlalchemy.orm import exc
 
 from quantum.api.v2 import attributes
-from quantum.common import utils
 from quantum.db import db_base_plugin_v2
+from quantum.openstack.common import uuidutils
 from quantum.plugins.nec.common import exceptions as q_exc
 from quantum.plugins.nec.db import models as nmodels
 
@@ -84,7 +84,7 @@ class NECPluginV2Base(db_base_plugin_v2.QuantumDbPluginV2):
             super(NECPluginV2Base, self).get_port(context, pf['in_port'])
 
         params = {'tenant_id': tenant_id,
-                  'id': pf.get('id') or utils.str_uuid(),
+                  'id': pf.get('id') or uuidutils.generate_uuid(),
                   'network_id': pf['network_id'],
                   'priority': pf['priority'],
                   'action': pf['action'],
index d531e3f50070862008a8e2497df78041a3cffbf0..de4a67bf0581b09dae8b609be972b36a4211730e 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
@@ -18,7 +18,7 @@
 import random
 import unittest
 
-from quantum.common import utils
+from quantum.openstack.common import uuidutils
 from quantum.plugins.nec.common import exceptions as nexc
 from quantum.plugins.nec.db import api as ndb
 from quantum.plugins.nec.db import models as nmodels
@@ -37,9 +37,9 @@ class NECPluginV2DBTest(unittest.TestCase):
 
     def get_ofc_item_random_params(self):
         """create random parameters for ofc_item test"""
-        ofc_id = utils.str_uuid()
-        quantum_id = utils.str_uuid()
-        none = utils.str_uuid()
+        ofc_id = uuidutils.generate_uuid()
+        quantum_id = uuidutils.generate_uuid()
+        none = uuidutils.generate_uuid()
         return ofc_id, quantum_id, none
 
     def testa_add_ofc_item(self):
@@ -91,12 +91,12 @@ class NECPluginV2DBTest(unittest.TestCase):
 
     def get_portinfo_random_params(self):
         """create random parameters for portinfo test"""
-        port_id = utils.str_uuid()
+        port_id = uuidutils.generate_uuid()
         datapath_id = hex(random.randint(0, 0xffffffff))
         port_no = random.randint(1, 100)
         vlan_id = random.randint(0, 4095)
         mac = ':'.join(["%02x" % random.randint(0, 0xff) for x in range(6)])
-        none = utils.str_uuid()
+        none = uuidutils.generate_uuid()
         return port_id, datapath_id, port_no, vlan_id, mac, none
 
     def testd_add_portinfo(self):
index 05dde8e52a06a2646edcce4fe91a508ece92c3d8..4d760245109646f7a80fe7d550121092c478b4a2 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
@@ -17,7 +17,7 @@
 
 import unittest
 
-from quantum.common import utils
+from quantum.openstack.common import uuidutils
 from quantum.plugins.nec.common import config
 from quantum.plugins.nec.db import api as ndb
 from quantum.plugins.nec.db import models as nmodels
@@ -38,11 +38,11 @@ class OFCManagerTest(unittest.TestCase):
 
     def get_random_params(self):
         """create random parameters for portinfo test"""
-        tenant = utils.str_uuid()
-        network = utils.str_uuid()
-        port = utils.str_uuid()
-        _filter = utils.str_uuid()
-        none = utils.str_uuid()
+        tenant = uuidutils.generate_uuid()
+        network = uuidutils.generate_uuid()
+        port = uuidutils.generate_uuid()
+        _filter = uuidutils.generate_uuid()
+        none = uuidutils.generate_uuid()
         return tenant, network, port, _filter, none
 
     def testa_create_ofc_tenant(self):
index 9effaa68bf08788a6393af7f63166ddf538b1816..90f630c3ee1e6fe9c7918b2e22f50c4f6ce932de 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
@@ -18,7 +18,7 @@
 import mox
 import unittest
 
-from quantum.common import utils
+from quantum.openstack.common import uuidutils
 from quantum.plugins.nec.common import ofc_client as ofc
 from quantum.plugins.nec.db import models as nmodels
 from quantum.plugins.nec import drivers
@@ -50,9 +50,9 @@ class PFCDriverTestBase(unittest.TestCase):
 
     def get_ofc_item_random_params(self):
         """create random parameters for ofc_item test"""
-        tenant_id = utils.str_uuid()
-        network_id = utils.str_uuid()
-        port_id = utils.str_uuid()
+        tenant_id = uuidutils.generate_uuid()
+        network_id = uuidutils.generate_uuid()
+        port_id = uuidutils.generate_uuid()
         portinfo = nmodels.PortInfo(id=port_id, datapath_id="0x123456789",
                                     port_no=1234, vlan_id=321,
                                     mac="11:22:33:44:55:66")
index 7f93ad14541fa6d42f713bd086bef7efe6c1a83e..5909c5dcacd88db4b5bde50b0320afba3589c09f 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
@@ -18,7 +18,7 @@
 import mox
 import unittest
 
-from quantum.common import utils
+from quantum.openstack.common import uuidutils
 from quantum.plugins.nec.common import ofc_client
 from quantum.plugins.nec.db import models as nmodels
 from quantum.plugins.nec import drivers
@@ -44,9 +44,9 @@ class TremaDriverTestBase():
 
     def get_ofc_item_random_params(self):
         """create random parameters for ofc_item test"""
-        tenant_id = utils.str_uuid()
-        network_id = utils.str_uuid()
-        port_id = utils.str_uuid()
+        tenant_id = uuidutils.generate_uuid()
+        network_id = uuidutils.generate_uuid()
+        port_id = uuidutils.generate_uuid()
         portinfo = nmodels.PortInfo(id=port_id, datapath_id="0x123456789",
                                     port_no=1234, vlan_id=321,
                                     mac="11:22:33:44:55:66")
@@ -185,7 +185,7 @@ class TremaFilterDriverTest(TremaDriverTestBase, unittest.TestCase):
         """create random parameters for ofc_item test"""
         t, n, p = (super(TremaFilterDriverTest, self).
                    get_ofc_item_random_params())
-        filter_id = utils.str_uuid()
+        filter_id = uuidutils.generate_uuid()
         filter_dict = {'tenant_id': t,
                        'id': filter_id,
                        'network_id': n,
index 99e5bee3151849fc5bb4443cc432dc98e16120ec..8dd1096e1d68d7144933716af367d05ad0e24ec4 100644 (file)
@@ -1,6 +1,5 @@
-"""
 # vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
+
 # Copyright 2012 Nicira Networks, Inc.  All rights reserved.
 #
 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -17,7 +16,6 @@
 #
 # @author: Dan Wendlandt, Nicira, Inc
 #
-"""
 
 import contextlib
 import copy
@@ -34,7 +32,6 @@ from quantum.api.v2 import attributes
 from quantum.common import config
 from quantum.common import exceptions as q_exc
 from quantum.common.test_lib import test_config
-from quantum.common import utils
 from quantum import context
 from quantum.db import db_base_plugin_v2
 from quantum.db import l3_db
@@ -42,10 +39,12 @@ from quantum.db import models_v2
 from quantum.extensions import l3
 from quantum import manager
 from quantum.openstack.common import cfg
+from quantum.openstack.common import uuidutils
 from quantum.tests.unit import test_api_v2
 from quantum.tests.unit import test_db_plugin
 from quantum.tests.unit import test_extensions
 
+
 LOG = logging.getLogger(__name__)
 
 _uuid = test_api_v2._uuid
@@ -1043,19 +1042,19 @@ class L3NatDBTestCase(test_db_plugin.QuantumDbPluginV2TestCase):
     def test_create_floatingip_invalid_floating_network_id_returns_400(self):
         # API-level test - no need to create all objects for l3 plugin
         res = self._create_floatingip('json', 'iamnotanuuid',
-                                      utils.str_uuid(), '192.168.0.1')
+                                      uuidutils.generate_uuid(), '192.168.0.1')
         self.assertEqual(res.status_int, 400)
 
     def test_create_floatingip_invalid_floating_port_id_returns_400(self):
         # API-level test - no need to create all objects for l3 plugin
-        res = self._create_floatingip('json', utils.str_uuid(),
+        res = self._create_floatingip('json', uuidutils.generate_uuid(),
                                       'iamnotanuuid', '192.168.0.1')
         self.assertEqual(res.status_int, 400)
 
     def test_create_floatingip_invalid_fixed_ip_address_returns_400(self):
         # API-level test - no need to create all objects for l3 plugin
-        res = self._create_floatingip('json', utils.str_uuid(),
-                                      utils.str_uuid(), 'iamnotnanip')
+        res = self._create_floatingip('json', uuidutils.generate_uuid(),
+                                      uuidutils.generate_uuid(), 'iamnotnanip')
         self.assertEqual(res.status_int, 400)
 
     def test_list_nets_external(self):