Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
Replaces uuid.uuid4 with uuidutils.generate_uuid()
Browse files Browse the repository at this point in the history
Openstack common has a wrapper for generating uuids.
We should only use that function when generating uuids for consistency.

Closes-bug: #1082248

Change-Id: I6132550fd638b4e386d3bd0a844239fddb55d36a
  • Loading branch information
melissaml committed Nov 11, 2016
1 parent 7fdb72a commit f78bf80
Show file tree
Hide file tree
Showing 22 changed files with 64 additions and 67 deletions.
6 changes: 2 additions & 4 deletions solum/api/controllers/camp/v1_1/plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.


import uuid

import jsonpatch
from oslo_db import exception as db_exc
from oslo_utils import uuidutils
import pecan
from pecan import rest
import six
Expand Down Expand Up @@ -203,7 +201,7 @@ def post(self):
# if the inline service spec doesn't have an id
# generate one
if s_spec.id == wsme.Unset:
s_spec.id = str(uuid.uuid4())
s_spec.id = uuidutils.generate_uuid()

# move the inline service spec to the 'services'
# section
Expand Down
5 changes: 2 additions & 3 deletions solum/api/controllers/v1/datamodel/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.

import uuid

from oslo_utils import uuidutils
import six
import wsme
from wsme.rest import json as wjson
Expand Down Expand Up @@ -128,7 +127,7 @@ def sample(cls):
'artifact_type': 'git_pull',
'content': {'href': 'git://example.com/project.git',
'private': False},
'language_pack': str(uuid.uuid4()),
'language_pack': uuidutils.generate_uuid(),
'requirements': [{
'requirement_type': 'git_pull',
'fulfillment': 'id:build'}]}],
Expand Down
6 changes: 3 additions & 3 deletions solum/api/handlers/app_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# under the License.

from oslo_log import log as logging
from oslo_utils import uuidutils

import json
import uuid

from solum.api.handlers import common
from solum.api.handlers import handler
Expand Down Expand Up @@ -75,7 +75,7 @@ def delete(self, id):
def create(self, data):
"""Create a new app."""
db_obj = objects.registry.App()
db_obj.id = str(uuid.uuid4())
db_obj.id = uuidutils.generate_uuid()
db_obj.user_id = self.context.user
db_obj.project_id = self.context.tenant
db_obj.deleted = False
Expand All @@ -92,7 +92,7 @@ def create(self, data):
db_obj.ports = data.get('ports')
db_obj.source = data.get('source')
db_obj.workflow_config = data.get('workflow_config')
db_obj.trigger_uuid = str(uuid.uuid4())
db_obj.trigger_uuid = uuidutils.generate_uuid()
db_obj.trigger_actions = data.get('trigger_actions')

raw_content = data.get('raw_content')
Expand Down
7 changes: 3 additions & 4 deletions solum/api/handlers/assembly_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.

import uuid

from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import uuidutils

