Removes quantum.common.utils.str_uuid()

Replaced str_uuid() with openstack.common.uuidutils.generate_uuid()

Fixes bug #1082236

Change-Id: Ib09b070bfa1de4435c831d1d3c0fb0b0d12011bd
This commit is contained in:
Zhongyue Luo 2012-11-15 09:02:20 +08:00
parent be77fd3f47
commit 081424cb3d
11 changed files with 93 additions and 96 deletions

View File

@ -20,16 +20,15 @@
"""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.

View 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

View 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):

View 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):

View 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'),

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
@ -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'],

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
@ -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):

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
@ -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):

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
@ -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")

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
@ -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,

View 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):