Merge "Replaces uuid.uuid4 with uuidutils.generate_uuid()"

This commit is contained in:
Jenkins 2017-07-14 19:23:36 +00:00 committed by Gerrit Code Review
commit 75e865e956
16 changed files with 66 additions and 55 deletions

View File

@ -22,6 +22,7 @@ import mimetypes
import uuid
from oslo_log import log
from oslo_utils import uuidutils
import pecan
import six
from six.moves.urllib import parse
@ -182,7 +183,7 @@ def get_class_for(module_name, class_name):
def generate_uuid():
return str(uuid.uuid4())
return uuidutils.generate_uuid()
def is_multiple_backends_enabled():

View File

@ -24,11 +24,11 @@ import logging
import re
import sys
import time
import uuid
from oslo_db import exception as db_exc
from oslo_db.sqlalchemy import session
from oslo_utils import timeutils
from oslo_utils import uuidutils
import sqlalchemy
from sqlalchemy import func as sa_func
from sqlalchemy import or_
@ -979,7 +979,7 @@ class KEKDatumRepo(BaseRepo):
kek_datum = models.KEKDatum()
kek_datum.kek_label = "project-{0}-key-{1}".format(
project.external_id, uuid.uuid4())
project.external_id, uuidutils.generate_uuid())
kek_datum.project_id = project.id
kek_datum.plugin_name = plugin_name
kek_datum.status = models.States.ACTIVE

View File

