Merge "Clean up pep8 E128 violations"

This commit is contained in:
Jenkins 2012-10-12 21:58:56 +00:00 committed by Gerrit Code Review
commit 99ebf103d4
45 changed files with 630 additions and 435 deletions

View File

@ -47,7 +47,8 @@ class BaseController(object):
except exception.Forbidden:
msg = _("Forbidden image access")
LOG.debug(msg)
raise webob.exc.HTTPForbidden(msg, request=request,
raise webob.exc.HTTPForbidden(msg,
request=request,
content_type='text/plain')
def get_active_image_meta_or_404(self, request, image_id):

View File

@ -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,
@ -600,7 +600,8 @@ 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 = self._validate_image_for_activation(req,
image_id,
image_meta)
image_meta = self._upload_and_activate(req, image_meta)
elif self._copy_from(req):

View File

@ -290,11 +290,12 @@ 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']
_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__()

View File

@ -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

View File

@ -239,7 +239,8 @@ 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'],
prop = _image_property_format(values['image_id'],
values['name'],
values['value'])
image['properties'].append(prop)
return prop

View File

@ -22,19 +22,26 @@ from glance.db.sqlalchemy.migrate_repo.schema import (
def define_images_table(meta):
images = Table('images', 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,
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,
Column('deleted',
Boolean(),
nullable=False,
default=False,
index=True),
mysql_engine='InnoDB',
extend_existing=True)

View File

@ -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,
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,
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

View File

@ -27,20 +27,27 @@ 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,
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,
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,
Column('deleted',
Boolean(),
nullable=False,
default=False,
index=True),
mysql_engine='InnoDB',
useexisting=True)

View File

@ -27,20 +27,27 @@ 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,
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,
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,
Column('deleted',
Boolean(),
nullable=False,
default=False,
index=True),
Column('checksum', String(32)),
mysql_engine='InnoDB',

View File

@ -28,20 +28,27 @@ 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,
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,
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,
Column('deleted',
Boolean(),
nullable=False,
default=False,
index=True),
mysql_engine='InnoDB',
useexisting=True)

View File

@ -43,16 +43,26 @@ 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,
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,
Column('deleted',
Boolean(),
nullable=False,
default=False,
index=True),
UniqueConstraint('image_id', 'name'),
mysql_engine='InnoDB',

View File

@ -28,20 +28,27 @@ 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,
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,
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,
Column('deleted',
Boolean(),
nullable=False,
default=False,
index=True),
Column('checksum', String(32)),
Column('owner', String(255)),

View File

@ -48,16 +48,29 @@ 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,
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('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,
Column('deleted',
Boolean(),
nullable=False,
default=False,
index=True),
UniqueConstraint('image_id', 'member'),
mysql_engine='InnoDB',

View File

@ -27,20 +27,27 @@ 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,
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,
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,
Column('deleted',
Boolean(),
nullable=False,
default=False,
index=True),
Column('checksum', String(32)),
Column('min_disk', Integer(), default=0),

View File

@ -22,16 +22,29 @@ 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,
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')

View File

@ -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

View File

@ -296,7 +296,8 @@ 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,
'accesskey': loc.accesskey,
'bucket': loc.bucket,
'obj_name': loc.key})
LOG.debug(msg)
@ -358,7 +359,8 @@ 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,
'access_key': self.access_key,
'bucket': self.bucket,
'obj_name': obj_name})
LOG.debug(msg)
@ -426,7 +428,8 @@ 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,
'accesskey': loc.accesskey,
'bucket': loc.bucket,
'obj_name': loc.key})
LOG.debug(msg)

View File

@ -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)
@ -683,8 +684,8 @@ def create_container_if_missing(container, swift_conn):
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())
"to add container to Swift automatically.") %
locals())
raise glance.store.BackendException(msg)
else:
raise

View File

@ -240,7 +240,9 @@ 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'])
@ -255,11 +257,15 @@ 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):
@ -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}

View File

@ -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)

View File

@ -25,10 +25,12 @@ from glance.tests.utils import execute
TEST_IMAGE_DATA = '*' * 5 * 1024
TEST_IMAGE_META = {'name': 'test_image',
TEST_IMAGE_META = {
'name': 'test_image',
'is_public': False,
'disk_format': 'raw',
'container_format': 'ovf'}
'container_format': 'ovf',
}
class TestScrubber(functional.FunctionalTest):

View File

