From cb64f58b991ff5a958cce9d904c7096cce095393 Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Thu, 20 Sep 2012 14:06:57 +0800 Subject: [PATCH] Clean up pep8 E128 violations Fixed E128 errors All ignores are to be removed in the next sequence of patches Change-Id: I3ccff7df8c382f83ae6aa9aa6a7f16324c3aec75 --- glance/api/common.py | 6 +- glance/api/middleware/cache_manage.py | 42 +++---- glance/api/v1/controller.py | 5 +- glance/api/v1/images.py | 25 +++-- glance/api/v2/image_data.py | 4 +- glance/api/v2/images.py | 13 ++- glance/common/exception.py | 6 +- glance/common/utils.py | 12 +- glance/common/wsgi.py | 16 ++- glance/db/simple/api.py | 5 +- .../versions/001_add_images_table.py | 39 ++++--- .../002_add_image_properties_table.py | 41 ++++--- .../versions/003_add_disk_format.py | 41 ++++--- .../migrate_repo/versions/004_add_checksum.py | 43 +++++--- .../versions/005_size_big_integer.py | 41 ++++--- .../migrate_repo/versions/006_key_to_name.py | 42 ++++--- .../migrate_repo/versions/007_add_owner.py | 45 ++++---- .../versions/008_add_image_members_table.py | 41 ++++--- .../versions/009_add_mindisk_and_minram.py | 47 ++++---- .../versions/014_add_image_tags_table.py | 37 +++++-- glance/image_cache/__init__.py | 2 +- glance/registry/api/v1/images.py | 8 +- glance/registry/client.py | 7 +- glance/store/filesystem.py | 2 +- glance/store/s3.py | 15 ++- glance/store/swift.py | 19 ++-- glance/tests/functional/db/__init__.py | 37 ++++--- glance/tests/functional/store/test_swift.py | 8 +- glance/tests/functional/store_utils.py | 2 +- glance/tests/functional/test_scrubber.py | 10 +- glance/tests/functional/v1/test_api.py | 97 ++++++++++------- glance/tests/functional/v1/test_ssl.py | 54 +++++---- glance/tests/unit/test_cache_middleware.py | 3 +- glance/tests/unit/test_clients.py | 3 +- glance/tests/unit/test_config.py | 2 +- glance/tests/unit/test_context_middleware.py | 2 +- glance/tests/unit/test_http_store.py | 10 +- glance/tests/unit/test_migrations.py | 28 +++-- glance/tests/unit/test_notifier.py | 7 +- glance/tests/unit/test_swift_store.py | 19 ++-- glance/tests/unit/test_wsgi.py | 2 +- glance/tests/unit/v1/test_api.py | 62 ++++++----- .../tests/unit/v2/test_image_data_resource.py | 10 +- glance/tests/unit/v2/test_images_resource.py | 103 ++++++++++++------ tox.ini | 2 +- 45 files changed, 630 insertions(+), 435 deletions(-) diff --git a/glance/api/common.py b/glance/api/common.py index 0841d12f..38449cce 100644 --- a/glance/api/common.py +++ b/glance/api/common.py @@ -22,13 +22,13 @@ LOG = logging.getLogger(__name__) def size_checked_iter(response, image_meta, expected_size, image_iter, - notifier): + notifier): image_id = image_meta['id'] bytes_written = 0 def notify_image_sent_hook(env): image_send_notification(bytes_written, expected_size, - image_meta, response.request, notifier) + image_meta, response.request, notifier) # Add hook to process after response is fully sent if 'eventlet.posthooks' in response.request.environ: @@ -55,7 +55,7 @@ def size_checked_iter(response, image_meta, expected_size, image_iter, def image_send_notification(bytes_written, expected_size, image_meta, request, - notifier): + notifier): """Send an image.send message to the notifier.""" try: context = request.context diff --git a/glance/api/middleware/cache_manage.py b/glance/api/middleware/cache_manage.py index bc827831..20885460 100644 --- a/glance/api/middleware/cache_manage.py +++ b/glance/api/middleware/cache_manage.py @@ -34,39 +34,39 @@ class CacheManageFilter(wsgi.Middleware): resource = cached_images.create_resource() mapper.connect("/v1/cached_images", - controller=resource, - action="get_cached_images", - conditions=dict(method=["GET"])) + controller=resource, + action="get_cached_images", + conditions=dict(method=["GET"])) mapper.connect("/v1/cached_images/{image_id}", - controller=resource, - action="delete_cached_image", - conditions=dict(method=["DELETE"])) + controller=resource, + action="delete_cached_image", + conditions=dict(method=["DELETE"])) mapper.connect("/v1/cached_images", - controller=resource, - action="delete_cached_images", - conditions=dict(method=["DELETE"])) + controller=resource, + action="delete_cached_images", + conditions=dict(method=["DELETE"])) mapper.connect("/v1/queued_images/{image_id}", - controller=resource, - action="queue_image", - conditions=dict(method=["PUT"])) + controller=resource, + action="queue_image", + conditions=dict(method=["PUT"])) mapper.connect("/v1/queued_images", - controller=resource, - action="get_queued_images", - conditions=dict(method=["GET"])) + controller=resource, + action="get_queued_images", + conditions=dict(method=["GET"])) mapper.connect("/v1/queued_images/{image_id}", - controller=resource, - action="delete_queued_image", - conditions=dict(method=["DELETE"])) + controller=resource, + action="delete_queued_image", + conditions=dict(method=["DELETE"])) mapper.connect("/v1/queued_images", - controller=resource, - action="delete_queued_images", - conditions=dict(method=["DELETE"])) + controller=resource, + action="delete_queued_images", + conditions=dict(method=["DELETE"])) self._mapper = mapper self._resource = resource diff --git a/glance/api/v1/controller.py b/glance/api/v1/controller.py index 24d69a4c..7130e0e7 100644 --- a/glance/api/v1/controller.py +++ b/glance/api/v1/controller.py @@ -47,8 +47,9 @@ class BaseController(object): except exception.Forbidden: msg = _("Forbidden image access") LOG.debug(msg) - raise webob.exc.HTTPForbidden(msg, request=request, - content_type='text/plain') + raise webob.exc.HTTPForbidden(msg, + request=request, + content_type='text/plain') def get_active_image_meta_or_404(self, request, image_id): """ diff --git a/glance/api/v1/images.py b/glance/api/v1/images.py index 097dc053..fb6354ba 100644 --- a/glance/api/v1/images.py +++ b/glance/api/v1/images.py @@ -58,7 +58,7 @@ SUPPORTED_PARAMS = glance.api.v1.SUPPORTED_PARAMS SUPPORTED_FILTERS = glance.api.v1.SUPPORTED_FILTERS CONTAINER_FORMATS = ['ami', 'ari', 'aki', 'bare', 'ovf'] DISK_FORMATS = ['ami', 'ari', 'aki', 'vhd', 'vmdk', 'raw', 'qcow2', 'vdi', - 'iso'] + 'iso'] # Defined at module level due to _is_opt_registered @@ -361,8 +361,8 @@ class Controller(controller.BaseController): image_meta = registry.add_image_metadata(req.context, image_meta) return image_meta except exception.Duplicate: - msg = (_("An image with identifier %s already exists") - % image_meta['id']) + msg = (_("An image with identifier %s already exists") % + image_meta['id']) LOG.error(msg) raise HTTPConflict(explanation=msg, request=req, @@ -440,9 +440,9 @@ class Controller(controller.BaseController): supplied_checksum = image_meta.get('checksum') if supplied_checksum and supplied_checksum != checksum: msg = _("Supplied checksum (%(supplied_checksum)s) and " - "checksum generated from uploaded image " - "(%(checksum)s) did not match. Setting image " - "status to 'killed'.") % locals() + "checksum generated from uploaded image " + "(%(checksum)s) did not match. Setting image " + "status to 'killed'.") % locals() LOG.error(msg) self._safe_kill(req, image_id) raise HTTPBadRequest(explanation=msg, @@ -515,7 +515,7 @@ class Controller(controller.BaseController): msg = _("Error uploading image: (%(class_name)s): " "%(exc)s") % ({'class_name': e.__class__.__name__, - 'exc': str(e)}) + 'exc': str(e)}) raise HTTPBadRequest(explanation=msg, request=req) @@ -534,8 +534,8 @@ class Controller(controller.BaseController): try: image_meta_data = registry.update_image_metadata(req.context, - image_id, - image_meta) + image_id, + image_meta) self.notifier.info("image.update", image_meta_data) return image_meta_data except exception.Invalid, e: @@ -572,7 +572,7 @@ class Controller(controller.BaseController): except Exception, e: LOG.error(_("Unable to kill image %(id)s: " "%(exc)s") % ({'id': image_id, - 'exc': repr(e)})) + 'exc': repr(e)})) def _upload_and_activate(self, req, image_meta): """ @@ -600,8 +600,9 @@ class Controller(controller.BaseController): def _handle_source(self, req, image_id, image_meta, image_data): if image_data: - image_meta = self._validate_image_for_activation(req, image_id, - image_meta) + image_meta = self._validate_image_for_activation(req, + image_id, + image_meta) image_meta = self._upload_and_activate(req, image_meta) elif self._copy_from(req): msg = _('Triggering asynchronous copy from external source') diff --git a/glance/api/v2/image_data.py b/glance/api/v2/image_data.py index f914e7c5..e9083f40 100644 --- a/glance/api/v2/image_data.py +++ b/glance/api/v2/image_data.py @@ -73,13 +73,13 @@ class ImageDataController(object): msg = _("Image storage media is full: %s") % e LOG.error(msg) raise webob.exc.HTTPRequestEntityTooLarge(explanation=msg, - request=req) + request=req) except exception.StorageWriteDenied, e: msg = _("Insufficient permissions on image storage media: %s") % e LOG.error(msg) raise webob.exc.HTTPServiceUnavailable(explanation=msg, - request=req) + request=req) except webob.exc.HTTPError, e: LOG.error("Failed to upload image data due to HTTP error") diff --git a/glance/api/v2/images.py b/glance/api/v2/images.py index afc65796..9127b89e 100644 --- a/glance/api/v2/images.py +++ b/glance/api/v2/images.py @@ -42,7 +42,7 @@ CONF = cfg.CONF class ImagesController(object): def __init__(self, db_api=None, policy_enforcer=None, notifier=None, - store_api=None): + store_api=None): self.db_api = db_api or glance.db.get_api() self.db_api.configure_db() self.policy = policy_enforcer or policy.Enforcer() @@ -289,12 +289,13 @@ class ImagesController(object): class RequestDeserializer(wsgi.JSONRequestDeserializer): _readonly_properties = ['created_at', 'updated_at', 'status', 'checksum', - 'size', 'direct_url', 'self', 'file', 'schema'] - _reserved_properties = ['owner', 'is_public', 'location', - 'deleted', 'deleted_at'] + 'size', 'direct_url', 'self', 'file', 'schema'] + _reserved_properties = ['owner', 'is_public', 'location', 'deleted', + 'deleted_at'] _base_properties = ['checksum', 'created_at', 'container_format', - 'disk_format', 'id', 'min_disk', 'min_ram', 'name', 'size', - 'status', 'tags', 'updated_at', 'visibility', 'protected'] + 'disk_format', 'id', 'min_disk', 'min_ram', 'name', + 'size', 'status', 'tags', 'updated_at', 'visibility', + 'protected'] def __init__(self, schema=None): super(RequestDeserializer, self).__init__() diff --git a/glance/common/exception.py b/glance/common/exception.py index a05ac1d7..4aeae543 100644 --- a/glance/common/exception.py +++ b/glance/common/exception.py @@ -189,12 +189,12 @@ class BadRegistryConnectionConfiguration(GlanceException): class BadStoreConfiguration(GlanceException): message = _("Store %(store_name)s could not be configured correctly. " - "Reason: %(reason)s") + "Reason: %(reason)s") class BadDriverConfiguration(GlanceException): message = _("Driver %(driver_name)s could not be configured correctly. " - "Reason: %(reason)s") + "Reason: %(reason)s") class StoreDeleteNotSupported(GlanceException): @@ -203,7 +203,7 @@ class StoreDeleteNotSupported(GlanceException): class StoreAddDisabled(GlanceException): message = _("Configuration for store failed. Adding images to this " - "store is disabled.") + "store is disabled.") class InvalidNotifierStrategy(GlanceException): diff --git a/glance/common/utils.py b/glance/common/utils.py index 68ddd1d7..6e715f9f 100644 --- a/glance/common/utils.py +++ b/glance/common/utils.py @@ -340,17 +340,17 @@ def get_terminal_size(): try: height_width = struct.unpack('hh', fcntl.ioctl(sys.stderr.fileno(), - termios.TIOCGWINSZ, - struct.pack('HH', 0, 0))) + termios.TIOCGWINSZ, + struct.pack('HH', 0, 0))) except: pass if not height_width: try: p = subprocess.Popen(['stty', 'size'], - shell=False, - stdout=subprocess.PIPE, - stderr=open(os.devnull, 'w')) + shell=False, + stdout=subprocess.PIPE, + stderr=open(os.devnull, 'w')) result = p.communicate() if p.returncode == 0: return tuple(int(x) for x in result[0].split()) @@ -371,7 +371,7 @@ def get_terminal_size(): import struct unpack_tmp = struct.unpack("hhhhHhhhhhh", csbi.raw) (bufx, bufy, curx, cury, wattr, - left, top, right, bottom, maxx, maxy) = unpack_tmp + left, top, right, bottom, maxx, maxy) = unpack_tmp height = bottom - top + 1 width = right - left + 1 return (height, width) diff --git a/glance/common/wsgi.py b/glance/common/wsgi.py index 90f4b1a1..5f0b3a1c 100644 --- a/glance/common/wsgi.py +++ b/glance/common/wsgi.py @@ -98,9 +98,13 @@ def get_socket(default_port): # TODO(jaypipes): eventlet's greened socket module does not actually # support IPv6 in getaddrinfo(). We need to get around this in the # future or monitor upstream for a fix - address_family = [addr[0] for addr in socket.getaddrinfo(bind_addr[0], - bind_addr[1], socket.AF_UNSPEC, socket.SOCK_STREAM) - if addr[0] in (socket.AF_INET, socket.AF_INET6)][0] + address_family = [ + addr[0] for addr in socket.getaddrinfo(bind_addr[0], + bind_addr[1], + socket.AF_UNSPEC, + socket.SOCK_STREAM) + if addr[0] in (socket.AF_INET, socket.AF_INET6) + ][0] cert_file = CONF.cert_file key_file = CONF.key_file @@ -272,8 +276,10 @@ class Server(object): raise exception.WorkerCreationFailure(reason=msg) self.pool = self.create_pool() try: - eventlet.wsgi.server(self.sock, self.app_func(), - log=WritableLogger(self.logger), custom_pool=self.pool) + eventlet.wsgi.server(self.sock, + self.app_func(), + log=WritableLogger(self.logger), + custom_pool=self.pool) except socket.error, err: if err[0] != errno.EINVAL: raise diff --git a/glance/db/simple/api.py b/glance/db/simple/api.py index b2003bdd..5a2fff48 100644 --- a/glance/db/simple/api.py +++ b/glance/db/simple/api.py @@ -239,8 +239,9 @@ def image_get_all(context, filters=None, marker=None, limit=None, @log_call def image_property_create(context, values): image = image_get(context, values['image_id']) - prop = _image_property_format(values['image_id'], values['name'], - values['value']) + prop = _image_property_format(values['image_id'], + values['name'], + values['value']) image['properties'].append(prop) return prop diff --git a/glance/db/sqlalchemy/migrate_repo/versions/001_add_images_table.py b/glance/db/sqlalchemy/migrate_repo/versions/001_add_images_table.py index f8aabd2d..ea124754 100644 --- a/glance/db/sqlalchemy/migrate_repo/versions/001_add_images_table.py +++ b/glance/db/sqlalchemy/migrate_repo/versions/001_add_images_table.py @@ -22,22 +22,29 @@ from glance.db.sqlalchemy.migrate_repo.schema import ( def define_images_table(meta): - images = Table('images', meta, - Column('id', Integer(), primary_key=True, nullable=False), - Column('name', String(255)), - Column('type', String(30)), - Column('size', Integer()), - Column('status', String(30), nullable=False), - Column('is_public', Boolean(), nullable=False, default=False, - index=True), - Column('location', Text()), - Column('created_at', DateTime(), nullable=False), - Column('updated_at', DateTime()), - Column('deleted_at', DateTime()), - Column('deleted', Boolean(), nullable=False, default=False, - index=True), - mysql_engine='InnoDB', - extend_existing=True) + images = Table('images', + meta, + Column('id', Integer(), primary_key=True, nullable=False), + Column('name', String(255)), + Column('type', String(30)), + Column('size', Integer()), + Column('status', String(30), nullable=False), + Column('is_public', + Boolean(), + nullable=False, + default=False, + index=True), + Column('location', Text()), + Column('created_at', DateTime(), nullable=False), + Column('updated_at', DateTime()), + Column('deleted_at', DateTime()), + Column('deleted', + Boolean(), + nullable=False, + default=False, + index=True), + mysql_engine='InnoDB', + extend_existing=True) return images diff --git a/glance/db/sqlalchemy/migrate_repo/versions/002_add_image_properties_table.py b/glance/db/sqlalchemy/migrate_repo/versions/002_add_image_properties_table.py index f99311b3..8ee24b05 100644 --- a/glance/db/sqlalchemy/migrate_repo/versions/002_add_image_properties_table.py +++ b/glance/db/sqlalchemy/migrate_repo/versions/002_add_image_properties_table.py @@ -29,22 +29,33 @@ def define_image_properties_table(meta): images = define_images_table(meta) - image_properties = Table('image_properties', meta, - Column('id', Integer(), primary_key=True, nullable=False), - Column('image_id', Integer(), ForeignKey('images.id'), nullable=False, - index=True), - Column('key', String(255), nullable=False), - Column('value', Text()), - Column('created_at', DateTime(), nullable=False), - Column('updated_at', DateTime()), - Column('deleted_at', DateTime()), - Column('deleted', Boolean(), nullable=False, default=False, - index=True), - UniqueConstraint('image_id', 'key'), - mysql_engine='InnoDB', - extend_existing=True) + image_properties = Table('image_properties', + meta, + Column('id', + Integer(), + primary_key=True, + nullable=False), + Column('image_id', + Integer(), + ForeignKey('images.id'), + nullable=False, + index=True), + Column('key', String(255), nullable=False), + Column('value', Text()), + Column('created_at', DateTime(), nullable=False), + Column('updated_at', DateTime()), + Column('deleted_at', DateTime()), + Column('deleted', + Boolean(), + nullable=False, + default=False, + index=True), + UniqueConstraint('image_id', 'key'), + mysql_engine='InnoDB', + extend_existing=True) - Index('ix_image_properties_image_id_key', image_properties.c.image_id, + Index('ix_image_properties_image_id_key', + image_properties.c.image_id, image_properties.c.key) return image_properties diff --git a/glance/db/sqlalchemy/migrate_repo/versions/003_add_disk_format.py b/glance/db/sqlalchemy/migrate_repo/versions/003_add_disk_format.py index 3abc19de..e86a5166 100644 --- a/glance/db/sqlalchemy/migrate_repo/versions/003_add_disk_format.py +++ b/glance/db/sqlalchemy/migrate_repo/versions/003_add_disk_format.py @@ -27,23 +27,30 @@ def get_images_table(meta): Returns the Table object for the images table that corresponds to the images table definition of this version. """ - images = Table('images', meta, - Column('id', Integer(), primary_key=True, nullable=False), - Column('name', String(255)), - Column('disk_format', String(20)), - Column('container_format', String(20)), - Column('size', Integer()), - Column('status', String(30), nullable=False), - Column('is_public', Boolean(), nullable=False, default=False, - index=True), - Column('location', Text()), - Column('created_at', DateTime(), nullable=False), - Column('updated_at', DateTime()), - Column('deleted_at', DateTime()), - Column('deleted', Boolean(), nullable=False, default=False, - index=True), - mysql_engine='InnoDB', - useexisting=True) + images = Table('images', + meta, + Column('id', Integer(), primary_key=True, nullable=False), + Column('name', String(255)), + Column('disk_format', String(20)), + Column('container_format', String(20)), + Column('size', Integer()), + Column('status', String(30), nullable=False), + Column('is_public', + Boolean(), + nullable=False, + default=False, + index=True), + Column('location', Text()), + Column('created_at', DateTime(), nullable=False), + Column('updated_at', DateTime()), + Column('deleted_at', DateTime()), + Column('deleted', + Boolean(), + nullable=False, + default=False, + index=True), + mysql_engine='InnoDB', + useexisting=True) return images diff --git a/glance/db/sqlalchemy/migrate_repo/versions/004_add_checksum.py b/glance/db/sqlalchemy/migrate_repo/versions/004_add_checksum.py index b9d7d06b..ecce474d 100644 --- a/glance/db/sqlalchemy/migrate_repo/versions/004_add_checksum.py +++ b/glance/db/sqlalchemy/migrate_repo/versions/004_add_checksum.py @@ -27,24 +27,31 @@ def get_images_table(meta): Returns the Table object for the images table that corresponds to the images table definition of this version. """ - images = Table('images', meta, - Column('id', Integer(), primary_key=True, nullable=False), - Column('name', String(255)), - Column('disk_format', String(20)), - Column('container_format', String(20)), - Column('size', Integer()), - Column('status', String(30), nullable=False), - Column('is_public', Boolean(), nullable=False, default=False, - index=True), - Column('location', Text()), - Column('created_at', DateTime(), nullable=False), - Column('updated_at', DateTime()), - Column('deleted_at', DateTime()), - Column('deleted', Boolean(), nullable=False, default=False, - index=True), - Column('checksum', String(32)), - mysql_engine='InnoDB', - extend_existing=True) + images = Table('images', + meta, + Column('id', Integer(), primary_key=True, nullable=False), + Column('name', String(255)), + Column('disk_format', String(20)), + Column('container_format', String(20)), + Column('size', Integer()), + Column('status', String(30), nullable=False), + Column('is_public', + Boolean(), + nullable=False, + default=False, + index=True), + Column('location', Text()), + Column('created_at', DateTime(), nullable=False), + Column('updated_at', DateTime()), + Column('deleted_at', DateTime()), + Column('deleted', + Boolean(), + nullable=False, + default=False, + index=True), + Column('checksum', String(32)), + mysql_engine='InnoDB', + extend_existing=True) return images diff --git a/glance/db/sqlalchemy/migrate_repo/versions/005_size_big_integer.py b/glance/db/sqlalchemy/migrate_repo/versions/005_size_big_integer.py index 61fa0206..727f7231 100644 --- a/glance/db/sqlalchemy/migrate_repo/versions/005_size_big_integer.py +++ b/glance/db/sqlalchemy/migrate_repo/versions/005_size_big_integer.py @@ -28,23 +28,30 @@ def get_images_table(meta): Returns the Table object for the images table that corresponds to the images table definition of this version. """ - images = Table('images', meta, - Column('id', Integer(), primary_key=True, nullable=False), - Column('name', String(255)), - Column('disk_format', String(20)), - Column('container_format', String(20)), - Column('size', BigInteger()), - Column('status', String(30), nullable=False), - Column('is_public', Boolean(), nullable=False, default=False, - index=True), - Column('location', Text()), - Column('created_at', DateTime(), nullable=False), - Column('updated_at', DateTime()), - Column('deleted_at', DateTime()), - Column('deleted', Boolean(), nullable=False, default=False, - index=True), - mysql_engine='InnoDB', - useexisting=True) + images = Table('images', + meta, + Column('id', Integer(), primary_key=True, nullable=False), + Column('name', String(255)), + Column('disk_format', String(20)), + Column('container_format', String(20)), + Column('size', BigInteger()), + Column('status', String(30), nullable=False), + Column('is_public', + Boolean(), + nullable=False, + default=False, + index=True), + Column('location', Text()), + Column('created_at', DateTime(), nullable=False), + Column('updated_at', DateTime()), + Column('deleted_at', DateTime()), + Column('deleted', + Boolean(), + nullable=False, + default=False, + index=True), + mysql_engine='InnoDB', + useexisting=True) return images diff --git a/glance/db/sqlalchemy/migrate_repo/versions/006_key_to_name.py b/glance/db/sqlalchemy/migrate_repo/versions/006_key_to_name.py index 3f371dd2..9417af08 100644 --- a/glance/db/sqlalchemy/migrate_repo/versions/006_key_to_name.py +++ b/glance/db/sqlalchemy/migrate_repo/versions/006_key_to_name.py @@ -43,20 +43,30 @@ def get_image_properties_table(meta): images = get_images_table(meta) - image_properties = Table('image_properties', meta, - Column('id', Integer(), primary_key=True, nullable=False), - Column('image_id', Integer(), ForeignKey('images.id'), nullable=False, - index=True), - Column('name', String(255), nullable=False), - Column('value', Text()), - Column('created_at', DateTime(), nullable=False), - Column('updated_at', DateTime()), - Column('deleted_at', DateTime()), - Column('deleted', Boolean(), nullable=False, default=False, - index=True), - UniqueConstraint('image_id', 'name'), - mysql_engine='InnoDB', - useexisting=True) + image_properties = Table('image_properties', + meta, + Column('id', + Integer(), + primary_key=True, + nullable=False), + Column('image_id', + Integer(), + ForeignKey('images.id'), + nullable=False, + index=True), + Column('name', String(255), nullable=False), + Column('value', Text()), + Column('created_at', DateTime(), nullable=False), + Column('updated_at', DateTime()), + Column('deleted_at', DateTime()), + Column('deleted', + Boolean(), + nullable=False, + default=False, + index=True), + UniqueConstraint('image_id', 'name'), + mysql_engine='InnoDB', + useexisting=True) return image_properties @@ -71,7 +81,7 @@ def upgrade(migrate_engine): index = Index('ix_image_properties_image_id_key', image_properties.c.image_id, - image_properties.c.key) + image_properties.c.key) index.rename('ix_image_properties_image_id_name') image_properties = get_image_properties_table(meta) @@ -86,7 +96,7 @@ def downgrade(migrate_engine): index = Index('ix_image_properties_image_id_name', image_properties.c.image_id, - image_properties.c.name) + image_properties.c.name) index.rename('ix_image_properties_image_id_key') image_properties.columns['name'].alter(name="key") diff --git a/glance/db/sqlalchemy/migrate_repo/versions/007_add_owner.py b/glance/db/sqlalchemy/migrate_repo/versions/007_add_owner.py index 267d57fd..53a9e8a1 100644 --- a/glance/db/sqlalchemy/migrate_repo/versions/007_add_owner.py +++ b/glance/db/sqlalchemy/migrate_repo/versions/007_add_owner.py @@ -28,25 +28,32 @@ def get_images_table(meta): Returns the Table object for the images table that corresponds to the images table definition of this version. """ - images = Table('images', meta, - Column('id', Integer(), primary_key=True, nullable=False), - Column('name', String(255)), - Column('disk_format', String(20)), - Column('container_format', String(20)), - Column('size', BigInteger()), - Column('status', String(30), nullable=False), - Column('is_public', Boolean(), nullable=False, default=False, - index=True), - Column('location', Text()), - Column('created_at', DateTime(), nullable=False), - Column('updated_at', DateTime()), - Column('deleted_at', DateTime()), - Column('deleted', Boolean(), nullable=False, default=False, - index=True), - Column('checksum', String(32)), - Column('owner', String(255)), - mysql_engine='InnoDB', - extend_existing=True) + images = Table('images', + meta, + Column('id', Integer(), primary_key=True, nullable=False), + Column('name', String(255)), + Column('disk_format', String(20)), + Column('container_format', String(20)), + Column('size', BigInteger()), + Column('status', String(30), nullable=False), + Column('is_public', + Boolean(), + nullable=False, + default=False, + index=True), + Column('location', Text()), + Column('created_at', DateTime(), nullable=False), + Column('updated_at', DateTime()), + Column('deleted_at', DateTime()), + Column('deleted', + Boolean(), + nullable=False, + default=False, + index=True), + Column('checksum', String(32)), + Column('owner', String(255)), + mysql_engine='InnoDB', + extend_existing=True) return images diff --git a/glance/db/sqlalchemy/migrate_repo/versions/008_add_image_members_table.py b/glance/db/sqlalchemy/migrate_repo/versions/008_add_image_members_table.py index 07367741..35c3e1e5 100644 --- a/glance/db/sqlalchemy/migrate_repo/versions/008_add_image_members_table.py +++ b/glance/db/sqlalchemy/migrate_repo/versions/008_add_image_members_table.py @@ -48,20 +48,33 @@ def get_image_properties_table(meta): def get_image_members_table(meta): images = get_images_table(meta) - image_members = Table('image_members', meta, - Column('id', Integer(), primary_key=True, nullable=False), - Column('image_id', Integer(), ForeignKey('images.id'), nullable=False, - index=True), - Column('member', String(255), nullable=False), - Column('can_share', Boolean(), nullable=False, default=False), - Column('created_at', DateTime(), nullable=False), - Column('updated_at', DateTime()), - Column('deleted_at', DateTime()), - Column('deleted', Boolean(), nullable=False, default=False, - index=True), - UniqueConstraint('image_id', 'member'), - mysql_engine='InnoDB', - extend_existing=True) + image_members = Table('image_members', + meta, + Column('id', + Integer(), + primary_key=True, + nullable=False), + Column('image_id', + Integer(), + ForeignKey('images.id'), + nullable=False, + index=True), + Column('member', String(255), nullable=False), + Column('can_share', + Boolean(), + nullable=False, + default=False), + Column('created_at', DateTime(), nullable=False), + Column('updated_at', DateTime()), + Column('deleted_at', DateTime()), + Column('deleted', + Boolean(), + nullable=False, + default=False, + index=True), + UniqueConstraint('image_id', 'member'), + mysql_engine='InnoDB', + extend_existing=True) Index('ix_image_members_image_id_member', image_members.c.image_id, image_members.c.member) diff --git a/glance/db/sqlalchemy/migrate_repo/versions/009_add_mindisk_and_minram.py b/glance/db/sqlalchemy/migrate_repo/versions/009_add_mindisk_and_minram.py index aed09551..a96cf5ec 100644 --- a/glance/db/sqlalchemy/migrate_repo/versions/009_add_mindisk_and_minram.py +++ b/glance/db/sqlalchemy/migrate_repo/versions/009_add_mindisk_and_minram.py @@ -27,26 +27,33 @@ def get_images_table(meta): Returns the Table object for the images table that corresponds to the images table definition of this version. """ - images = Table('images', meta, - Column('id', Integer(), primary_key=True, nullable=False), - Column('name', String(255)), - Column('disk_format', String(20)), - Column('container_format', String(20)), - Column('size', Integer()), - Column('status', String(30), nullable=False), - Column('is_public', Boolean(), nullable=False, default=False, - index=True), - Column('location', Text()), - Column('created_at', DateTime(), nullable=False), - Column('updated_at', DateTime()), - Column('deleted_at', DateTime()), - Column('deleted', Boolean(), nullable=False, default=False, - index=True), - Column('checksum', String(32)), - Column('min_disk', Integer(), default=0), - Column('min_ram', Integer(), default=0), - mysql_engine='InnoDB', - extend_existing=True) + images = Table('images', + meta, + Column('id', Integer(), primary_key=True, nullable=False), + Column('name', String(255)), + Column('disk_format', String(20)), + Column('container_format', String(20)), + Column('size', Integer()), + Column('status', String(30), nullable=False), + Column('is_public', + Boolean(), + nullable=False, + default=False, + index=True), + Column('location', Text()), + Column('created_at', DateTime(), nullable=False), + Column('updated_at', DateTime()), + Column('deleted_at', DateTime()), + Column('deleted', + Boolean(), + nullable=False, + default=False, + index=True), + Column('checksum', String(32)), + Column('min_disk', Integer(), default=0), + Column('min_ram', Integer(), default=0), + mysql_engine='InnoDB', + extend_existing=True) return images diff --git a/glance/db/sqlalchemy/migrate_repo/versions/014_add_image_tags_table.py b/glance/db/sqlalchemy/migrate_repo/versions/014_add_image_tags_table.py index 7a5c954e..cffa9411 100644 --- a/glance/db/sqlalchemy/migrate_repo/versions/014_add_image_tags_table.py +++ b/glance/db/sqlalchemy/migrate_repo/versions/014_add_image_tags_table.py @@ -22,18 +22,31 @@ def define_image_tags_table(meta): # Load the images table so the foreign key can be set up properly schema.Table('images', meta, autoload=True) - image_tags = schema.Table('image_tags', meta, - schema.Column('id', glance_schema.Integer(), - primary_key=True, nullable=False), - schema.Column('image_id', glance_schema.String(36), - schema.ForeignKey('images.id'), nullable=False), - schema.Column('value', glance_schema.String(255), nullable=False), - schema.Column('created_at', glance_schema.DateTime(), nullable=False), - schema.Column('updated_at', glance_schema.DateTime()), - schema.Column('deleted_at', glance_schema.DateTime()), - schema.Column('deleted', glance_schema.Boolean(), nullable=False, - default=False), - mysql_engine='InnoDB') + image_tags = schema.Table('image_tags', + meta, + schema.Column('id', + glance_schema.Integer(), + primary_key=True, + nullable=False), + schema.Column('image_id', + glance_schema.String(36), + schema.ForeignKey('images.id'), + nullable=False), + schema.Column('value', + glance_schema.String(255), + nullable=False), + schema.Column('created_at', + glance_schema.DateTime(), + nullable=False), + schema.Column('updated_at', + glance_schema.DateTime()), + schema.Column('deleted_at', + glance_schema.DateTime()), + schema.Column('deleted', + glance_schema.Boolean(), + nullable=False, + default=False), + mysql_engine='InnoDB') schema.Index('ix_image_tags_image_id', image_tags.c.image_id) diff --git a/glance/image_cache/__init__.py b/glance/image_cache/__init__.py index e9bafd4c..761f8065 100644 --- a/glance/image_cache/__init__.py +++ b/glance/image_cache/__init__.py @@ -289,7 +289,7 @@ class ImageCache(object): CHUNKSIZE = 64 * 1024 * 1024 return self.cache_image_iter(image_id, - utils.chunkiter(image_file, CHUNKSIZE)) + utils.chunkiter(image_file, CHUNKSIZE)) def open_for_read(self, image_id): """ diff --git a/glance/registry/api/v1/images.py b/glance/registry/api/v1/images.py index c522fbb3..51f99fb9 100644 --- a/glance/registry/api/v1/images.py +++ b/glance/registry/api/v1/images.py @@ -399,8 +399,8 @@ class Controller(object): msg = _("Image %(id)s not found") LOG.info(msg % {'id': id}) raise exc.HTTPNotFound(body='Image not found', - request=req, - content_type='text/plain') + request=req, + content_type='text/plain') except exception.ForbiddenPublicImage: msg = _("Update denied for public image %(id)s") LOG.info(msg % {'id': id}) @@ -411,8 +411,8 @@ class Controller(object): msg = _("Access denied to image %(id)s but returning 'not found'") LOG.info(msg % {'id': id}) raise exc.HTTPNotFound(body='Image not found', - request=req, - content_type='text/plain') + request=req, + content_type='text/plain') def make_image_dict(image): diff --git a/glance/registry/client.py b/glance/registry/client.py index 6e6a7a76..6445a5c1 100644 --- a/glance/registry/client.py +++ b/glance/registry/client.py @@ -86,7 +86,8 @@ class RegistryClient(BaseClient): def do_request(self, method, action, **kwargs): try: res = super(RegistryClient, self).do_request(method, - action, **kwargs) + action, + **kwargs) status = res.status request_id = res.getheader('x-openstack-request-id') msg = _("Registry request %(method)s %(action)s HTTP %(status)s" @@ -94,8 +95,8 @@ class RegistryClient(BaseClient): LOG.debug(msg % locals()) except: - LOG.exception(_("Registry request %(method)s %(action)s Exception") - % locals()) + LOG.exception(_("Registry request %(method)s %(action)s " + "Exception") % locals()) raise return res diff --git a/glance/store/filesystem.py b/glance/store/filesystem.py index b3ef89cb..fbb6f23d 100644 --- a/glance/store/filesystem.py +++ b/glance/store/filesystem.py @@ -208,7 +208,7 @@ class Store(glance.store.base.Store): try: with open(filepath, 'wb') as f: for buf in utils.chunkreadable(image_file, - ChunkedFile.CHUNKSIZE): + ChunkedFile.CHUNKSIZE): bytes_written += len(buf) checksum.update(buf) f.write(buf) diff --git a/glance/store/s3.py b/glance/store/s3.py index 01dcb21f..395465f9 100644 --- a/glance/store/s3.py +++ b/glance/store/s3.py @@ -296,8 +296,9 @@ class Store(glance.store.base.Store): msg = _("Retrieved image object from S3 using (s3_host=%(s3_host)s, " "access_key=%(accesskey)s, bucket=%(bucket)s, " "key=%(obj_name)s)") % ({'s3_host': loc.s3serviceurl, - 'accesskey': loc.accesskey, 'bucket': loc.bucket, - 'obj_name': loc.key}) + 'accesskey': loc.accesskey, + 'bucket': loc.bucket, + 'obj_name': loc.key}) LOG.debug(msg) return key @@ -358,8 +359,9 @@ class Store(glance.store.base.Store): msg = _("Adding image object to S3 using (s3_host=%(s3_host)s, " "access_key=%(access_key)s, bucket=%(bucket)s, " "key=%(obj_name)s)") % ({'s3_host': self.s3_host, - 'access_key': self.access_key, 'bucket': self.bucket, - 'obj_name': obj_name}) + 'access_key': self.access_key, + 'bucket': self.bucket, + 'obj_name': obj_name}) LOG.debug(msg) key = bucket_obj.new_key(obj_name) @@ -426,8 +428,9 @@ class Store(glance.store.base.Store): msg = _("Deleting image object from S3 using (s3_host=%(s3_host)s, " "access_key=%(accesskey)s, bucket=%(bucket)s, " "key=%(obj_name)s)") % ({'s3_host': loc.s3serviceurl, - 'accesskey': loc.accesskey, 'bucket': loc.bucket, - 'obj_name': loc.key}) + 'accesskey': loc.accesskey, + 'bucket': loc.bucket, + 'obj_name': loc.key}) LOG.debug(msg) return key.delete() diff --git a/glance/store/swift.py b/glance/store/swift.py index 95e2d6b3..69e4c1fc 100644 --- a/glance/store/swift.py +++ b/glance/store/swift.py @@ -294,7 +294,7 @@ class Store(glance.store.base.Store): if e.http_status == httplib.NOT_FOUND: uri = location.get_store_uri() raise exception.NotFound(_("Swift could not find image at " - "uri %(uri)s") % locals()) + "uri %(uri)s") % locals()) else: raise @@ -543,7 +543,8 @@ class Store(glance.store.base.Store): except swiftclient.ClientException, e: if e.http_status == httplib.CONFLICT: raise exception.Duplicate(_("Swift already has an image at " - "location %s") % location.get_uri()) + "location %s") % + location.get_uri()) msg = (_("Failed to add object to Swift.\n" "Got error from Swift: %(e)s") % locals()) LOG.error(msg) @@ -597,7 +598,7 @@ class Store(glance.store.base.Store): if e.http_status == httplib.NOT_FOUND: uri = location.get_store_uri() raise exception.NotFound(_("Swift could not find image at " - "uri %(uri)s") % locals()) + "uri %(uri)s") % locals()) else: raise @@ -638,7 +639,7 @@ class Store(glance.store.base.Store): if e.http_status == httplib.NOT_FOUND: uri = location.get_store_uri() raise exception.NotFound(_("Swift could not find image at " - "uri %(uri)s") % locals()) + "uri %(uri)s") % locals()) else: raise @@ -677,14 +678,14 @@ def create_container_if_missing(container, swift_conn): swift_conn.put_container(container) except swiftclient.ClientException, e: msg = _("Failed to add container to Swift.\n" - "Got error from Swift: %(e)s") % locals() + "Got error from Swift: %(e)s") % locals() raise glance.store.BackendException(msg) else: msg = (_("The container %(container)s does not exist in " - "Swift. Please set the " - "swift_store_create_container_on_put option" - "to add container to Swift automatically.") - % locals()) + "Swift. Please set the " + "swift_store_create_container_on_put option" + "to add container to Swift automatically.") % + locals()) raise glance.store.BackendException(msg) else: raise diff --git a/glance/tests/functional/db/__init__.py b/glance/tests/functional/db/__init__.py index 507eeb8d..4074ac10 100644 --- a/glance/tests/functional/db/__init__.py +++ b/glance/tests/functional/db/__init__.py @@ -240,13 +240,15 @@ class BaseTestCase(object): def test_image_get_all_with_filter(self): images = self.db_api.image_get_all(self.context, - filters={'id': self.fixtures[0]['id']}) + filters={ + 'id': self.fixtures[0]['id'], + }) self.assertEquals(len(images), 1) self.assertEquals(images[0]['id'], self.fixtures[0]['id']) def test_image_get_all_with_filter_user_defined_property(self): images = self.db_api.image_get_all(self.context, - filters={'foo': 'bar'}) + filters={'foo': 'bar'}) self.assertEquals(len(images), 1) self.assertEquals(images[0]['id'], self.fixtures[0]['id']) @@ -255,16 +257,20 @@ class BaseTestCase(object): prop = self.db_api.image_property_create(self.context, fixture) images = self.db_api.image_get_all(self.context, - filters={'properties': {'poo': 'bear'}}) + filters={ + 'properties': {'poo': 'bear'}, + }) self.assertEquals(len(images), 1) self.db_api.image_property_delete(self.context, prop) images = self.db_api.image_get_all(self.context, - filters={'properties': {'poo': 'bear'}}) + filters={ + 'properties': {'poo': 'bear'}, + }) self.assertEquals(len(images), 0) def test_image_get_all_with_filter_undefined_property(self): images = self.db_api.image_get_all(self.context, - filters={'poo': 'bear'}) + filters={'poo': 'bear'}) self.assertEquals(len(images), 0) def test_image_get_all_size_min_max(self): @@ -278,20 +284,20 @@ class BaseTestCase(object): def test_image_get_all_size_min(self): images = self.db_api.image_get_all(self.context, - filters={'size_min': 15}) + filters={'size_min': 15}) self.assertEquals(len(images), 2) self.assertEquals(images[0]['id'], self.fixtures[2]['id']) self.assertEquals(images[1]['id'], self.fixtures[1]['id']) def test_image_get_all_size_range(self): images = self.db_api.image_get_all(self.context, - filters={'size_max': 15, - 'size_min': 20}) + filters={'size_max': 15, + 'size_min': 20}) self.assertEquals(len(images), 0) def test_image_get_all_size_max(self): images = self.db_api.image_get_all(self.context, - filters={'size_max': 15}) + filters={'size_max': 15}) self.assertEquals(len(images), 1) self.assertEquals(images[0]['id'], self.fixtures[0]['id']) @@ -352,14 +358,16 @@ class BaseTestCase(object): TENANT1 = utils.generate_uuid() ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1) UUIDX = utils.generate_uuid() - self.db_api.image_create(ctxt1, - {'id': UUIDX, 'status': 'queued', 'owner': TENANT1}) + self.db_api.image_create(ctxt1, {'id': UUIDX, + 'status': 'queued', + 'owner': TENANT1}) TENANT2 = utils.generate_uuid() ctxt2 = context.RequestContext(is_admin=False, tenant=TENANT2) UUIDY = utils.generate_uuid() - self.db_api.image_create(ctxt2, - {'id': UUIDY, 'status': 'queued', 'owner': TENANT2}) + self.db_api.image_create(ctxt2, {'id': UUIDY, + 'status': 'queued', + 'owner': TENANT2}) # NOTE(bcwaldon): the is_public=True flag indicates that you want # to get all images that are public AND those that are owned by the @@ -457,7 +465,8 @@ class BaseTestCase(object): def test_image_member_update(self): TENANT1 = utils.generate_uuid() member = self.db_api.image_member_create(self.context, - {'member': TENANT1, 'image_id': UUID1}) + {'member': TENANT1, + 'image_id': UUID1}) member_id = member.pop('id') expected = {'member': TENANT1, 'image_id': UUID1, 'can_share': False} diff --git a/glance/tests/functional/store/test_swift.py b/glance/tests/functional/store/test_swift.py index 537b6b80..3cffd2ed 100644 --- a/glance/tests/functional/store/test_swift.py +++ b/glance/tests/functional/store/test_swift.py @@ -127,7 +127,7 @@ def swift_head_object(swift_conn, container_name, obj_name): def keystone_authenticate(auth_url, auth_version, tenant_name, - username, password): + username, password): assert int(auth_version) == 2, 'Only auth version 2 is supported' import keystoneclient.v2_0.client @@ -314,8 +314,10 @@ class TestSwiftStore(store_tests.BaseTestCase, unittest.TestCase): read_tenant = utils.generate_uuid() write_tenant = utils.generate_uuid() - store.set_acls(location, public=False, - read_tenants=[read_tenant], write_tenants=[write_tenant]) + store.set_acls(location, + public=False, + read_tenants=[read_tenant], + write_tenants=[write_tenant]) container_name = location.store_location.container container, _ = swift_get_container(self.swift_client, container_name) diff --git a/glance/tests/functional/store_utils.py b/glance/tests/functional/store_utils.py index b098460e..f4c80c08 100644 --- a/glance/tests/functional/store_utils.py +++ b/glance/tests/functional/store_utils.py @@ -200,7 +200,7 @@ def get_swift_uri(test, image_id): uri = ('swift+https://%(swift_store_user)s:%(swift_store_key)s' % test.__dict__) uri += ('@%(swift_store_auth_address)s/%(swift_store_container)s/' % - test.__dict__) + test.__dict__) uri += image_id return uri.replace('@http://', '@') diff --git a/glance/tests/functional/test_scrubber.py b/glance/tests/functional/test_scrubber.py index 8bf89ab0..1e419e02 100644 --- a/glance/tests/functional/test_scrubber.py +++ b/glance/tests/functional/test_scrubber.py @@ -25,10 +25,12 @@ from glance.tests.utils import execute TEST_IMAGE_DATA = '*' * 5 * 1024 -TEST_IMAGE_META = {'name': 'test_image', - 'is_public': False, - 'disk_format': 'raw', - 'container_format': 'ovf'} +TEST_IMAGE_META = { + 'name': 'test_image', + 'is_public': False, + 'disk_format': 'raw', + 'container_format': 'ovf', +} class TestScrubber(functional.FunctionalTest): diff --git a/glance/tests/functional/v1/test_api.py b/glance/tests/functional/v1/test_api.py index 61768c6f..43c5a04e 100644 --- a/glance/tests/functional/v1/test_api.py +++ b/glance/tests/functional/v1/test_api.py @@ -133,16 +133,17 @@ class TestApi(functional.FunctionalTest): for expected_key, expected_value in expected_image_headers.items(): self.assertEqual(response[expected_key], expected_value, - "For key '%s' expected header value '%s'. Got '%s'" - % (expected_key, expected_value, - response[expected_key])) + "For key '%s' expected header value '%s'. " + "Got '%s'" % (expected_key, + expected_value, + response[expected_key])) for expected_key, expected_value in expected_std_headers.items(): self.assertEqual(response[expected_key], expected_value, - "For key '%s' expected header value '%s'. Got '%s'" - % (expected_key, - expected_value, - response[expected_key])) + "For key '%s' expected header value '%s'. " + "Got '%s'" % (expected_key, + expected_value, + response[expected_key])) self.assertEqual(content, "*" * FIVE_KB) self.assertEqual(hashlib.md5(content).hexdigest(), @@ -187,10 +188,10 @@ class TestApi(functional.FunctionalTest): for expected_key, expected_value in expected_image.items(): self.assertEqual(expected_value, image['images'][0][expected_key], - "For key '%s' expected header value '%s'. Got '%s'" - % (expected_key, - expected_value, - image['images'][0][expected_key])) + "For key '%s' expected header value '%s'. " + "Got '%s'" % (expected_key, + expected_value, + image['images'][0][expected_key])) # 7. PUT image with custom properties of "distro" and "arch" # Verify 200 returned @@ -228,10 +229,10 @@ class TestApi(functional.FunctionalTest): for expected_key, expected_value in expected_image.items(): self.assertEqual(expected_value, image['images'][0][expected_key], - "For key '%s' expected header value '%s'. Got '%s'" - % (expected_key, - expected_value, - image['images'][0][expected_key])) + "For key '%s' expected header value '%s'. " + "Got '%s'" % (expected_key, + expected_value, + image['images'][0][expected_key])) # 9. PUT image and remove a previously existing property. headers = {'X-Image-Meta-Property-Arch': 'x86_64'} @@ -358,8 +359,9 @@ class TestApi(functional.FunctionalTest): # 4. PUT image with image data, verify 200 returned image_data = "*" * FIVE_KB headers = {'Content-Type': 'application/octet-stream'} - path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port, - image_id) + path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", + self.api_port, + image_id) http = httplib2.Http() response, content = http.request(path, 'PUT', headers=headers, body=image_data) @@ -532,9 +534,10 @@ class TestApi(functional.FunctionalTest): http = httplib2.Http() headers = minimal_headers('Image1') headers['Content-Type'] = 'not octet-stream' - response, content = http.request(path, 'POST', - body=test_data_file.name, - headers=headers) + response, content = http.request(path, + 'POST', + body=test_data_file.name, + headers=headers) self.assertEqual(response.status, 400) expected = "Content-Type must be application/octet-stream" self.assertTrue(expected in content, @@ -811,8 +814,9 @@ class TestApi(functional.FunctionalTest): yesterday = timeutils.isotime(timeutils.utcnow() - datetime.timedelta(1)) params = "changes-since=%s" % yesterday - path = "http://%s:%d/v1/images?%s" % ("127.0.0.1", self.api_port, - params) + path = "http://%s:%d/v1/images?%s" % ("127.0.0.1", + self.api_port, + params) response, content = http.request(path, 'GET') self.assertEqual(response.status, 200) data = json.loads(content) @@ -826,8 +830,9 @@ class TestApi(functional.FunctionalTest): now = timeutils.utcnow() hour_ago = now.strftime('%Y-%m-%dT%H:%M:%S%%2B01:00') params = "changes-since=%s" % hour_ago - path = "http://%s:%d/v1/images?%s" % ("127.0.0.1", self.api_port, - params) + path = "http://%s:%d/v1/images?%s" % ("127.0.0.1", + self.api_port, + params) response, content = http.request(path, 'GET') self.assertEqual(response.status, 200) data = json.loads(content) @@ -837,8 +842,9 @@ class TestApi(functional.FunctionalTest): tomorrow = timeutils.isotime(timeutils.utcnow() + datetime.timedelta(1)) params = "changes-since=%s" % tomorrow - path = "http://%s:%d/v1/images?%s" % ("127.0.0.1", self.api_port, - params) + path = "http://%s:%d/v1/images?%s" % ("127.0.0.1", + self.api_port, + params) response, content = http.request(path, 'GET') self.assertEqual(response.status, 200) data = json.loads(content) @@ -848,8 +854,9 @@ class TestApi(functional.FunctionalTest): now = timeutils.utcnow() hour_hence = now.strftime('%Y-%m-%dT%H:%M:%S-01:00') params = "changes-since=%s" % hour_hence - path = "http://%s:%d/v1/images?%s" % ("127.0.0.1", self.api_port, - params) + path = "http://%s:%d/v1/images?%s" % ("127.0.0.1", + self.api_port, + params) response, content = http.request(path, 'GET') self.assertEqual(response.status, 200) data = json.loads(content) @@ -1076,8 +1083,9 @@ class TestApi(functional.FunctionalTest): # 3. GET /images sorted by name asc params = 'sort_key=name&sort_dir=asc' - path = "http://%s:%d/v1/images?%s" % ("127.0.0.1", self.api_port, - params) + path = "http://%s:%d/v1/images?%s" % ("127.0.0.1", + self.api_port, + params) http = httplib2.Http() response, content = http.request(path, 'GET') self.assertEqual(response.status, 200) @@ -1089,8 +1097,9 @@ class TestApi(functional.FunctionalTest): # 4. GET /images sorted by size desc params = 'sort_key=size&sort_dir=desc' - path = "http://%s:%d/v1/images?%s" % ("127.0.0.1", self.api_port, - params) + path = "http://%s:%d/v1/images?%s" % ("127.0.0.1", + self.api_port, + params) http = httplib2.Http() response, content = http.request(path, 'GET') self.assertEqual(response.status, 200) @@ -1102,8 +1111,9 @@ class TestApi(functional.FunctionalTest): # 5. GET /images sorted by size desc with a marker params = 'sort_key=size&sort_dir=desc&marker=%s' % image_ids[0] - path = "http://%s:%d/v1/images?%s" % ("127.0.0.1", self.api_port, - params) + path = "http://%s:%d/v1/images?%s" % ("127.0.0.1", + self.api_port, + params) http = httplib2.Http() response, content = http.request(path, 'GET') self.assertEqual(response.status, 200) @@ -1114,8 +1124,9 @@ class TestApi(functional.FunctionalTest): # 6. GET /images sorted by name asc with a marker params = 'sort_key=name&sort_dir=asc&marker=%s' % image_ids[2] - path = "http://%s:%d/v1/images?%s" % ("127.0.0.1", self.api_port, - params) + path = "http://%s:%d/v1/images?%s" % ("127.0.0.1", + self.api_port, + params) http = httplib2.Http() response, content = http.request(path, 'GET') self.assertEqual(response.status, 200) @@ -1258,9 +1269,10 @@ class TestApi(functional.FunctionalTest): test_data_file.write("XXX") test_data_file.flush() http = httplib2.Http() - response, content = http.request(path, 'POST', - headers=headers, - body=test_data_file.name) + response, content = http.request(path, + 'POST', + headers=headers, + body=test_data_file.name) self.assertEqual(response.status, 400) type = format.replace('_format', '') expected = "Invalid %s format 'bad_value' for image" % type @@ -1319,9 +1331,10 @@ class TestApi(functional.FunctionalTest): test_data_file.write("XXX") test_data_file.flush() http = httplib2.Http() - response, content = http.request(path, 'PUT', - headers=headers, - body=test_data_file.name) + response, content = http.request(path, + 'PUT', + headers=headers, + body=test_data_file.name) self.assertEqual(response.status, 400) type = format.replace('_format', '') expected = "Invalid %s format 'None' for image" % type diff --git a/glance/tests/functional/v1/test_ssl.py b/glance/tests/functional/v1/test_ssl.py index 3689ec38..4e0231d4 100644 --- a/glance/tests/functional/v1/test_ssl.py +++ b/glance/tests/functional/v1/test_ssl.py @@ -147,8 +147,10 @@ class TestSSL(functional.FunctionalTest): headers = minimal_headers('Image1') path = "https://%s:%d/v1/images" % ("127.0.0.1", self.api_port) https = httplib2.Http(disable_ssl_certificate_validation=True) - response, content = https.request(path, 'POST', headers=headers, - body=image_data) + response, content = https.request(path, + 'POST', + headers=headers, + body=image_data) self.assertEqual(response.status, 201) data = json.loads(content) self.assertEqual(data['image']['checksum'], @@ -191,16 +193,17 @@ class TestSSL(functional.FunctionalTest): for expected_key, expected_value in expected_image_headers.items(): self.assertEqual(response[expected_key], expected_value, - "For key '%s' expected header value '%s'. Got '%s'" - % (expected_key, expected_value, - response[expected_key])) + "For key '%s' expected header value '%s'. " + "Got '%s'" % (expected_key, + expected_value, + response[expected_key])) for expected_key, expected_value in expected_std_headers.items(): self.assertEqual(response[expected_key], expected_value, - "For key '%s' expected header value '%s'. Got '%s'" - % (expected_key, - expected_value, - response[expected_key])) + "For key '%s' expected header value '%s'. " + "Got '%s'" % (expected_key, + expected_value, + response[expected_key])) self.assertEqual(content, "*" * FIVE_KB) self.assertEqual(hashlib.md5(content).hexdigest(), @@ -244,11 +247,12 @@ class TestSSL(functional.FunctionalTest): image = json.loads(content) for expected_key, expected_value in expected_image.items(): - self.assertEqual(expected_value, image['images'][0][expected_key], - "For key '%s' expected header value '%s'. Got '%s'" - % (expected_key, - expected_value, - image['images'][0][expected_key])) + self.assertEqual(expected_value, + image['images'][0][expected_key], + "For key '%s' expected header value '%s'. " + "Got '%s'" % (expected_key, + expected_value, + image['images'][0][expected_key])) # 7. PUT image with custom properties of "distro" and "arch" # Verify 200 returned @@ -285,11 +289,12 @@ class TestSSL(functional.FunctionalTest): image = json.loads(content) for expected_key, expected_value in expected_image.items(): - self.assertEqual(expected_value, image['images'][0][expected_key], - "For key '%s' expected header value '%s'. Got '%s'" - % (expected_key, - expected_value, - image['images'][0][expected_key])) + self.assertEqual(expected_value, + image['images'][0][expected_key], + "For key '%s' expected header value '%s'. " + "Got '%s'" % (expected_key, + expected_value, + image['images'][0][expected_key])) # 9. PUT image and remove a previously existing property. headers = {'X-Image-Meta-Property-Arch': 'x86_64'} @@ -411,8 +416,10 @@ class TestSSL(functional.FunctionalTest): path = "https://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port, image_id) https = httplib2.Http(disable_ssl_certificate_validation=True) - response, content = https.request(path, 'PUT', headers=headers, - body=image_data) + response, content = https.request(path, + 'PUT', + headers=headers, + body=image_data) self.assertEqual(response.status, 200) data = json.loads(content) self.assertEqual(data['image']['checksum'], @@ -669,8 +676,9 @@ class TestSSL(functional.FunctionalTest): test_data_file.flush() path = "https://%s:%d/v1/images" % ("127.0.0.1", self.api_port) https = httplib2.Http(disable_ssl_certificate_validation=True) - response, content = https.request(path, 'POST', - body=test_data_file.name) + response, content = https.request(path, + 'POST', + body=test_data_file.name) self.assertEqual(response.status, 400) expected = "Content-Type must be application/octet-stream" self.assertTrue(expected in content, diff --git a/glance/tests/unit/test_cache_middleware.py b/glance/tests/unit/test_cache_middleware.py index 77967fe3..300bfb54 100644 --- a/glance/tests/unit/test_cache_middleware.py +++ b/glance/tests/unit/test_cache_middleware.py @@ -76,8 +76,7 @@ class TestCacheMiddlewareRequestStashCacheInfo(unittest.TestCase): class ChecksumTestCacheFilter(glance.api.middleware.cache.CacheFilter): def __init__(self): class DummyCache(object): - def get_caching_iter(self, image_id, image_checksum, - app_iter): + def get_caching_iter(self, image_id, image_checksum, app_iter): self.image_checksum = image_checksum self.cache = DummyCache() diff --git a/glance/tests/unit/test_clients.py b/glance/tests/unit/test_clients.py index 1d4af295..0a27db44 100644 --- a/glance/tests/unit/test_clients.py +++ b/glance/tests/unit/test_clients.py @@ -1030,7 +1030,8 @@ class TestRegistryClient(base.IsolatedUnitTest): """Tests replacing image members""" self.assertTrue(self.client.add_member(UUID2, 'pattieblack')) self.assertTrue(self.client.replace_members(UUID2, - dict(member_id='pattieblack2'))) + dict(member_id='pattie' + 'black2'))) def test_add_delete_member(self): """Tests deleting image members""" diff --git a/glance/tests/unit/test_config.py b/glance/tests/unit/test_config.py index ca73f90b..1d6ceb8c 100644 --- a/glance/tests/unit/test_config.py +++ b/glance/tests/unit/test_config.py @@ -84,7 +84,7 @@ class TestPasteApp(test_utils.BaseTestCase): def test_load_paste_app_paste_config_not_found(self): expected_middleware = context.UnauthenticatedContextMiddleware self.assertRaises(RuntimeError, self._do_test_load_paste_app, - expected_middleware, make_paste_file=False) + expected_middleware, make_paste_file=False) def test_load_paste_app_with_paste_flavor(self): pipeline = ('[pipeline:glance-registry-incomplete]\n' diff --git a/glance/tests/unit/test_context_middleware.py b/glance/tests/unit/test_context_middleware.py index 265c8682..5ecb0bf0 100644 --- a/glance/tests/unit/test_context_middleware.py +++ b/glance/tests/unit/test_context_middleware.py @@ -8,7 +8,7 @@ from glance.tests.unit import base class TestContextMiddleware(base.IsolatedUnitTest): def _build_request(self, roles=None, identity_status='Confirmed', - service_catalog=None): + service_catalog=None): req = webob.Request.blank('/') req.headers['x-auth-token'] = 'token1' req.headers['x-identity-status'] = identity_status diff --git a/glance/tests/unit/test_http_store.py b/glance/tests/unit/test_http_store.py index 10de952b..25b356de 100644 --- a/glance/tests/unit/test_http_store.py +++ b/glance/tests/unit/test_http_store.py @@ -113,10 +113,10 @@ class TestHttpStore(base.StoreClearingUnitTest): # both redirects. redirect_headers_1 = {"location": "http://example.com/teapot.img"} redirect_resp_1 = utils.FakeHTTPResponse(status=302, - headers=redirect_headers_1) + headers=redirect_headers_1) redirect_headers_2 = {"location": "http://example.com/teapot_real.img"} redirect_resp_2 = utils.FakeHTTPResponse(status=301, - headers=redirect_headers_2) + headers=redirect_headers_2) FAKE_RESPONSE_STACK.append(redirect_resp_1) FAKE_RESPONSE_STACK.append(redirect_resp_2) @@ -134,7 +134,7 @@ class TestHttpStore(base.StoreClearingUnitTest): # Add more than MAX_REDIRECTS redirects to the response stack redirect_headers = {"location": "http://example.com/teapot.img"} redirect_resp = utils.FakeHTTPResponse(status=302, - headers=redirect_headers) + headers=redirect_headers) for i in xrange(MAX_REDIRECTS + 2): FAKE_RESPONSE_STACK.append(redirect_resp) @@ -145,7 +145,7 @@ class TestHttpStore(base.StoreClearingUnitTest): def test_http_get_redirect_invalid(self): redirect_headers = {"location": "http://example.com/teapot.img"} redirect_resp = utils.FakeHTTPResponse(status=307, - headers=redirect_headers) + headers=redirect_headers) FAKE_RESPONSE_STACK.append(redirect_resp) uri = "http://netloc/path/to/file.tar.gz" @@ -154,7 +154,7 @@ class TestHttpStore(base.StoreClearingUnitTest): def test_http_get_not_found(self): not_found_resp = utils.FakeHTTPResponse(status=404, - data="404 Not Found") + data="404 Not Found") FAKE_RESPONSE_STACK.append(not_found_resp) uri = "http://netloc/path/to/file.tar.gz" diff --git a/glance/tests/unit/test_migrations.py b/glance/tests/unit/test_migrations.py index 20aae383..e833e9e7 100644 --- a/glance/tests/unit/test_migrations.py +++ b/glance/tests/unit/test_migrations.py @@ -165,18 +165,22 @@ class TestMigrations(utils.BaseTestCase): # Create the initial version of the images table meta = MetaData() meta.bind = engine - images_001 = Table('images', meta, - Column('id', models.Integer, primary_key=True), - Column('name', String(255)), - Column('type', String(30)), - Column('size', Integer), - Column('status', String(30)), - Column('is_public', Boolean, default=False), - Column('location', Text), - Column('created_at', DateTime(), nullable=False), - Column('updated_at', DateTime()), - Column('deleted_at', DateTime()), - Column('deleted', Boolean(), nullable=False, default=False)) + images_001 = Table('images', + meta, + Column('id', models.Integer, primary_key=True), + Column('name', String(255)), + Column('type', String(30)), + Column('size', Integer), + Column('status', String(30)), + Column('is_public', Boolean, default=False), + Column('location', Text), + Column('created_at', DateTime(), nullable=False), + Column('updated_at', DateTime()), + Column('deleted_at', DateTime()), + Column('deleted', + Boolean(), + nullable=False, + default=False)) images_001.create() def _walk_versions(self, initial_version=0): diff --git a/glance/tests/unit/test_notifier.py b/glance/tests/unit/test_notifier.py index 61fc523b..f92be805 100644 --- a/glance/tests/unit/test_notifier.py +++ b/glance/tests/unit/test_notifier.py @@ -330,9 +330,10 @@ class TestQpidNotifier(utils.BaseTestCase): self.mock_connection.open() self.mock_connection.session().AndReturn(self.mock_session) for p in ["info", "warn", "error"]: - expected_address = ('glance/glance_notifications.%s ; {"node": ' - '{"x-declare": {"auto-delete": true, "durable": false}, ' - '"type": "topic"}, "create": "always"}' % p) + expected_address = ('glance/glance_notifications.%s ; ' + '{"node": {"x-declare": {"auto-delete": true, ' + '"durable": false}, "type": "topic"}, ' + '"create": "always"}' % p) self.mock_session.sender(expected_address).AndReturn( self.mock_sender) self.mock_sender.send(mox.IgnoreArg()) diff --git a/glance/tests/unit/test_swift_store.py b/glance/tests/unit/test_swift_store.py index 01f53dfd..24d5f040 100644 --- a/glance/tests/unit/test_swift_store.py +++ b/glance/tests/unit/test_swift_store.py @@ -59,9 +59,12 @@ SWIFT_CONF = {'verbose': True, def stub_out_swiftclient(stubs, swift_store_auth_version): fixture_containers = ['glance'] fixture_container_headers = {} - fixture_headers = {'glance/%s' % FAKE_UUID: - {'content-length': FIVE_KB, - 'etag': 'c2e5db72bd7fd153f53ede5da5a06de3'}} + fixture_headers = { + 'glance/%s' % FAKE_UUID: { + 'content-length': FIVE_KB, + 'etag': 'c2e5db72bd7fd153f53ede5da5a06de3' + } + } fixture_objects = {'glance/%s' % FAKE_UUID: StringIO.StringIO("*" * FIVE_KB)} @@ -69,7 +72,7 @@ def stub_out_swiftclient(stubs, swift_store_auth_version): if container not in fixture_containers: msg = "No container %s found" % container raise swiftclient.ClientException(msg, - http_status=httplib.NOT_FOUND) + http_status=httplib.NOT_FOUND) return fixture_container_headers def fake_put_container(url, token, container, **kwargs): @@ -118,7 +121,7 @@ def stub_out_swiftclient(stubs, swift_store_auth_version): msg = ("Object PUT failed - Object with key %s already exists" % fixture_key) raise swiftclient.ClientException(msg, - http_status=httplib.CONFLICT) + http_status=httplib.CONFLICT) def fake_get_object(url, token, container, name, **kwargs): # GET returns the tuple (list of headers, file object) @@ -126,7 +129,7 @@ def stub_out_swiftclient(stubs, swift_store_auth_version): if not fixture_key in fixture_headers: msg = "Object GET failed" raise swiftclient.ClientException(msg, - http_status=httplib.NOT_FOUND) + http_status=httplib.NOT_FOUND) fixture = fixture_headers[fixture_key] if 'manifest' in fixture: @@ -151,7 +154,7 @@ def stub_out_swiftclient(stubs, swift_store_auth_version): except KeyError: msg = "Object HEAD failed - Object does not exist" raise swiftclient.ClientException(msg, - http_status=httplib.NOT_FOUND) + http_status=httplib.NOT_FOUND) def fake_delete_object(url, token, container, name, **kwargs): # DELETE returns nothing @@ -159,7 +162,7 @@ def stub_out_swiftclient(stubs, swift_store_auth_version): if fixture_key not in fixture_headers.keys(): msg = "Object DELETE failed - Object does not exist" raise swiftclient.ClientException(msg, - http_status=httplib.NOT_FOUND) + http_status=httplib.NOT_FOUND) else: del fixture_headers[fixture_key] del fixture_objects[fixture_key] diff --git a/glance/tests/unit/test_wsgi.py b/glance/tests/unit/test_wsgi.py index dfe415e9..a3a6469f 100644 --- a/glance/tests/unit/test_wsgi.py +++ b/glance/tests/unit/test_wsgi.py @@ -180,7 +180,7 @@ class JSONRequestDeserializerTest(test_utils.BaseTestCase): def test_from_json_malformed(self): fixture = 'kjasdklfjsklajf' self.assertRaises(webob.exc.HTTPBadRequest, - wsgi.JSONRequestDeserializer().from_json, fixture) + wsgi.JSONRequestDeserializer().from_json, fixture) def test_default_no_body(self): request = wsgi.Request.blank('/') diff --git a/glance/tests/unit/v1/test_api.py b/glance/tests/unit/v1/test_api.py index 829385f8..148205e6 100644 --- a/glance/tests/unit/v1/test_api.py +++ b/glance/tests/unit/v1/test_api.py @@ -1701,7 +1701,7 @@ class TestRegistryAPI(base.IsolatedUnitTest): res_dict = json.loads(res.body) self.assertNotEquals(res_dict['image']['created_at'], - res_dict['image']['updated_at']) + res_dict['image']['updated_at']) for k, v in fixture.iteritems(): self.assertEquals(v, res_dict['image'][k]) @@ -1954,11 +1954,13 @@ class TestGlanceAPI(base.IsolatedUnitTest): self._do_test_defaulted_format(key, value) def test_bad_disk_format(self): - fixture_headers = {'x-image-meta-store': 'bad', - 'x-image-meta-name': 'bogus', - 'x-image-meta-location': 'http://localhost:0/image.tar.gz', - 'x-image-meta-disk-format': 'invalid', - 'x-image-meta-container-format': 'ami'} + fixture_headers = { + 'x-image-meta-store': 'bad', + 'x-image-meta-name': 'bogus', + 'x-image-meta-location': 'http://localhost:0/image.tar.gz', + 'x-image-meta-disk-format': 'invalid', + 'x-image-meta-container-format': 'ami', + } req = webob.Request.blank("/images") req.method = 'POST' @@ -1970,10 +1972,12 @@ class TestGlanceAPI(base.IsolatedUnitTest): self.assertTrue('Invalid disk format' in res.body, res.body) def test_create_with_location_no_container_format(self): - fixture_headers = {'x-image-meta-store': 'bad', - 'x-image-meta-name': 'bogus', - 'x-image-meta-location': 'http://localhost:0/image.tar.gz', - 'x-image-meta-disk-format': 'vhd'} + fixture_headers = { + 'x-image-meta-store': 'bad', + 'x-image-meta-name': 'bogus', + 'x-image-meta-location': 'http://localhost:0/image.tar.gz', + 'x-image-meta-disk-format': 'vhd', + } req = webob.Request.blank("/images") req.method = 'POST' @@ -1985,11 +1989,13 @@ class TestGlanceAPI(base.IsolatedUnitTest): self.assertTrue('Invalid container format' in res.body) def test_bad_container_format(self): - fixture_headers = {'x-image-meta-store': 'bad', - 'x-image-meta-name': 'bogus', - 'x-image-meta-location': 'http://localhost:0/image.tar.gz', - 'x-image-meta-disk-format': 'vhd', - 'x-image-meta-container-format': 'invalid'} + fixture_headers = { + 'x-image-meta-store': 'bad', + 'x-image-meta-name': 'bogus', + 'x-image-meta-location': 'http://localhost:0/image.tar.gz', + 'x-image-meta-disk-format': 'vhd', + 'x-image-meta-container-format': 'invalid', + } req = webob.Request.blank("/images") req.method = 'POST' @@ -2001,12 +2007,14 @@ class TestGlanceAPI(base.IsolatedUnitTest): self.assertTrue('Invalid container format' in res.body) def test_bad_image_size(self): - fixture_headers = {'x-image-meta-store': 'bad', - 'x-image-meta-name': 'bogus', - 'x-image-meta-location': 'http://example.com/image.tar.gz', - 'x-image-meta-disk-format': 'vhd', - 'x-image-meta-size': 'invalid', - 'x-image-meta-container-format': 'bare'} + fixture_headers = { + 'x-image-meta-store': 'bad', + 'x-image-meta-name': 'bogus', + 'x-image-meta-location': 'http://example.com/image.tar.gz', + 'x-image-meta-disk-format': 'vhd', + 'x-image-meta-size': 'invalid', + 'x-image-meta-container-format': 'bare', + } req = webob.Request.blank("/images") req.method = 'POST' @@ -2018,11 +2026,13 @@ class TestGlanceAPI(base.IsolatedUnitTest): self.assertTrue('Incoming image size' in res.body) def test_bad_image_name(self): - fixture_headers = {'x-image-meta-store': 'bad', - 'x-image-meta-name': 'X' * 256, - 'x-image-meta-location': 'http://example.com/image.tar.gz', - 'x-image-meta-disk-format': 'vhd', - 'x-image-meta-container-format': 'bare'} + fixture_headers = { + 'x-image-meta-store': 'bad', + 'x-image-meta-name': 'X' * 256, + 'x-image-meta-location': 'http://example.com/image.tar.gz', + 'x-image-meta-disk-format': 'vhd', + 'x-image-meta-container-format': 'bare', + } req = webob.Request.blank("/images") req.method = 'POST' diff --git a/glance/tests/unit/v2/test_image_data_resource.py b/glance/tests/unit/v2/test_image_data_resource.py index 18108899..d551bf7e 100644 --- a/glance/tests/unit/v2/test_image_data_resource.py +++ b/glance/tests/unit/v2/test_image_data_resource.py @@ -81,8 +81,8 @@ class TestImagesController(base.StoreClearingUnitTest): def test_upload_storage_full(self): request = unit_test_utils.get_fake_request() self.assertRaises(webob.exc.HTTPRequestEntityTooLarge, - self.controller.upload, - request, unit_test_utils.UUID2, 'YYYYYYY', 7) + self.controller.upload, + request, unit_test_utils.UUID2, 'YYYYYYY', 7) def test_upload_storage_forbidden(self): request = unit_test_utils.get_fake_request(user=unit_test_utils.USER2) @@ -92,8 +92,8 @@ class TestImagesController(base.StoreClearingUnitTest): def test_upload_storage_write_denied(self): request = unit_test_utils.get_fake_request(user=unit_test_utils.USER3) self.assertRaises(webob.exc.HTTPServiceUnavailable, - self.controller.upload, - request, unit_test_utils.UUID2, 'YY', 2) + self.controller.upload, + request, unit_test_utils.UUID2, 'YY', 2) def test_upload_download_no_size(self): request = unit_test_utils.get_fake_request() @@ -183,7 +183,7 @@ class TestImageDataDeserializer(test_utils.BaseTestCase): request.headers['Content-Type'] = 'application/json' request.body = 'YYYYY' self.assertRaises(webob.exc.HTTPUnsupportedMediaType, - self.deserializer.upload, request) + self.deserializer.upload, request) class TestImageDataSerializer(test_utils.BaseTestCase): diff --git a/glance/tests/unit/v2/test_images_resource.py b/glance/tests/unit/v2/test_images_resource.py index b1036839..671fa6eb 100644 --- a/glance/tests/unit/v2/test_images_resource.py +++ b/glance/tests/unit/v2/test_images_resource.py @@ -208,7 +208,10 @@ class TestImagesController(test_utils.BaseTestCase): url = '/images?status=queued&name=2' request = unit_test_utils.get_fake_request(url) output = self.controller.index(request, - filters={'status': 'queued', 'name': '2'}) + filters={ + 'status': 'queued', + 'name': '2', + }) self.assertEqual(1, len(output['images'])) actual = set([image['id'] for image in output['images']]) expected = set([UUID2]) @@ -1101,7 +1104,7 @@ class TestImagesDeserializerWithExtendedSchema(test_utils.BaseTestCase): request = unit_test_utils.get_fake_request() request.body = json.dumps({'name': 'image-1', 'pants': 'borked'}) self.assertRaises(webob.exc.HTTPBadRequest, - self.deserializer.create, request) + self.deserializer.create, request) def test_update(self): request = unit_test_utils.get_fake_request() @@ -1118,7 +1121,8 @@ class TestImagesDeserializerWithExtendedSchema(test_utils.BaseTestCase): request.content_type = 'application/openstack-images-v2.0-json-patch' request.body = json.dumps([{'add': '/pants', 'value': 'cutoffs'}]) self.assertRaises(webob.exc.HTTPBadRequest, - self.deserializer.update, request) + self.deserializer.update, + request) class TestImagesDeserializerWithAdditionalProperties(test_utils.BaseTestCase): @@ -1199,11 +1203,19 @@ class TestImagesSerializer(test_utils.BaseTestCase): self.serializer = glance.api.v2.images.ResponseSerializer() self.fixtures = [ #NOTE(bcwaldon): This first fixture has every property defined - _fixture(UUID1, name='image-1', size=1024, tags=['one', 'two'], - created_at=DATETIME, updated_at=DATETIME, owner=TENANT1, - is_public=True, container_format='ami', disk_format='ami', - checksum='ca425b88f047ce8ec45ee90e813ada91', - min_ram=128, min_disk=10), + _fixture(UUID1, + name='image-1', + size=1024, + tags=['one', 'two'], + created_at=DATETIME, + updated_at=DATETIME, + owner=TENANT1, + is_public=True, + container_format='ami', + disk_format='ami', + checksum='ca425b88f047ce8ec45ee90e813ada91', + min_ram=128, + min_disk=10), #NOTE(bcwaldon): This second fixture depends on default behavior # and sets most values to None @@ -1377,14 +1389,23 @@ class TestImagesSerializerWithUnicode(test_utils.BaseTestCase): self.serializer = glance.api.v2.images.ResponseSerializer() self.fixtures = [ #NOTE(bcwaldon): This first fixture has every property defined - _fixture(UUID1, name=u'OpenStack\u2122-1', - size=1024, tags=[u'\u2160', u'\u2161'], - created_at=DATETIME, updated_at=DATETIME, owner=TENANT1, - is_public=True, container_format='ami', disk_format='ami', - checksum=u'ca425b88f047ce8ec45ee90e813ada91', - min_ram=128, min_disk=10, - properties={'lang': u'Fran\u00E7ais', - u'dispos\u00E9': u'f\u00E2ch\u00E9'}), + _fixture(UUID1, + name=u'OpenStack\u2122-1', + size=1024, + tags=[u'\u2160', u'\u2161'], + created_at=DATETIME, + updated_at=DATETIME, + owner=TENANT1, + is_public=True, + container_format='ami', + disk_format='ami', + checksum=u'ca425b88f047ce8ec45ee90e813ada91', + min_ram=128, + min_disk=10, + properties={ + 'lang': u'Fran\u00E7ais', + u'dispos\u00E9': u'f\u00E2ch\u00E9', + }), ] def test_index(self): @@ -1521,10 +1542,17 @@ class TestImagesSerializerWithExtendedSchema(test_utils.BaseTestCase): schema = glance.api.v2.images.get_schema(custom_image_properties) self.serializer = glance.api.v2.images.ResponseSerializer(schema) - self.fixture = _fixture(UUID2, name='image-2', owner=TENANT2, - checksum='ca425b88f047ce8ec45ee90e813ada91', - created_at=DATETIME, updated_at=DATETIME, - size=1024, properties={'color': 'green', 'mood': 'grouchy'}) + self.fixture = _fixture(UUID2, + name='image-2', + owner=TENANT2, + checksum='ca425b88f047ce8ec45ee90e813ada91', + created_at=DATETIME, + updated_at=DATETIME, + size=1024, + properties={ + 'color': 'green', + 'mood': 'grouchy', + }) def test_show(self): expected = { @@ -1575,10 +1603,14 @@ class TestImagesSerializerWithAdditionalProperties(test_utils.BaseTestCase): def setUp(self): super(TestImagesSerializerWithAdditionalProperties, self).setUp() self.config(allow_additional_image_properties=True) - self.fixture = _fixture(UUID2, name='image-2', owner=TENANT2, - checksum='ca425b88f047ce8ec45ee90e813ada91', - created_at=DATETIME, updated_at=DATETIME, - properties={'marx': 'groucho'}, size=1024) + self.fixture = _fixture(UUID2, + name='image-2', + owner=TENANT2, + checksum='ca425b88f047ce8ec45ee90e813ada91', + created_at=DATETIME, + updated_at=DATETIME, + properties={'marx': 'groucho'}, + size=1024) def test_show(self): serializer = glance.api.v2.images.ResponseSerializer() @@ -1656,20 +1688,27 @@ class TestImagesSerializerDirectUrl(test_utils.BaseTestCase): super(TestImagesSerializerDirectUrl, self).setUp() self.serializer = glance.api.v2.images.ResponseSerializer() - self.active_image = _fixture(UUID1, name='image-1', is_public=True, - status='active', size=1024, - created_at=DATETIME, updated_at=DATETIME, - location='http://some/fake/location') + self.active_image = _fixture(UUID1, + name='image-1', + is_public=True, + status='active', size=1024, + created_at=DATETIME, updated_at=DATETIME, + location='http://some/fake/location') - self.queued_image = _fixture(UUID2, name='image-2', status='active', - created_at=DATETIME, updated_at=DATETIME, - checksum='ca425b88f047ce8ec45ee90e813ada91') + self.queued_image = _fixture(UUID2, + name='image-2', + status='active', + created_at=DATETIME, + updated_at=DATETIME, + checksum='ca425b88f047ce8e' + 'c45ee90e813ada91') def _do_index(self): request = webob.Request.blank('/v2/images') response = webob.Response(request=request) self.serializer.index(response, - {'images': [self.active_image, self.queued_image]}) + {'images': [self.active_image, + self.queued_image]}) return json.loads(response.body)['images'] def _do_show(self, image): diff --git a/tox.ini b/tox.ini index 4b800a6a..d821275a 100644 --- a/tox.ini +++ b/tox.ini @@ -18,7 +18,7 @@ downloadcache = ~/cache/pip [testenv:pep8] deps = pep8==1.3.3 -commands = pep8 --ignore=E125,E126,E128,E711 --repeat --show-source --exclude=.venv,.tox,dist,doc,openstack . +commands = pep8 --ignore=E125,E126,E711 --repeat --show-source --exclude=.venv,.tox,dist,doc,openstack . [testenv:cover] setenv = NOSE_WITH_COVERAGE=1