@ -17,7 +17,7 @@ import base64
import copy
import datetime
import os
import uuid
from oslo_utils import uuidutils
from Crypto.PublicKey import RSA
from Crypto.Util import asn1
@ -202,7 +202,7 @@ class DogtagKRAPlugin(sstore.SecretStoreBase):
the key_id
"""
data_type = key.KeyClient.PASS_PHRASE_TYPE
client_key_id = uuid.uuid4().hex
client_key_id = uuidutils.generate_uuid(dashed=False)
if secret_dto.transport_key is not None:
# TODO(alee-3) send the transport key with the archival request
# once the Dogtag Client API changes.
@ -380,7 +380,7 @@ class DogtagKRAPlugin(sstore.SecretStoreBase):
usages = [key.SymKeyGenerationRequest.DECRYPT_USAGE,
key.SymKeyGenerationRequest.ENCRYPT_USAGE]
client_key_id = uuid.uuid4().hex
client_key_id = uuidutils.generate_uuid()
algorithm = self._map_algorithm(key_spec.alg.lower())
if algorithm is None:
@ -420,7 +420,7 @@ class DogtagKRAPlugin(sstore.SecretStoreBase):
usages = [key.AsymKeyGenerationRequest.DECRYPT_USAGE,
key.AsymKeyGenerationRequest.ENCRYPT_USAGE]
client_key_id = uuid.uuid4().hex
client_key_id = uuidutils.generate_uuid()
algorithm = self._map_algorithm(key_spec.alg.lower())
passphrase = key_spec.passphrase
@ -437,7 +437,7 @@ class DogtagKRAPlugin(sstore.SecretStoreBase):
)
stored_passphrase_info = self.keyclient.archive_key(
uuid.uuid4().hex,
uuidutils.generate_uuid(),
self.keyclient.PASS_PHRASE_TYPE,
base64.b64encode(passphrase))

View File

@ -24,6 +24,7 @@ import uuid
from OpenSSL import crypto
from oslo_config import cfg
from oslo_utils import fnmatch
from oslo_utils import uuidutils
from barbican.common import config
from barbican.common import utils
@ -415,7 +416,7 @@ class SnakeoilCACertificatePlugin(cert_manager.CertificatePluginBase):
"Invalid parent id passed to snake oil plugin:" + parent_ca_id)
# create a new ca, passing in key and issuer from the parent
new_ca_id = str(uuid.uuid4())
new_ca_id = uuidutils.generate_uuid()
new_cert_path = os.path.join(self.subca_directory, new_ca_id + ".cert")
new_key_path = os.path.join(self.subca_directory, new_ca_id + ".key")
new_chain_path = os.path.join(self.subca_directory,

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import uuid
from oslo_utils import uuidutils
from barbican.api.controllers import acls
from barbican.model import repositories
@ -209,7 +209,7 @@ class WhenTestingSecretACLsResource(utils.BarbicanAPIBaseTestCase,
read_user_ids=['u1', 'u3', 'u4'])
resp = self.app.get(
'/secrets/{0}/acl'.format(uuid.uuid4().hex),
'/secrets/{0}/acl'.format(uuidutils.generate_uuid(dashed=False)),
expect_errors=True)
self.assertEqual(404, resp.status_int)
@ -679,7 +679,7 @@ class WhenTestingContainerAclsResource(utils.BarbicanAPIBaseTestCase,
read_project_access=True)
resp = self.app.get(
'/containers/{0}/acl'.format(uuid.uuid4().hex),
'/containers/{0}/acl'.format(uuidutils.generate_uuid()),
expect_errors=True)
self.assertEqual(404, resp.status_int)

View File

@ -23,6 +23,7 @@ from barbican.model import repositories
from barbican.tests.api.controllers import test_acls
from barbican.tests.api import test_resources_policy as test_policy
from barbican.tests import utils
from oslo_utils import uuidutils
order_repo = repositories.get_order_repository()
@ -189,7 +190,7 @@ class WhenGettingOrDeletingOrders(utils.BarbicanAPIBaseTestCase):
self.assertEqual(204, delete_resp.status_int)
def test_get_call_on_non_existant_order_should_give_404(self):
bogus_uuid = uuid.uuid4()
bogus_uuid = uuidutils.generate_uuid()
resp = self.app.get(
'/orders/{0}'.format(bogus_uuid),
expect_errors=True
@ -204,7 +205,7 @@ class WhenGettingOrDeletingOrders(utils.BarbicanAPIBaseTestCase):
self.assertEqual(404, resp.status_int)
def test_delete_call_on_non_existant_order_should_give_404(self):
bogus_uuid = uuid.uuid4()
bogus_uuid = uuidutils.generate_uuid()
resp = self.app.delete(
'/orders/{0}'.format(bogus_uuid),
expect_errors=True

View File

@ -15,7 +15,7 @@
import json
import mock
import os
import uuid
from oslo_utils import uuidutils
from barbican.tests import utils
@ -61,7 +61,8 @@ class WhenTestingSecretMetadataResource(utils.BarbicanAPIBaseTestCase):
self.valid_metadata,
secret_resp)
get_resp = self.app.get('/secrets/%s/metadata' % uuid.uuid4().hex,
get_resp = self.app.get('/secrets/%s/metadata' %
uuidutils.generate_uuid(dashed=False),
expect_errors=True)
self.assertEqual(404, get_resp.status_int)

View File

@ -13,7 +13,7 @@
# under the License.
import mock
import uuid
from oslo_utils import uuidutils
from barbican.model import models
from barbican.model import repositories as repos
@ -27,7 +27,8 @@ class SecretStoresMixin(utils.MultipleBackendsTestCase):
session = repos.get_project_repository().get_session()
project = models.Project()
project.external_id = "keystone_project_id" + uuid.uuid4().hex
project.external_id = ("keystone_project_id" +
uuidutils.generate_uuid(dashed=False))
project.save(session=session)
return project
@ -254,7 +255,7 @@ class WhenTestingProjectSecretStore(utils.BarbicanAPIBaseTestCase,
stores = self.secret_store_repo.get_all()
proj_external_id = uuid.uuid4().hex
proj_external_id = uuidutils.generate_uuid(dashed=False)
# get ids as secret store are not bound to session after a rest call.
store_ids = [store.id for store in stores]
for store_id in store_ids:
@ -275,7 +276,7 @@ class WhenTestingProjectSecretStore(utils.BarbicanAPIBaseTestCase,
stores = self.secret_store_repo.get_all()
proj_external_id = uuid.uuid4().hex
proj_external_id = uuidutils.generate_uuid(dashed=False)
# get ids as secret store are not bound to session after a rest call.
store_ids = [store.id for store in stores]
for store_id in store_ids:
@ -300,7 +301,7 @@ class WhenTestingProjectSecretStore(utils.BarbicanAPIBaseTestCase,
self._init_multiple_backends()
stores = self.secret_store_repo.get_all()
proj_external_id = uuid.uuid4().hex
proj_external_id = uuidutils.generate_uuid(dashed=False)
self.app.extra_environ = {
'barbican.context': self._build_context(proj_external_id)
}
@ -314,7 +315,7 @@ class WhenTestingProjectSecretStore(utils.BarbicanAPIBaseTestCase,
secret_stores = self.secret_store_repo.get_all()
store_id = secret_stores[0].id
proj_external_id = uuid.uuid4().hex
proj_external_id = uuidutils.generate_uuid(dashed=False)
self.app.extra_environ = {
'barbican.context': self._build_context(proj_external_id)

View File

@ -9,7 +9,7 @@
# 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 uuid
from oslo_utils import uuidutils
from barbican.common import exception
from barbican.model import models
@ -205,7 +205,8 @@ class WhenTestingProjectSecretStoreRepo(database_utils.RepositoryTestCase):
session = self.proj_store_repo.get_session()
project = models.Project()
project.external_id = "keystone_project_id" + uuid.uuid4().hex
project.external_id = ("keystone_project_id" +
uuidutils.generate_uuid(dashed=False))
project.save(session=session)
return project
@ -359,7 +360,8 @@ class WhenTestingProjectSecretStoreRepo(database_utils.RepositoryTestCase):
self.assertIsNone(returned_value)
def test_get_project_entities(self):
entities = self.proj_store_repo.get_project_entities(uuid.uuid4().hex)
entities = self.proj_store_repo.get_project_entities(
uuidutils.generate_uuid(dashed=False))
self.assertEqual([], entities)
def test_create_or_update_for_project(self):

View File

@ -15,7 +15,7 @@
import collections
import mock
import uuid
from oslo_utils import uuidutils
from barbican.common import config
from barbican.common import exception
@ -319,7 +319,7 @@ class TestGetApplicablePlugins(test_utils.MultipleBackendsTestCase):
cr_plugins = ['cr_p1', 'cr_p2', 'cr_p3']
self.init_via_conf_file(ss_plugins, cr_plugins, enabled=True)
ss_manager = MockedManager(ss_plugins)
project_id = uuid.uuid4().hex
project_id = uuidutils.generate_uuid(dashed=False)
with mock.patch('barbican.model.repositories.ProjectSecretStoreRepo.'
'get_secret_store_for_project') as pref_func:
@ -343,7 +343,7 @@ class TestGetApplicablePlugins(test_utils.MultipleBackendsTestCase):
self.init_via_conf_file(ss_plugins, cr_plugins, enabled=True)
ss_manager = MockedManager(ss_plugins)
project_id = uuid.uuid4().hex
project_id = uuidutils.generate_uuid(dashed=False)
with mock.patch('barbican.model.repositories.ProjectSecretStoreRepo.'
'get_secret_store_for_project') as pref_func:
@ -367,7 +367,7 @@ class TestGetApplicablePlugins(test_utils.MultipleBackendsTestCase):
global_default_index=1)
cr_manager = MockedManager(cr_plugins,
plugin_lookup_field='crypto_plugin')
project_id = uuid.uuid4().hex
project_id = uuidutils.generate_uuid(dashed=False)
with mock.patch('barbican.plugin.util.multiple_backends.'
'get_global_default_secret_store') as gd_func:
@ -441,7 +441,8 @@ class TestPluginsGenerateStoreAPIMultipleBackend(
session = repositories.get_project_repository().get_session()
project = models.Project()
project.external_id = "keystone_project_id" + uuid.uuid4().hex
project.external_id = ("keystone_project_id" +
uuidutils.generate_uuid(dashed=False))
project.save(session=session)
return project

View File

@ -12,7 +12,7 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import uuid
from oslo_utils import uuidutils
import mock
import oslo_messaging
@ -64,7 +64,8 @@ class WhenUsingNotificationTask(UtilMixin, utils.BaseTestCase):
super(WhenUsingNotificationTask, self).setUp()
self.task = keystone_listener.NotificationTask(self.conf)
self.payload = {'resource_info': uuid.uuid4().hex}
self.payload = {'resource_info': uuidutils.generate_uuid(
dashed=False)}
self.type_index = 2
self.payload_index = 3
@ -101,7 +102,7 @@ class WhenUsingNotificationTask(UtilMixin, utils.BaseTestCase):
def test_delete_project_event_notification_with_required_data(
self, mock_process):
project_id = uuid.uuid4().hex
project_id = uuidutils.generate_uuid(dashed=False)
self.task_args[self.type_index] = 'identity.project.deleted'
self.task_args[self.payload_index] = {'resource_info': project_id}
result = self.task.info(*self.task_args)
@ -115,7 +116,7 @@ class WhenUsingNotificationTask(UtilMixin, utils.BaseTestCase):
def test_delete_project_event_with_different_service_name_in_event_type(
self, mock_process):
project_id = uuid.uuid4().hex
project_id = uuidutils.generate_uuid(dashed=False)
self.task_args[self.type_index] = 'aaa.project.deleted'
self.task_args[self.payload_index] = {'resource_info': project_id}
result = self.task.info(*self.task_args)
@ -130,7 +131,7 @@ class WhenUsingNotificationTask(UtilMixin, utils.BaseTestCase):
def test_delete_project_event_with_event_type_in_different_case(
self, mock_process):
project_id = uuid.uuid4().hex
project_id = uuidutils.generate_uuid(dashed=False)
self.task_args[self.type_index] = 'Identity.PROJECT.DeleteD'
self.task_args[self.payload_index] = {'resource_info': project_id}
result = self.task.info(*self.task_args)
@ -145,7 +146,7 @@ class WhenUsingNotificationTask(UtilMixin, utils.BaseTestCase):
def test_delete_project_event_with_incomplete_event_type_format(
self, mock_process):
project_id = uuid.uuid4().hex
project_id = uuidutils.generate_uuid(dashed=False)
self.task_args[self.type_index] = 'project.deleted'
self.task_args[self.payload_index] = {'resource_info': project_id}
result = self.task.info(*self.task_args)
@ -200,7 +201,7 @@ class WhenUsingNotificationTask(UtilMixin, utils.BaseTestCase):
return_value=None)
def test_event_notification_with_missing_event_type(self, mock_process):
project_id = uuid.uuid4().hex
project_id = uuidutils.generate_uuid(dashed=False)
self.task_args[self.type_index] = None
self.task_args[self.payload_index] = {'resource_info': project_id}
result = self.task.info(*self.task_args)
@ -214,7 +215,7 @@ class WhenUsingNotificationTask(UtilMixin, utils.BaseTestCase):
return_value=None)
def test_event_notification_with_blank_event_type(self, mock_process):
project_id = uuid.uuid4().hex
project_id = uuidutils.generate_uuid(dashed=False)
self.task_args[self.type_index] = ''
self.task_args[self.payload_index] = {'resource_info': project_id}
result = self.task.info(*self.task_args)
@ -232,7 +233,7 @@ class WhenUsingNotificationTask(UtilMixin, utils.BaseTestCase):
local_task = keystone_listener.NotificationTask(self.conf)
mock_process.side_effect = Exception('Dummy Error')
project_id = uuid.uuid4().hex
project_id = uuidutils.generate_uuid(dashed=False)
self.task_args[self.type_index] = 'identity.project.deleted'
self.task_args[self.payload_index] = {'resource_info': project_id}
result = local_task.info(*self.task_args)
@ -249,7 +250,7 @@ class WhenUsingNotificationTask(UtilMixin, utils.BaseTestCase):
local_task = keystone_listener.NotificationTask(self.conf)
mock_process.side_effect = Exception('Dummy Error')
project_id = uuid.uuid4().hex
project_id = uuidutils.generate_uuid(dashed=False)
self.task_args[self.type_index] = 'identity.project.deleted'
self.task_args[self.payload_index] = {'resource_info': project_id}
result = local_task.info(*self.task_args)

View File

@ -12,7 +12,6 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import uuid
import mock
import sqlalchemy
@ -25,6 +24,7 @@ from barbican.plugin.crypto import manager
from barbican.plugin import resources as plugin
from barbican.tasks import keystone_consumer as consumer
from barbican.tests import database_utils
from oslo_utils import uuidutils
class InitializeDatabaseMixin(object):
@ -37,8 +37,8 @@ class InitializeDatabaseMixin(object):
['simple_crypto'],
group='crypto')
self.project_id1 = uuid.uuid4().hex
self.project_id2 = uuid.uuid4().hex
self.project_id1 = uuidutils.generate_uuid()
self.project_id2 = uuidutils.generate_uuid(dashed=False)
self.project1_data = c_resources.get_or_create_project(
self.project_id1)
@ -50,8 +50,8 @@ class InitializeDatabaseMixin(object):
def _create_secret_for_project(self, project_data):
secret_info = {"name": uuid.uuid4().hex, "algorithm": "aes",
"bit_length": 256, "mode": "cbc",
secret_info = {"name": uuidutils.generate_uuid(dashed=False),
"algorithm": "aes", "bit_length": 256, "mode": "cbc",
"payload_content_type": "application/octet-stream"}
new_secret = plugin.generate_secret(
secret_info, secret_info.get('payload_content_type'), project_data)

View File

@ -19,10 +19,10 @@ import os
from os import path
import time
import types
import uuid
import mock
from oslo_config import cfg
from oslo_utils import uuidutils
import oslotest.base as oslotest
from oslotest import createfile
@ -642,7 +642,7 @@ def generate_test_uuid(tail_value=0):
def generate_test_valid_uuid():
"""Returns a valid uuid value, similar to uuid generated in barbican"""
return str(uuid.uuid4())
return uuidutils.generate_uuid()
def get_symmetric_key():

View File

@ -17,7 +17,7 @@ import abc
import fixtures
import logging
import os
import uuid
from oslo_utils import uuidutils
import oslotest.base as oslotest
import six
@ -99,7 +99,7 @@ class PagingTestCase(TestCase):
super(PagingTestCase, self).tearDown()
def _set_filter_field(self, model):
filter = str(uuid.uuid4())
filter = uuidutils.generate_uuid()
self.set_filter_field(filter, model)
return filter

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import uuid
from oslo_utils import uuidutils
from barbican.tests import utils
from functionaltests.api import base
@ -143,7 +143,7 @@ class RBACQuotasTestCase(base.TestCase):
"""
request_model = quota_models.ProjectQuotaRequestModel(
**get_set_project_quotas_request())
project_id = str(uuid.uuid4())
project_id = uuidutils.generate_uuid()
resp = self.behaviors.set_project_quotas(project_id,
request_model,
user_name=user)
@ -162,7 +162,7 @@ class RBACQuotasTestCase(base.TestCase):
"""
request_model = quota_models.ProjectQuotaRequestModel(
**get_set_project_quotas_request())
project_id = str(uuid.uuid4())
project_id = uuidutils.generate_uuid()
resp = self.behaviors.set_project_quotas(project_id,
request_model,
user_name=service_admin)

View File

@ -14,13 +14,13 @@
# limitations under the License.
from oslo_serialization import jsonutils
from testtools import testcase
import uuid
from barbican.tests import utils
from functionaltests.api import base
from functionaltests.api.v1.behaviors import secret_behaviors
from functionaltests.api.v1.behaviors import secretmeta_behaviors
from functionaltests.api.v1.models import secret_models
from oslo_utils import uuidutils
@utils.parameterized_test_case
@ -82,7 +82,8 @@ class SecretMetadataTestCase(base.TestCase):
@testcase.attr('negative')
def test_secret_metadata_create_no_secret(self):
secret_ref = 'http://localhost:9311/secrets/%s' % uuid.uuid4().hex
secret_ref = ('http://localhost:9311/secrets/%s' %
uuidutils.generate_uuid(dashed=False))
meta_resp, metadata_ref = self.behaviors.create_or_update_metadata(
secret_ref, self.invalid_metadata)
@ -110,7 +111,8 @@ class SecretMetadataTestCase(base.TestCase):
@testcase.attr('negative')
def test_secret_metadata_get_no_secret(self):
secret_ref = 'http://localhost:9311/secrets/%s' % uuid.uuid4().hex
secret_ref = ('http://localhost:9311/secrets/%s' %
uuidutils.generate_uuid(dashed=False))
get_resp = self.behaviors.get_metadata(secret_ref)
self.assertEqual(404, get_resp.status_code)