Use uuid instead of uuidutils

Each project should directly use the standard uuid module.
uuidutils will be deprecated/removed in this cycle.

This patch replaces every uuidutils.generate_uuid() with
str(uuid.uuid4()) and uuidutils.is_uuid_like()
with utils.is_uuid_like().

Change-Id: I43642d4f1e137c14134b3d544e367b504b9851ac
Closes-Bug: #1253497
This commit is contained in:
Arnaud Legendre 2013-12-06 17:02:35 -08:00
parent 448ef4a899
commit 11b5487eff
35 changed files with 269 additions and 251 deletions

@ -21,7 +21,6 @@ import urllib
import webob.exc import webob.exc
from oslo.config import cfg from oslo.config import cfg
from glance.openstack.common import uuidutils
import glance.db import glance.db
import glance.gateway import glance.gateway
@ -31,6 +30,7 @@ import glance.store
from glance.api import policy from glance.api import policy
from glance.common import wsgi from glance.common import wsgi
from glance.common import exception from glance.common import exception
from glance.common import utils
import glance.openstack.common.jsonutils as json import glance.openstack.common.jsonutils as json
from glance.openstack.common import timeutils from glance.openstack.common import timeutils
@ -131,7 +131,7 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer):
return filters return filters
def _validate_marker(self, marker): def _validate_marker(self, marker):
if marker and not uuidutils.is_uuid_like(marker): if marker and not utils.is_uuid_like(marker):
msg = _('Invalid marker format') msg = _('Invalid marker format')
raise webob.exc.HTTPBadRequest(explanation=msg) raise webob.exc.HTTPBadRequest(explanation=msg)
return marker return marker

@ -524,3 +524,15 @@ def get_test_suite_socket():
os.close(fd) os.close(fd)
return sock return sock
return None return None
def is_uuid_like(val):
"""Returns validation of a value as a UUID.
For our purposes, a UUID is a canonical form string:
aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
"""
try:
return str(uuid.UUID(val)) == val
except (TypeError, ValueError, AttributeError):
return False

@ -15,9 +15,10 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import uuid
from glance.api import policy from glance.api import policy
from glance.openstack.common import local from glance.openstack.common import local
from glance.openstack.common import uuidutils
class RequestContext(object): class RequestContext(object):
@ -37,7 +38,7 @@ class RequestContext(object):
self.read_only = read_only self.read_only = read_only
self._show_deleted = show_deleted self._show_deleted = show_deleted
self.owner_is_tenant = owner_is_tenant self.owner_is_tenant = owner_is_tenant
self.request_id = uuidutils.generate_uuid() self.request_id = str(uuid.uuid4())
self.service_catalog = service_catalog self.service_catalog = service_catalog
self.policy_enforcer = policy_enforcer or policy.Enforcer() self.policy_enforcer = policy_enforcer or policy.Enforcer()
self.is_admin = is_admin self.is_admin = is_admin

