utils: use oslo_utils.uuidutils
Change-Id: Ie9e38c194b80b903b2113f3c29c9ccb1a9cbe065
This commit is contained in:
parent
fc44ebb8e9
commit
e61ae05e4d
|
@ -22,6 +22,7 @@ from oslo_log import log as logging
|
|||
import oslo_serialization.jsonutils as json
|
||||
from oslo_utils import encodeutils
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
import six.moves.urllib.parse as urlparse
|
||||
import webob.exc
|
||||
|
@ -29,7 +30,6 @@ import webob.exc
|
|||
from glance.api import common
|
||||
from glance.api import policy
|
||||
from glance.common import exception
|
||||
from glance.common import utils
|
||||
from glance.common import wsgi
|
||||
import glance.db
|
||||
import glance.gateway
|
||||
|
@ -164,7 +164,7 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer):
|
|||
return filters
|
||||
|
||||
def _validate_marker(self, marker):
|
||||
if marker and not utils.is_uuid_like(marker):
|
||||
if marker and not uuidutils.is_uuid_like(marker):
|
||||
msg = _('Invalid marker format')
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
return marker
|
||||
|
|
|
@ -25,6 +25,7 @@ from oslo_config import cfg
|
|||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import encodeutils
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
from six.moves import http_client
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
@ -446,7 +447,7 @@ def replication_load(options, args):
|
|||
updated = []
|
||||
|
||||
for ent in os.listdir(path):
|
||||
if utils.is_uuid_like(ent):
|
||||
if uuidutils.is_uuid_like(ent):
|
||||
image_uuid = ent
|
||||
LOG.info(_LI('Considering: %s'), image_uuid)
|
||||
|
||||
|
|
|
@ -591,18 +591,6 @@ def get_test_suite_socket():
|
|||
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
|
||||
|
||||
|
||||
def is_valid_hostname(hostname):
|
||||
"""Verify whether a hostname (not an FQDN) is valid."""
|
||||
return re.match('^[a-zA-Z0-9-]+$', hostname) is not None
|
||||
|
|
|
@ -22,6 +22,7 @@ from oslo_log import log as logging
|
|||
from oslo_utils import encodeutils
|
||||
from oslo_utils import strutils
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
from webob import exc
|
||||
|
||||
from glance.common import exception
|
||||
|
@ -276,7 +277,7 @@ class Controller(object):
|
|||
"""Parse a marker query param into something usable."""
|
||||
marker = req.params.get('marker', None)
|
||||
|
||||
if marker and not utils.is_uuid_like(marker):
|
||||
if marker and not uuidutils.is_uuid_like(marker):
|
||||
msg = _('Invalid marker format')
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
|
@ -406,7 +407,7 @@ class Controller(object):
|
|||
image_data['owner'] = req.context.owner
|
||||
|
||||
image_id = image_data.get('id')
|
||||
if image_id and not utils.is_uuid_like(image_id):
|
||||
if image_id and not uuidutils.is_uuid_like(image_id):
|
||||
LOG.info(_LI("Rejecting image creation request for invalid image "
|
||||
"id '%(bad_id)s'"), {'bad_id': image_id})
|
||||
msg = _("Invalid image id format")
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
import os
|
||||
import tempfile
|
||||
import uuid
|
||||
|
||||
import six
|
||||
import webob
|
||||
|
@ -408,15 +407,3 @@ class TestUtils(test_utils.BaseTestCase):
|
|||
self.assertRaises(ValueError,
|
||||
utils.parse_valid_host_port,
|
||||
pair)
|
||||
|
||||
|
||||
class UUIDTestCase(test_utils.BaseTestCase):
|
||||
|
||||
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'))
|
||||
|
|
|
@ -38,6 +38,7 @@ from oslo_db.sqlalchemy import test_migrations
|
|||
from oslo_db.sqlalchemy import utils as db_utils
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
||||
from six.moves import range
|
||||
import sqlalchemy
|
||||
|
@ -45,7 +46,6 @@ from sqlalchemy import inspect
|
|||
|
||||
from glance.common import crypt
|
||||
from glance.common import exception
|
||||
from glance.common import utils
|
||||
from glance.db import migration
|
||||
from glance.db.sqlalchemy import migrate_repo
|
||||
from glance.db.sqlalchemy.migrate_repo.schema import from_migration_import
|
||||
|
@ -346,7 +346,7 @@ class MigrationsMixin(test_migrations.WalkVersionsMixin):
|
|||
self.assertEqual(1, len(rows))
|
||||
|
||||
row = rows[0]
|
||||
self.assertTrue(utils.is_uuid_like(row['id']))
|
||||
self.assertTrue(uuidutils.is_uuid_like(row['id']))
|
||||
|
||||
uuids[name] = row['id']
|
||||
|
||||
|
@ -385,7 +385,7 @@ class MigrationsMixin(test_migrations.WalkVersionsMixin):
|
|||
self.assertEqual(1, len(rows))
|
||||
|
||||
row = rows[0]
|
||||
self.assertFalse(utils.is_uuid_like(row['id']))
|
||||
self.assertFalse(uuidutils.is_uuid_like(row['id']))
|
||||
|
||||
ids[name] = row['id']
|
||||
|
||||
|
|
Loading…
Reference in New Issue