Enable F841 check

Enable F841 check: local variable 'name' assigned but never used.

Make appropriate changes to files listed below.

Change-Id: I02837d4abf421dc9d85f3b01587120fd68acfa12
This commit is contained in:
Julia Varlamova 2014-01-27 19:40:57 +04:00
parent 31253812f5
commit 3fa66f63c4
29 changed files with 46 additions and 79 deletions

View File

@ -68,7 +68,7 @@ def safe_kill(req, image_id):
"""
try:
_kill(req, image_id)
except Exception as e:
except Exception:
LOG.exception(_("Unable to kill image %(id)s: ") % {'id': image_id})

View File

@ -25,7 +25,7 @@ def define_image_properties_table(meta):
(define_images_table,) = from_migration_import(
'001_add_images_table', ['define_images_table'])
images = define_images_table(meta)
images = define_images_table(meta) # noqa
# NOTE(dperaza) DB2: specify the UniqueConstraint option when creating the
# table will cause an index being created to specify the index

View File

@ -39,7 +39,7 @@ def get_image_properties_table(meta):
(get_images_table,) = from_migration_import(
'004_add_checksum', ['get_images_table'])
images = get_images_table(meta)
images = get_images_table(meta) # noqa
image_properties = Table('image_properties',
meta,

View File

@ -44,7 +44,7 @@ def get_image_properties_table(meta):
def get_image_members_table(meta):
images = get_images_table(meta)
images = get_images_table(meta) # noqa
image_members = Table('image_members',
meta,

View File

@ -418,7 +418,7 @@ class Driver(base.Driver):
path = self.get_image_filepath(image_id, 'queue')
# Touch the file to add it to the queue
with open(path, "w") as f:
with open(path, "w"):
pass
return True

View File

@ -351,7 +351,7 @@ class Driver(base.Driver):
LOG.debug(_("Queueing image '%s'."), image_id)
# Touch the file to add it to the queue
with open(path, "w") as f:
with open(path, "w"):
pass
return True

View File

@ -281,7 +281,7 @@ class ImageProxy(glance.domain.proxy.Image):
data = utils.LimitingReader(data, remaining)
try:
self.image.set_data(data, size=size)
except exception.ImageSizeLimitExceeded as ex:
except exception.ImageSizeLimitExceeded:
raise exception.StorageQuotaFull(image_size=size,
remaining=remaining)

View File

@ -311,7 +311,7 @@ class Controller(object):
"""
try:
members = self.db_api.image_member_find(req.context, member=id)
except exception.NotFound as e:
except exception.NotFound:
msg = _("Member %(id)s not found")
LOG.info(msg % {'id': id})
msg = _("Membership could not be found.")

View File

@ -340,7 +340,7 @@ class ScrubDBQueue(ScrubQueue):
try:
image = self.registry.get_image(image_id)
return image['status'] == 'pending_delete'
except exception.NotFound as e:
except exception.NotFound:
return False

View File

@ -209,8 +209,7 @@ class Store(glance.store.base.Store):
raise exception.BadStoreConfiguration(
store_name='vmware_datastore', reason=reason)
else:
ds_validated = True
_datastore_info_valid = True
self.store_image_dir = CONF.vmware_store_image_dir
def _option_get(self, param):

View File