@ -16,11 +16,11 @@
import copy import copy
import functools import functools
import uuid
from glance.common import exception from glance.common import exception
import glance.openstack.common.log as logging import glance.openstack.common.log as logging
from glance.openstack.common import timeutils from glance.openstack.common import timeutils
from glance.openstack.common import uuidutils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -87,7 +87,7 @@ def _get_session():
def _image_locations_format(image_id, value, meta_data): def _image_locations_format(image_id, value, meta_data):
dt = timeutils.utcnow() dt = timeutils.utcnow()
return { return {
'id': uuidutils.generate_uuid(), 'id': str(uuid.uuid4()),
'image_id': image_id, 'image_id': image_id,
'created_at': dt, 'created_at': dt,
'updated_at': dt, 'updated_at': dt,
@ -111,7 +111,7 @@ def _image_property_format(image_id, name, value):
def _image_member_format(image_id, tenant_id, can_share, status='pending'): def _image_member_format(image_id, tenant_id, can_share, status='pending'):
dt = timeutils.utcnow() dt = timeutils.utcnow()
return { return {
'id': uuidutils.generate_uuid(), 'id': str(uuid.uuid4()),
'image_id': image_id, 'image_id': image_id,
'member': tenant_id, 'member': tenant_id,
'can_share': can_share, 'can_share': can_share,
@ -510,7 +510,7 @@ def _image_location_get_all(image_id):
@log_call @log_call
def image_create(context, image_values): def image_create(context, image_values):
global DATA global DATA
image_id = image_values.get('id', uuidutils.generate_uuid()) image_id = image_values.get('id', str(uuid.uuid4()))
if image_id in DATA['images']: if image_id in DATA['images']:
raise exception.Duplicate() raise exception.Duplicate()
@ -698,7 +698,7 @@ def task_create(context, values):
global DATA global DATA
task_values = copy.deepcopy(values) task_values = copy.deepcopy(values)
task_id = task_values.get('id', uuidutils.generate_uuid()) task_id = task_values.get('id', str(uuid.uuid4()))
required_attributes = ['type', 'status', 'input'] required_attributes = ['type', 'status', 'input']
allowed_attributes = ['id', 'type', 'status', 'input', 'result', 'owner', allowed_attributes = ['id', 'type', 'status', 'input', 'result', 'owner',
'message', 'expires_at', 'created_at', 'message', 'expires_at', 'created_at',

@ -22,11 +22,11 @@ there are known issues with these libraries so SQLite and non-SQLite
migrations must be done separately. migrations must be done separately.
""" """
import uuid
import migrate import migrate
import sqlalchemy import sqlalchemy
from glance.openstack.common import uuidutils
meta = sqlalchemy.MetaData() meta = sqlalchemy.MetaData()
and_ = sqlalchemy.and_ and_ = sqlalchemy.and_
@ -522,7 +522,7 @@ def _update_all_ids_to_uuids(t_images, t_image_members, t_image_properties):
for image in images: for image in images:
old_id = image["id"] old_id = image["id"]
new_id = uuidutils.generate_uuid() new_id = str(uuid.uuid4())
t_images.update().\ t_images.update().\
where(t_images.c.id == old_id).\ where(t_images.c.id == old_id).\

@ -20,6 +20,7 @@
SQLAlchemy models for glance data SQLAlchemy models for glance data
""" """
import json import json
import uuid
from sqlalchemy import Column, Integer, String, BigInteger from sqlalchemy import Column, Integer, String, BigInteger
from sqlalchemy.ext.compiler import compiles from sqlalchemy.ext.compiler import compiles
@ -31,7 +32,6 @@ from sqlalchemy import Index, UniqueConstraint
from glance.openstack.common.db.sqlalchemy import models from glance.openstack.common.db.sqlalchemy import models
from glance.openstack.common import timeutils from glance.openstack.common import timeutils
from glance.openstack.common import uuidutils
BASE = declarative_base() BASE = declarative_base()
@ -123,7 +123,8 @@ class Image(BASE, GlanceBase):
Index('ix_images_deleted', 'deleted'), Index('ix_images_deleted', 'deleted'),
Index('owner_image_idx', 'owner'),) Index('owner_image_idx', 'owner'),)
id = Column(String(36), primary_key=True, default=uuidutils.generate_uuid) id = Column(String(36), primary_key=True,
default=lambda: str(uuid.uuid4()))
name = Column(String(255)) name = Column(String(255))
disk_format = Column(String(20)) disk_format = Column(String(20))
container_format = Column(String(20)) container_format = Column(String(20))
@ -216,7 +217,8 @@ class Task(BASE, GlanceBase):
Index('ix_tasks_deleted', 'deleted'), Index('ix_tasks_deleted', 'deleted'),
Index('ix_tasks_updated_at', 'updated_at')) Index('ix_tasks_updated_at', 'updated_at'))
id = Column(String(36), primary_key=True, default=uuidutils.generate_uuid) id = Column(String(36), primary_key=True,
default=lambda: str(uuid.uuid4()))
type = Column(String(30)) type = Column(String(30))
status = Column(String(30)) status = Column(String(30))
owner = Column(String(255), nullable=False) owner = Column(String(255), nullable=False)

@ -16,13 +16,13 @@
import collections import collections
import datetime import datetime
import uuid
from oslo.config import cfg from oslo.config import cfg
from glance.common import exception from glance.common import exception
import glance.openstack.common.log as logging import glance.openstack.common.log as logging
from glance.openstack.common import timeutils from glance.openstack.common import timeutils
from glance.openstack.common import uuidutils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -81,7 +81,7 @@ class ImageFactory(object):
self._check_reserved(extra_properties) self._check_reserved(extra_properties)
if image_id is None: if image_id is None:
image_id = uuidutils.generate_uuid() image_id = str(uuid.uuid4())
created_at = timeutils.utcnow() created_at = timeutils.utcnow()
updated_at = created_at updated_at = created_at
status = 'queued' status = 'queued'
@ -338,7 +338,7 @@ class Task(object):
class TaskFactory(object): class TaskFactory(object):
def new_task(self, task_type, task_input, owner): def new_task(self, task_type, task_input, owner):
task_id = uuidutils.generate_uuid() task_id = str(uuid.uuid4())
status = 'pending' status = 'pending'
result = None result = None
message = None message = None

@ -1,39 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (c) 2012 Intel Corporation.
# 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
#
# 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.
"""
UUID related utilities and helper functions.
"""
import uuid
def generate_uuid():
return str(uuid.uuid4())
def is_uuid_like(val):
"""Returns validation of a value as a UUID.
For our purposes, a UUID is a canonical form string:
aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
"""
try:
return str(uuid.UUID(val)) == val
except (TypeError, ValueError, AttributeError):
return False

@ -29,7 +29,6 @@ import glance.db
import glance.openstack.common.log as logging import glance.openstack.common.log as logging
from glance.openstack.common import strutils from glance.openstack.common import strutils
from glance.openstack.common import timeutils from glance.openstack.common import timeutils
from glance.openstack.common import uuidutils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -248,7 +247,7 @@ class Controller(object):
"""Parse a marker query param into something usable.""" """Parse a marker query param into something usable."""
marker = req.params.get('marker', None) marker = req.params.get('marker', None)
if marker and not uuidutils.is_uuid_like(marker): if marker and not utils.is_uuid_like(marker):
msg = _('Invalid marker format') msg = _('Invalid marker format')
raise exc.HTTPBadRequest(explanation=msg) raise exc.HTTPBadRequest(explanation=msg)
@ -376,7 +375,7 @@ class Controller(object):
image_data['owner'] = req.context.owner image_data['owner'] = req.context.owner
image_id = image_data.get('id') image_id = image_data.get('id')
if image_id and not uuidutils.is_uuid_like(image_id): if image_id and not utils.is_uuid_like(image_id):
msg = _("Rejecting image creation request for invalid image " msg = _("Rejecting image creation request for invalid image "
"id '%(bad_id)s'") "id '%(bad_id)s'")
LOG.info(msg % {'bad_id': image_id}) LOG.info(msg % {'bad_id': image_id})

@ -21,9 +21,9 @@ from cinderclient.v2 import client as cinderclient
from oslo.config import cfg from oslo.config import cfg
from glance.common import exception from glance.common import exception
from glance.common import utils
import glance.openstack.common.log as logging import glance.openstack.common.log as logging
from glance.openstack.common import units from glance.openstack.common import units
import glance.openstack.common.uuidutils as uuidutils
import glance.store import glance.store
import glance.store.base import glance.store.base
import glance.store.location import glance.store.location
@ -125,7 +125,7 @@ class StoreLocation(glance.store.location.StoreLocation):
self.scheme = 'cinder' self.scheme = 'cinder'
self.volume_id = uri[9:] self.volume_id = uri[9:]
if not uuidutils.is_uuid_like(self.volume_id): if not utils.is_uuid_like(self.volume_id):
reason = _("URI contains invalid volume ID: %s") % self.volume_id reason = _("URI contains invalid volume ID: %s") % self.volume_id
LOG.error(reason) LOG.error(reason)
raise exception.BadStoreUri(uri, reason) raise exception.BadStoreUri(uri, reason)

@ -29,7 +29,6 @@ from glance.common import utils
from glance import context from glance import context
from glance.openstack.common import lockutils from glance.openstack.common import lockutils
import glance.openstack.common.log as logging import glance.openstack.common.log as logging
import glance.openstack.common.uuidutils as uuidutils
import glance.registry.client.v1.api as registry import glance.registry.client.v1.api as registry
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -214,7 +213,7 @@ class ScrubFileQueue(ScrubQueue):
ret = [] ret = []
for root, dirs, files in os.walk(self.scrubber_datadir): for root, dirs, files in os.walk(self.scrubber_datadir):
for image_id in files: for image_id in files:
if not uuidutils.is_uuid_like(image_id): if not utils.is_uuid_like(image_id):
continue continue
with lockutils.lock("scrubber-%s" % image_id, with lockutils.lock("scrubber-%s" % image_id,
lock_file_prefix='glance-', external=True): lock_file_prefix='glance-', external=True):

@ -24,7 +24,6 @@ import uuid
from glance.common import exception from glance.common import exception
from glance import context from glance import context
from glance.openstack.common import timeutils from glance.openstack.common import timeutils
from glance.openstack.common import uuidutils
import glance.tests.functional.db as db_tests import glance.tests.functional.db as db_tests
from glance.tests import utils as test_utils from glance.tests import utils as test_utils
@ -34,13 +33,13 @@ from glance.tests import utils as test_utils
# we get the default (created_at). Some tests below expect the fixtures to be # we get the default (created_at). Some tests below expect the fixtures to be
# returned in array-order, so if if the created_at timestamps are the same, # returned in array-order, so if if the created_at timestamps are the same,
# these tests rely on the UUID* values being in order # these tests rely on the UUID* values being in order
UUID1, UUID2, UUID3 = sorted([uuidutils.generate_uuid() for x in range(3)]) UUID1, UUID2, UUID3 = sorted([str(uuid.uuid4()) for x in range(3)])
def build_image_fixture(**kwargs): def build_image_fixture(**kwargs):
default_datetime = timeutils.utcnow() default_datetime = timeutils.utcnow()
image = { image = {
'id': uuidutils.generate_uuid(), 'id': str(uuid.uuid4()),
'name': 'fake image #2', 'name': 'fake image #2',
'status': 'active', 'status': 'active',
'disk_format': 'vhd', 'disk_format': 'vhd',
@ -64,11 +63,11 @@ def build_image_fixture(**kwargs):
def build_task_fixture(**kwargs): def build_task_fixture(**kwargs):
default_datetime = timeutils.utcnow() default_datetime = timeutils.utcnow()
task = { task = {
'id': uuidutils.generate_uuid(), 'id': str(uuid.uuid4()),
'type': 'import', 'type': 'import',
'status': 'pending', 'status': 'pending',
'input': {'ping': 'pong'}, 'input': {'ping': 'pong'},
'owner': uuidutils.generate_uuid(), 'owner': str(uuid.uuid4()),
'message': None, 'message': None,
'expires_at': None, 'expires_at': None,
'created_at': default_datetime, 'created_at': default_datetime,
@ -287,8 +286,8 @@ class DriverTests(object):
self.assertEqual(image['id'], self.fixtures[0]['id']) self.assertEqual(image['id'], self.fixtures[0]['id'])
def test_image_get_not_owned(self): def test_image_get_not_owned(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
TENANT2 = uuidutils.generate_uuid() TENANT2 = str(uuid.uuid4())
ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1,
auth_tok='user:%s:user' % TENANT1) auth_tok='user:%s:user' % TENANT1)
ctxt2 = context.RequestContext(is_admin=False, tenant=TENANT2, ctxt2 = context.RequestContext(is_admin=False, tenant=TENANT2,
@ -299,7 +298,7 @@ class DriverTests(object):
self.db_api.image_get, ctxt2, image['id']) self.db_api.image_get, ctxt2, image['id'])
def test_image_get_not_found(self): def test_image_get_not_found(self):
UUID = uuidutils.generate_uuid() UUID = str(uuid.uuid4())
self.assertRaises(exception.NotFound, self.assertRaises(exception.NotFound,
self.db_api.image_get, self.context, UUID) self.db_api.image_get, self.context, UUID)
@ -442,10 +441,10 @@ class DriverTests(object):
Check an image with name null is handled Check an image with name null is handled
marker is specified and order is descending marker is specified and order is descending
""" """
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1,
auth_tok='user:%s:user' % TENANT1) auth_tok='user:%s:user' % TENANT1)
UUIDX = uuidutils.generate_uuid() UUIDX = str(uuid.uuid4())
self.db_api.image_create(ctxt1, {'id': UUIDX, self.db_api.image_create(ctxt1, {'id': UUIDX,
'status': 'queued', 'status': 'queued',
'name': None, 'name': None,
@ -464,10 +463,10 @@ class DriverTests(object):
Check an image with disk_format null is handled when Check an image with disk_format null is handled when
marker is specified and order is descending marker is specified and order is descending
""" """
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1,
auth_tok='user:%s:user' % TENANT1) auth_tok='user:%s:user' % TENANT1)
UUIDX = uuidutils.generate_uuid() UUIDX = str(uuid.uuid4())
self.db_api.image_create(ctxt1, {'id': UUIDX, self.db_api.image_create(ctxt1, {'id': UUIDX,
'status': 'queued', 'status': 'queued',
'disk_format': None, 'disk_format': None,
@ -486,10 +485,10 @@ class DriverTests(object):
Check an image with container_format null is handled when Check an image with container_format null is handled when
marker is specified and order is descending marker is specified and order is descending
""" """
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1,
auth_tok='user:%s:user' % TENANT1) auth_tok='user:%s:user' % TENANT1)
UUIDX = uuidutils.generate_uuid() UUIDX = str(uuid.uuid4())
self.db_api.image_create(ctxt1, {'id': UUIDX, self.db_api.image_create(ctxt1, {'id': UUIDX,
'status': 'queued', 'status': 'queued',
'container_format': None, 'container_format': None,
@ -508,10 +507,10 @@ class DriverTests(object):
Check an image with name null is handled when Check an image with name null is handled when
marker is specified and order is ascending marker is specified and order is ascending
""" """
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1,
auth_tok='user:%s:user' % TENANT1) auth_tok='user:%s:user' % TENANT1)
UUIDX = uuidutils.generate_uuid() UUIDX = str(uuid.uuid4())
self.db_api.image_create(ctxt1, {'id': UUIDX, self.db_api.image_create(ctxt1, {'id': UUIDX,
'status': 'queued', 'status': 'queued',
'name': None, 'name': None,
@ -530,10 +529,10 @@ class DriverTests(object):
Check an image with disk_format null is handled when Check an image with disk_format null is handled when
marker is specified and order is ascending marker is specified and order is ascending
""" """
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1,
auth_tok='user:%s:user' % TENANT1) auth_tok='user:%s:user' % TENANT1)
UUIDX = uuidutils.generate_uuid() UUIDX = str(uuid.uuid4())
self.db_api.image_create(ctxt1, {'id': UUIDX, self.db_api.image_create(ctxt1, {'id': UUIDX,
'status': 'queued', 'status': 'queued',
'disk_format': None, 'disk_format': None,
@ -552,10 +551,10 @@ class DriverTests(object):
Check an image with container_format null is handled when Check an image with container_format null is handled when
marker is specified and order is ascending marker is specified and order is ascending
""" """
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1,
auth_tok='user:%s:user' % TENANT1) auth_tok='user:%s:user' % TENANT1)
UUIDX = uuidutils.generate_uuid() UUIDX = str(uuid.uuid4())
self.db_api.image_create(ctxt1, {'id': UUIDX, self.db_api.image_create(ctxt1, {'id': UUIDX,
'status': 'queued', 'status': 'queued',
'container_format': None, 'container_format': None,
@ -581,19 +580,19 @@ class DriverTests(object):
self.assertEqual(0, len(images)) self.assertEqual(0, len(images))
def test_image_get_all_owned(self): def test_image_get_all_owned(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
ctxt1 = context.RequestContext(is_admin=False, ctxt1 = context.RequestContext(is_admin=False,
tenant=TENANT1, tenant=TENANT1,
auth_tok='user:%s:user' % TENANT1) auth_tok='user:%s:user' % TENANT1)
UUIDX = uuidutils.generate_uuid() UUIDX = str(uuid.uuid4())
image_meta_data = {'id': UUIDX, 'status': 'queued', 'owner': TENANT1} image_meta_data = {'id': UUIDX, 'status': 'queued', 'owner': TENANT1}
self.db_api.image_create(ctxt1, image_meta_data) self.db_api.image_create(ctxt1, image_meta_data)
TENANT2 = uuidutils.generate_uuid() TENANT2 = str(uuid.uuid4())
ctxt2 = context.RequestContext(is_admin=False, ctxt2 = context.RequestContext(is_admin=False,
tenant=TENANT2, tenant=TENANT2,
auth_tok='user:%s:user' % TENANT2) auth_tok='user:%s:user' % TENANT2)
UUIDY = uuidutils.generate_uuid() UUIDY = str(uuid.uuid4())
image_meta_data = {'id': UUIDY, 'status': 'queued', 'owner': TENANT2} image_meta_data = {'id': UUIDY, 'status': 'queued', 'owner': TENANT2}
self.db_api.image_create(ctxt2, image_meta_data) self.db_api.image_create(ctxt2, image_meta_data)
@ -604,11 +603,11 @@ class DriverTests(object):
self.assertEqual(sorted(expected), sorted(image_ids)) self.assertEqual(sorted(expected), sorted(image_ids))
def test_image_get_all_owned_checksum(self): def test_image_get_all_owned_checksum(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
ctxt1 = context.RequestContext(is_admin=False, ctxt1 = context.RequestContext(is_admin=False,
tenant=TENANT1, tenant=TENANT1,
auth_tok='user:%s:user' % TENANT1) auth_tok='user:%s:user' % TENANT1)
UUIDX = uuidutils.generate_uuid() UUIDX = str(uuid.uuid4())
CHECKSUM1 = '91264c3edf5972c9f1cb309543d38a5c' CHECKSUM1 = '91264c3edf5972c9f1cb309543d38a5c'
image_meta_data = { image_meta_data = {
'id': UUIDX, 'id': UUIDX,
@ -625,11 +624,11 @@ class DriverTests(object):
} }
self.db_api.image_member_create(ctxt1, image_member_data) self.db_api.image_member_create(ctxt1, image_member_data)
TENANT2 = uuidutils.generate_uuid() TENANT2 = str(uuid.uuid4())
ctxt2 = context.RequestContext(is_admin=False, ctxt2 = context.RequestContext(is_admin=False,
tenant=TENANT2, tenant=TENANT2,
auth_tok='user:%s:user' % TENANT2) auth_tok='user:%s:user' % TENANT2)
UUIDY = uuidutils.generate_uuid() UUIDY = str(uuid.uuid4())
CHECKSUM2 = '92264c3edf5972c9f1cb309543d38a5c' CHECKSUM2 = '92264c3edf5972c9f1cb309543d38a5c'
image_meta_data = { image_meta_data = {
'id': UUIDY, 'id': UUIDY,
@ -703,7 +702,7 @@ class DriverTests(object):
def test_image_paginate(self): def test_image_paginate(self):
"""Paginate through a list of images using limit and marker""" """Paginate through a list of images using limit and marker"""
extra_uuids = [uuidutils.generate_uuid() for i in range(2)] extra_uuids = [str(uuid.uuid4()) for i in range(2)]
extra_images = [build_image_fixture(id=_id) for _id in extra_uuids] extra_images = [build_image_fixture(id=_id) for _id in extra_uuids]
self.create_images(extra_images) self.create_images(extra_images)
@ -737,7 +736,7 @@ class DriverTests(object):
fixture = {'name': 'ping', 'value': 'pong', 'image_id': IMG_ID} fixture = {'name': 'ping', 'value': 'pong', 'image_id': IMG_ID}
prop = self.db_api.image_property_create(self.context, fixture) prop = self.db_api.image_property_create(self.context, fixture)
TENANT2 = uuidutils.generate_uuid() TENANT2 = str(uuid.uuid4())
fixture = {'image_id': IMG_ID, 'member': TENANT2, 'can_share': False} fixture = {'image_id': IMG_ID, 'member': TENANT2, 'can_share': False}
member = self.db_api.image_member_create(self.context, fixture) member = self.db_api.image_member_create(self.context, fixture)
self.db_api.image_tag_create(self.context, IMG_ID, 'snarf') self.db_api.image_tag_create(self.context, IMG_ID, 'snarf')
@ -774,7 +773,7 @@ class DriverTests(object):
checks if all the image_delete_all methods deletes only the child checks if all the image_delete_all methods deletes only the child
elements of the image to be deleted. elements of the image to be deleted.
""" """
TENANT2 = uuidutils.generate_uuid() TENANT2 = str(uuid.uuid4())
location_data = [{'url': 'a', 'metadata': {'key': 'value'}}, location_data = [{'url': 'a', 'metadata': {'key': 'value'}},
{'url': 'b', 'metadata': {}}] {'url': 'b', 'metadata': {}}]
@ -823,15 +822,15 @@ class DriverTests(object):
self.assertEqual(['snarf'], tags) self.assertEqual(['snarf'], tags)
def test_image_get_multiple_members(self): def test_image_get_multiple_members(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
TENANT2 = uuidutils.generate_uuid() TENANT2 = str(uuid.uuid4())
ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1,
auth_tok='user:%s:user' % TENANT1, auth_tok='user:%s:user' % TENANT1,
owner_is_tenant=True) owner_is_tenant=True)
ctxt2 = context.RequestContext(is_admin=False, user=TENANT2, ctxt2 = context.RequestContext(is_admin=False, user=TENANT2,
auth_tok='user:%s:user' % TENANT2, auth_tok='user:%s:user' % TENANT2,
owner_is_tenant=False) owner_is_tenant=False)
UUIDX = uuidutils.generate_uuid() UUIDX = str(uuid.uuid4())
#we need private image and context.owner should not match image owner #we need private image and context.owner should not match image owner
self.db_api.image_create(ctxt1, {'id': UUIDX, self.db_api.image_create(ctxt1, {'id': UUIDX,
'status': 'queued', 'status': 'queued',
@ -875,15 +874,15 @@ class DriverTests(object):
self.assertEqual(4, len(images)) self.assertEqual(4, len(images))
def test_is_image_visible(self): def test_is_image_visible(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
TENANT2 = uuidutils.generate_uuid() TENANT2 = str(uuid.uuid4())
ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1,
auth_tok='user:%s:user' % TENANT1, auth_tok='user:%s:user' % TENANT1,
owner_is_tenant=True) owner_is_tenant=True)
ctxt2 = context.RequestContext(is_admin=False, user=TENANT2, ctxt2 = context.RequestContext(is_admin=False, user=TENANT2,
auth_tok='user:%s:user' % TENANT2, auth_tok='user:%s:user' % TENANT2,
owner_is_tenant=False) owner_is_tenant=False)
UUIDX = uuidutils.generate_uuid() UUIDX = str(uuid.uuid4())
#we need private image and context.owner should not match image owner #we need private image and context.owner should not match image owner
image = self.db_api.image_create(ctxt1, {'id': UUIDX, image = self.db_api.image_create(ctxt1, {'id': UUIDX,
'status': 'queued', 'status': 'queued',
@ -937,7 +936,7 @@ class DriverTests(object):
self.assertEqual([], actual) self.assertEqual([], actual)
def test_image_tag_get_all_non_existant_image(self): def test_image_tag_get_all_non_existant_image(self):
bad_image_id = uuidutils.generate_uuid() bad_image_id = str(uuid.uuid4())
actual = self.db_api.image_tag_get_all(self.context, bad_image_id) actual = self.db_api.image_tag_get_all(self.context, bad_image_id)
self.assertEqual([], actual) self.assertEqual([], actual)
@ -952,7 +951,7 @@ class DriverTests(object):
memberships = self.db_api.image_member_find(self.context) memberships = self.db_api.image_member_find(self.context)
self.assertEqual([], memberships) self.assertEqual([], memberships)
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
# NOTE(flaper87): Update auth token, otherwise # NOTE(flaper87): Update auth token, otherwise
# non visible members won't be returned. # non visible members won't be returned.
self.context.auth_tok = 'user:%s:user' % TENANT1 self.context.auth_tok = 'user:%s:user' % TENANT1
@ -976,7 +975,7 @@ class DriverTests(object):
self.assertEqual(expected, actual) self.assertEqual(expected, actual)
def test_image_member_update(self): def test_image_member_update(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
# NOTE(flaper87): Update auth token, otherwise # NOTE(flaper87): Update auth token, otherwise
# non visible members won't be returned. # non visible members won't be returned.
@ -1018,7 +1017,7 @@ class DriverTests(object):
self.assertEqual(expected, member) self.assertEqual(expected, member)
def test_image_member_update_status(self): def test_image_member_update_status(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
# NOTE(flaper87): Update auth token, otherwise # NOTE(flaper87): Update auth token, otherwise
# non visible members won't be returned. # non visible members won't be returned.
self.context.auth_tok = 'user:%s:user' % TENANT1 self.context.auth_tok = 'user:%s:user' % TENANT1
@ -1059,8 +1058,8 @@ class DriverTests(object):
self.assertEqual(expected, member) self.assertEqual(expected, member)
def test_image_member_find(self): def test_image_member_find(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
TENANT2 = uuidutils.generate_uuid() TENANT2 = str(uuid.uuid4())
fixtures = [ fixtures = [
{'member': TENANT1, 'image_id': UUID1}, {'member': TENANT1, 'image_id': UUID1},
{'member': TENANT1, 'image_id': UUID2, 'status': 'rejected'}, {'member': TENANT1, 'image_id': UUID2, 'status': 'rejected'},
@ -1114,14 +1113,14 @@ class DriverTests(object):
image_id=UUID2) image_id=UUID2)
_assertMemberListMatch([], output) _assertMemberListMatch([], output)
image_id = uuidutils.generate_uuid() image_id = str(uuid.uuid4())
output = self.db_api.image_member_find(self.context, output = self.db_api.image_member_find(self.context,
member=TENANT2, member=TENANT2,
image_id=image_id) image_id=image_id)
_assertMemberListMatch([], output) _assertMemberListMatch([], output)
def test_image_member_count(self): def test_image_member_count(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
self.db_api.image_member_create(self.context, self.db_api.image_member_create(self.context,
{'member': TENANT1, {'member': TENANT1,
'image_id': UUID1}) 'image_id': UUID1})
@ -1131,7 +1130,7 @@ class DriverTests(object):
self.assertEqual(actual, 1) self.assertEqual(actual, 1)
def test_image_member_count_invalid_image_id(self): def test_image_member_count_invalid_image_id(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
self.db_api.image_member_create(self.context, self.db_api.image_member_create(self.context,
{'member': TENANT1, {'member': TENANT1,
'image_id': UUID1}) 'image_id': UUID1})
@ -1140,7 +1139,7 @@ class DriverTests(object):
self.context, None) self.context, None)
def test_image_member_count_empty_image_id(self): def test_image_member_count_empty_image_id(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
self.db_api.image_member_create(self.context, self.db_api.image_member_create(self.context,
{'member': TENANT1, {'member': TENANT1,
'image_id': UUID1}) 'image_id': UUID1})
@ -1149,7 +1148,7 @@ class DriverTests(object):
self.context, "") self.context, "")
def test_image_member_delete(self): def test_image_member_delete(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
# NOTE(flaper87): Update auth token, otherwise # NOTE(flaper87): Update auth token, otherwise
# non visible members won't be returned. # non visible members won't be returned.
self.context.auth_tok = 'user:%s:user' % TENANT1 self.context.auth_tok = 'user:%s:user' % TENANT1
@ -1164,7 +1163,7 @@ class DriverQuotaTests(test_utils.BaseTestCase):
def setUp(self): def setUp(self):
super(DriverQuotaTests, self).setUp() super(DriverQuotaTests, self).setUp()
self.owner_id1 = uuidutils.generate_uuid() self.owner_id1 = str(uuid.uuid4())
self.context1 = context.RequestContext( self.context1 = context.RequestContext(
is_admin=False, auth_tok='user:user:user', user=self.owner_id1) is_admin=False, auth_tok='user:user:user', user=self.owner_id1)
self.db_api = db_tests.get_db(self.config) self.db_api = db_tests.get_db(self.config)
@ -1237,7 +1236,7 @@ class TaskTests(test_utils.BaseTestCase):
def setUp(self): def setUp(self):
super(TaskTests, self).setUp() super(TaskTests, self).setUp()
self.owner_id1 = uuidutils.generate_uuid() self.owner_id1 = str(uuid.uuid4())
self.adm_context = context.RequestContext(is_admin=True, self.adm_context = context.RequestContext(is_admin=True,
auth_tok='user:user:admin') auth_tok='user:user:admin')
self.context = context.RequestContext( self.context = context.RequestContext(
@ -1248,7 +1247,7 @@ class TaskTests(test_utils.BaseTestCase):
self.addCleanup(timeutils.clear_time_override) self.addCleanup(timeutils.clear_time_override)
def build_task_fixtures(self): def build_task_fixtures(self):
self.context.tenant = uuidutils.generate_uuid() self.context.tenant = str(uuid.uuid4())
fixtures = [ fixtures = [
{ {
'owner': self.context.owner, 'owner': self.context.owner,
@ -1333,7 +1332,7 @@ class TaskTests(test_utils.BaseTestCase):
self.assertEqual(0, len(tasks)) self.assertEqual(0, len(tasks))
def test_task_get_all_owned(self): def test_task_get_all_owned(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
ctxt1 = context.RequestContext(is_admin=False, ctxt1 = context.RequestContext(is_admin=False,
tenant=TENANT1, tenant=TENANT1,
auth_tok='user:%s:user' % TENANT1) auth_tok='user:%s:user' % TENANT1)
@ -1342,7 +1341,7 @@ class TaskTests(test_utils.BaseTestCase):
'input': '{"loc": "fake"}', 'owner': TENANT1} 'input': '{"loc": "fake"}', 'owner': TENANT1}
self.db_api.task_create(ctxt1, task_values) self.db_api.task_create(ctxt1, task_values)
TENANT2 = uuidutils.generate_uuid() TENANT2 = str(uuid.uuid4())
ctxt2 = context.RequestContext(is_admin=False, ctxt2 = context.RequestContext(is_admin=False,
tenant=TENANT2, tenant=TENANT2,
auth_tok='user:%s:user' % TENANT2) auth_tok='user:%s:user' % TENANT2)
@ -1359,7 +1358,7 @@ class TaskTests(test_utils.BaseTestCase):
def test_task_get(self): def test_task_get(self):
expires_at = timeutils.utcnow() expires_at = timeutils.utcnow()
image_id = uuidutils.generate_uuid() image_id = str(uuid.uuid4())
fixture = { fixture = {
'owner': self.context.owner, 'owner': self.context.owner,
'type': 'import', 'type': 'import',
@ -1390,7 +1389,7 @@ class TaskTests(test_utils.BaseTestCase):
def test_task_get_all(self): def test_task_get_all(self):
now = timeutils.utcnow() now = timeutils.utcnow()
image_id = uuidutils.generate_uuid() image_id = str(uuid.uuid4())
fixture1 = { fixture1 = {
'owner': self.context.owner, 'owner': self.context.owner,
'type': 'import', 'type': 'import',
@ -1445,8 +1444,8 @@ class TaskTests(test_utils.BaseTestCase):
self.assertEqual(task['message'], fixture['message']) self.assertEqual(task['message'], fixture['message'])
def test_task_create(self): def test_task_create(self):
task_id = uuidutils.generate_uuid() task_id = str(uuid.uuid4())
self.context.tenant = uuidutils.generate_uuid() self.context.tenant = str(uuid.uuid4())
values = { values = {
'id': task_id, 'id': task_id,
'owner': self.context.owner, 'owner': self.context.owner,
@ -1463,8 +1462,8 @@ class TaskTests(test_utils.BaseTestCase):
self.assertEqual(task['input'], {'ping': 'pong'}) self.assertEqual(task['input'], {'ping': 'pong'})
def test_task_create_with_all_task_info_null(self): def test_task_create_with_all_task_info_null(self):
task_id = uuidutils.generate_uuid() task_id = str(uuid.uuid4())
self.context.tenant = uuidutils.generate_uuid() self.context.tenant = str(uuid.uuid4())
values = { values = {
'id': task_id, 'id': task_id,
'owner': self.context.owner, 'owner': self.context.owner,
@ -1486,7 +1485,7 @@ class TaskTests(test_utils.BaseTestCase):
self.assertEqual(task['message'], None) self.assertEqual(task['message'], None)
def test_task_update(self): def test_task_update(self):
self.context.tenant = uuidutils.generate_uuid() self.context.tenant = str(uuid.uuid4())
result = {'foo': 'bar'} result = {'foo': 'bar'}
task_values = build_task_fixture(owner=self.context.owner, task_values = build_task_fixture(owner=self.context.owner,
result=result) result=result)
@ -1513,7 +1512,7 @@ class TaskTests(test_utils.BaseTestCase):
self.assertTrue(task['updated_at'] > task['created_at']) self.assertTrue(task['updated_at'] > task['created_at'])
def test_task_update_with_all_task_info_null(self): def test_task_update_with_all_task_info_null(self):
self.context.tenant = uuidutils.generate_uuid() self.context.tenant = str(uuid.uuid4())
task_values = build_task_fixture(owner=self.context.owner, task_values = build_task_fixture(owner=self.context.owner,
input=None, input=None,
result=None, result=None,
@ -1580,9 +1579,9 @@ class TestVisibility(test_utils.BaseTestCase):
self.create_images(self.fixtures) self.create_images(self.fixtures)
def setup_tenants(self): def setup_tenants(self):
self.admin_tenant = uuidutils.generate_uuid() self.admin_tenant = str(uuid.uuid4())
self.tenant1 = uuidutils.generate_uuid() self.tenant1 = str(uuid.uuid4())
self.tenant2 = uuidutils.generate_uuid() self.tenant2 = str(uuid.uuid4())
def setup_contexts(self): def setup_contexts(self):
self.admin_context = context.RequestContext( self.admin_context = context.RequestContext(
@ -1864,7 +1863,7 @@ class TestMembershipVisibility(test_utils.BaseTestCase):
self.admin_tenant, self.admin_ctx = self._user_fixture(admin=True) self.admin_tenant, self.admin_ctx = self._user_fixture(admin=True)
def _user_fixture(self, admin=False): def _user_fixture(self, admin=False):
tenant_id = uuidutils.generate_uuid() tenant_id = str(uuid.uuid4())
ctx = context.RequestContext(tenant=tenant_id, is_admin=admin) ctx = context.RequestContext(tenant=tenant_id, is_admin=admin)
return tenant_id, ctx return tenant_id, ctx

@ -16,11 +16,12 @@
# under the License. # under the License.
import StringIO import StringIO
import uuid
from oslo.config import cfg from oslo.config import cfg
from glance.common import exception from glance.common import exception
from glance.openstack.common import uuidutils
import glance.store.location import glance.store.location
#NOTE(bcwaldon): importing this to get the default_store option #NOTE(bcwaldon): importing this to get the default_store option
import glance.api.v1.images import glance.api.v1.images
@ -76,7 +77,7 @@ class BaseTestCase(object):
"""Add, get and delete an image""" """Add, get and delete an image"""
store = self.get_store() store = self.get_store()
image_id = uuidutils.generate_uuid() image_id = str(uuid.uuid4())
image_data = StringIO.StringIO('XXX') image_data = StringIO.StringIO('XXX')
image_checksum = 'bc9189406be84ec297464a514221406d' image_checksum = 'bc9189406be84ec297464a514221406d'
try: try:
@ -108,7 +109,7 @@ class BaseTestCase(object):
def test_get_remote_image(self): def test_get_remote_image(self):
"""Get an image that was created externally to Glance""" """Get an image that was created externally to Glance"""
image_id = uuidutils.generate_uuid() image_id = str(uuid.uuid4())
try: try:
image_uri = self.stash_image(image_id, 'XXX') image_uri = self.stash_image(image_id, 'XXX')
except NotImplementedError: except NotImplementedError:

@ -25,12 +25,13 @@ RBD backend. This backend must be running Ceph Bobtail (0.56) or later.
import ConfigParser import ConfigParser
import os import os
import StringIO import StringIO
import uuid
import oslo.config.cfg import oslo.config.cfg
import testtools import testtools
from glance.common import exception from glance.common import exception
from glance.openstack.common import uuidutils
import glance.store.rbd import glance.store.rbd
import glance.tests.functional.store as store_tests import glance.tests.functional.store as store_tests
@ -134,7 +135,7 @@ class TestRBDStore(store_tests.BaseTestCase, testtools.TestCase):
# and uri to ascii before passing it to librbd. # and uri to ascii before passing it to librbd.
store = self.get_store() store = self.get_store()
image_id = unicode(uuidutils.generate_uuid()) image_id = unicode(str(uuid.uuid4()))
image_size = 300 image_size = 300
image_data = StringIO.StringIO('X' * image_size) image_data = StringIO.StringIO('X' * image_size)
image_checksum = '41757066eaff7c4c6c965556b4d3c6c5' image_checksum = '41757066eaff7c4c6c965556b4d3c6c5'

@ -29,13 +29,14 @@ import random
import StringIO import StringIO
import urllib import urllib
import urlparse import urlparse
import uuid
import oslo.config.cfg import oslo.config.cfg
import testtools import testtools
from glance.common import exception from glance.common import exception
import glance.common.utils as common_utils import glance.common.utils as common_utils
from glance.openstack.common import uuidutils
import glance.store.swift import glance.store.swift
import glance.tests.functional.store as store_tests import glance.tests.functional.store as store_tests
@ -192,7 +193,7 @@ class TestSwiftStore(store_tests.BaseTestCase, testtools.TestCase):
swift_store_large_object_chunk_size=2, # 2 MB swift_store_large_object_chunk_size=2, # 2 MB
) )
store = self.get_store() store = self.get_store()
image_id = uuidutils.generate_uuid() image_id = str(uuid.uuid4())
image_size = 5242880 # 5 MB image_size = 5242880 # 5 MB
image_data = StringIO.StringIO('X' * image_size) image_data = StringIO.StringIO('X' * image_size)
image_checksum = 'eb7f8c3716b9f059cee7617a4ba9d0d3' image_checksum = 'eb7f8c3716b9f059cee7617a4ba9d0d3'
@ -278,7 +279,7 @@ class TestSwiftStore(store_tests.BaseTestCase, testtools.TestCase):
# Simulate exceeding 'image_size_cap' setting # Simulate exceeding 'image_size_cap' setting
image_data = StringIO.StringIO('X' * image_size) image_data = StringIO.StringIO('X' * image_size)
image_data = common_utils.LimitingReader(image_data, image_size - 1) image_data = common_utils.LimitingReader(image_data, image_size - 1)
image_id = uuidutils.generate_uuid() image_id = str(uuid.uuid4())
self.assertRaises(exception.ImageSizeLimitExceeded, self.assertRaises(exception.ImageSizeLimitExceeded,
store.add, store.add,
image_id, image_id,
@ -333,7 +334,7 @@ class TestSwiftStore(store_tests.BaseTestCase, testtools.TestCase):
auth_tok=auth_token) auth_tok=auth_token)
store = self.get_store(context=context) store = self.get_store(context=context)
image_id = uuidutils.generate_uuid() image_id = str(uuid.uuid4())
image_data = StringIO.StringIO('XXX') image_data = StringIO.StringIO('XXX')
uri, _, _, _ = store.add(image_id, image_data, 3) uri, _, _, _ = store.add(image_id, image_data, 3)
@ -343,8 +344,8 @@ class TestSwiftStore(store_tests.BaseTestCase, testtools.TestCase):
uri=uri, uri=uri,
image_id=image_id) image_id=image_id)
read_tenant = uuidutils.generate_uuid() read_tenant = str(uuid.uuid4())
write_tenant = uuidutils.generate_uuid() write_tenant = str(uuid.uuid4())
store.set_acls(location, store.set_acls(location,
public=False, public=False,
read_tenants=[read_tenant], read_tenants=[read_tenant],

@ -36,10 +36,11 @@ import httplib2
import json import json
import os import os
import tempfile import tempfile
import uuid
from glance.openstack.common import timeutils from glance.openstack.common import timeutils
from glance.openstack.common import units from glance.openstack.common import units
from glance.openstack.common import uuidutils
from glance.tests import functional from glance.tests import functional
from glance.tests.utils import skip_if_disabled, minimal_headers from glance.tests.utils import skip_if_disabled, minimal_headers
@ -1259,7 +1260,7 @@ class TestSSL(functional.FunctionalTest):
# 1. DELETE /images/1 # 1. DELETE /images/1
# Verify 404 returned # Verify 404 returned
path = "https://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port, path = "https://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
uuidutils.generate_uuid()) str(uuid.uuid4()))
https = httplib2.Http(disable_ssl_certificate_validation=True) https = httplib2.Http(disable_ssl_certificate_validation=True)
response, content = https.request(path, 'DELETE') response, content = https.request(path, 'DELETE')
self.assertEqual(response.status, 404) self.assertEqual(response.status, 404)

@ -16,17 +16,18 @@
# under the License. # under the License.
import json import json
import uuid
import requests import requests
from glance.openstack.common import uuidutils
from glance.tests import functional from glance.tests import functional
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
TENANT2 = uuidutils.generate_uuid() TENANT2 = str(uuid.uuid4())
TENANT3 = uuidutils.generate_uuid() TENANT3 = str(uuid.uuid4())
TENANT4 = uuidutils.generate_uuid() TENANT4 = str(uuid.uuid4())
class TestImages(functional.FunctionalTest): class TestImages(functional.FunctionalTest):
@ -2176,12 +2177,12 @@ class TestImageMembers(functional.FunctionalTest):
# Adding 11 image members should fail since configured limit is 10 # Adding 11 image members should fail since configured limit is 10
path = self._url('/v2/images/%s/members' % image_fixture[1]['id']) path = self._url('/v2/images/%s/members' % image_fixture[1]['id'])
for i in range(10): for i in range(10):
body = json.dumps({'member': uuidutils.generate_uuid()}) body = json.dumps({'member': str(uuid.uuid4())})
response = requests.post(path, headers=get_header('tenant1'), response = requests.post(path, headers=get_header('tenant1'),
data=body) data=body)
self.assertEqual(200, response.status_code) self.assertEqual(200, response.status_code)
body = json.dumps({'member': uuidutils.generate_uuid()}) body = json.dumps({'member': str(uuid.uuid4())})
response = requests.post(path, headers=get_header('tenant1'), response = requests.post(path, headers=get_header('tenant1'),
data=body) data=body)
self.assertEqual(413, response.status_code) self.assertEqual(413, response.status_code)

@ -18,18 +18,18 @@
import json import json
import os import os
import uuid
import fixtures import fixtures
import requests import requests
from glance.openstack.common import uuidutils
from glance.tests import functional from glance.tests import functional
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
TENANT2 = uuidutils.generate_uuid() TENANT2 = str(uuid.uuid4())
TENANT3 = uuidutils.generate_uuid() TENANT3 = str(uuid.uuid4())
TENANT4 = uuidutils.generate_uuid() TENANT4 = str(uuid.uuid4())
class TestTasks(functional.FunctionalTest): class TestTasks(functional.FunctionalTest):

@ -14,13 +14,14 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import uuid
from oslo.config import cfg from oslo.config import cfg
from glance.common import crypt from glance.common import crypt
from glance.common import exception from glance.common import exception
import glance.context import glance.context
import glance.db import glance.db
from glance.openstack.common import uuidutils
import glance.tests.unit.utils as unit_test_utils import glance.tests.unit.utils as unit_test_utils
import glance.tests.utils as test_utils import glance.tests.utils as test_utils
@ -161,7 +162,7 @@ class TestImageRepo(test_utils.BaseTestCase):
self.assertEqual(image.locations, []) self.assertEqual(image.locations, [])
def test_get_not_found(self): def test_get_not_found(self):
fake_uuid = uuidutils.generate_uuid() fake_uuid = str(uuid.uuid4())
exc = self.assertRaises(exception.NotFound, self.image_repo.get, exc = self.assertRaises(exception.NotFound, self.image_repo.get,
fake_uuid) fake_uuid)
self.assertTrue(fake_uuid in unicode(exc)) self.assertTrue(fake_uuid in unicode(exc))
@ -300,7 +301,7 @@ class TestImageRepo(test_utils.BaseTestCase):
self.assertEqual(image.updated_at, current_update_time) self.assertEqual(image.updated_at, current_update_time)
def test_save_image_not_found(self): def test_save_image_not_found(self):
fake_uuid = uuidutils.generate_uuid() fake_uuid = str(uuid.uuid4())
image = self.image_repo.get(UUID1) image = self.image_repo.get(UUID1)
image.image_id = fake_uuid image.image_id = fake_uuid
exc = self.assertRaises(exception.NotFound, self.image_repo.save, exc = self.assertRaises(exception.NotFound, self.image_repo.save,
@ -315,7 +316,7 @@ class TestImageRepo(test_utils.BaseTestCase):
self.assertRaises(exception.NotFound, self.image_repo.get, UUID1) self.assertRaises(exception.NotFound, self.image_repo.get, UUID1)
def test_remove_image_not_found(self): def test_remove_image_not_found(self):
fake_uuid = uuidutils.generate_uuid() fake_uuid = str(uuid.uuid4())
image = self.image_repo.get(UUID1) image = self.image_repo.get(UUID1)
image.image_id = fake_uuid image.image_id = fake_uuid
exc = self.assertRaises(exception.NotFound, self.image_repo.remove, exc = self.assertRaises(exception.NotFound, self.image_repo.remove,
@ -501,7 +502,7 @@ class TestImageMemberRepo(test_utils.BaseTestCase):
TENANT2) TENANT2)
def test_remove_image_member_does_not_exist(self): def test_remove_image_member_does_not_exist(self):
fake_uuid = uuidutils.generate_uuid() fake_uuid = str(uuid.uuid4())
image = self.image_repo.get(UUID2) image = self.image_repo.get(UUID2)
fake_member = glance.domain.ImageMemberFactory()\ fake_member = glance.domain.ImageMemberFactory()\
.new_image_member(image, TENANT4) .new_image_member(image, TENANT4)
@ -568,7 +569,7 @@ class TestTaskRepo(test_utils.BaseTestCase):
def test_get_not_found(self): def test_get_not_found(self):
self.assertRaises(exception.NotFound, self.task_repo.get, self.assertRaises(exception.NotFound, self.task_repo.get,
uuidutils.generate_uuid()) str(uuid.uuid4()))
def test_get_forbidden(self): def test_get_forbidden(self):
self.assertRaises(exception.NotFound, self.task_repo.get, UUID4) self.assertRaises(exception.NotFound, self.task_repo.get, UUID4)

@ -15,12 +15,13 @@
# under the License. # under the License.
import datetime import datetime
import uuid
from oslo.config import cfg from oslo.config import cfg
from glance.common import exception from glance.common import exception
from glance import domain from glance import domain
from glance.openstack.common import uuidutils, timeutils from glance.openstack.common import timeutils
import glance.tests.utils as test_utils import glance.tests.utils as test_utils
import glance.tests.unit.utils as unittest_utils import glance.tests.unit.utils as unittest_utils
@ -331,7 +332,7 @@ class TestTask(test_utils.BaseTestCase):
self.task = self.task_factory.new_task(task_type, task_input, owner) self.task = self.task_factory.new_task(task_type, task_input, owner)
def test_task_invalid_status(self): def test_task_invalid_status(self):
task_id = uuidutils.generate_uuid() task_id = str(uuid.uuid4())
status = 'blah' status = 'blah'
self.assertRaises( self.assertRaises(
exception.InvalidTaskStatus, exception.InvalidTaskStatus,

@ -23,12 +23,13 @@ import hashlib
import json import json
import os import os
import StringIO import StringIO
import uuid
import mox import mox
from glance.common import exception from glance.common import exception
from glance.openstack.common import units from glance.openstack.common import units
from glance.openstack.common import uuidutils
from glance.store.filesystem import Store, ChunkedFile from glance.store.filesystem import Store, ChunkedFile
from glance.store.location import get_location_from_uri from glance.store.location import get_location_from_uri
from glance.tests.unit import base from glance.tests.unit import base
@ -51,7 +52,7 @@ class TestStore(base.IsolatedUnitTest):
def test_get(self): def test_get(self):
"""Test a "normal" retrieval of an image in chunks""" """Test a "normal" retrieval of an image in chunks"""
# First add an image... # First add an image...
image_id = uuidutils.generate_uuid() image_id = str(uuid.uuid4())
file_contents = "chunk00000remainder" file_contents = "chunk00000remainder"
image_file = StringIO.StringIO(file_contents) image_file = StringIO.StringIO(file_contents)
@ -88,7 +89,7 @@ class TestStore(base.IsolatedUnitTest):
def test_add(self): def test_add(self):
"""Test that we can add an image via the filesystem backend""" """Test that we can add an image via the filesystem backend"""
ChunkedFile.CHUNKSIZE = 1024 ChunkedFile.CHUNKSIZE = 1024
expected_image_id = uuidutils.generate_uuid() expected_image_id = str(uuid.uuid4())
expected_file_size = 5 * units.Ki # 5K expected_file_size = 5 * units.Ki # 5K
expected_file_contents = "*" * expected_file_size expected_file_contents = "*" * expected_file_size
expected_checksum = hashlib.md5(expected_file_contents).hexdigest() expected_checksum = hashlib.md5(expected_file_contents).hexdigest()
@ -118,7 +119,7 @@ class TestStore(base.IsolatedUnitTest):
self.assertEqual(expected_file_size, new_image_file_size) self.assertEqual(expected_file_size, new_image_file_size)
def test_add_check_metadata_success(self): def test_add_check_metadata_success(self):
expected_image_id = uuidutils.generate_uuid() expected_image_id = str(uuid.uuid4())
in_metadata = {'akey': u'some value', 'list': [u'1', u'2', u'3']} in_metadata = {'akey': u'some value', 'list': [u'1', u'2', u'3']}
jsonfilename = os.path.join(self.test_dir, jsonfilename = os.path.join(self.test_dir,
"storage_metadata.%s" % expected_image_id) "storage_metadata.%s" % expected_image_id)
@ -137,7 +138,7 @@ class TestStore(base.IsolatedUnitTest):
self.assertEqual(metadata, in_metadata) self.assertEqual(metadata, in_metadata)
def test_add_check_metadata_bad_data(self): def test_add_check_metadata_bad_data(self):
expected_image_id = uuidutils.generate_uuid() expected_image_id = str(uuid.uuid4())
in_metadata = {'akey': 10} # only unicode is allowed in_metadata = {'akey': 10} # only unicode is allowed
jsonfilename = os.path.join(self.test_dir, jsonfilename = os.path.join(self.test_dir,
"storage_metadata.%s" % expected_image_id) "storage_metadata.%s" % expected_image_id)
@ -156,7 +157,7 @@ class TestStore(base.IsolatedUnitTest):
self.assertEqual(metadata, {}) self.assertEqual(metadata, {})
def test_add_check_metadata_bad_nosuch_file(self): def test_add_check_metadata_bad_nosuch_file(self):
expected_image_id = uuidutils.generate_uuid() expected_image_id = str(uuid.uuid4())
jsonfilename = os.path.join(self.test_dir, jsonfilename = os.path.join(self.test_dir,
"storage_metadata.%s" % expected_image_id) "storage_metadata.%s" % expected_image_id)
@ -177,7 +178,7 @@ class TestStore(base.IsolatedUnitTest):
raises an appropriate exception raises an appropriate exception
""" """
ChunkedFile.CHUNKSIZE = 1024 ChunkedFile.CHUNKSIZE = 1024
image_id = uuidutils.generate_uuid() image_id = str(uuid.uuid4())
file_size = 5 * units.Ki # 5K file_size = 5 * units.Ki # 5K
file_contents = "*" * file_size file_contents = "*" * file_size
image_file = StringIO.StringIO(file_contents) image_file = StringIO.StringIO(file_contents)
@ -192,7 +193,7 @@ class TestStore(base.IsolatedUnitTest):
def _do_test_add_write_failure(self, errno, exception): def _do_test_add_write_failure(self, errno, exception):
ChunkedFile.CHUNKSIZE = 1024 ChunkedFile.CHUNKSIZE = 1024
image_id = uuidutils.generate_uuid() image_id = str(uuid.uuid4())
file_size = 5 * units.Ki # 5K file_size = 5 * units.Ki # 5K
file_contents = "*" * file_size file_contents = "*" * file_size
path = os.path.join(self.test_dir, image_id) path = os.path.join(self.test_dir, image_id)
@ -249,7 +250,7 @@ class TestStore(base.IsolatedUnitTest):
failure. failure.
""" """
ChunkedFile.CHUNKSIZE = 1024 ChunkedFile.CHUNKSIZE = 1024
image_id = uuidutils.generate_uuid() image_id = str(uuid.uuid4())
file_size = 5 * units.Ki # 5K file_size = 5 * units.Ki # 5K
file_contents = "*" * file_size file_contents = "*" * file_size
path = os.path.join(self.test_dir, image_id) path = os.path.join(self.test_dir, image_id)
@ -270,7 +271,7 @@ class TestStore(base.IsolatedUnitTest):
Test we can delete an existing image in the filesystem store Test we can delete an existing image in the filesystem store
""" """
# First add an image # First add an image
image_id = uuidutils.generate_uuid() image_id = str(uuid.uuid4())
file_size = 5 * units.Ki # 5K file_size = 5 * units.Ki # 5K
file_contents = "*" * file_size file_contents = "*" * file_size
image_file = StringIO.StringIO(file_contents) image_file = StringIO.StringIO(file_contents)

@ -34,20 +34,22 @@ import os
import pickle import pickle
import subprocess import subprocess
import urlparse import urlparse
import uuid
from migrate.versioning.repository import Repository from migrate.versioning.repository import Repository
from oslo.config import cfg from oslo.config import cfg
import sqlalchemy import sqlalchemy
from glance.common import crypt from glance.common import crypt
from glance.common import utils
import glance.db.migration as migration import glance.db.migration as migration
import glance.db.sqlalchemy.migrate_repo import glance.db.sqlalchemy.migrate_repo
from glance.db.sqlalchemy.migration import versioning_api as migration_api from glance.db.sqlalchemy.migration import versioning_api as migration_api
from glance.db.sqlalchemy import models from glance.db.sqlalchemy import models
from glance.openstack.common import log as logging from glance.openstack.common import log as logging
from glance.openstack.common import timeutils from glance.openstack.common import timeutils
from glance.openstack.common import uuidutils
from glance.tests import utils from glance.tests import utils as test_utils
CONF = cfg.CONF CONF = cfg.CONF
@ -114,7 +116,7 @@ def get_table(engine, name):
return sqlalchemy.Table(name, metadata, autoload=True) return sqlalchemy.Table(name, metadata, autoload=True)
class TestMigrations(utils.BaseTestCase): class TestMigrations(test_utils.BaseTestCase):
"""Test sqlalchemy-migrate migrations.""" """Test sqlalchemy-migrate migrations."""
DEFAULT_CONFIG_FILE = os.path.join(os.path.dirname(__file__), DEFAULT_CONFIG_FILE = os.path.join(os.path.dirname(__file__),
@ -634,7 +636,7 @@ class TestMigrations(utils.BaseTestCase):
self.assertEqual(len(rows), 1) self.assertEqual(len(rows), 1)
row = rows[0] row = rows[0]
self.assertTrue(uuidutils.is_uuid_like(row['id'])) self.assertTrue(utils.is_uuid_like(row['id']))
uuids[name] = row['id'] uuids[name] = row['id']
@ -677,7 +679,7 @@ class TestMigrations(utils.BaseTestCase):
self.assertEqual(len(rows), 1) self.assertEqual(len(rows), 1)
row = rows[0] row = rows[0]
self.assertFalse(uuidutils.is_uuid_like(row['id'])) self.assertFalse(utils.is_uuid_like(row['id']))
ids[name] = row['id'] ids[name] = row['id']
@ -720,7 +722,7 @@ class TestMigrations(utils.BaseTestCase):
min_ram=0) min_ram=0)
data = [] data = []
for i, location in enumerate(unquoted_locations): for i, location in enumerate(unquoted_locations):
temp.update(location=location, id=uuidutils.generate_uuid()) temp.update(location=location, id=str(uuid.uuid4()))
data.append(temp) data.append(temp)
images.insert().values(temp).execute() images.insert().values(temp).execute()
return data return data
@ -802,7 +804,7 @@ class TestMigrations(utils.BaseTestCase):
min_disk=0, min_disk=0,
min_ram=0) min_ram=0)
for i, location in enumerate(locations): for i, location in enumerate(locations):
temp.update(location=location, id=uuidutils.generate_uuid()) temp.update(location=location, id=str(uuid.uuid4()))
data.append(temp) data.append(temp)
images.insert().values(temp).execute() images.insert().values(temp).execute()
return data return data

@ -19,13 +19,14 @@
import hashlib import hashlib
import StringIO import StringIO
import uuid
import boto.s3.connection import boto.s3.connection
import stubout import stubout
from glance.common import exception from glance.common import exception
from glance.openstack.common import units from glance.openstack.common import units
from glance.openstack.common import uuidutils
from glance.store.location import get_location_from_uri from glance.store.location import get_location_from_uri
import glance.store.s3 import glance.store.s3
from glance.store.s3 import Store, get_s3_location from glance.store.s3 import Store, get_s3_location
@ -33,7 +34,7 @@ from glance.store import UnsupportedBackend
from glance.tests.unit import base from glance.tests.unit import base
FAKE_UUID = uuidutils.generate_uuid() FAKE_UUID = str(uuid.uuid4())
FIVE_KB = 5 * units.Ki FIVE_KB = 5 * units.Ki
S3_CONF = {'verbose': True, S3_CONF = {'verbose': True,
@ -229,7 +230,7 @@ class TestStore(base.StoreClearingUnitTest):
def test_add(self): def test_add(self):
"""Test that we can add an image via the s3 backend""" """Test that we can add an image via the s3 backend"""
expected_image_id = uuidutils.generate_uuid() expected_image_id = str(uuid.uuid4())
expected_s3_size = FIVE_KB expected_s3_size = FIVE_KB
expected_s3_contents = "*" * expected_s3_size expected_s3_contents = "*" * expected_s3_size
expected_checksum = hashlib.md5(expected_s3_contents).hexdigest() expected_checksum = hashlib.md5(expected_s3_contents).hexdigest()
@ -275,7 +276,7 @@ class TestStore(base.StoreClearingUnitTest):
'localhost', 'localhost',
'localhost:8080/v1'] 'localhost:8080/v1']
for variation in variations: for variation in variations:
expected_image_id = uuidutils.generate_uuid() expected_image_id = str(uuid.uuid4())
expected_s3_size = FIVE_KB expected_s3_size = FIVE_KB
expected_s3_contents = "*" * expected_s3_size expected_s3_contents = "*" * expected_s3_size
expected_checksum = hashlib.md5(expected_s3_contents).hexdigest() expected_checksum = hashlib.md5(expected_s3_contents).hexdigest()

@ -19,12 +19,13 @@ import os
import shutil import shutil
import time import time
import tempfile import tempfile
import uuid
import eventlet import eventlet
import mox import mox
from glance.common import exception from glance.common import exception
from glance.openstack.common import uuidutils
import glance.store import glance.store
import glance.store.scrubber import glance.store.scrubber
from glance.tests import utils as test_utils from glance.tests import utils as test_utils
@ -46,7 +47,7 @@ class TestScrubber(test_utils.BaseTestCase):
super(TestScrubber, self).tearDown() super(TestScrubber, self).tearDown()
def _scrubber_cleanup_with_store_delete_exception(self, ex): def _scrubber_cleanup_with_store_delete_exception(self, ex):
fname = uuidutils.generate_uuid fname = lambda: str(uuid.uuid4())
uri = 'file://some/path/%s' % (fname) uri = 'file://some/path/%s' % (fname)
id = 'helloworldid' id = 'helloworldid'

@ -23,6 +23,7 @@ import mock
import StringIO import StringIO
import tempfile import tempfile
import urllib import urllib
import uuid
from oslo.config import cfg from oslo.config import cfg
import stubout import stubout
@ -31,7 +32,7 @@ import swiftclient
import glance.common.auth import glance.common.auth
from glance.common import exception from glance.common import exception
from glance.openstack.common import units from glance.openstack.common import units
from glance.openstack.common import uuidutils
from glance.store import BackendException from glance.store import BackendException
from glance.store.location import get_location_from_uri from glance.store.location import get_location_from_uri
import glance.store.swift import glance.store.swift
@ -39,7 +40,7 @@ from glance.tests.unit import base
CONF = cfg.CONF CONF = cfg.CONF
FAKE_UUID = uuidutils.generate_uuid FAKE_UUID = lambda: str(uuid.uuid4())
Store = glance.store.swift.Store Store = glance.store.swift.Store
FIVE_KB = 5 * units.Ki FIVE_KB = 5 * units.Ki
@ -281,7 +282,7 @@ class SwiftTests(object):
expected_swift_size = FIVE_KB expected_swift_size = FIVE_KB
expected_swift_contents = "*" * expected_swift_size expected_swift_contents = "*" * expected_swift_size
expected_checksum = hashlib.md5(expected_swift_contents).hexdigest() expected_checksum = hashlib.md5(expected_swift_contents).hexdigest()
expected_image_id = uuidutils.generate_uuid() expected_image_id = str(uuid.uuid4())
loc = 'swift+https://%s:key@localhost:8080/glance/%s' loc = 'swift+https://%s:key@localhost:8080/glance/%s'
expected_location = loc % (self.swift_store_user, expected_location = loc % (self.swift_store_user,
expected_image_id) expected_image_id)
@ -334,7 +335,7 @@ class SwiftTests(object):
} }
for variation, expected_location in variations.items(): for variation, expected_location in variations.items():
image_id = uuidutils.generate_uuid() image_id = str(uuid.uuid4())
expected_location = expected_location % ( expected_location = expected_location % (
self.swift_store_user, image_id) self.swift_store_user, image_id)
expected_swift_size = FIVE_KB expected_swift_size = FIVE_KB
@ -384,7 +385,7 @@ class SwiftTests(object):
# simply used self.assertRaises here # simply used self.assertRaises here
exception_caught = False exception_caught = False
try: try:
self.store.add(uuidutils.generate_uuid(), image_swift, 0) self.store.add(str(uuid.uuid4()), image_swift, 0)
except BackendException as e: except BackendException as e:
exception_caught = True exception_caught = True
self.assertTrue("container noexist does not exist " self.assertTrue("container noexist does not exist "
@ -400,7 +401,7 @@ class SwiftTests(object):
expected_swift_size = FIVE_KB expected_swift_size = FIVE_KB
expected_swift_contents = "*" * expected_swift_size expected_swift_contents = "*" * expected_swift_size
expected_checksum = hashlib.md5(expected_swift_contents).hexdigest() expected_checksum = hashlib.md5(expected_swift_contents).hexdigest()
expected_image_id = uuidutils.generate_uuid() expected_image_id = str(uuid.uuid4())
loc = 'swift+https://%s:key@localhost:8080/noexist/%s' loc = 'swift+https://%s:key@localhost:8080/noexist/%s'
expected_location = loc % (self.swift_store_user, expected_location = loc % (self.swift_store_user,
expected_image_id) expected_image_id)
@ -439,7 +440,7 @@ class SwiftTests(object):
expected_swift_size = FIVE_KB expected_swift_size = FIVE_KB
expected_swift_contents = "*" * expected_swift_size expected_swift_contents = "*" * expected_swift_size
expected_checksum = hashlib.md5(expected_swift_contents).hexdigest() expected_checksum = hashlib.md5(expected_swift_contents).hexdigest()
expected_image_id = uuidutils.generate_uuid() expected_image_id = str(uuid.uuid4())
loc = 'swift+https://%s:key@localhost:8080/glance/%s' loc = 'swift+https://%s:key@localhost:8080/glance/%s'
expected_location = loc % (self.swift_store_user, expected_location = loc % (self.swift_store_user,
expected_image_id) expected_image_id)
@ -492,7 +493,7 @@ class SwiftTests(object):
expected_swift_size = FIVE_KB expected_swift_size = FIVE_KB
expected_swift_contents = "*" * expected_swift_size expected_swift_contents = "*" * expected_swift_size
expected_checksum = hashlib.md5(expected_swift_contents).hexdigest() expected_checksum = hashlib.md5(expected_swift_contents).hexdigest()
expected_image_id = uuidutils.generate_uuid() expected_image_id = str(uuid.uuid4())
loc = 'swift+https://%s:key@localhost:8080/glance/%s' loc = 'swift+https://%s:key@localhost:8080/glance/%s'
expected_location = loc % (self.swift_store_user, expected_location = loc % (self.swift_store_user,
expected_image_id) expected_image_id)
@ -548,7 +549,7 @@ class SwiftTests(object):
FAKE_UUID, image_swift, 0) FAKE_UUID, image_swift, 0)
def test_add_saves_and_reraises_and_not_uses_wildcard_raise(self): def test_add_saves_and_reraises_and_not_uses_wildcard_raise(self):
image_id = uuidutils.generate_uuid() image_id = str(uuid.uuid4())
swift_size = self.store.large_object_size = 1024 swift_size = self.store.large_object_size = 1024
loc = 'swift+https://%s:key@localhost:8080/glance/%s' loc = 'swift+https://%s:key@localhost:8080/glance/%s'
swift_contents = "*" * swift_size swift_contents = "*" * swift_size

@ -21,6 +21,7 @@ import datetime
import hashlib import hashlib
import json import json
import StringIO import StringIO
import uuid
from oslo.config import cfg from oslo.config import cfg
import routes import routes
@ -35,7 +36,7 @@ import glance.context
from glance.db.sqlalchemy import api as db_api from glance.db.sqlalchemy import api as db_api
from glance.db.sqlalchemy import models as db_models from glance.db.sqlalchemy import models as db_models
from glance.openstack.common import timeutils from glance.openstack.common import timeutils
from glance.openstack.common import uuidutils
import glance.registry.client.v1.api as registry import glance.registry.client.v1.api as registry
import glance.store.filesystem import glance.store.filesystem
from glance.tests.unit import base from glance.tests.unit import base
@ -44,7 +45,7 @@ import glance.tests.unit.utils as unit_test_utils
CONF = cfg.CONF CONF = cfg.CONF
_gen_uuid = uuidutils.generate_uuid _gen_uuid = lambda: str(uuid.uuid4())
UUID1 = _gen_uuid() UUID1 = _gen_uuid()
UUID2 = _gen_uuid() UUID2 = _gen_uuid()

@ -18,6 +18,7 @@
import datetime import datetime
import json import json
import uuid
from oslo.config import cfg from oslo.config import cfg
import routes import routes
@ -31,7 +32,7 @@ from glance import context
from glance.db.sqlalchemy import api as db_api from glance.db.sqlalchemy import api as db_api
from glance.db.sqlalchemy import models as db_models from glance.db.sqlalchemy import models as db_models
from glance.openstack.common import timeutils from glance.openstack.common import timeutils
from glance.openstack.common import uuidutils
from glance.registry.api import v1 as rserver from glance.registry.api import v1 as rserver
import glance.store.filesystem import glance.store.filesystem
from glance.tests.unit import base from glance.tests.unit import base
@ -39,7 +40,7 @@ from glance.tests import utils as test_utils
CONF = cfg.CONF CONF = cfg.CONF
_gen_uuid = uuidutils.generate_uuid _gen_uuid = lambda: str(uuid.uuid4())
UUID1 = _gen_uuid() UUID1 = _gen_uuid()
UUID2 = _gen_uuid() UUID2 = _gen_uuid()
@ -1919,15 +1920,15 @@ class TestSharability(test_utils.BaseTestCase):
db_models.register_models(db_api._ENGINE) db_models.register_models(db_api._ENGINE)
def test_is_image_sharable_as_admin(self): def test_is_image_sharable_as_admin(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
TENANT2 = uuidutils.generate_uuid() TENANT2 = str(uuid.uuid4())
ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1,
auth_tok='user:%s:user' % TENANT1, auth_tok='user:%s:user' % TENANT1,
owner_is_tenant=True) owner_is_tenant=True)
ctxt2 = context.RequestContext(is_admin=True, user=TENANT2, ctxt2 = context.RequestContext(is_admin=True, user=TENANT2,
auth_tok='user:%s:admin' % TENANT2, auth_tok='user:%s:admin' % TENANT2,
owner_is_tenant=False) owner_is_tenant=False)
UUIDX = uuidutils.generate_uuid() UUIDX = str(uuid.uuid4())
#we need private image and context.owner should not match image owner #we need private image and context.owner should not match image owner
image = db_api.image_create(ctxt1, {'id': UUIDX, image = db_api.image_create(ctxt1, {'id': UUIDX,
'status': 'queued', 'status': 'queued',
@ -1938,11 +1939,11 @@ class TestSharability(test_utils.BaseTestCase):
self.assertTrue(result) self.assertTrue(result)
def test_is_image_sharable_owner_can_share(self): def test_is_image_sharable_owner_can_share(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1,
auth_tok='user:%s:user' % TENANT1, auth_tok='user:%s:user' % TENANT1,
owner_is_tenant=True) owner_is_tenant=True)
UUIDX = uuidutils.generate_uuid() UUIDX = str(uuid.uuid4())
#we need private image and context.owner should not match image owner #we need private image and context.owner should not match image owner
image = db_api.image_create(ctxt1, {'id': UUIDX, image = db_api.image_create(ctxt1, {'id': UUIDX,
'status': 'queued', 'status': 'queued',
@ -1953,15 +1954,15 @@ class TestSharability(test_utils.BaseTestCase):
self.assertTrue(result) self.assertTrue(result)
def test_is_image_sharable_non_owner_cannot_share(self): def test_is_image_sharable_non_owner_cannot_share(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
TENANT2 = uuidutils.generate_uuid() TENANT2 = str(uuid.uuid4())
ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1,
auth_tok='user:%s:user' % TENANT1, auth_tok='user:%s:user' % TENANT1,
owner_is_tenant=True) owner_is_tenant=True)
ctxt2 = context.RequestContext(is_admin=False, user=TENANT2, ctxt2 = context.RequestContext(is_admin=False, user=TENANT2,
auth_tok='user:%s:user' % TENANT2, auth_tok='user:%s:user' % TENANT2,
owner_is_tenant=False) owner_is_tenant=False)
UUIDX = uuidutils.generate_uuid() UUIDX = str(uuid.uuid4())
#we need private image and context.owner should not match image owner #we need private image and context.owner should not match image owner
image = db_api.image_create(ctxt1, {'id': UUIDX, image = db_api.image_create(ctxt1, {'id': UUIDX,
'status': 'queued', 'status': 'queued',
@ -1972,15 +1973,15 @@ class TestSharability(test_utils.BaseTestCase):
self.assertFalse(result) self.assertFalse(result)
def test_is_image_sharable_non_owner_can_share_as_image_member(self): def test_is_image_sharable_non_owner_can_share_as_image_member(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
TENANT2 = uuidutils.generate_uuid() TENANT2 = str(uuid.uuid4())
ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1,
auth_tok='user:%s:user' % TENANT1, auth_tok='user:%s:user' % TENANT1,
owner_is_tenant=True) owner_is_tenant=True)
ctxt2 = context.RequestContext(is_admin=False, user=TENANT2, ctxt2 = context.RequestContext(is_admin=False, user=TENANT2,
auth_tok='user:%s:user' % TENANT2, auth_tok='user:%s:user' % TENANT2,
owner_is_tenant=False) owner_is_tenant=False)
UUIDX = uuidutils.generate_uuid() UUIDX = str(uuid.uuid4())
#we need private image and context.owner should not match image owner #we need private image and context.owner should not match image owner
image = db_api.image_create(ctxt1, {'id': UUIDX, image = db_api.image_create(ctxt1, {'id': UUIDX,
'status': 'queued', 'status': 'queued',
@ -1997,15 +1998,15 @@ class TestSharability(test_utils.BaseTestCase):
self.assertTrue(result) self.assertTrue(result)
def test_is_image_sharable_non_owner_as_image_member_without_sharing(self): def test_is_image_sharable_non_owner_as_image_member_without_sharing(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
TENANT2 = uuidutils.generate_uuid() TENANT2 = str(uuid.uuid4())
ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1,
auth_tok='user:%s:user' % TENANT1, auth_tok='user:%s:user' % TENANT1,
owner_is_tenant=True) owner_is_tenant=True)
ctxt2 = context.RequestContext(is_admin=False, user=TENANT2, ctxt2 = context.RequestContext(is_admin=False, user=TENANT2,
auth_tok='user:%s:user' % TENANT2, auth_tok='user:%s:user' % TENANT2,
owner_is_tenant=False) owner_is_tenant=False)
UUIDX = uuidutils.generate_uuid() UUIDX = str(uuid.uuid4())
#we need private image and context.owner should not match image owner #we need private image and context.owner should not match image owner
image = db_api.image_create(ctxt1, {'id': UUIDX, image = db_api.image_create(ctxt1, {'id': UUIDX,
'status': 'queued', 'status': 'queued',
@ -2022,14 +2023,14 @@ class TestSharability(test_utils.BaseTestCase):
self.assertFalse(result) self.assertFalse(result)
def test_is_image_sharable_owner_is_none(self): def test_is_image_sharable_owner_is_none(self):
TENANT1 = uuidutils.generate_uuid() TENANT1 = str(uuid.uuid4())
ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1, ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1,
auth_tok='user:%s:user' % TENANT1, auth_tok='user:%s:user' % TENANT1,
owner_is_tenant=True) owner_is_tenant=True)
ctxt2 = context.RequestContext(is_admin=False, tenant=None, ctxt2 = context.RequestContext(is_admin=False, tenant=None,
auth_tok='user:%s:user' % TENANT1, auth_tok='user:%s:user' % TENANT1,
owner_is_tenant=True) owner_is_tenant=True)
UUIDX = uuidutils.generate_uuid() UUIDX = str(uuid.uuid4())
#we need private image and context.owner should not match image owner #we need private image and context.owner should not match image owner
image = db_api.image_create(ctxt1, {'id': UUIDX, image = db_api.image_create(ctxt1, {'id': UUIDX,
'status': 'queued', 'status': 'queued',

@ -18,6 +18,7 @@
import copy import copy
import datetime import datetime
import os import os
import uuid
import mox import mox
import testtools import testtools
@ -28,7 +29,7 @@ from glance.common import client as test_client
from glance import context from glance import context
from glance.db.sqlalchemy import api as db_api from glance.db.sqlalchemy import api as db_api
from glance.openstack.common import timeutils from glance.openstack.common import timeutils
from glance.openstack.common import uuidutils
import glance.registry.client.v1.api as rapi import glance.registry.client.v1.api as rapi
from glance.registry.api.v1.images import Controller as rcontroller from glance.registry.api.v1.images import Controller as rcontroller
from glance.registry.client.v1.api import client as rclient from glance.registry.client.v1.api import client as rclient
@ -36,7 +37,7 @@ from glance.tests.unit import base
from glance.tests import utils as test_utils from glance.tests import utils as test_utils
_gen_uuid = uuidutils.generate_uuid _gen_uuid = lambda: str(uuid.uuid4())
UUID1 = _gen_uuid() UUID1 = _gen_uuid()
UUID2 = _gen_uuid() UUID2 = _gen_uuid()

@ -15,12 +15,13 @@
import mock import mock
import StringIO import StringIO
import uuid
import webob import webob
import glance.api.v2.image_data import glance.api.v2.image_data
from glance.common import exception from glance.common import exception
from glance.openstack.common import uuidutils
from glance.tests.unit import base from glance.tests.unit import base
import glance.tests.unit.utils as unit_test_utils import glance.tests.unit.utils as unit_test_utils
import glance.tests.utils as test_utils import glance.tests.utils as test_utils
@ -116,13 +117,13 @@ class TestImagesController(base.StoreClearingUnitTest):
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request()
self.image_repo.result = exception.NotFound() self.image_repo.result = exception.NotFound()
self.assertRaises(webob.exc.HTTPNotFound, self.controller.download, self.assertRaises(webob.exc.HTTPNotFound, self.controller.download,
request, uuidutils.generate_uuid()) request, str(uuid.uuid4()))
def test_download_forbidden(self): def test_download_forbidden(self):
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request()
self.image_repo.result = exception.Forbidden() self.image_repo.result = exception.Forbidden()
self.assertRaises(webob.exc.HTTPForbidden, self.controller.download, self.assertRaises(webob.exc.HTTPForbidden, self.controller.download,
request, uuidutils.generate_uuid()) request, str(uuid.uuid4()))
def test_download_get_image_location_forbidden(self): def test_download_get_image_location_forbidden(self):
class ImageLocations(object): class ImageLocations(object):
@ -134,7 +135,7 @@ class TestImagesController(base.StoreClearingUnitTest):
self.image_repo.result = image self.image_repo.result = image
image.locations = ImageLocations() image.locations = ImageLocations()
self.assertRaises(webob.exc.HTTPForbidden, self.controller.download, self.assertRaises(webob.exc.HTTPForbidden, self.controller.download,
request, uuidutils.generate_uuid()) request, str(uuid.uuid4()))
def test_upload(self): def test_upload(self):
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request()
@ -187,14 +188,14 @@ class TestImagesController(base.StoreClearingUnitTest):
self.image_repo.save = fake_save self.image_repo.save = fake_save
image.delete = mock.Mock() image.delete = mock.Mock()
self.assertRaises(webob.exc.HTTPGone, self.controller.upload, self.assertRaises(webob.exc.HTTPGone, self.controller.upload,
request, uuidutils.generate_uuid(), 'ABC', 3) request, str(uuid.uuid4()), 'ABC', 3)
self.assertTrue(image.delete.called) self.assertTrue(image.delete.called)
def test_upload_non_existent_image_before_save(self): def test_upload_non_existent_image_before_save(self):
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request()
self.image_repo.result = exception.NotFound() self.image_repo.result = exception.NotFound()
self.assertRaises(webob.exc.HTTPNotFound, self.controller.upload, self.assertRaises(webob.exc.HTTPNotFound, self.controller.upload,
request, uuidutils.generate_uuid(), 'ABC', 3) request, str(uuid.uuid4()), 'ABC', 3)
def test_upload_data_exists(self): def test_upload_data_exists(self):
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request()

@ -15,6 +15,7 @@
import datetime import datetime
import json import json
import uuid
from oslo.config import cfg from oslo.config import cfg
import testtools import testtools
@ -22,7 +23,7 @@ import webob
import glance.api.v2.images import glance.api.v2.images
from glance.common import exception from glance.common import exception
from glance.openstack.common import uuidutils
import glance.schema import glance.schema
import glance.store import glance.store
from glance.tests.unit import base from glance.tests.unit import base
@ -309,7 +310,7 @@ class TestImagesController(base.IsolatedUnitTest):
self.assertEqual(0, len(images)) self.assertEqual(0, len(images))
def test_index_with_non_default_is_public_filter(self): def test_index_with_non_default_is_public_filter(self):
image = _db_fixture(uuidutils.generate_uuid(), image = _db_fixture(str(uuid.uuid4()),
is_public=False, is_public=False,
owner=TENANT3) owner=TENANT3)
self.db.image_create(None, image) self.db.image_create(None, image)
@ -389,7 +390,7 @@ class TestImagesController(base.IsolatedUnitTest):
self.assertEqual(UUID1, actual[2]) self.assertEqual(UUID1, actual[2])
def test_index_with_marker_not_found(self): def test_index_with_marker_not_found(self):
fake_uuid = uuidutils.generate_uuid() fake_uuid = str(uuid.uuid4())
path = '/images' path = '/images'
request = unit_test_utils.get_fake_request(path) request = unit_test_utils.get_fake_request(path)
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
@ -494,7 +495,7 @@ class TestImagesController(base.IsolatedUnitTest):
# get the image properties into the odd state # get the image properties into the odd state
image = { image = {
'id': uuidutils.generate_uuid(), 'id': str(uuid.uuid4()),
'status': 'active', 'status': 'active',
'properties': {'poo': 'bear'}, 'properties': {'poo': 'bear'},
} }
@ -509,7 +510,7 @@ class TestImagesController(base.IsolatedUnitTest):
def test_show_non_existent(self): def test_show_non_existent(self):
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request()
image_id = uuidutils.generate_uuid() image_id = str(uuid.uuid4())
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller.show, request, image_id) self.controller.show, request, image_id)
@ -621,7 +622,7 @@ class TestImagesController(base.IsolatedUnitTest):
def test_update_image_doesnt_exist(self): def test_update_image_doesnt_exist(self):
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request()
self.assertRaises(webob.exc.HTTPNotFound, self.controller.update, self.assertRaises(webob.exc.HTTPNotFound, self.controller.update,
request, uuidutils.generate_uuid(), changes=[]) request, str(uuid.uuid4()), changes=[])
def test_update_deleted_image_admin(self): def test_update_deleted_image_admin(self):
request = unit_test_utils.get_fake_request(is_admin=True) request = unit_test_utils.get_fake_request(is_admin=True)
@ -733,7 +734,7 @@ class TestImagesController(base.IsolatedUnitTest):
request = unit_test_utils.get_fake_request(is_admin=True) request = unit_test_utils.get_fake_request(is_admin=True)
for status in statuses_for_immutability: for status in statuses_for_immutability:
image = { image = {
'id': uuidutils.generate_uuid(), 'id': str(uuid.uuid4()),
'status': status, 'status': status,
'disk_format': 'ari', 'disk_format': 'ari',
'container_format': 'ari', 'container_format': 'ari',
@ -1568,7 +1569,7 @@ class TestImagesController(base.IsolatedUnitTest):
def test_delete_non_existent(self): def test_delete_non_existent(self):
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request()
self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete, self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete,
request, uuidutils.generate_uuid()) request, str(uuid.uuid4()))
def test_delete_already_deleted_image_admin(self): def test_delete_already_deleted_image_admin(self):
request = unit_test_utils.get_fake_request(is_admin=True) request = unit_test_utils.get_fake_request(is_admin=True)
@ -1582,7 +1583,7 @@ class TestImagesController(base.IsolatedUnitTest):
request, UUID4) request, UUID4)
def test_index_with_invalid_marker(self): def test_index_with_invalid_marker(self):
fake_uuid = uuidutils.generate_uuid() fake_uuid = str(uuid.uuid4())
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request()
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.index, request, marker=fake_uuid) self.controller.index, request, marker=fake_uuid)
@ -2107,7 +2108,7 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
self.deserializer.update, request) self.deserializer.update, request)
def test_index(self): def test_index(self):
marker = uuidutils.generate_uuid() marker = str(uuid.uuid4())
path = '/images?limit=1&marker=%s&member_status=pending' % marker path = '/images?limit=1&marker=%s&member_status=pending' % marker
request = unit_test_utils.get_fake_request(path) request = unit_test_utils.get_fake_request(path)
expected = {'limit': 1, expected = {'limit': 1,
@ -2136,7 +2137,7 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
def test_index_with_many_filter(self): def test_index_with_many_filter(self):
name = 'My Little Image' name = 'My Little Image'
instance_id = uuidutils.generate_uuid() instance_id = str(uuid.uuid4())
path = '/images?name=%(name)s&id=%(instance_id)s' % locals() path = '/images?name=%(name)s&id=%(instance_id)s' % locals()
request = unit_test_utils.get_fake_request(path) request = unit_test_utils.get_fake_request(path)
output = self.deserializer.index(request) output = self.deserializer.index(request)
@ -2183,7 +2184,7 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
self.deserializer.index, request) self.deserializer.index, request)
def test_index_marker(self): def test_index_marker(self):
marker = uuidutils.generate_uuid() marker = str(uuid.uuid4())
path = '/images?marker=%s' % marker path = '/images?marker=%s' % marker
request = unit_test_utils.get_fake_request(path) request = unit_test_utils.get_fake_request(path)
output = self.deserializer.index(request) output = self.deserializer.index(request)

@ -18,6 +18,7 @@
import datetime import datetime
import json import json
import uuid
from oslo.config import cfg from oslo.config import cfg
import routes import routes
@ -29,7 +30,7 @@ import glance.context
from glance.db.sqlalchemy import api as db_api from glance.db.sqlalchemy import api as db_api
from glance.db.sqlalchemy import models as db_models from glance.db.sqlalchemy import models as db_models
from glance.openstack.common import timeutils from glance.openstack.common import timeutils
from glance.openstack.common import uuidutils
from glance.registry.api import v2 as rserver from glance.registry.api import v2 as rserver
import glance.store.filesystem import glance.store.filesystem
from glance.tests.unit import base from glance.tests.unit import base
@ -37,7 +38,7 @@ from glance.tests import utils as test_utils
CONF = cfg.CONF CONF = cfg.CONF
_gen_uuid = uuidutils.generate_uuid _gen_uuid = lambda: str(uuid.uuid4())
UUID1 = _gen_uuid() UUID1 = _gen_uuid()
UUID2 = _gen_uuid() UUID2 = _gen_uuid()

@ -24,6 +24,7 @@ the registry's driver tests will be added.
import copy import copy
import datetime import datetime
import os import os
import uuid
import mox import mox
@ -32,7 +33,7 @@ from glance.common import exception
from glance import context from glance import context
from glance.db.sqlalchemy import api as db_api from glance.db.sqlalchemy import api as db_api
from glance.openstack.common import timeutils from glance.openstack.common import timeutils
from glance.openstack.common import uuidutils
import glance.registry.client.v2.api as rapi import glance.registry.client.v2.api as rapi
from glance.registry.client.v2.api import client as rclient from glance.registry.client.v2.api import client as rclient
from glance.registry.api import v2 as rserver from glance.registry.api import v2 as rserver
@ -40,10 +41,10 @@ from glance.tests.unit import base
from glance.tests import utils as test_utils from glance.tests import utils as test_utils
_gen_uuid = uuidutils.generate_uuid _gen_uuid = lambda: str(uuid.uuid4())
UUID1 = _gen_uuid() UUID1 = str(uuid.uuid4())
UUID2 = _gen_uuid() UUID2 = str(uuid.uuid4())
#NOTE(bcwaldon): needed to init config_dir cli opt #NOTE(bcwaldon): needed to init config_dir cli opt
config.parse_args(args=[]) config.parse_args(args=[])
@ -289,12 +290,14 @@ class TestRegistryV2Client(base.IsolatedUnitTest,
def test_image_get_index_limit(self): def test_image_get_index_limit(self):
"""Test correct number of images returned with limit param.""" """Test correct number of images returned with limit param."""
extra_fixture = self.get_fixture(id=_gen_uuid(), name='new name! #123', extra_fixture = self.get_fixture(id=_gen_uuid(),
name='new name! #123',
status='saving') status='saving')
db_api.image_create(self.context, extra_fixture) db_api.image_create(self.context, extra_fixture)
extra_fixture = self.get_fixture(id=_gen_uuid(), name='new name! #125', extra_fixture = self.get_fixture(id=_gen_uuid(),
name='new name! #125',
status='saving') status='saving')
db_api.image_create(self.context, extra_fixture) db_api.image_create(self.context, extra_fixture)
@ -322,12 +325,14 @@ class TestRegistryV2Client(base.IsolatedUnitTest,
def test_image_get_index_limit_None(self): def test_image_get_index_limit_None(self):
"""Test correct set of images returned with limit param == None.""" """Test correct set of images returned with limit param == None."""
extra_fixture = self.get_fixture(id=_gen_uuid(), name='new name! #123', extra_fixture = self.get_fixture(id=_gen_uuid(),
name='new name! #123',
status='saving') status='saving')
db_api.image_create(self.context, extra_fixture) db_api.image_create(self.context, extra_fixture)
extra_fixture = self.get_fixture(id=_gen_uuid(), name='new name! #125', extra_fixture = self.get_fixture(id=_gen_uuid(),
name='new name! #125',
status='saving') status='saving')
db_api.image_create(self.context, extra_fixture) db_api.image_create(self.context, extra_fixture)
@ -340,7 +345,8 @@ class TestRegistryV2Client(base.IsolatedUnitTest,
Test correct set of public, name-filtered image returned. This Test correct set of public, name-filtered image returned. This
is just a sanity check, we test the details call more in-depth. is just a sanity check, we test the details call more in-depth.
""" """
extra_fixture = self.get_fixture(id=_gen_uuid(), name='new name! #123') extra_fixture = self.get_fixture(id=_gen_uuid(),
name='new name! #123')
db_api.image_create(self.context, extra_fixture) db_api.image_create(self.context, extra_fixture)

@ -16,13 +16,13 @@
import datetime import datetime
import json import json
import uuid
import webob import webob
import glance.api.v2.tasks import glance.api.v2.tasks
import glance.domain import glance.domain
from glance.openstack.common import timeutils from glance.openstack.common import timeutils
from glance.openstack.common import uuidutils
from glance.tests.unit import base from glance.tests.unit import base
import glance.tests.unit.utils as unit_test_utils import glance.tests.unit.utils as unit_test_utils
import glance.tests.utils as test_utils import glance.tests.utils as test_utils
@ -235,7 +235,7 @@ class TestTasksController(test_utils.BaseTestCase):
self.assertEquals(UUID2, actual[2]) self.assertEquals(UUID2, actual[2])
def test_index_with_marker_not_found(self): def test_index_with_marker_not_found(self):
fake_uuid = uuidutils.generate_uuid() fake_uuid = str(uuid.uuid4())
path = '/tasks' path = '/tasks'
request = unit_test_utils.get_fake_request(path) request = unit_test_utils.get_fake_request(path)
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
@ -268,7 +268,7 @@ class TestTasksController(test_utils.BaseTestCase):
def test_get_non_existent(self): def test_get_non_existent(self):
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request()
task_id = uuidutils.generate_uuid() task_id = str(uuid.uuid4())
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller.get, request, task_id) self.controller.get, request, task_id)
@ -362,7 +362,7 @@ class TestTasksDeserializer(test_utils.BaseTestCase):
self.assertEqual(expected, output) self.assertEqual(expected, output)
def test_index(self): def test_index(self):
marker = uuidutils.generate_uuid() marker = str(uuid.uuid4())
path = '/tasks?limit=1&marker=%s' % marker path = '/tasks?limit=1&marker=%s' % marker
request = unit_test_utils.get_fake_request(path) request = unit_test_utils.get_fake_request(path)
expected = {'limit': 1, expected = {'limit': 1,
@ -429,7 +429,7 @@ class TestTasksDeserializer(test_utils.BaseTestCase):
self.deserializer.index, request) self.deserializer.index, request)
def test_index_marker(self): def test_index_marker(self):
marker = uuidutils.generate_uuid() marker = str(uuid.uuid4())
path = '/tasks?marker=%s' % marker path = '/tasks?marker=%s' % marker
request = unit_test_utils.get_fake_request(path) request = unit_test_utils.get_fake_request(path)
output = self.deserializer.index(request) output = self.deserializer.index(request)

@ -26,6 +26,7 @@ import shutil
import socket import socket
import StringIO import StringIO
import subprocess import subprocess
import uuid
import fixtures import fixtures
from oslo.config import cfg from oslo.config import cfg
@ -35,6 +36,7 @@ import webob
from glance.common import config from glance.common import config
from glance.common import exception from glance.common import exception
from glance.common import utils
from glance.common import wsgi from glance.common import wsgi
from glance.db.sqlalchemy import api as db_api from glance.db.sqlalchemy import api as db_api
from glance.db.sqlalchemy import models as db_models from glance.db.sqlalchemy import models as db_models
@ -559,3 +561,22 @@ class HttplibWsgiAdapter(object):
response = self.req.get_response(self.app) response = self.req.get_response(self.app)
return FakeHTTPResponse(response.status_code, response.headers, return FakeHTTPResponse(response.status_code, response.headers,
response.body) response.body)
class UUIDTestCase(testtools.TestCase):
def test_generate_uuid(self):
uuid_string = utils.generate_uuid()
self.assertTrue(isinstance(uuid_string, str))
self.assertEqual(len(uuid_string), 36)
# make sure there are 4 dashes
self.assertEqual(len(uuid_string.replace('-', '')), 32)
def test_is_uuid_like(self):
self.assertTrue(utils.is_uuid_like(str(uuid.uuid4())))
def test_id_is_uuid_like(self):
self.assertFalse(utils.is_uuid_like(1234567))
def test_name_is_uuid_like(self):
self.assertFalse(utils.is_uuid_like('zhongyueluo'))

@ -17,7 +17,6 @@ module=strutils
module=test module=test
module=timeutils module=timeutils
module=units module=units
module=uuidutils
# The base module to hold the copy of openstack.common # The base module to hold the copy of openstack.common
base=glance base=glance