Replaces uuid.uuid4 with uuidutils.generate_uuid()

Openstack oslo_utils has a generate_uuid function for generating
uuids. We should use that function when generating uuids for
consistency.

Change-Id: I493c787ebb5fc7fbed484b5e60b94b66e434bd15
This commit is contained in:
sudhir_agarwal 2017-07-18 12:01:10 +05:30 committed by sudhir agarwal
parent 107f89834c
commit a214de6629
13 changed files with 61 additions and 58 deletions

View File

@ -11,11 +11,11 @@
# under the License.
from datetime import datetime
import uuid
from oslo_db.exception import DBDuplicateEntry
from oslo_utils import strutils
from oslo_utils import timeutils
from oslo_utils import uuidutils
from sqlalchemy.orm import exc as orm_exc
from sqlalchemy import sql
@ -90,7 +90,7 @@ class NfvoPluginDb(nfvo.NFVOPluginBase, db_base.CommonDbMixin):
deleted_at=datetime.min)
context.session.add(vim_db)
vim_auth_db = nfvo_db.VimAuth(
id=str(uuid.uuid4()),
id=uuidutils.generate_uuid(),
vim_id=vim.get('id'),
password=vim_cred.pop('password'),
vim_project=vim.get('vim_project'),

View File

@ -12,11 +12,11 @@
import ast
from datetime import datetime
import uuid
from oslo_db.exception import DBDuplicateEntry
from oslo_log import log as logging
from oslo_utils import timeutils
from oslo_utils import uuidutils
import sqlalchemy as sa
from sqlalchemy import orm
@ -170,7 +170,7 @@ class NSPluginDb(network_service.NSPluginBase, db_base.CommonDbMixin):
try:
with context.session.begin(subtransactions=True):
nsd_id = str(uuid.uuid4())
nsd_id = uuidutils.generate_uuid()
nsd_db = NSD(
id=nsd_id,
tenant_id=tenant_id,
@ -181,7 +181,7 @@ class NSPluginDb(network_service.NSPluginBase, db_base.CommonDbMixin):
context.session.add(nsd_db)
for (key, value) in nsd.get('attributes', {}).items():
attribute_db = NSDAttribute(
id=str(uuid.uuid4()),
id=uuidutils.generate_uuid(),
nsd_id=nsd_id,
key=key,
value=value)
@ -245,7 +245,7 @@ class NSPluginDb(network_service.NSPluginBase, db_base.CommonDbMixin):
nsd_id = ns['nsd_id']
vim_id = ns['vim_id']
name = ns.get('name')
ns_id = str(uuid.uuid4())
ns_id = uuidutils.generate_uuid()
try:
with context.session.begin(subtransactions=True):
nsd_db = self._get_resource(context, NSD,

View File

@ -15,9 +15,9 @@
import random
import sqlalchemy as sa
import uuid
from oslo_log import log as logging
from oslo_utils import uuidutils
from sqlalchemy import orm
from sqlalchemy.orm import exc as orm_exc
from tacker._i18n import _
@ -192,8 +192,8 @@ class VnffgPluginDbMixin(vnffg.VNFFGPluginBase, db_base.CommonDbMixin):
def create_vnffg(self, context, vnffg):
vnffg_dict = self._create_vnffg_pre(context, vnffg)
sfc_instance = str(uuid.uuid4())
fc_instance = str(uuid.uuid4())
sfc_instance = uuidutils.generate_uuid()
fc_instance = uuidutils.generate_uuid()
self._create_vnffg_post(context, sfc_instance,
fc_instance, vnffg_dict)
self._create_vnffg_status(context, vnffg_dict)
@ -222,7 +222,7 @@ class VnffgPluginDbMixin(vnffg.VNFFGPluginBase, db_base.CommonDbMixin):
tenant_id = self._get_tenant_id_for_create(context, template)
with context.session.begin(subtransactions=True):
template_id = str(uuid.uuid4())
template_id = uuidutils.generate_uuid()
template_db = VnffgTemplate(
id=template_id,
tenant_id=tenant_id,
@ -324,7 +324,7 @@ class VnffgPluginDbMixin(vnffg.VNFFGPluginBase, db_base.CommonDbMixin):
LOG.debug(_('vnffg %s'), vnffg)
tenant_id = self._get_tenant_id_for_create(context, vnffg)
name = vnffg.get('name')
vnffg_id = vnffg.get('id') or str(uuid.uuid4())
vnffg_id = vnffg.get('id') or uuidutils.generate_uuid()
template_id = vnffg['vnffgd_id']
symmetrical = vnffg['symmetrical']
@ -362,9 +362,9 @@ class VnffgPluginDbMixin(vnffg.VNFFGPluginBase, db_base.CommonDbMixin):
status=constants.PENDING_CREATE)
context.session.add(vnffg_db)
nfp_id = str(uuid.uuid4())
sfc_id = str(uuid.uuid4())
classifier_id = str(uuid.uuid4())
nfp_id = uuidutils.generate_uuid()
sfc_id = uuidutils.generate_uuid()
classifier_id = uuidutils.generate_uuid()
nfp_db = VnffgNfp(id=nfp_id, vnffg_id=vnffg_id,
tenant_id=tenant_id,
@ -400,7 +400,7 @@ class VnffgPluginDbMixin(vnffg.VNFFGPluginBase, db_base.CommonDbMixin):
LOG.debug(_('acl_match %s'), match)
match_db_table = ACLMatchCriteria(
id=str(uuid.uuid4()),
id=uuidutils.generate_uuid(),
vnffgc_id=classifier_id,
**match)
@ -663,7 +663,7 @@ class VnffgPluginDbMixin(vnffg.VNFFGPluginBase, db_base.CommonDbMixin):
"""
# this should be overridden with driver call to find ID given name
# for resource
return str(uuid.uuid4())
return uuidutils.generate_uuid()
# called internally, not by REST API
# instance_id = None means error on creation

View File

@ -15,7 +15,6 @@
# under the License.
from datetime import datetime
import uuid
from oslo_db.exception import DBDuplicateEntry
from oslo_log import log as logging
@ -251,7 +250,7 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin):
try:
with context.session.begin(subtransactions=True):
vnfd_id = str(uuid.uuid4())
vnfd_id = uuidutils.generate_uuid()
vnfd_db = VNFD(
id=vnfd_id,
tenant_id=tenant_id,
@ -263,7 +262,7 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin):
context.session.add(vnfd_db)
for (key, value) in vnfd.get('attributes', {}).items():
attribute_db = VNFDAttribute(
id=str(uuid.uuid4()),
id=uuidutils.generate_uuid(),
vnfd_id=vnfd_id,
key=key,
value=value)
@ -271,7 +270,7 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin):
for service_type in (item['service_type']
for item in vnfd['service_types']):
service_type_db = ServiceType(
id=str(uuid.uuid4()),
id=uuidutils.generate_uuid(),
tenant_id=tenant_id,
vnfd_id=vnfd_id,
service_type=service_type)
@ -382,7 +381,7 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin):
arg.value = value
else:
arg = VNFAttribute(
id=str(uuid.uuid4()), vnf_id=vnf_id,
id=uuidutils.generate_uuid(), vnf_id=vnf_id,
key=key, value=value)
context.session.add(arg)
@ -392,7 +391,7 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin):
tenant_id = self._get_tenant_id_for_create(context, vnf)
vnfd_id = vnf['vnfd_id']
name = vnf.get('name')
vnf_id = str(uuid.uuid4())
vnf_id = uuidutils.generate_uuid()
attributes = vnf.get('attributes', {})
vim_id = vnf.get('vim_id')
placement_attr = vnf.get('placement_attr', {})
@ -414,7 +413,7 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin):
context.session.add(vnf_db)
for key, value in attributes.items():
arg = VNFAttribute(
id=str(uuid.uuid4()), vnf_id=vnf_id,
id=uuidutils.generate_uuid(), vnf_id=vnf_id,
key=key, value=value)
context.session.add(arg)
except DBDuplicateEntry as e:
@ -602,7 +601,7 @@ class VNFMPluginDb(vnfm.VNFMPluginBase, db_base.CommonDbMixin):
# start actual creation of hosting vnf.
# Waiting for completion of creation should be done backgroundly
# by another thread if it takes a while.
instance_id = str(uuid.uuid4())
instance_id = uuidutils.generate_uuid()
vnf_dict['instance_id'] = instance_id
self._create_vnf_post(context, vnf_dict['id'], instance_id, None,
vnf_dict)

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import uuid
from oslo_utils import uuidutils
class WorkflowGeneratorBase(object):
@ -18,7 +18,7 @@ class WorkflowGeneratorBase(object):
self.resource = resource
self.action = action
self.wf_name = self.action + '_' + self.resource
self.wf_identifier = 'std.' + self.wf_name + str(uuid.uuid4())
self.wf_identifier = 'std.' + self.wf_name + uuidutils.generate_uuid()
self.task = getattr(self, self.wf_name)
self.input_dict = dict()
self._build_basic_workflow()

View File

@ -13,9 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import uuid
from oslo_log import log as logging
from oslo_utils import uuidutils
from tacker.common import log
from tacker.nfvo.drivers.vnffg import abstract_vnffg_driver
@ -41,7 +40,7 @@ class VNFFGNoop(abstract_vnffg_driver.VnffgAbstractDriver):
@log.log
def create_chain(self, name, fc_id, vnfs, auth_attr=None):
instance_id = str(uuid.uuid4())
instance_id = uuidutils.generate_uuid()
self._instances.add(instance_id)
return instance_id
@ -57,7 +56,7 @@ class VNFFGNoop(abstract_vnffg_driver.VnffgAbstractDriver):
@log.log
def create_flow_classifier(self, name, fc, auth_attr=None):
instance_id = str(uuid.uuid4())
instance_id = uuidutils.generate_uuid()
self._instances.add(instance_id)
return instance_id

View File

@ -11,7 +11,7 @@
# under the License.
import ast
import uuid
from oslo_utils import uuidutils
from tacker.mistral import workflow_generator
@ -110,7 +110,7 @@ class WorkflowGenerator(workflow_generator.WorkflowGeneratorBase):
def build_input(self, ns, params):
vnfds = ns['vnfd_details']
id = str(uuid.uuid4())
id = uuidutils.generate_uuid()
self.input_dict = {'vnf': {}}
for vnfd_name, vnfd_info in (vnfds).items():
nodes = vnfd_info['instances']

View File

@ -17,7 +17,6 @@
import copy
import os
import time
import uuid
import yaml
from cryptography import fernet
@ -26,6 +25,7 @@ from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import excutils
from oslo_utils import strutils
from oslo_utils import uuidutils
from tempfile import mkstemp
from toscaparser.tosca_template import ToscaTemplate
@ -104,7 +104,7 @@ class NfvoPlugin(nfvo_db_plugin.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
strutils.mask_password(vim))
vim_obj = vim['vim']
vim_type = vim_obj['type']
vim_obj['id'] = str(uuid.uuid4())
vim_obj['id'] = uuidutils.generate_uuid()
vim_obj['status'] = 'PENDING'
try:
self._vim_drivers.invoke(vim_type,

View File

@ -12,7 +12,8 @@
# under the License.
import mock
import uuid
from oslo_utils import uuidutils
from tacker import context
from tacker.nfvo.drivers.vim import openstack_driver
@ -29,7 +30,7 @@ class FakeNeutronClient(mock.Mock):
self.__chain_dict = {}
def flow_classifier_create(self, fc_create_dict):
fc_id = uuid.uuid4()
fc_id = uuidutils.generate_uuid()
self.__fc_dict[fc_id] = fc_create_dict
return fc_id
@ -54,7 +55,7 @@ class FakeNeutronClient(mock.Mock):
self.__fc_dict.pop(fc_id)
def port_pair_create(self, port_pair):
pp_id = uuid.uuid4()
pp_id = uuidutils.generate_uuid()
self.__pp_dict[pp_id] = port_pair
return pp_id
@ -68,7 +69,7 @@ class FakeNeutronClient(mock.Mock):
return None
def port_pair_group_create(self, port_pair_group):
ppg_id = uuid.uuid4()
ppg_id = uuidutils.generate_uuid()
self.__ppg_dict[ppg_id] = port_pair_group
return ppg_id
@ -82,7 +83,7 @@ class FakeNeutronClient(mock.Mock):
return None
def port_chain_create(self, port_chain):
chain_id = uuid.uuid4()
chain_id = uuidutils.generate_uuid()
self.__chain_dict[chain_id] = port_chain
return chain_id
@ -185,11 +186,14 @@ class TestChainSFC(base.TestCase):
self.assertIsNotNone(fc_id)
vnf_1 = {'name': 'test_create_chain_vnf_1',
'connection_points': [uuid.uuid4(), uuid.uuid4()]}
'connection_points': [uuidutils.generate_uuid(),
uuidutils.generate_uuid()]}
vnf_2 = {'name': 'test_create_chain_vnf_2',
'connection_points': [uuid.uuid4(), uuid.uuid4()]}
'connection_points': [uuidutils.generate_uuid(),
uuidutils.generate_uuid()]}
vnf_3 = {'name': 'test_create_chain_vnf_3',
'connection_points': [uuid.uuid4(), uuid.uuid4()]}
'connection_points': [uuidutils.generate_uuid(),
uuidutils.generate_uuid()]}
vnfs = [vnf_1, vnf_2, vnf_3]
result = self.sfc_driver.create_chain(name='fake_ffg',
@ -213,11 +217,14 @@ class TestChainSFC(base.TestCase):
self.assertIsNotNone(fc_id)
vnf_1 = {'name': 'test_delete_chain_vnf_1',
'connection_points': [uuid.uuid4(), uuid.uuid4()]}
'connection_points': [uuidutils.generate_uuid(),
uuidutils.generate_uuid()]}
vnf_2 = {'name': 'test_delete_chain_vnf_2',
'connection_points': [uuid.uuid4(), uuid.uuid4()]}
'connection_points': [uuidutils.generate_uuid(),
uuidutils.generate_uuid()]}
vnf_3 = {'name': 'test_delete_chain_vnf_3',
'connection_points': [uuid.uuid4(), uuid.uuid4()]}
'connection_points': [uuidutils.generate_uuid(),
uuidutils.generate_uuid()]}
vnfs = [vnf_1, vnf_2, vnf_3]
chain_id = self.sfc_driver.create_chain(name='fake_ffg',

View File

@ -17,10 +17,10 @@ import codecs
from datetime import datetime
import mock
import os
import uuid
from mock import patch
from oslo_utils import uuidutils
from tacker import context
from tacker.db.common_services import common_services_db_plugin
@ -57,7 +57,7 @@ class FakeDriverManager(mock.Mock):
def invoke(self, *args, **kwargs):
if any(x in ['create', 'create_chain', 'create_flow_classifier'] for
x in args):
return str(uuid.uuid4())
return uuidutils.generate_uuid()
elif 'execute_workflow' in args:
mock_execution = mock.Mock()
mock_execution.id.return_value = \
@ -673,7 +673,7 @@ class TestNfvoPlugin(db_base.SqlTestCase):
session.add(nsd_template)
for (key, value) in attributes.items():
attribute_db = ns_db.NSDAttribute(
id=str(uuid.uuid4()),
id=uuidutils.generate_uuid(),
nsd_id='eb094833-995e-49f0-a047-dfb56aaf7c4e',
key=key,
value=value)

View File

@ -14,10 +14,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
@ -103,7 +102,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

@ -14,10 +14,10 @@
# under the License.
from datetime import datetime
import uuid
import mock
from mock import patch
from oslo_utils import uuidutils
import yaml
from tacker import context
@ -34,12 +34,12 @@ from tacker.vnfm import plugin
class FakeDriverManager(mock.Mock):
def invoke(self, *args, **kwargs):
if 'create' in args:
return str(uuid.uuid4())
return uuidutils.generate_uuid()
if 'get_resource_info' in args:
return {'resources': {'name': 'dummy_vnf',
'type': 'dummy',
'id': str(uuid.uuid4())}}
'id': uuidutils.generate_uuid()}}
class FakeVNFMonitor(mock.Mock):

View File

@ -15,9 +15,8 @@
# under the License.
# TODO(yamahata): once unittests are impletemted, move this there
import uuid
from oslo_log import log as logging
from oslo_utils import uuidutils
from tacker.common import log
from tacker.vnfm.infra_drivers import abstract_driver
@ -45,7 +44,7 @@ class DeviceNoop(abstract_driver.DeviceAbstractDriver):
@log.log
def create(self, **kwargs):
instance_id = str(uuid.uuid4())
instance_id = uuidutils.generate_uuid()
self._instances.add(instance_id)
return instance_id
@ -73,4 +72,4 @@ class DeviceNoop(abstract_driver.DeviceAbstractDriver):
def get_resource_info(self, plugin, context, vnf_info, auth_attr,
region_name=None):
return {'noop': {'id': str(uuid.uuid4()), 'type': 'noop'}}
return {'noop': {'id': uuidutils.generate_uuid(), 'type': 'noop'}}