@ -1331,8 +1331,8 @@ class TaskTests(test_utils.BaseTestCase):
def test_task_get_all_marker(self):
for fixture in self.fixtures:
task = self.db_api.task_create(self.context,
build_task_fixture(**fixture))
self.db_api.task_create(self.context,
build_task_fixture(**fixture))
tasks = self.db_api.task_get_all(self.context, sort_key='id')
task_ids = [t['id'] for t in tasks]
tasks = self.db_api.task_get_all(self.context, sort_key='id',

View File

@ -101,8 +101,7 @@ class TestSqlAlchemyDBDataIntegrity(base.TestDriver):
self.stubs.Set(self.db_api, '_paginate_query',
fake_paginate_query)
images = self.db_api.image_get_all(self.context,
sort_key='created_at')
self.db_api.image_get_all(self.context, sort_key='created_at')
def test_paginate_non_redundant_sort_keys(self):
original_method = self.db_api._paginate_query
@ -115,8 +114,7 @@ class TestSqlAlchemyDBDataIntegrity(base.TestDriver):
self.stubs.Set(self.db_api, '_paginate_query',
fake_paginate_query)
images = self.db_api.image_get_all(self.context,
sort_key='name')
self.db_api.image_get_all(self.context, sort_key='name')
class TestSqlAlchemyTask(base.TaskTests):

View File

@ -42,7 +42,7 @@ class TestSheepdogStore(store_tests.BaseTestCase, testtools.TestCase):
sheepdog.DEFAULT_CHUNKSIZE)
try:
image.create(512)
except BackendException as e:
except BackendException:
msg = "Sheepdog cluster isn't set up"
self.skipTest(msg)
image.delete()

View File

@ -436,7 +436,6 @@ class TestSwiftStore(store_tests.BaseTestCase, testtools.TestCase):
def test_multitenant(self):
"""Ensure an image is properly configured when using multitenancy."""
fake_swift_admin = 'd2f68325-8e2c-4fb1-8c8b-89de2f3d9c4a'
self.config(
swift_store_multi_tenant=True,
)

View File

@ -102,7 +102,6 @@ class TestMiscellaneous(functional.FunctionalTest):
self.start_servers()
api_port = self.api_port
registry_port = self.registry_port
cmd = "curl -g http://127.0.0.1:%d/v1/images" % api_port

View File

