Start using PyFlakes and Hacking
Instead of globally ignoring Pyflakes and Hacking warnings, blacklist explitly only those that trigger numerously. Fix the rest alongway and start to gate on those that are now passing. Change-Id: Ia19dc708cf0ccab2da5b46d1652f16e901499c24
This commit is contained in:
parent
0c1f60d06b
commit
6ba3ebbf8d
|
@ -334,7 +334,7 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer):
|
|||
return raw_change[op]
|
||||
|
||||
def _decode_json_pointer(self, pointer):
|
||||
""" Parse a json pointer.
|
||||
"""Parse a json pointer.
|
||||
|
||||
Json Pointers are defined in
|
||||
http://tools.ietf.org/html/draft-pbryan-zyp-json-pointer .
|
||||
|
@ -350,7 +350,7 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer):
|
|||
return ret
|
||||
|
||||
def _validate_json_pointer(self, pointer):
|
||||
""" Validate a json pointer.
|
||||
"""Validate a json pointer.
|
||||
|
||||
We only accept a limited form of json pointers.
|
||||
"""
|
||||
|
|
|
@ -35,9 +35,9 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
|
|||
if os.path.exists(os.path.join(possible_topdir, 'glance', '__init__.py')):
|
||||
sys.path.insert(0, possible_topdir)
|
||||
|
||||
import glance.image_cache.client
|
||||
from glance.common import exception
|
||||
from glance.common import utils
|
||||
import glance.image_cache.client
|
||||
from glance.openstack.common import timeutils
|
||||
from glance.version import version_info as version
|
||||
|
||||
|
@ -78,10 +78,10 @@ def catch_error(action):
|
|||
|
||||
@catch_error('show cached images')
|
||||
def list_cached(options, args):
|
||||
"""
|
||||
%(prog)s list-cached [options]
|
||||
"""%(prog)s list-cached [options]
|
||||
|
||||
List all images currently cached"""
|
||||
List all images currently cached.
|
||||
"""
|
||||
client = get_client(options)
|
||||
images = client.get_cached_images()
|
||||
if not images:
|
||||
|
@ -120,10 +120,10 @@ List all images currently cached"""
|
|||
|
||||
@catch_error('show queued images')
|
||||
def list_queued(options, args):
|
||||
"""
|
||||
%(prog)s list-queued [options]
|
||||
"""%(prog)s list-queued [options]
|
||||
|
||||
List all images currently queued for caching"""
|
||||
List all images currently queued for caching.
|
||||
"""
|
||||
client = get_client(options)
|
||||
images = client.get_queued_images()
|
||||
if not images:
|
||||
|
@ -143,10 +143,10 @@ List all images currently queued for caching"""
|
|||
|
||||
@catch_error('queue the specified image for caching')
|
||||
def queue_image(options, args):
|
||||
"""
|
||||
%(prog)s queue-image <IMAGE_ID> [options]
|
||||
"""%(prog)s queue-image <IMAGE_ID> [options]
|
||||
|
||||
Queues an image for caching"""
|
||||
Queues an image for caching
|
||||
"""
|
||||
if len(args) == 1:
|
||||
image_id = args.pop()
|
||||
else:
|
||||
|
@ -173,7 +173,8 @@ def delete_cached_image(options, args):
|
|||
"""
|
||||
%(prog)s delete-cached-image <IMAGE_ID> [options]
|
||||
|
||||
Deletes an image from the cache"""
|
||||
Deletes an image from the cache
|
||||
"""
|
||||
if len(args) == 1:
|
||||
image_id = args.pop()
|
||||
else:
|
||||
|
@ -197,10 +198,10 @@ Deletes an image from the cache"""
|
|||
|
||||
@catch_error('Delete all cached images')
|
||||
def delete_all_cached_images(options, args):
|
||||
"""
|
||||
%(prog)s delete-all-cached-images [options]
|
||||
"""%(prog)s delete-all-cached-images [options]
|
||||
|
||||
Removes all images from the cache"""
|
||||
Remove all images from the cache.
|
||||
"""
|
||||
if (not options.force and
|
||||
not user_confirm("Delete all cached images?", default=False)):
|
||||
return SUCCESS
|
||||
|
@ -219,7 +220,8 @@ def delete_queued_image(options, args):
|
|||
"""
|
||||
%(prog)s delete-queued-image <IMAGE_ID> [options]
|
||||
|
||||
Deletes an image from the cache"""
|
||||
Deletes an image from the cache
|
||||
"""
|
||||
if len(args) == 1:
|
||||
image_id = args.pop()
|
||||
else:
|
||||
|
@ -243,10 +245,10 @@ Deletes an image from the cache"""
|
|||
|
||||
@catch_error('Delete all queued images')
|
||||
def delete_all_queued_images(options, args):
|
||||
"""
|
||||
%(prog)s delete-all-queued-images [options]
|
||||
"""%(prog)s delete-all-queued-images [options]
|
||||
|
||||
Removes all images from the cache queue"""
|
||||
Remove all images from the cache queue.
|
||||
"""
|
||||
if (not options.force and
|
||||
not user_confirm("Delete all queued images?", default=False)):
|
||||
return SUCCESS
|
||||
|
@ -261,8 +263,8 @@ Removes all images from the cache queue"""
|
|||
|
||||
|
||||
def get_client(options):
|
||||
"""
|
||||
Returns a new client object to a Glance server
|
||||
"""Return a new client object to a Glance server.
|
||||
|
||||
specified by the --host and --port options
|
||||
supplied to the CLI
|
||||
"""
|
||||
|
@ -280,7 +282,7 @@ def get_client(options):
|
|||
|
||||
|
||||
def env(*vars, **kwargs):
|
||||
"""Search for the first defined of possibly many env vars
|
||||
"""Search for the first defined of possibly many env vars.
|
||||
|
||||
Returns the first environment variable defined in vars, or
|
||||
returns the default defined in kwargs.
|
||||
|
@ -293,8 +295,7 @@ def env(*vars, **kwargs):
|
|||
|
||||
|
||||
def create_options(parser):
|
||||
"""
|
||||
Sets up the CLI and config-file options that may be
|
||||
"""Set up the CLI and config-file options that may be
|
||||
parsed and program commands.
|
||||
|
||||
:param parser: The option parser
|
||||
|
@ -450,8 +451,7 @@ def lookup_command(parser, command_name):
|
|||
|
||||
|
||||
def user_confirm(prompt, default=False):
|
||||
"""
|
||||
Yes/No question dialog with user.
|
||||
"""Yes/No question dialog with user.
|
||||
|
||||
:param prompt: question/statement to present to user (string)
|
||||
:param default: boolean value to return if empty string
|
||||
|
|
|
@ -78,7 +78,7 @@ class UploadException(Exception):
|
|||
|
||||
class ImageService(object):
|
||||
def __init__(self, conn, auth_token):
|
||||
""" Initialize the ImageService.
|
||||
"""Initialize the ImageService.
|
||||
|
||||
conn: a httplib.HTTPConnection to the glance server
|
||||
auth_token: authentication token to pass in the x-auth-token header
|
||||
|
@ -723,6 +723,8 @@ def logging_excepthook(type, value, tb):
|
|||
|
||||
|
||||
def main():
|
||||
"""The main function."""
|
||||
|
||||
usage = """
|
||||
%%prog <command> [options] [args]
|
||||
|
||||
|
|
|
@ -128,7 +128,8 @@ class PropertyRules(object):
|
|||
raise exception.InvalidPropertyProtectionConfiguration()
|
||||
|
||||
def _add_policy_rules(self, property_exp, action, rule):
|
||||
""" Add policy rules to the policy enforcer.
|
||||
"""Add policy rules to the policy enforcer.
|
||||
|
||||
For example, if the file listed as property_protection_file has:
|
||||
[prop_a]
|
||||
create = glance_creator
|
||||
|
|
|
@ -491,11 +491,11 @@ def validate_key_cert(key_file, cert_file):
|
|||
error_filename = cert_file
|
||||
cert_str = open(cert_file, "r").read()
|
||||
cert = crypto.load_certificate(crypto.FILETYPE_PEM, cert_str)
|
||||
except IOError, ioe:
|
||||
except IOError as ioe:
|
||||
raise RuntimeError(_("There is a problem with your %s "
|
||||
"%s. Please verify it. Error: %s")
|
||||
% (error_key_name, error_filename, ioe))
|
||||
except crypto.Error, ce:
|
||||
except crypto.Error as ce:
|
||||
raise RuntimeError(_("There is a problem with your %s "
|
||||
"%s. Please verify it. OpenSSL error: %s")
|
||||
% (error_key_name, error_filename, ce))
|
||||
|
@ -506,7 +506,7 @@ def validate_key_cert(key_file, cert_file):
|
|||
|
||||
out = crypto.sign(key, data, digest)
|
||||
crypto.verify(cert, out, data, digest)
|
||||
except crypto.Error, ce:
|
||||
except crypto.Error as ce:
|
||||
raise RuntimeError(_("There is a problem with your key pair. "
|
||||
"Please verify that cert %s and key %s "
|
||||
"belong together. OpenSSL error %s")
|
||||
|
|
|
@ -390,7 +390,7 @@ def image_member_find(context, image_id=None, member=None, status=None):
|
|||
|
||||
for f in filters:
|
||||
members = filter(f, members)
|
||||
return [copy.deepcopy(member) for member in members]
|
||||
return [copy.deepcopy(m) for m in members]
|
||||
|
||||
|
||||
@log_call
|
||||
|
|
|
@ -19,9 +19,8 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
Defines interface for DB access
|
||||
"""
|
||||
|
||||
"""Defines interface for DB access."""
|
||||
|
||||
import logging
|
||||
import time
|
||||
|
@ -91,9 +90,7 @@ def add_cli_options():
|
|||
|
||||
|
||||
def _ping_listener(dbapi_conn, connection_rec, connection_proxy):
|
||||
|
||||
"""
|
||||
Ensures that MySQL connections checked out of the
|
||||
"""Ensures that MySQL connections checked out of the
|
||||
pool are alive.
|
||||
|
||||
Borrowed from:
|
||||
|
@ -112,9 +109,7 @@ def _ping_listener(dbapi_conn, connection_rec, connection_proxy):
|
|||
|
||||
|
||||
def setup_db_env():
|
||||
"""
|
||||
Setup global configuration for database.
|
||||
"""
|
||||
"""Setup global configuration for database."""
|
||||
global sa_logger, _IDLE_TIMEOUT, _MAX_RETRIES, _RETRY_INTERVAL, _CONNECTION
|
||||
|
||||
_IDLE_TIMEOUT = CONF.sql_idle_timeout
|
||||
|
@ -150,7 +145,7 @@ def _check_mutate_authorization(context, image_ref):
|
|||
|
||||
|
||||
def _get_session(autocommit=True, expire_on_commit=False):
|
||||
"""Helper method to grab session"""
|
||||
"""Helper method to grab session."""
|
||||
global _MAKER
|
||||
if not _MAKER:
|
||||
get_engine()
|
||||
|
@ -946,7 +941,7 @@ def _image_child_entry_delete_all(child_model_cls, image_id, delete_time=None,
|
|||
|
||||
|
||||
def image_property_create(context, values, session=None):
|
||||
"""Create an ImageProperty object"""
|
||||
"""Create an ImageProperty object."""
|
||||
prop_ref = models.ImageProperty()
|
||||
prop = _image_property_update(context, prop_ref, values, session=session)
|
||||
return prop.to_dict()
|
||||
|
@ -954,7 +949,7 @@ def image_property_create(context, values, session=None):
|
|||
|
||||
def _image_property_update(context, prop_ref, values, session=None):
|
||||
"""
|
||||
Used internally by image_property_create and image_property_update
|
||||
Used internally by image_property_create and image_property_update.
|
||||
"""
|
||||
_drop_protected_attrs(models.ImageProperty, values)
|
||||
values["deleted"] = False
|
||||
|
@ -965,7 +960,7 @@ def _image_property_update(context, prop_ref, values, session=None):
|
|||
|
||||
def image_property_delete(context, prop_ref, image_ref, session=None):
|
||||
"""
|
||||
Used internally by image_property_create and image_property_update
|
||||
Used internally by image_property_create and image_property_update.
|
||||
"""
|
||||
session = session or _get_session()
|
||||
prop = session.query(models.ImageProperty).filter_by(image_id=image_ref,
|
||||
|
@ -985,14 +980,14 @@ def _image_property_delete_all(context, image_id, delete_time=None,
|
|||
|
||||
|
||||
def image_member_create(context, values, session=None):
|
||||
"""Create an ImageMember object"""
|
||||
"""Create an ImageMember object."""
|
||||
memb_ref = models.ImageMember()
|
||||
_image_member_update(context, memb_ref, values, session=session)
|
||||
return _image_member_format(memb_ref)
|
||||
|
||||
|
||||
def _image_member_format(member_ref):
|
||||
"""Format a member ref for consumption outside of this module"""
|
||||
"""Format a member ref for consumption outside of this module."""
|
||||
return {
|
||||
'id': member_ref['id'],
|
||||
'image_id': member_ref['image_id'],
|
||||
|
@ -1005,7 +1000,7 @@ def _image_member_format(member_ref):
|
|||
|
||||
|
||||
def image_member_update(context, memb_id, values):
|
||||
"""Update an ImageMember object"""
|
||||
"""Update an ImageMember object."""
|
||||
session = _get_session()
|
||||
memb_ref = _image_member_get(context, memb_id, session)
|
||||
_image_member_update(context, memb_ref, values, session)
|
||||
|
@ -1023,7 +1018,7 @@ def _image_member_update(context, memb_ref, values, session=None):
|
|||
|
||||
|
||||
def image_member_delete(context, memb_id, session=None):
|
||||
"""Delete an ImageMember object"""
|
||||
"""Delete an ImageMember object."""
|
||||
session = session or _get_session()
|
||||
member_ref = _image_member_get(context, memb_id, session)
|
||||
_image_member_delete(context, member_ref, session)
|
||||
|
@ -1044,7 +1039,7 @@ def _image_member_delete_all(context, image_id, delete_time=None,
|
|||
|
||||
|
||||
def _image_member_get(context, memb_id, session):
|
||||
"""Fetch an ImageMember entity by id"""
|
||||
"""Fetch an ImageMember entity by id."""
|
||||
query = session.query(models.ImageMember)
|
||||
query = query.filter_by(id=memb_id)
|
||||
return query.one()
|
||||
|
|
|
@ -57,7 +57,9 @@ class JSONEncodedDict(TypeDecorator):
|
|||
|
||||
|
||||
class ModelBase(object):
|
||||
"""Base class for Nova and Glance Models"""
|
||||
|
||||
"""Base class for Nova and Glance Models."""
|
||||
|
||||
__table_args__ = {'mysql_engine': 'InnoDB'}
|
||||
__table_initialized__ = False
|
||||
__protected_attributes__ = set([
|
||||
|
@ -71,7 +73,7 @@ class ModelBase(object):
|
|||
deleted = Column(Boolean, nullable=False, default=False)
|
||||
|
||||
def save(self, session=None):
|
||||
"""Save this object"""
|
||||
"""Save this object."""
|
||||
# import api here to prevent circular dependency problem
|
||||
import glance.db.sqlalchemy.api as db_api
|
||||
session = session or db_api._get_session()
|
||||
|
@ -79,7 +81,7 @@ class ModelBase(object):
|
|||
session.flush()
|
||||
|
||||
def delete(self, session=None):
|
||||
"""Delete this object"""
|
||||
"""Delete this object."""
|
||||
self.deleted = True
|
||||
self.deleted_at = timeutils.utcnow()
|
||||
self.save(session=session)
|
||||
|
@ -123,7 +125,7 @@ class ModelBase(object):
|
|||
|
||||
|
||||
class Image(BASE, ModelBase):
|
||||
"""Represents an image in the datastore"""
|
||||
"""Represents an image in the datastore."""
|
||||
__tablename__ = 'images'
|
||||
__table_args__ = (Index('checksum_image_idx', 'checksum'),
|
||||
Index('ix_images_is_public', 'is_public'),
|
||||
|
@ -145,7 +147,7 @@ class Image(BASE, ModelBase):
|
|||
|
||||
|
||||
class ImageProperty(BASE, ModelBase):
|
||||
"""Represents an image properties in the datastore"""
|
||||
"""Represents an image properties in the datastore."""
|
||||
__tablename__ = 'image_properties'
|
||||
__table_args__ = (Index('ix_image_properties_image_id', 'image_id'),
|
||||
Index('ix_image_properties_deleted', 'deleted'),
|
||||
|
@ -164,7 +166,7 @@ class ImageProperty(BASE, ModelBase):
|
|||
|
||||
|
||||
class ImageTag(BASE, ModelBase):
|
||||
"""Represents an image tag in the datastore"""
|
||||
"""Represents an image tag in the datastore."""
|
||||
__tablename__ = 'image_tags'
|
||||
__table_args__ = (Index('ix_image_tags_image_id', 'image_id'),
|
||||
Index('ix_image_tags_image_id_tag_value',
|
||||
|
@ -178,7 +180,7 @@ class ImageTag(BASE, ModelBase):
|
|||
|
||||
|
||||
class ImageLocation(BASE, ModelBase):
|
||||
"""Represents an image location in the datastore"""
|
||||
"""Represents an image location in the datastore."""
|
||||
__tablename__ = 'image_locations'
|
||||
__table_args__ = (Index('ix_image_locations_image_id', 'image_id'),
|
||||
Index('ix_image_locations_deleted', 'deleted'),)
|
||||
|
@ -191,7 +193,7 @@ class ImageLocation(BASE, ModelBase):
|
|||
|
||||
|
||||
class ImageMember(BASE, ModelBase):
|
||||
"""Represents an image members in the datastore"""
|
||||
"""Represents an image members in the datastore."""
|
||||
__tablename__ = 'image_members'
|
||||
unique_constraint_key_name = 'image_members_image_id_member_deleted_at_key'
|
||||
__table_args__ = (Index('ix_image_members_deleted', 'deleted'),
|
||||
|
@ -234,18 +236,14 @@ class Task(BASE, ModelBase):
|
|||
|
||||
|
||||
def register_models(engine):
|
||||
"""
|
||||
Creates database tables for all models with the given engine
|
||||
"""
|
||||
"""Create database tables for all models with the given engine."""
|
||||
models = (Image, ImageProperty, ImageMember)
|
||||
for model in models:
|
||||
model.metadata.create_all(engine)
|
||||
|
||||
|
||||
def unregister_models(engine):
|
||||
"""
|
||||
Drops database tables for all models with the given engine
|
||||
"""
|
||||
"""Drop database tables for all models with the given engine."""
|
||||
models = (Image, ImageProperty)
|
||||
for model in models:
|
||||
model.metadata.drop_all(engine)
|
||||
|
|
|
@ -95,9 +95,7 @@ class Controller(object):
|
|||
self.db_api.setup_db_env()
|
||||
|
||||
def _get_images(self, context, filters, **params):
|
||||
"""
|
||||
Get images, wrapping in exception if necessary.
|
||||
"""
|
||||
"""Get images, wrapping in exception if necessary."""
|
||||
# NOTE(markwash): for backwards compatibility, is_public=True for
|
||||
# admins actually means "treat me as if I'm not an admin and show me
|
||||
# all my images"
|
||||
|
@ -112,8 +110,7 @@ class Controller(object):
|
|||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
def index(self, req):
|
||||
"""
|
||||
Return a basic filtered list of public, non-deleted images
|
||||
"""Return a basic filtered list of public, non-deleted images
|
||||
|
||||
:param req: the Request object coming from the wsgi layer
|
||||
:retval a mapping of the following form::
|
||||
|
@ -145,8 +142,7 @@ class Controller(object):
|
|||
return dict(images=results)
|
||||
|
||||
def detail(self, req):
|
||||
"""
|
||||
Return a filtered list of public, non-deleted images in detail
|
||||
"""Return a filtered list of public, non-deleted images in detail
|
||||
|
||||
:param req: the Request object coming from the wsgi layer
|
||||
:retval a mapping of the following form::
|
||||
|
@ -164,8 +160,7 @@ class Controller(object):
|
|||
return dict(images=image_dicts)
|
||||
|
||||
def _get_query_params(self, req):
|
||||
"""
|
||||
Extract necessary query parameters from http request.
|
||||
"""Extract necessary query parameters from http request.
|
||||
|
||||
:param req: the Request object coming from the wsgi layer
|
||||
:retval dictionary of filters to apply to list of images
|
||||
|
@ -192,8 +187,7 @@ class Controller(object):
|
|||
return params
|
||||
|
||||
def _get_filters(self, req):
|
||||
"""
|
||||
Return a dictionary of query param filters from the request
|
||||
"""Return a dictionary of query param filters from the request
|
||||
|
||||
:param req: the Request object coming from the wsgi layer
|
||||
:retval a dict of key/value filters
|
||||
|
@ -333,8 +327,7 @@ class Controller(object):
|
|||
|
||||
@utils.mutating
|
||||
def delete(self, req, id):
|
||||
"""
|
||||
Deletes an existing image with the registry.
|
||||
"""Deletes an existing image with the registry.
|
||||
|
||||
:param req: wsgi Request object
|
||||
:param id: The opaque internal identifier for the image
|
||||
|
@ -364,8 +357,7 @@ class Controller(object):
|
|||
|
||||
@utils.mutating
|
||||
def create(self, req, body):
|
||||
"""
|
||||
Registers a new image with the registry.
|
||||
"""Registers a new image with the registry.
|
||||
|
||||
:param req: wsgi Request object
|
||||
:param body: Dictionary of information about the image
|
||||
|
@ -412,8 +404,7 @@ class Controller(object):
|
|||
|
||||
@utils.mutating
|
||||
def update(self, req, id, body):
|
||||
"""
|
||||
Updates an existing image with the registry.
|
||||
"""Updates an existing image with the registry.
|
||||
|
||||
:param req: wsgi Request object
|
||||
:param body: Dictionary of information about the image
|
||||
|
@ -479,8 +470,7 @@ def _limit_locations(image):
|
|||
|
||||
|
||||
def make_image_dict(image):
|
||||
"""
|
||||
Create a dict representation of an image which we can use to
|
||||
"""Create a dict representation of an image which we can use to
|
||||
serialize the image.
|
||||
"""
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ LOG = logging.getLogger(__name__)
|
|||
|
||||
class RegistryClient(BaseClient):
|
||||
|
||||
"""A client for the Registry image metadata service"""
|
||||
"""A client for the Registry image metadata service."""
|
||||
|
||||
DEFAULT_PORT = 9191
|
||||
|
||||
|
@ -139,7 +139,7 @@ class RegistryClient(BaseClient):
|
|||
return image_list
|
||||
|
||||
def get_image(self, image_id):
|
||||
"""Returns a mapping of image metadata from Registry"""
|
||||
"""Returns a mapping of image metadata from Registry."""
|
||||
res = self.do_request("GET", "/images/%s" % image_id)
|
||||
data = json.loads(res.read())['image']
|
||||
return self.decrypt_metadata(data)
|
||||
|
@ -199,19 +199,19 @@ class RegistryClient(BaseClient):
|
|||
return image
|
||||
|
||||
def get_image_members(self, image_id):
|
||||
"""Returns a list of membership associations from Registry"""
|
||||
"""Return a list of membership associations from Registry."""
|
||||
res = self.do_request("GET", "/images/%s/members" % image_id)
|
||||
data = json.loads(res.read())['members']
|
||||
return data
|
||||
|
||||
def get_member_images(self, member_id):
|
||||
"""Returns a list of membership associations from Registry"""
|
||||
"""Return a list of membership associations from Registry."""
|
||||
res = self.do_request("GET", "/shared-images/%s" % member_id)
|
||||
data = json.loads(res.read())['shared_images']
|
||||
return data
|
||||
|
||||
def replace_members(self, image_id, member_data):
|
||||
"""Replaces Registry's information about image membership"""
|
||||
"""Replace registry's information about image membership."""
|
||||
if isinstance(member_data, (list, tuple)):
|
||||
member_data = dict(memberships=list(member_data))
|
||||
elif (isinstance(member_data, dict) and
|
||||
|
@ -227,7 +227,7 @@ class RegistryClient(BaseClient):
|
|||
return self.get_status_code(res) == 204
|
||||
|
||||
def add_member(self, image_id, member_id, can_share=None):
|
||||
"""Adds to Registry's information about image membership"""
|
||||
"""Add to registry's information about image membership."""
|
||||
body = None
|
||||
headers = {}
|
||||
# Build up a body if can_share is specified
|
||||
|
@ -241,7 +241,7 @@ class RegistryClient(BaseClient):
|
|||
return self.get_status_code(res) == 204
|
||||
|
||||
def delete_member(self, image_id, member_id):
|
||||
"""Deletes Registry's information about image membership"""
|
||||
"""Delete registry's information about image membership."""
|
||||
res = self.do_request("DELETE", "/images/%s/members/%s" %
|
||||
(image_id, member_id))
|
||||
return self.get_status_code(res) == 204
|
||||
|
|
|
@ -195,7 +195,7 @@ class ChunkedFile(object):
|
|||
self.close()
|
||||
|
||||
def getvalue(self):
|
||||
"""Return entire string value... used in testing"""
|
||||
"""Return entire string value... used in testing."""
|
||||
data = ""
|
||||
self.len = 0
|
||||
for chunk in self:
|
||||
|
@ -205,7 +205,7 @@ class ChunkedFile(object):
|
|||
return data
|
||||
|
||||
def close(self):
|
||||
"""Close the internal file pointer"""
|
||||
"""Close the internal file pointer."""
|
||||
if self.fp:
|
||||
self.fp.close()
|
||||
self.fp = None
|
||||
|
|
|
@ -409,7 +409,7 @@ class Scrubber(object):
|
|||
|
||||
delete_jobs = {}
|
||||
for image_id, image_uri in image_id_uri_list:
|
||||
if not image_id in delete_jobs:
|
||||
if image_id not in delete_jobs:
|
||||
delete_jobs[image_id] = []
|
||||
delete_jobs[image_id].append((image_id, image_uri))
|
||||
return delete_jobs
|
||||
|
|
|
@ -746,7 +746,7 @@ class DriverTests(object):
|
|||
self.assertEquals([], tags)
|
||||
|
||||
def test_image_destroy_with_delete_all(self):
|
||||
""" Check the image child element's _image_delete_all methods
|
||||
"""Check the image child element's _image_delete_all methods.
|
||||
|
||||
checks if all the image_delete_all methods deletes only the child
|
||||
elements of the image to be deleted.
|
||||
|
@ -1702,7 +1702,7 @@ class MembershipVisibilityTests(object):
|
|||
self.assertEqual(set(expected), set(facets))
|
||||
|
||||
def test_owner1_finding_user1_memberships(self):
|
||||
""" Owner1 should see images it owns that are shared with User1 """
|
||||
"""Owner1 should see images it owns that are shared with User1."""
|
||||
expected = [
|
||||
(self.owner1, 'shared-with-1'),
|
||||
(self.owner1, 'shared-with-both'),
|
||||
|
@ -1710,7 +1710,7 @@ class MembershipVisibilityTests(object):
|
|||
self._check_by_member(self.owner1_ctx, self.tenant1, expected)
|
||||
|
||||
def test_user1_finding_user1_memberships(self):
|
||||
""" User1 should see all images shared with User1 """
|
||||
"""User1 should see all images shared with User1 """
|
||||
expected = [
|
||||
(self.owner1, 'shared-with-1'),
|
||||
(self.owner1, 'shared-with-both'),
|
||||
|
@ -1720,12 +1720,12 @@ class MembershipVisibilityTests(object):
|
|||
self._check_by_member(self.user1_ctx, self.tenant1, expected)
|
||||
|
||||
def test_user2_finding_user1_memberships(self):
|
||||
""" User2 should see no images shared with User1 """
|
||||
"""User2 should see no images shared with User1 """
|
||||
expected = []
|
||||
self._check_by_member(self.user2_ctx, self.tenant1, expected)
|
||||
|
||||
def test_admin_finding_user1_memberships(self):
|
||||
""" Admin should see all images shared with User1 """
|
||||
"""Admin should see all images shared with User1 """
|
||||
expected = [
|
||||
(self.owner1, 'shared-with-1'),
|
||||
(self.owner1, 'shared-with-both'),
|
||||
|
@ -1740,31 +1740,31 @@ class MembershipVisibilityTests(object):
|
|||
self.assertEqual(set(expected), set(member_ids))
|
||||
|
||||
def test_owner1_finding_owner1s_image_members(self):
|
||||
""" Owner1 should see all memberships of its image """
|
||||
"""Owner1 should see all memberships of its image """
|
||||
expected = [self.tenant1, self.tenant2]
|
||||
image_id = self.image_ids[(self.owner1, 'shared-with-both')]
|
||||
self._check_by_image(self.owner1_ctx, image_id, expected)
|
||||
|
||||
def test_admin_finding_owner1s_image_members(self):
|
||||
""" Admin should see all memberships of owner1's image """
|
||||
"""Admin should see all memberships of owner1's image """
|
||||
expected = [self.tenant1, self.tenant2]
|
||||
image_id = self.image_ids[(self.owner1, 'shared-with-both')]
|
||||
self._check_by_image(self.admin_ctx, image_id, expected)
|
||||
|
||||
def test_user1_finding_owner1s_image_members(self):
|
||||
""" User1 should see its own membership of owner1's image """
|
||||
"""User1 should see its own membership of owner1's image """
|
||||
expected = [self.tenant1]
|
||||
image_id = self.image_ids[(self.owner1, 'shared-with-both')]
|
||||
self._check_by_image(self.user1_ctx, image_id, expected)
|
||||
|
||||
def test_user2_finding_owner1s_image_members(self):
|
||||
""" User2 should see its own membership of owner1's image """
|
||||
"""User2 should see its own membership of owner1's image """
|
||||
expected = [self.tenant2]
|
||||
image_id = self.image_ids[(self.owner1, 'shared-with-both')]
|
||||
self._check_by_image(self.user2_ctx, image_id, expected)
|
||||
|
||||
def test_user3_finding_owner1s_image_members(self):
|
||||
""" User3 should see no memberships of owner1's image """
|
||||
"""User3 should see no memberships of owner1's image """
|
||||
expected = []
|
||||
image_id = self.image_ids[(self.owner1, 'shared-with-both')]
|
||||
self._check_by_image(self.user3_ctx, image_id, expected)
|
||||
|
|
|
@ -61,7 +61,8 @@ class TestSqlAlchemyMembershipVisibility(base.TestMembershipVisibility,
|
|||
|
||||
|
||||
class TestSqlAlchemyDBDataIntegrity(base.TestDriver):
|
||||
""" Test class for checking the data integrity in the database.
|
||||
"""Test class for checking the data integrity in the database.
|
||||
|
||||
Helpful in testing scenarios specific to the sqlalchemy api.
|
||||
"""
|
||||
|
||||
|
|
|
@ -274,7 +274,7 @@ class JSONRequestDeserializerTest(test_utils.BaseTestCase):
|
|||
|
||||
class ServerTest(test_utils.BaseTestCase):
|
||||
def test_create_pool(self):
|
||||
""" Ensure the wsgi thread pool is an eventlet.greenpool.GreenPool. """
|
||||
"""Ensure the wsgi thread pool is an eventlet.greenpool.GreenPool."""
|
||||
actual = wsgi.Server(threads=1).create_pool()
|
||||
self.assertTrue(isinstance(actual, eventlet.greenpool.GreenPool))
|
||||
|
||||
|
|
|
@ -52,16 +52,14 @@ class ImageCacheTestCase(object):
|
|||
|
||||
@skip_if_disabled
|
||||
def test_is_cached(self):
|
||||
"""
|
||||
Verify is_cached(1) returns 0, then add something to the cache
|
||||
"""Verify is_cached(1) returns 0, then add something to the cache
|
||||
and verify is_cached(1) returns 1.
|
||||
"""
|
||||
self._setup_fixture_file()
|
||||
|
||||
@skip_if_disabled
|
||||
def test_read(self):
|
||||
"""
|
||||
Verify is_cached(1) returns 0, then add something to the cache
|
||||
"""Verify is_cached(1) returns 0, then add something to the cache
|
||||
and verify after a subsequent read from the cache that
|
||||
is_cached(1) returns 1.
|
||||
"""
|
||||
|
@ -76,8 +74,7 @@ class ImageCacheTestCase(object):
|
|||
|
||||
@skip_if_disabled
|
||||
def test_open_for_read(self):
|
||||
"""
|
||||
Test convenience wrapper for opening a cache file via
|
||||
"""Test convenience wrapper for opening a cache file via
|
||||
its image identifier.
|
||||
"""
|
||||
self._setup_fixture_file()
|
||||
|
@ -91,8 +88,7 @@ class ImageCacheTestCase(object):
|
|||
|
||||
@skip_if_disabled
|
||||
def test_get_image_size(self):
|
||||
"""
|
||||
Test convenience wrapper for querying cache file size via
|
||||
"""Test convenience wrapper for querying cache file size via
|
||||
its image identifier.
|
||||
"""
|
||||
self._setup_fixture_file()
|
||||
|
@ -103,9 +99,7 @@ class ImageCacheTestCase(object):
|
|||
|
||||
@skip_if_disabled
|
||||
def test_delete(self):
|
||||
"""
|
||||
Test delete method that removes an image from the cache
|
||||
"""
|
||||
"""Test delete method that removes an image from the cache."""
|
||||
self._setup_fixture_file()
|
||||
|
||||
self.cache.delete_cached_image(1)
|
||||
|
@ -114,9 +108,7 @@ class ImageCacheTestCase(object):
|
|||
|
||||
@skip_if_disabled
|
||||
def test_delete_all(self):
|
||||
"""
|
||||
Test delete method that removes an image from the cache
|
||||
"""
|
||||
"""Test delete method that removes an image from the cache."""
|
||||
for image_id in (1, 2):
|
||||
self.assertFalse(self.cache.is_cached(image_id))
|
||||
|
||||
|
@ -135,9 +127,7 @@ class ImageCacheTestCase(object):
|
|||
|
||||
@skip_if_disabled
|
||||
def test_clean_stalled(self):
|
||||
"""
|
||||
Test the clean method removes expected images
|
||||
"""
|
||||
"""Test the clean method removes expected images."""
|
||||
incomplete_file_path = os.path.join(self.cache_dir, 'incomplete', '1')
|
||||
incomplete_file = open(incomplete_file_path, 'w')
|
||||
incomplete_file.write(FIXTURE_DATA)
|
||||
|
|
|
@ -107,7 +107,8 @@ def get_table(engine, name):
|
|||
"""Returns an sqlalchemy table dynamically from db.
|
||||
|
||||
Needed because the models don't work for us in migrations
|
||||
as models will be far out of sync with the current data."""
|
||||
as models will be far out of sync with the current data.
|
||||
"""
|
||||
metadata = sqlalchemy.schema.MetaData()
|
||||
metadata.bind = engine
|
||||
return sqlalchemy.Table(name, metadata, autoload=True)
|
||||
|
@ -452,7 +453,8 @@ class TestMigrations(utils.BaseTestCase):
|
|||
|
||||
def _pre_upgrade_004(self, engine):
|
||||
"""Insert checksum data sample to check if migration goes fine with
|
||||
data"""
|
||||
data.
|
||||
"""
|
||||
now = timeutils.utcnow()
|
||||
images = get_table(engine, 'images')
|
||||
data = [
|
||||
|
@ -530,7 +532,8 @@ class TestMigrations(utils.BaseTestCase):
|
|||
|
||||
def _pre_upgrade_010(self, engine):
|
||||
"""Test rows in images with NULL updated_at get updated to equal
|
||||
created_at"""
|
||||
created_at.
|
||||
"""
|
||||
|
||||
initial_values = [
|
||||
(datetime.datetime(1999, 1, 2, 4, 10, 20),
|
||||
|
@ -573,7 +576,8 @@ class TestMigrations(utils.BaseTestCase):
|
|||
def _pre_upgrade_012(self, engine):
|
||||
"""Test rows in images have id changes from int to varchar(32) and
|
||||
value changed from int to UUID. Also test image_members and
|
||||
image_properties gets updated to point to new UUID keys"""
|
||||
image_properties gets updated to point to new UUID keys.
|
||||
"""
|
||||
|
||||
images = get_table(engine, 'images')
|
||||
image_members = get_table(engine, 'image_members')
|
||||
|
@ -825,7 +829,7 @@ class TestMigrations(utils.BaseTestCase):
|
|||
'swift://acct3A%foobar:pass@example.com/container/obj-id2']
|
||||
|
||||
for location in loc_list:
|
||||
if not location in actual_location:
|
||||
if location not in actual_location:
|
||||
self.fail(_("location: %s data lost") % location)
|
||||
|
||||
def _pre_upgrade_019(self, engine):
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
# Copyright 2013, Red Hat, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the 'License'); you may
|
||||
# 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
|
||||
# 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.
|
||||
|
|
|
@ -85,7 +85,7 @@ class TestStoreLocation(base.StoreClearingUnitTest):
|
|||
self.assertEqual(uri, loc.get_uri())
|
||||
|
||||
bad_uri = 'fil://'
|
||||
self.assertRaises(Exception, loc.parse_uri, bad_uri)
|
||||
self.assertRaises(AssertionError, loc.parse_uri, bad_uri)
|
||||
|
||||
bad_uri = 'file://'
|
||||
self.assertRaises(exception.BadStoreUri, loc.parse_uri, bad_uri)
|
||||
|
@ -132,7 +132,7 @@ class TestStoreLocation(base.StoreClearingUnitTest):
|
|||
self.assertEqual(uri, loc.get_uri())
|
||||
|
||||
bad_uri = 'htt://'
|
||||
self.assertRaises(Exception, loc.parse_uri, bad_uri)
|
||||
self.assertRaises(AssertionError, loc.parse_uri, bad_uri)
|
||||
|
||||
bad_uri = 'http://'
|
||||
self.assertRaises(exception.BadStoreUri, loc.parse_uri, bad_uri)
|
||||
|
@ -207,7 +207,7 @@ class TestStoreLocation(base.StoreClearingUnitTest):
|
|||
self.assertEqual(uri, loc.get_uri())
|
||||
|
||||
bad_uri = 'swif://'
|
||||
self.assertRaises(Exception, loc.parse_uri, bad_uri)
|
||||
self.assertRaises(AssertionError, loc.parse_uri, bad_uri)
|
||||
|
||||
bad_uri = 'swift://'
|
||||
self.assertRaises(exception.BadStoreUri, loc.parse_uri, bad_uri)
|
||||
|
@ -267,7 +267,7 @@ class TestStoreLocation(base.StoreClearingUnitTest):
|
|||
self.assertEqual(uri, loc.get_uri())
|
||||
|
||||
bad_uri = 's://'
|
||||
self.assertRaises(Exception, loc.parse_uri, bad_uri)
|
||||
self.assertRaises(AssertionError, loc.parse_uri, bad_uri)
|
||||
|
||||
bad_uri = 's3://'
|
||||
self.assertRaises(exception.BadStoreUri, loc.parse_uri, bad_uri)
|
||||
|
|
|
@ -779,31 +779,31 @@ class TestRegistryV1Client(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn):
|
|||
self.assertEquals(new_num_images, orig_num_images - 1)
|
||||
|
||||
def test_delete_image_not_existing(self):
|
||||
"""Tests cannot delete non-existing image"""
|
||||
"""Check that one cannot delete non-existing image."""
|
||||
self.assertRaises(exception.NotFound,
|
||||
self.client.delete_image,
|
||||
_gen_uuid())
|
||||
|
||||
def test_get_image_members(self):
|
||||
"""Tests getting image members"""
|
||||
"""Test getting image members."""
|
||||
memb_list = self.client.get_image_members(UUID2)
|
||||
num_members = len(memb_list)
|
||||
self.assertEquals(num_members, 0)
|
||||
|
||||
def test_get_image_members_not_existing(self):
|
||||
"""Tests getting non-existent image members"""
|
||||
"""Test getting non-existent image members."""
|
||||
self.assertRaises(exception.NotFound,
|
||||
self.client.get_image_members,
|
||||
_gen_uuid())
|
||||
|
||||
def test_get_member_images(self):
|
||||
"""Tests getting member images"""
|
||||
"""Test getting member images."""
|
||||
memb_list = self.client.get_member_images('pattieblack')
|
||||
num_members = len(memb_list)
|
||||
self.assertEquals(num_members, 0)
|
||||
|
||||
def test_add_replace_members(self):
|
||||
"""Tests replacing image members"""
|
||||
"""Test replacing image members."""
|
||||
self.assertTrue(self.client.add_member(UUID2, 'pattieblack'))
|
||||
self.assertTrue(self.client.replace_members(UUID2,
|
||||
dict(member_id='pattie'
|
||||
|
@ -840,14 +840,14 @@ class TestBaseClient(testtools.TestCase):
|
|||
class TestRegistryV1ClientApi(base.IsolatedUnitTest):
|
||||
|
||||
def setUp(self):
|
||||
"""Establish a clean test environment"""
|
||||
"""Establish a clean test environment."""
|
||||
super(TestRegistryV1ClientApi, self).setUp()
|
||||
self.mox = mox.Mox()
|
||||
self.context = context.RequestContext()
|
||||
reload(rapi)
|
||||
|
||||
def tearDown(self):
|
||||
"""Clear the test environment"""
|
||||
"""Clear the test environment."""
|
||||
super(TestRegistryV1ClientApi, self).tearDown()
|
||||
self.mox.UnsetStubs()
|
||||
|
||||
|
|
|
@ -460,7 +460,7 @@ class TestImagesController(base.IsolatedUnitTest):
|
|||
self.assertEqual('2', output.name)
|
||||
|
||||
def test_show_deleted_properties(self):
|
||||
""" Ensure that the api filters out deleted image properties. """
|
||||
"""Ensure that the api filters out deleted image properties."""
|
||||
|
||||
# get the image properties into the odd state
|
||||
image = {
|
||||
|
|
25
tox.ini
25
tox.ini
|
@ -27,6 +27,29 @@ setenv = NOSE_WITH_COVERAGE=1
|
|||
commands = {posargs}
|
||||
|
||||
[flake8]
|
||||
ignore = E125,E126,E711,E712,F,H
|
||||
# TODO(dmllr): Analyze or fix the warnings blacklisted below
|
||||
# E125 continuation line does not distinguish itself from next logical line
|
||||
# E126 continuation line over-indented for hanging indent
|
||||
# E711 comparison to None should be 'if cond is not None:'
|
||||
# E712 comparison to True should be 'if cond is True:' or 'if cond:'
|
||||
# F401 'module' imported but unused
|
||||
# F403 unable to detect undefined names with wildcard import
|
||||
# F811 redefinition of function
|
||||
# F821 undefined name 'name'
|
||||
# F841 local variable 'name' assigned but never used
|
||||
# H102 Apache 2.0 license header not found
|
||||
# H201 use at least except Exception
|
||||
# H202 assertRaises Exception too broad
|
||||
# H233 use of print operator
|
||||
# H301 one import per line
|
||||
# H302 import only modules
|
||||
# H306 imports not in alphabetical order
|
||||
# H402 one line docstring needs punctuation.
|
||||
# H404 multi line docstring should start with a summary
|
||||
# H501 do not use locals() for formatting
|
||||
# H701 Empty localisation string
|
||||
# H702 Formatting operation should be outside of localization
|
||||
# H703 multiple positional placeholders
|
||||
ignore = E125,E126,E711,E712,F401,F403,F811,F821,F841,H102,H201,H202,H233,H301,H302,H306,H402,H404,H501,H701,H702,H703
|
||||
builtins = _
|
||||
exclude = .venv,.git,.tox,dist,doc,etc,*glance/locale*,*openstack/common*,*lib/python*,*egg,build
|
||||
|
|
Loading…
Reference in New Issue