@ -133,14 +133,15 @@ 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,
"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,
"For key '%s' expected header value '%s'. "
"Got '%s'" % (expected_key,
expected_value,
response[expected_key]))
@ -187,8 +188,8 @@ 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,
"For key '%s' expected header value '%s'. "
"Got '%s'" % (expected_key,
expected_value,
image['images'][0][expected_key]))
@ -228,8 +229,8 @@ 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,
"For key '%s' expected header value '%s'. "
"Got '%s'" % (expected_key,
expected_value,
image['images'][0][expected_key]))
@ -358,7 +359,8 @@ 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,
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,
@ -532,7 +534,8 @@ class TestApi(functional.FunctionalTest):
http = httplib2.Http()
headers = minimal_headers('Image1')
headers['Content-Type'] = 'not octet-stream'
response, content = http.request(path, 'POST',
response, content = http.request(path,
'POST',
body=test_data_file.name,
headers=headers)
self.assertEqual(response.status, 400)
@ -811,7 +814,8 @@ 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,
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)
@ -826,7 +830,8 @@ 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,
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)
@ -837,7 +842,8 @@ 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,
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)
@ -848,7 +854,8 @@ 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,
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)
@ -1076,7 +1083,8 @@ 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,
path = "http://%s:%d/v1/images?%s" % ("127.0.0.1",
self.api_port,
params)
http = httplib2.Http()
response, content = http.request(path, 'GET')
@ -1089,7 +1097,8 @@ 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,
path = "http://%s:%d/v1/images?%s" % ("127.0.0.1",
self.api_port,
params)
http = httplib2.Http()
response, content = http.request(path, 'GET')
@ -1102,7 +1111,8 @@ 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,
path = "http://%s:%d/v1/images?%s" % ("127.0.0.1",
self.api_port,
params)
http = httplib2.Http()
response, content = http.request(path, 'GET')
@ -1114,7 +1124,8 @@ 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,
path = "http://%s:%d/v1/images?%s" % ("127.0.0.1",
self.api_port,
params)
http = httplib2.Http()
response, content = http.request(path, 'GET')
@ -1258,7 +1269,8 @@ class TestApi(functional.FunctionalTest):
test_data_file.write("XXX")
test_data_file.flush()
http = httplib2.Http()
response, content = http.request(path, 'POST',
response, content = http.request(path,
'POST',
headers=headers,
body=test_data_file.name)
self.assertEqual(response.status, 400)
@ -1319,7 +1331,8 @@ class TestApi(functional.FunctionalTest):
test_data_file.write("XXX")
test_data_file.flush()
http = httplib2.Http()
response, content = http.request(path, 'PUT',
response, content = http.request(path,
'PUT',
headers=headers,
body=test_data_file.name)
self.assertEqual(response.status, 400)

View File

@ -147,7 +147,9 @@ 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,
response, content = https.request(path,
'POST',
headers=headers,
body=image_data)
self.assertEqual(response.status, 201)
data = json.loads(content)
@ -191,14 +193,15 @@ 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,
"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,
"For key '%s' expected header value '%s'. "
"Got '%s'" % (expected_key,
expected_value,
response[expected_key]))
@ -244,9 +247,10 @@ 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,
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]))
@ -285,9 +289,10 @@ 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,
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]))
@ -411,7 +416,9 @@ 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,
response, content = https.request(path,
'PUT',
headers=headers,
body=image_data)
self.assertEqual(response.status, 200)
data = json.loads(content)
@ -669,7 +676,8 @@ 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',
response, content = https.request(path,
'POST',
body=test_data_file.name)
self.assertEqual(response.status, 400)
expected = "Content-Type must be application/octet-stream"

View File

@ -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()

View File

@ -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"""

View File

@ -165,7 +165,8 @@ class TestMigrations(utils.BaseTestCase):
# Create the initial version of the images table
meta = MetaData()
meta.bind = engine
images_001 = Table('images', meta,
images_001 = Table('images',
meta,
Column('id', models.Integer, primary_key=True),
Column('name', String(255)),
Column('type', String(30)),
@ -176,7 +177,10 @@ class TestMigrations(utils.BaseTestCase):
Column('created_at', DateTime(), nullable=False),
Column('updated_at', DateTime()),
Column('deleted_at', DateTime()),
Column('deleted', Boolean(), nullable=False, default=False))
Column('deleted',
Boolean(),
nullable=False,
default=False))
images_001.create()
def _walk_versions(self, initial_version=0):

View File

@ -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())

View File

@ -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)}

View File

@ -1955,11 +1955,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',
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'}
'x-image-meta-container-format': 'ami',
}
req = webob.Request.blank("/images")
req.method = 'POST'
@ -1971,10 +1973,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',
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-disk-format': 'vhd',
}
req = webob.Request.blank("/images")
req.method = 'POST'
@ -1986,11 +1990,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',
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'}
'x-image-meta-container-format': 'invalid',
}
req = webob.Request.blank("/images")
req.method = 'POST'
@ -2002,12 +2008,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',
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'}
'x-image-meta-container-format': 'bare',
}
req = webob.Request.blank("/images")
req.method = 'POST'
@ -2019,11 +2027,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',
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'}
'x-image-meta-container-format': 'bare',
}
req = webob.Request.blank("/images")
req.method = 'POST'

View File

@ -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])
@ -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',
_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),
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',
_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'}),
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,
self.fixture = _fixture(UUID2,
name='image-2',
owner=TENANT2,
checksum='ca425b88f047ce8ec45ee90e813ada91',
created_at=DATETIME, updated_at=DATETIME,
size=1024, properties={'color': 'green', 'mood': 'grouchy'})
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,
self.fixture = _fixture(UUID2,
name='image-2',
owner=TENANT2,
checksum='ca425b88f047ce8ec45ee90e813ada91',
created_at=DATETIME, updated_at=DATETIME,
properties={'marx': 'groucho'}, size=1024)
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,
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):

View File

@ -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