@ -1213,8 +1213,8 @@ class TestImages(functional.FunctionalTest):
self.assertEqual('2', image['x_all_permitted_joe_soap'])
path = self._url('/v2/images/%s' % image_id)
media_type = 'application/openstack-images-v2.1-json-patch'
header = self._headers({'content-type': media_type,
'X-Roles': 'joe_soap'})
headers = self._headers({'content-type': media_type,
'X-Roles': 'joe_soap'})
data = jsonutils.dumps([
{'op': 'replace',
'path': '/x_all_permitted_joe_soap', 'value': '3'}

View File

@ -355,7 +355,7 @@ class GetSocketTestCase(test_utils.BaseTestCase):
self.useFixture(fixtures.MonkeyPatch(
'glance.common.wsgi.eventlet.listen',
lambda *x, **y: None))
sock = wsgi.get_socket(1234)
wsgi.get_socket(1234)
self.assertTrue(mock.call().setsockopt(
socket.SOL_SOCKET,
socket.SO_REUSEADDR,

View File

@ -302,7 +302,7 @@ class ImageCacheTestCase(object):
image_id = '1'
self.assertFalse(self.cache.is_cached(image_id))
try:
with self.cache.driver.open_for_write(image_id) as cache_file:
with self.cache.driver.open_for_write(image_id):
raise IOError
except Exception as e:
self.assertIsInstance(e, IOError)

View File

@ -1070,7 +1070,6 @@ class TestMigrations(test_utils.BaseTestCase):
images.insert().values(temp).execute()
locations_table = get_table(engine, 'image_locations')
data = image_id
locations = [
('file://ab', '{"a": "yo yo"}'),
('file://ab', '{}'),

View File

@ -16,7 +16,6 @@
import os
import shutil
import tempfile
import time
import uuid
import eventlet
@ -52,7 +51,6 @@ class TestScrubber(test_utils.BaseTestCase):
uri = 'file://some/path/%s' % (fname)
id = 'helloworldid'
now = time.time()
scrub = scrubber.Scrubber(glance.store)
scrub.registry = self.mox.CreateMockAnything()
scrub.registry.get_image(id).AndReturn({'status': 'pending_delete'})

View File

@ -462,7 +462,7 @@ class TestStoreLocation(base.StoreClearingUnitTest):
self.stubs.Set(glance.store, 'get_size_from_backend',
fake_get_size_from_backend)
with mock.patch('glance.store._check_image_location') as _:
with mock.patch('glance.store._check_image_location'):
loc1 = {'url': 'file:///fake1.img.tar.gz', 'metadata': {}}
loc2 = {'url': 'file:///fake2.img.tar.gz', 'metadata': {}}

View File

@ -586,7 +586,6 @@ class SwiftTests(object):
def test_add_saves_and_reraises_and_not_uses_wildcard_raise(self):
image_id = str(uuid.uuid4())
swift_size = self.store.large_object_size = 1024
loc = 'swift+https://%s:key@localhost:8080/glance/%s'
swift_contents = "*" * swift_size
connection = mock.Mock()
@ -966,7 +965,7 @@ class TestCreatingLocations(base.IsolatedUnitTest):
context = glance.context.RequestContext(
user='user', tenant='tenant', auth_tok='123',
service_catalog={})
store = glance.store.swift.MultiTenantStore(context)
glance.store.swift.MultiTenantStore(context)
self.assertEqual(fake_get_endpoint.endpoint_region, 'WestCarolina')
def test_multi_tenant_location_custom_service_type(self):
@ -976,7 +975,7 @@ class TestCreatingLocations(base.IsolatedUnitTest):
context = glance.context.RequestContext(
user='user', tenant='tenant', auth_tok='123',
service_catalog={})
store = glance.store.swift.MultiTenantStore(context)
glance.store.swift.MultiTenantStore(context)
self.assertEqual(fake_get_endpoint.service_type, 'toy-store')
def test_multi_tenant_location_custom_endpoint_type(self):
@ -986,7 +985,7 @@ class TestCreatingLocations(base.IsolatedUnitTest):
context = glance.context.RequestContext(
user='user', tenant='tenant', auth_tok='123',
service_catalog={})
store = glance.store.swift.MultiTenantStore(context)
glance.store.swift.MultiTenantStore(context)
self.assertEqual(fake_get_endpoint.endpoint_type, 'InternalURL')

View File

@ -108,19 +108,18 @@ class TestStore(base.StoreClearingUnitTest):
class FakeCookieJar:
pass
with mock.patch.object(Store, 'configure') as store:
self.store.scheme = VMWARE_DATASTORE_CONF['default_store']
self.store.server_host = (
VMWARE_DATASTORE_CONF['vmware_server_host'])
self.store.datacenter_path = (
VMWARE_DATASTORE_CONF['vmware_datacenter_path'])
self.store.datastore_name = (
VMWARE_DATASTORE_CONF['vmware_datastore_name'])
self.store.api_insecure = (
VMWARE_DATASTORE_CONF['vmware_api_insecure'])
self.store._session = FakeSession()
self.store._session.invoke_api = mock.Mock()
self.store._session.wait_for_task = mock.Mock()
self.store.scheme = VMWARE_DATASTORE_CONF['default_store']
self.store.server_host = (
VMWARE_DATASTORE_CONF['vmware_server_host'])
self.store.datacenter_path = (
VMWARE_DATASTORE_CONF['vmware_datacenter_path'])
self.store.datastore_name = (
VMWARE_DATASTORE_CONF['vmware_datastore_name'])
self.store.api_insecure = (
VMWARE_DATASTORE_CONF['vmware_api_insecure'])
self.store._session = FakeSession()
self.store._session.invoke_api = mock.Mock()
self.store._session.wait_for_task = mock.Mock()
self.store.store_image_dir = (
VMWARE_DATASTORE_CONF['vmware_store_image_dir'])

View File

@ -2531,7 +2531,6 @@ class TestGlanceAPI(base.IsolatedUnitTest):
req.method = 'HEAD'
res = req.get_response(self.api)
self.assertEqual(res.status_int, 200)
orig_value = res.headers[k]
req = webob.Request.blank('/images/%s' % UUID2)
req.headers[k] = v
@ -3348,8 +3347,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest):
permitted role 'member' can read that protected property via
/images/detail
"""
image_id = self._create_admin_image(
{'x-image-meta-property-x_owner_foo': 'bar'})
self._create_admin_image({'x-image-meta-property-x_owner_foo': 'bar'})
another_request = unit_test_utils.get_fake_request(
method='GET', path='/images/detail')
headers = {'x-auth-token': 'user:tenant:member'}
@ -3367,8 +3365,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest):
/images/detail
"""
self.set_property_protections(use_policies=True)
image_id = self._create_admin_image(
{'x-image-meta-property-x_owner_foo': 'bar'})
self._create_admin_image({'x-image-meta-property-x_owner_foo': 'bar'})
another_request = unit_test_utils.get_fake_request(
method='GET', path='/images/detail')
headers = {'x-auth-token': 'user:tenant:member'}
@ -3385,8 +3382,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest):
permitted role 'fake_role' can *not* read that protected property via
/images/detail
"""
image_id = self._create_admin_image(
{'x-image-meta-property-x_owner_foo': 'bar'})
self._create_admin_image({'x-image-meta-property-x_owner_foo': 'bar'})
another_request = unit_test_utils.get_fake_request(
method='GET', path='/images/detail')
headers = {'x-auth-token': 'user:tenant:fake_role'}
@ -3405,8 +3401,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest):
/images/detail
"""
self.set_property_protections(use_policies=True)
image_id = self._create_admin_image(
{'x-image-meta-property-x_owner_foo': 'bar'})
self._create_admin_image({'x-image-meta-property-x_owner_foo': 'bar'})
another_request = unit_test_utils.get_fake_request(
method='GET', path='/images/detail')
headers = {'x-auth-token': 'user:tenant:fake_role'}

View File

@ -518,7 +518,6 @@ class TestRegistryV1Client(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn):
iso2 = timeutils.isotime(dt2)
dt3 = timeutils.utcnow() + datetime.timedelta(2)
iso3 = timeutils.isotime(dt3)
dt4 = timeutils.utcnow() + datetime.timedelta(3)
iso4 = timeutils.isotime(dt4)

View File

@ -196,9 +196,7 @@ class TestUploadUtils(base.StoreClearingUnitTest):
def _test_upload_data_to_store_exception(self, exc_class, expected_class):
req = unit_test_utils.get_fake_request()
location = "file://foo/bar"
size = 10
checksum = "checksum"
image_meta = {'id': unit_test_utils.UUID1,
'size': size}
@ -227,9 +225,7 @@ class TestUploadUtils(base.StoreClearingUnitTest):
image_killed=True):
req = unit_test_utils.get_fake_request()
location = "file://foo/bar"
size = 10
checksum = "checksum"
image_meta = {'id': unit_test_utils.UUID1,
'size': size}

View File

@ -305,15 +305,11 @@ class TestImageMembersController(test_utils.BaseTestCase):
def test_update_done_by_owner(self):
request = unit_test_utils.get_fake_request(tenant=TENANT1)
image_id = UUID2
member_id = TENANT4
self.assertRaises(webob.exc.HTTPForbidden, self.controller.update,
request, UUID2, TENANT4, status='accepted')
def test_update_invalid_status(self):
request = unit_test_utils.get_fake_request(tenant=TENANT4)
image_id = UUID2
member_id = TENANT4
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
request, UUID2, TENANT4, status='accept')
@ -513,14 +509,12 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
def test_create(self):
request = unit_test_utils.get_fake_request()
request.body = jsonutils.dumps({'member': TENANT1})
image_id = UUID1
output = self.deserializer.create(request)
expected = {'member_id': TENANT1}
self.assertEqual(expected, output)
def test_create_invalid(self):
request = unit_test_utils.get_fake_request()
image_id = UUID1
request.body = jsonutils.dumps({'mem': TENANT1})
self.assertRaises(webob.exc.HTTPBadRequest, self.deserializer.create,
request)
@ -539,16 +533,12 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
def test_update(self):
request = unit_test_utils.get_fake_request()
request.body = jsonutils.dumps({'status': 'accepted'})
image_id = UUID1
member_id = TENANT1
output = self.deserializer.update(request)
expected = {'status': 'accepted'}
self.assertEqual(expected, output)
def test_update_invalid(self):
request = unit_test_utils.get_fake_request()
image_id = UUID1
member_id = TENANT1
request.body = jsonutils.dumps({'mem': TENANT1})
self.assertRaises(webob.exc.HTTPBadRequest, self.deserializer.update,
request)

View File

@ -704,7 +704,6 @@ class TestImagesController(base.IsolatedUnitTest):
def test_update_add_too_many_properties(self):
self.config(image_property_quota=1)
request = unit_test_utils.get_fake_request()
output = self.controller.show(request, UUID1)
changes = [
{'op': 'add', 'path': ['foo'], 'value': 'baz'},
@ -1021,7 +1020,7 @@ class TestImagesController(base.IsolatedUnitTest):
{'op': 'replace', 'path': ['x_owner_foo'], 'value': 'baz'},
]
self.assertRaises(webob.exc.HTTPConflict, self.controller.update,
request, UUID1, changes)
another_request, created_image.image_id, changes)
def test_prop_protection_with_delete_and_permitted_role(self):
enforcer = glance.api.policy.Enforcer()
@ -1063,7 +1062,7 @@ class TestImagesController(base.IsolatedUnitTest):
{'op': 'remove', 'path': ['x_owner_foo']}
]
self.assertRaises(webob.exc.HTTPConflict, self.controller.update,
request, UUID1, changes)
another_request, created_image.image_id, changes)
def test_create_non_protected_prop(self):
"""
@ -1081,7 +1080,7 @@ class TestImagesController(base.IsolatedUnitTest):
'1')
another_request = unit_test_utils.get_fake_request(roles=['joe_soap'])
extra_props = {'x_all_permitted_2': '2'}
created_image = self.controller.create(request, image=image,
created_image = self.controller.create(another_request, image=image,
extra_properties=extra_props,
tags=[])
self.assertEqual(created_image.extra_properties['x_all_permitted_2'],
@ -1195,7 +1194,7 @@ class TestImagesController(base.IsolatedUnitTest):
{'op': 'replace', 'path': ['x_none_update'], 'value': 'baz'},
]
self.assertRaises(webob.exc.HTTPConflict, self.controller.update,
request, UUID1, changes)
another_request, created_image.image_id, changes)
def test_delete_locked_down_protected_prop(self):
"""
@ -1213,7 +1212,7 @@ class TestImagesController(base.IsolatedUnitTest):
{'op': 'remove', 'path': ['x_none_delete']}
]
self.assertRaises(webob.exc.HTTPConflict, self.controller.update,
request, UUID1, changes)
another_request, created_image.image_id, changes)
def test_update_replace_locations(self):
self.stubs.Set(glance.store, 'get_size_from_backend',
@ -1643,7 +1642,7 @@ class TestImagesController(base.IsolatedUnitTest):
request = unit_test_utils.get_fake_request()
self.assertTrue(filter(lambda k: UUID1 in k, self.store.data))
try:
image = self.controller.delete(request, UUID1)
self.controller.delete(request, UUID1)
output_logs = self.notifier.get_logs()
self.assertEqual(len(output_logs), 1)
output_log = output_logs[0]
@ -1736,7 +1735,6 @@ class TestImagesController(base.IsolatedUnitTest):
self.controller.index, request, marker=fake_uuid)
def test_invalid_locations_op_pos(self):
request = unit_test_utils.get_fake_request()
pos = self.controller._get_locations_op_pos(None, 2, True)
self.assertEqual(pos, None)
pos = self.controller._get_locations_op_pos('1', None, True)

View File

@ -31,10 +31,9 @@ commands = {posargs}
# E711 comparison to None should be 'if cond is not None:'
# E712 comparison to True should be 'if cond is True:' or 'if cond:'
# F821 undefined name 'name'
# F841 local variable 'name' assigned but never used
# H301 one import per line
# H402 one line docstring needs punctuation.
# H404 multi line docstring should start with a summary
ignore = E711,E712,F821,F841,H301,H402,H404
ignore = E711,E712,F821,H301,H402,H404
builtins = _
exclude = .venv,.git,.tox,dist,doc,etc,*glance/locale*,*openstack/common*,*lib/python*,*egg,build