Remove trivial cases of unused variables (1)

Kill some of the variables marked as unused by flakes8. This should
allow to enable F841 check in the future.
Only trivial cases with no function calls and obviously pure functions
(like datetime.now(), or len()) are cleaned up here.

Part 1, split to reduce conflicts.

Change-Id: I82854349574ec4bcb9336aba626eefdaed81a8c8
This commit is contained in:
Stanislaw Pitucha 2013-06-13 13:57:15 +00:00
parent 77595f8e08
commit 9f7eaca80d
22 changed files with 28 additions and 44 deletions

View File

@ -802,7 +802,6 @@ class CloudController(object):
'detaching': 'in-use'}
instance_ec2_id = None
instance_data = None
if volume.get('instance_uuid', None):
instance_uuid = volume['instance_uuid']
@ -810,8 +809,7 @@ class CloudController(object):
instance_uuid)
instance_ec2_id = ec2utils.id_to_ec2_inst_id(instance_uuid)
instance_data = '%s[%s]' % (instance_ec2_id,
instance['host'])
v = {}
v['volumeId'] = ec2utils.id_to_ec2_vol_id(volume['id'])
v['status'] = valid_ec2_api_volume_status_map.get(volume['status'],

View File

@ -49,7 +49,6 @@ def convert_password(context, password):
def handle_password(req, meta_data):
ctxt = context.get_admin_context()
password = meta_data.password
if req.method == 'GET':
return meta_data.password
elif req.method == 'POST':

View File

@ -60,7 +60,7 @@ class InterfaceAttachmentController(object):
port_id = id
try:
instance = self.compute_api.get(context, server_id)
self.compute_api.get(context, server_id)
except exception.NotFound:
raise exc.HTTPNotFound()

View File

@ -94,7 +94,7 @@ def make_server(elem):
class ExtendedIpsServerTemplate(xmlutil.TemplateBuilder):
def construct(self):
root = xmlutil.TemplateElement('server', selector='server')
elem = xmlutil.SubTemplateElement(root, 'server', selector='servers')
xmlutil.SubTemplateElement(root, 'server', selector='servers')
make_server(root)
return xmlutil.SlaveTemplate(root, 1, nsmap={
Extended_ips.alias: Extended_ips.namespace})

View File

@ -69,8 +69,7 @@ class FixedIPController(object):
fixed_ip = db.fixed_ip_get_by_address(context, address)
db.fixed_ip_update(context, fixed_ip['address'],
{'reserved': reserved})
except (exception.FixedIpNotFoundForAddress,
exception.FixedIpInvalid) as ex:
except (exception.FixedIpNotFoundForAddress, exception.FixedIpInvalid):
msg = _("Fixed IP %s not found") % address
raise webob.exc.HTTPNotFound(explanation=msg)

View File

@ -104,7 +104,7 @@ class FlavorExtraSpecsController(object):
extra_spec = db.instance_type_extra_specs_get_item(context,
flavor_id, id)
return extra_spec
except exception.InstanceTypeExtraSpecsNotFound as e:
except exception.InstanceTypeExtraSpecsNotFound:
raise exc.HTTPNotFound()
def delete(self, req, flavor_id, id):

View File

@ -183,8 +183,7 @@ class ServiceController(object):
raise webob.exc.HTTPUnprocessableEntity(detail=msg)
try:
svc = self.host_api.service_update(context, host, binary,
status_detail)
self.host_api.service_update(context, host, binary, status_detail)
except exception.ServiceNotFound:
raise webob.exc.HTTPNotFound(_("Unknown service"))

View File

@ -552,10 +552,10 @@ class Controller(wsgi.Controller):
search_opts=search_opts,
limit=limit,
marker=marker)
except exception.MarkerNotFound as e:
except exception.MarkerNotFound:
msg = _('marker [%s] not found') % marker
raise exc.HTTPBadRequest(explanation=msg)
except exception.FlavorNotFound as e:
except exception.FlavorNotFound:
log_msg = _("Flavor '%s' could not be found ")
LOG.debug(log_msg, search_opts['flavor'])
instance_list = []
@ -1094,11 +1094,11 @@ class Controller(wsgi.Controller):
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'resize')
except exception.ImageNotAuthorized as image_error:
except exception.ImageNotAuthorized:
msg = _("You are not authorized to access the image "
"the instance was started with.")
raise exc.HTTPUnauthorized(explanation=msg)
except exception.ImageNotFound as image_error:
except exception.ImageNotFound:
msg = _("Image that the instance was started "
"with could not be found.")
raise exc.HTTPBadRequest(explanation=msg)

View File