from solum.api.handlers import handler
from solum.common import exception
Expand Down Expand Up @@ -112,7 +111,7 @@ def create(self, data, commit_sha='', status_url=None):
data['workflow'] = ['unittest', 'build', 'deploy']
db_obj = objects.registry.Assembly()
db_obj.update(data)
db_obj.uuid = str(uuid.uuid4())
db_obj.uuid = uuidutils.generate_uuid()
db_obj.user_id = self.context.user
db_obj.project_id = self.context.tenant
db_obj.username = self.context.user_name
Expand Down Expand Up @@ -142,7 +141,7 @@ def _build_artifact(self, assem, artifact, verb='launch_workflow',
image.source_format = artifact.get('artifact_type',
CONF.api.source_format)
image.image_format = CONF.api.image_format
image.uuid = str(uuid.uuid4())
image.uuid = uuidutils.generate_uuid()
image.user_id = self.context.user
image.project_id = self.context.tenant
image.status = IMAGE_STATES.QUEUED
Expand Down
6 changes: 3 additions & 3 deletions solum/api/handlers/camp/assembly_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.

import uuid
from oslo_utils import uuidutils

from solum.api.handlers import assembly_handler as solum_assem_handler
from solum import objects
Expand All @@ -22,10 +22,10 @@ class AssemblyHandler(solum_assem_handler.AssemblyHandler):
def create_from_plan(self, plan_obj):
"""Create an application using a plan resource as a template."""
db_obj = objects.registry.Assembly()
db_obj.uuid = str(uuid.uuid4())
db_obj.uuid = uuidutils.generate_uuid()
db_obj.user_id = self.context.user
db_obj.project_id = self.context.tenant
db_obj.trigger_id = str(uuid.uuid4())
db_obj.trigger_id = uuidutils.generate_uuid()
db_obj.username = self.context.user_name

# use the plan name as the name of this application
Expand Down
4 changes: 2 additions & 2 deletions solum/api/handlers/component_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.

import uuid
from oslo_utils import uuidutils

from solum.api.handlers import handler
from solum import objects
Expand All @@ -39,7 +39,7 @@ def delete(self, id):
def create(self, data):
"""Create a new resource."""
db_obj = objects.registry.Component()
db_obj.uuid = str(uuid.uuid4())
db_obj.uuid = uuidutils.generate_uuid()
db_obj.update(data)
db_obj.user_id = self.context.user
db_obj.project_id = self.context.tenant
Expand Down
4 changes: 2 additions & 2 deletions solum/api/handlers/extension_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.

import uuid
from oslo_utils import uuidutils

from solum.api.handlers import handler
from solum import objects
Expand Down Expand Up @@ -38,7 +38,7 @@ def create(self, data):
"""Create a new extension."""
db_obj = objects.registry.Extension()
db_obj.update(data)
db_obj.uuid = str(uuid.uuid4())
db_obj.uuid = uuidutils.generate_uuid()
db_obj.user_id = self.context.user
db_obj.project_id = self.context.tenant
db_obj.create(self.context)
Expand Down
4 changes: 2 additions & 2 deletions solum/api/handlers/infrastructure_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.

import uuid
from oslo_utils import uuidutils

from solum.api.handlers import handler
from solum.common import catalog
Expand Down Expand Up @@ -48,7 +48,7 @@ def create(self, data):
"""
db_obj = objects.registry.InfrastructureStack()
db_obj.update(data)
db_obj.uuid = str(uuid.uuid4())
db_obj.uuid = uuidutils.generate_uuid()
db_obj.user_id = self.context.user
db_obj.project_id = self.context.tenant

Expand Down
5 changes: 2 additions & 3 deletions solum/api/handlers/language_pack_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.

import uuid

from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import uuidutils
from swiftclient import exceptions as swiftexp

from solum.api.handlers import common
Expand Down Expand Up @@ -109,7 +108,7 @@ def create(self, data, lp_metadata, lp_params):
except exc.ResourceNotFound:
db_obj = objects.registry.Image()
db_obj.update(data)
db_obj.uuid = str(uuid.uuid4())
db_obj.uuid = uuidutils.generate_uuid()
db_obj.user_id = self.context.user
db_obj.project_id = self.context.tenant
db_obj.status = image.States.QUEUED
Expand Down
4 changes: 2 additions & 2 deletions solum/api/handlers/operation_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.

import uuid
from oslo_utils import uuidutils

from solum.api.handlers import handler
from solum import objects
Expand Down Expand Up @@ -38,7 +38,7 @@ def create(self, data):
"""Create a new operation."""
db_obj = objects.registry.Operation()
db_obj.update(data)
db_obj.uuid = str(uuid.uuid4())
db_obj.uuid = uuidutils.generate_uuid()
db_obj.create(self.context)
return db_obj

Expand Down
6 changes: 3 additions & 3 deletions solum/api/handlers/pipeline_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# under the License.

import json
import uuid

from mistralclient.api import base
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import uuidutils

from solum.api.handlers import handler
from solum.common import catalog
Expand Down Expand Up @@ -196,10 +196,10 @@ def create(self, data):
"""Create a new resource."""
db_obj = objects.registry.Pipeline()
db_obj.update(data)
db_obj.uuid = str(uuid.uuid4())
db_obj.uuid = uuidutils.generate_uuid()
db_obj.user_id = self.context.user
db_obj.project_id = self.context.tenant
db_obj.trigger_id = str(uuid.uuid4())
db_obj.trigger_id = uuidutils.generate_uuid()

# create the trust_id and store it.
trust_context = self._clients.keystone().create_trust_context()
Expand Down
6 changes: 3 additions & 3 deletions solum/api/handlers/plan_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import errno
import os
import shelve
import uuid

from Crypto.PublicKey import RSA
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import uuidutils

from solum.api.handlers import assembly_handler
from solum.api.handlers import handler
Expand Down Expand Up @@ -96,10 +96,10 @@ def create(self, data):
db_obj = objects.registry.Plan()
if 'name' in data:
db_obj.name = data['name']
db_obj.uuid = str(uuid.uuid4())
db_obj.uuid = uuidutils.generate_uuid()
db_obj.user_id = self.context.user
db_obj.project_id = self.context.tenant
db_obj.trigger_id = str(uuid.uuid4())
db_obj.trigger_id = uuidutils.generate_uuid()

# create a delegation trust_id\token, if required
db_obj.trust_id = keystone_utils.create_delegation_token(self.context)
Expand Down
4 changes: 2 additions & 2 deletions solum/api/handlers/sensor_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.

import uuid
from oslo_utils import uuidutils

from solum.api.handlers import handler
from solum import objects
Expand Down Expand Up @@ -38,7 +38,7 @@ def create(self, data):
"""Create a new sensor."""
db_obj = objects.registry.Sensor()
db_obj.update(data)
db_obj.uuid = str(uuid.uuid4())
db_obj.uuid = uuidutils.generate_uuid()
db_obj.user_id = self.context.user
db_obj.project_id = self.context.tenant
db_obj.create(self.context)
Expand Down
4 changes: 2 additions & 2 deletions solum/api/handlers/service_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.

import uuid
from oslo_utils import uuidutils

from solum.api.handlers import handler
from solum import objects
Expand Down Expand Up @@ -40,7 +40,7 @@ def create(self, data):
"""Create a new resource."""
db_obj = objects.registry.Service()
db_obj.update(data)
db_obj.uuid = str(uuid.uuid4())
db_obj.uuid = uuidutils.generate_uuid()
db_obj.user_id = self.context.user
db_obj.project_id = self.context.tenant
db_obj.create(self.context)
Expand Down
8 changes: 4 additions & 4 deletions solum/api/handlers/workflow_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

import datetime
import json
import uuid

from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import uuidutils

from solum.api.handlers import handler
from solum.common import exception
Expand Down Expand Up @@ -114,7 +114,7 @@ def create(self, data, commit_sha, status_url, du_id):
"""Create a new workflow."""

db_obj = objects.registry.Workflow()
db_obj.id = str(uuid.uuid4())
db_obj.id = uuidutils.generate_uuid()
db_obj.user_id = self.context.user
db_obj.project_id = self.context.tenant
db_obj.deleted = False
Expand Down Expand Up @@ -178,7 +178,7 @@ def _execute_workflow_actions(self, wf_obj, app_obj, assem,
image.source_uri = wf_obj.source['repository']
image.base_image_id = app_obj.languagepack
image.image_format = CONF.api.image_format
image.uuid = str(uuid.uuid4())
image.uuid = uuidutils.generate_uuid()
image.user_id = self.context.user
image.project_id = self.context.tenant
image.status = IMAGE_STATES.QUEUED
Expand Down Expand Up @@ -273,7 +273,7 @@ def create_dummies(self):
assembly.user_id = self.context.user
assembly.project_id = self.context.tenant
assembly.name = self.app_obj.name
assembly.uuid = str(uuid.uuid4())
assembly.uuid = uuidutils.generate_uuid()

assembly.workflow = self.wf_obj.actions

Expand Down
6 changes: 3 additions & 3 deletions solum/common/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import collections
import functools
import sys
import uuid

from keystoneclient import exceptions as keystone_exceptions
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import excutils
from oslo_utils import uuidutils
import pecan
import six
import wsme
Expand Down Expand Up @@ -122,7 +122,7 @@ def wrapped(*args, **kw):
if http_error_code >= 500:
# log the error message with its associated
# correlation id
log_correlation_id = str(uuid.uuid4())
log_correlation_id = uuidutils.generate_uuid()
LOG.error("%s:%s", log_correlation_id, str(excp))
# raise a client error with an obfuscated message
func_server_error(log_correlation_id, http_error_code)
Expand Down Expand Up @@ -196,7 +196,7 @@ def wrapped(*args, **kw):
ismapping = isinstance(ret, collections.Mapping)
if (pecan.response.status_code >= 500 and ismapping):

log_correlation_id = str(uuid.uuid4())
log_correlation_id = uuidutils.generate_uuid()
LOG.error("%s:%s", log_correlation_id, ret.get("faultstring",
"Unknown Error"))
ret['faultstring'] = six.text_type(OBFUSCATED_MSG %
Expand Down
6 changes: 3 additions & 3 deletions solum/objects/sqlalchemy/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
# License for the specific language governing permissions and limitations
# under the License.

import uuid

import sqlalchemy as sa

from solum import objects
from solum.objects import component as abstract
from solum.objects.sqlalchemy import models as sql

from oslo_utils import uuidutils


class Component(sql.Base, abstract.Component):
"""Represent an component in sqlalchemy."""
Expand Down Expand Up @@ -61,7 +61,7 @@ def assign_and_create(ctxt, assem, name, type, description, resource_uri,
stack_id):
"""Helper function to make creating components easier."""
comp = objects.registry.Component()
comp.uuid = str(uuid.uuid4())
comp.uuid = uuidutils.generate_uuid()
comp.name = name
comp.component_type = type
comp.description = description
Expand Down
Loading

0 comments on commit f78bf80

Please sign in to comment.