@ -72,7 +72,6 @@ from nova.openstack.common.db import exception as db_exc
from nova.openstack.common import importutils
from nova.openstack.common import log as logging
from nova.openstack.common import rpc
from nova.openstack.common import timeutils
from nova import quota
from nova import servicegroup
from nova import version
@ -655,7 +654,6 @@ class ServiceCommands(object):
"""
servicegroup_api = servicegroup.API()
ctxt = context.get_admin_context()
now = timeutils.utcnow()
services = db.service_get_all(ctxt)
services = availability_zones.set_availability_zones(ctxt, services)
if host:
@ -1003,13 +1001,12 @@ class AgentBuildCommands(object):
hypervisor='xen'):
"""Creates a new agent build."""
ctxt = context.get_admin_context()
agent_build = db.agent_build_create(ctxt,
{'hypervisor': hypervisor,
'os': os,
'architecture': architecture,
'version': version,
'url': url,
'md5hash': md5hash})
db.agent_build_create(ctxt, {'hypervisor': hypervisor,
'os': os,
'architecture': architecture,
'version': version,
'url': url,
'md5hash': md5hash})
def delete(self, os, architecture, hypervisor='xen'):
"""Deletes an existing agent build."""

View File

@ -494,7 +494,7 @@ class ComputeManager(manager.SchedulerDependentManager):
'assuming it\'s not on shared storage'),
instance=instance)
shared_storage = False
except Exception as e:
except Exception:
LOG.exception(_('Failed to check if instance shared'),
instance=instance)
finally:

View File

@ -395,7 +395,7 @@ class API(LocalAPI):
self.base_rpcapi.ping(context, '1.21 GigaWatts',
timeout=timeout)
break
except rpc_common.Timeout as e:
except rpc_common.Timeout:
LOG.warning(_('Timed out waiting for nova-conductor. '
'Is it running? Or did this service start '
'before nova-conductor?'))

View File

@ -111,9 +111,6 @@ def _upgrade_bdm_v2(meta, bdm_table, bdm_shadow_table):
_bdm_rows_v1 = ('id', 'device_name', 'virtual_name',
'snapshot_id', 'volume_id', 'instance_uuid')
_bdm_rows_v2 = ('id', 'source_type', 'destination_type', 'guest_format',
'device_type', 'disk_bus', 'boot_index', 'image_id')
_instance_cols = ('uuid', 'image_ref', 'root_device_name')
def _get_columns(table, names):

View File

@ -70,7 +70,7 @@ def visit_insert_from_select(element, compiler, **kw):
def _get_not_supported_column(col_name_col_instance, column_name):
try:
column = col_name_col_instance[column_name]
except Exception as e:
except Exception:
msg = _("Please specify column %s in col_name_col_instance "
"param. It is required because column has unsupported "
"type by sqlite).")

View File

@ -198,13 +198,11 @@ class S3ImageService(object):
def _s3_parse_manifest(self, context, metadata, manifest):
manifest = etree.fromstring(manifest)
image_format = 'ami'
image_type = 'machine'
try:
kernel_id = manifest.find('machine_configuration/kernel_id').text
if kernel_id == 'true':
image_format = 'aki'
image_type = 'kernel'
kernel_id = None
except Exception:
kernel_id = None
@ -213,7 +211,6 @@ class S3ImageService(object):
ramdisk_id = manifest.find('machine_configuration/ramdisk_id').text
if ramdisk_id == 'true':
image_format = 'ari'
image_type = 'ramdisk'
ramdisk_id = None
except Exception:
ramdisk_id = None
@ -270,7 +267,7 @@ class S3ImageService(object):
#TODO(bcwaldon): right now, this removes user-defined ids.
# We need to re-enable this.
image_id = metadata.pop('id', None)
metadata.pop('id', None)
image = self.service.create(context, metadata)

View File

@ -72,7 +72,7 @@ class IP(Model):
if self['address'] and not self['version']:
try:
self['version'] = netaddr.IPAddress(self['address']).version
except netaddr.AddrFormatError as e:
except netaddr.AddrFormatError:
raise exception.InvalidIpAddressError(self['address'])
def __eq__(self, other):

View File

@ -325,7 +325,7 @@ class API(base.Base):
for port in ports:
try:
quantumv2.get_client(context).delete_port(port['id'])
except Exception as ex:
except Exception:
LOG.exception(_("Failed to delete quantum port %(portid)s ")
% {'portid': port['id']})

View File

@ -153,7 +153,7 @@ class AttestationService(object):
return httplib.OK, res
return status_code, None
except (socket.error, IOError) as e:
except (socket.error, IOError):
return IOError, None
def _request(self, cmd, subcmd, hosts):

View File

@ -286,7 +286,7 @@ class Service(service.Service):
"""Perform basic config checks before starting processing."""
# Make sure the tempdir exists and is writable
try:
with utils.tempdir() as tmpdir:
with utils.tempdir():
pass
except Exception as e:
LOG.error(_('Temporary directory is invalid: %s'), e)

View File

@ -57,7 +57,7 @@ class XCPVNCProxy(object):
while True:
try:
d = source.recv(32384)
except Exception as e:
except Exception:
d = None
# If recv fails, send a write shutdown the other direction
@ -68,7 +68,7 @@ class XCPVNCProxy(object):
try:
# sendall raises an exception on write error, unlike send
dest.sendall(d)
except Exception as e:
except Exception:
source.close()
dest.close()
break
@ -102,7 +102,6 @@ class XCPVNCProxy(object):
client = req.environ['eventlet.input'].get_socket()
client.sendall("HTTP/1.1 200 OK\r\n\r\n")
socketsserver = None
sockets['client'] = client
sockets['server'] = server

View File

@ -98,7 +98,7 @@ class SmokeTestCase(unittest.TestCase):
try:
conn = self.connect_ssh(ip, key_name)
conn.close()
except Exception as e:
except Exception:
time.sleep(wait)
else:
return True

View File

@ -96,7 +96,7 @@ class InstanceTestsFromPublic(base.UserSmokeTestCase):
conn = self.connect_ssh(
self.data['ip_v6'], TEST_KEY)
conn.close()
except Exception as ex:
except Exception:
time.sleep(1)
else:
break

View File

@ -161,7 +161,6 @@ class InstanceTests(base.UserSmokeTestCase):
self.data['instance'] = reservation.instances[0]
def test_003_instance_runs_within_60_seconds(self):
instance = self.data['instance']
# allow 60 seconds to exit pending with IP
if not self.wait_for_running(self.data['instance']):
self.fail('instance failed to start')