From 56ae8fdfc564b3081599e73f945496edcc2a5ef6 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 22 Jul 2013 01:08:39 -0700 Subject: [PATCH] Enable pep8 F841 checking. This check looks to see whether a local variable is unused. Also fixed all violators of said check. Change-Id: I7c186df41b5601078ffc54588aace8136c6576bd --- .../dashboards/admin/domains/workflows.py | 8 ++++---- .../dashboards/admin/flavors/tests.py | 1 - .../dashboards/admin/groups/forms.py | 2 +- .../dashboards/admin/projects/tests.py | 2 +- openstack_dashboard/dashboards/admin/roles/tests.py | 2 -- .../project/images_and_snapshots/tests.py | 1 - .../dashboards/project/instances/tests.py | 4 ---- .../dashboards/project/loadbalancers/tests.py | 2 -- .../dashboards/project/loadbalancers/workflows.py | 2 +- .../dashboards/project/networks/workflows.py | 4 ++-- .../dashboards/project/routers/views.py | 2 +- .../dashboards/project/volumes/tests.py | 13 ------------- .../dashboards/project/volumes/views.py | 2 -- .../dashboards/settings/password/forms.py | 2 +- openstack_dashboard/test/api_tests/network_tests.py | 4 ++-- openstack_dashboard/test/test_data/neutron_data.py | 1 - tox.ini | 3 +-- 17 files changed, 14 insertions(+), 41 deletions(-) diff --git a/openstack_dashboard/dashboards/admin/domains/workflows.py b/openstack_dashboard/dashboards/admin/domains/workflows.py index 8993f47f4..d810553e6 100644 --- a/openstack_dashboard/dashboards/admin/domains/workflows.py +++ b/openstack_dashboard/dashboards/admin/domains/workflows.py @@ -72,10 +72,10 @@ class CreateDomain(workflows.Workflow): try: LOG.info('Creating domain with name "%s"' % data['name']) desc = data['description'] - new_domain = api.keystone.domain_create(request, - name=data['name'], - description=desc, - enabled=data['enabled']) + api.keystone.domain_create(request, + name=data['name'], + description=desc, + enabled=data['enabled']) except: exceptions.handle(request, ignore=True) return False diff --git a/openstack_dashboard/dashboards/admin/flavors/tests.py b/openstack_dashboard/dashboards/admin/flavors/tests.py index d69f94c1c..4f56dbedb 100644 --- a/openstack_dashboard/dashboards/admin/flavors/tests.py +++ b/openstack_dashboard/dashboards/admin/flavors/tests.py @@ -164,7 +164,6 @@ class FlavorsTests(test.BaseAdminViewTests): 'flavor_get'), }) def test_edit_flavor_set_invalid_name(self): flavor_a = self.flavors.list()[0] - flavor_b = self.flavors.list()[1] eph = getattr(flavor_a, 'OS-FLV-EXT-DATA:ephemeral') invalid_flavor_name = "m1.tiny()" diff --git a/openstack_dashboard/dashboards/admin/groups/forms.py b/openstack_dashboard/dashboards/admin/groups/forms.py index 121fff7a5..cdbdadedd 100644 --- a/openstack_dashboard/dashboards/admin/groups/forms.py +++ b/openstack_dashboard/dashboards/admin/groups/forms.py @@ -39,7 +39,7 @@ class CreateGroupForm(forms.SelfHandlingForm): try: LOG.info('Creating group with name "%s"' % data['name']) domain_context = request.session.get('domain_context', None) - new_group = api.keystone.group_create( + api.keystone.group_create( request, domain_id=domain_context, name=data['name'], diff --git a/openstack_dashboard/dashboards/admin/projects/tests.py b/openstack_dashboard/dashboards/admin/projects/tests.py index 3339f80bb..a571424ed 100644 --- a/openstack_dashboard/dashboards/admin/projects/tests.py +++ b/openstack_dashboard/dashboards/admin/projects/tests.py @@ -1064,6 +1064,6 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests): # step action cannot be instantiated logging.disable(logging.ERROR) with self.assertRaises(exceptions.NotFound): - res = self.client.get(url) + self.client.get(url) finally: logging.disable(logging.NOTSET) diff --git a/openstack_dashboard/dashboards/admin/roles/tests.py b/openstack_dashboard/dashboards/admin/roles/tests.py index c97a528b8..4fa9127e1 100644 --- a/openstack_dashboard/dashboards/admin/roles/tests.py +++ b/openstack_dashboard/dashboards/admin/roles/tests.py @@ -47,8 +47,6 @@ class RolesViewTests(test.BaseAdminViewTests): @test.create_stubs({api.keystone: ('role_list', 'keystone_can_edit_role', )}) def test_index_with_keystone_can_edit_role_false(self): - role = self.roles.first() - api.keystone.role_list(IgnoreArg()).AndReturn(self.roles.list()) api.keystone.keystone_can_edit_role() \ .MultipleTimes().AndReturn(False) diff --git a/openstack_dashboard/dashboards/project/images_and_snapshots/tests.py b/openstack_dashboard/dashboards/project/images_and_snapshots/tests.py index 68fa8024b..ed10d44de 100644 --- a/openstack_dashboard/dashboards/project/images_and_snapshots/tests.py +++ b/openstack_dashboard/dashboards/project/images_and_snapshots/tests.py @@ -36,7 +36,6 @@ class ImagesAndSnapshotsTests(test.TestCase): api.cinder: ('volume_snapshot_list', 'volume_get')}) def test_index(self): images = self.images.list() - snapshots = self.snapshots.list() volumes = self.volumes.list() for volume in volumes: diff --git a/openstack_dashboard/dashboards/project/instances/tests.py b/openstack_dashboard/dashboards/project/instances/tests.py index 9d29f82e6..5e0c045e0 100644 --- a/openstack_dashboard/dashboards/project/instances/tests.py +++ b/openstack_dashboard/dashboards/project/instances/tests.py @@ -702,8 +702,6 @@ class InstanceTests(test.TestCase): server_groups = [secgroups[0], secgroups[1]] wanted_groups = [secgroups[1].id, secgroups[2].id] - expect_add = secgroups[2].id - expect_rm = secgroups[0].id api.nova.server_get(IsA(http.HttpRequest), server.id).AndReturn(server) api.network.security_group_list(IsA(http.HttpRequest)) \ @@ -925,7 +923,6 @@ class InstanceTests(test.TestCase): server = self.servers.first() volume = self.volumes.first() sec_group = self.security_groups.first() - avail_zone = self.availability_zones.first() customization_script = 'user data' device_name = u'vda' volume_choice = "%s:vol" % volume.id @@ -1491,7 +1488,6 @@ class InstanceTests(test.TestCase): api.glance: ('image_list_detailed',)}) def test_select_default_keypair_if_only_one(self): keypair = self.keypairs.first() - image = self.images.first() cinder.volume_list(IsA(http.HttpRequest)) \ .AndReturn(self.volumes.list()) diff --git a/openstack_dashboard/dashboards/project/loadbalancers/tests.py b/openstack_dashboard/dashboards/project/loadbalancers/tests.py index 4a344a064..872fe0c0a 100644 --- a/openstack_dashboard/dashboards/project/loadbalancers/tests.py +++ b/openstack_dashboard/dashboards/project/loadbalancers/tests.py @@ -60,8 +60,6 @@ class LoadBalancerTests(test.TestCase): def set_up_expect(self): # retrieve pools - subnet = self.subnets.first() - vip1 = self.vips.first() vip2 = self.vips.list()[1] diff --git a/openstack_dashboard/dashboards/project/loadbalancers/workflows.py b/openstack_dashboard/dashboards/project/loadbalancers/workflows.py index f58507ef3..2525703fa 100644 --- a/openstack_dashboard/dashboards/project/loadbalancers/workflows.py +++ b/openstack_dashboard/dashboards/project/loadbalancers/workflows.py @@ -107,7 +107,7 @@ class AddPool(workflows.Workflow): def handle(self, request, context): try: - pool = api.lbaas.pool_create(request, **context) + api.lbaas.pool_create(request, **context) return True except: return False diff --git a/openstack_dashboard/dashboards/project/networks/workflows.py b/openstack_dashboard/dashboards/project/networks/workflows.py index f91147ac4..4ad029790 100644 --- a/openstack_dashboard/dashboards/project/networks/workflows.py +++ b/openstack_dashboard/dashboards/project/networks/workflows.py @@ -218,8 +218,8 @@ class CreateSubnetDetailAction(workflows.Action): 'Destination CIDR and nexthop must be specified ' '(value=%s)') % r raise forms.ValidationError(msg) - dest = self._convert_ip_network(route[0], "host_routes") - nexthop = self._convert_ip_address(route[1], "host_routes") + self._convert_ip_network(route[0], "host_routes") + self._convert_ip_address(route[1], "host_routes") def clean(self): cleaned_data = super(CreateSubnetDetailAction, self).clean() diff --git a/openstack_dashboard/dashboards/project/routers/views.py b/openstack_dashboard/dashboards/project/routers/views.py index f48b7957f..a4c06f955 100644 --- a/openstack_dashboard/dashboards/project/routers/views.py +++ b/openstack_dashboard/dashboards/project/routers/views.py @@ -112,7 +112,7 @@ class DetailView(tables.MultiTableView): expand_subnet=False) ext_net.set_id_as_name_if_empty(length=0) router.external_gateway_info['network'] = ext_net.name - except Exception as e: + except Exception: msg = _('Unable to retrieve an external network "%s".') \ % (ext_net_id) exceptions.handle(self.request, msg) diff --git a/openstack_dashboard/dashboards/project/volumes/tests.py b/openstack_dashboard/dashboards/project/volumes/tests.py index fe492cf7c..c474b4ab5 100644 --- a/openstack_dashboard/dashboards/project/volumes/tests.py +++ b/openstack_dashboard/dashboards/project/volumes/tests.py @@ -569,23 +569,10 @@ class VolumeViewTests(test.TestCase): 'tenant_absolute_limits', 'volume_list',), api.glance: ('image_list_detailed',)}) def test_create_volume_cannot_encrypt(self): - volume = self.volumes.first() - volume_type = self.volume_types.first() - usage = {'gigabytes': {'available': 250}, 'volumes': {'available': 6}} - formData = {'name': u'An Encrypted Volume', - 'description': u'This volume has metadata for encryption.', - 'method': u'CreateForm', - 'type': volume_type.name, - 'size': 50, - 'snapshot_source': '', - 'encryption': u'LUKS'} - # check that widget is hidden if can_encrypt_volumes = false PREV = settings.OPENSTACK_HYPERVISOR_FEATURES['can_encrypt_volumes'] settings.OPENSTACK_HYPERVISOR_FEATURES['can_encrypt_volumes'] = False - volume = self.volumes.first() - volume_type = self.volume_types.first() usage_limit = {'maxTotalVolumeGigabytes': 250, 'gigabytesUsed': 20, 'maxTotalVolumes': 6} diff --git a/openstack_dashboard/dashboards/project/volumes/views.py b/openstack_dashboard/dashboards/project/volumes/views.py index 003d1354b..cf3fbd95c 100644 --- a/openstack_dashboard/dashboards/project/volumes/views.py +++ b/openstack_dashboard/dashboards/project/volumes/views.py @@ -108,8 +108,6 @@ class CreateView(forms.ModalFormView): def get_context_data(self, **kwargs): context = super(CreateView, self).get_context_data(**kwargs) try: - tenant_id = self.kwargs.get('tenant_id', - self.request.user.tenant_id) context['usages'] = cinder.tenant_absolute_limits(self.request) volumes = cinder.volume_list(self.request) total_size = sum([getattr(volume, 'size', 0) for volume diff --git a/openstack_dashboard/dashboards/settings/password/forms.py b/openstack_dashboard/dashboards/settings/password/forms.py index 54b7c80eb..36963d494 100644 --- a/openstack_dashboard/dashboards/settings/password/forms.py +++ b/openstack_dashboard/dashboards/settings/password/forms.py @@ -53,7 +53,7 @@ class PasswordForm(forms.SelfHandlingForm): if user_is_editable: try: - passwd = api.keystone.user_update_own_password(request, + api.keystone.user_update_own_password(request, data['current_password'], data['new_password']) messages.success(request, _('Password changed.')) diff --git a/openstack_dashboard/test/api_tests/network_tests.py b/openstack_dashboard/test/api_tests/network_tests.py index a96626499..c29f59b8a 100644 --- a/openstack_dashboard/test/api_tests/network_tests.py +++ b/openstack_dashboard/test/api_tests/network_tests.py @@ -293,7 +293,7 @@ class NetworkApiNeutronSecurityGroupTests(NetworkApiNeutronTestBase): .AndReturn({'security_groups': secgroups}) self.mox.ReplayAll() - ret = api.network.server_security_groups(self.request, instance_id) + api.network.server_security_groups(self.request, instance_id) def test_server_update_security_groups(self): cur_sg_ids = [self.api_q_secgroups.first()['id']] @@ -306,7 +306,7 @@ class NetworkApiNeutronSecurityGroupTests(NetworkApiNeutronTestBase): body = {'port': {'security_groups': new_sg_ids}} self.qclient.update_port(p['id'], body=body).AndReturn({'port': p}) self.mox.ReplayAll() - ret = api.network.server_update_security_groups( + api.network.server_update_security_groups( self.request, instance_id, new_sg_ids) def test_security_group_backend(self): diff --git a/openstack_dashboard/test/test_data/neutron_data.py b/openstack_dashboard/test/test_data/neutron_data.py index 889837200..cabf6b3fc 100644 --- a/openstack_dashboard/test/test_data/neutron_data.py +++ b/openstack_dashboard/test/test_data/neutron_data.py @@ -193,7 +193,6 @@ def data(TEST): 'network_id': network_dict['id'], 'tenant_id': network_dict['tenant_id']} ext_net = network_dict - ext_subnet = subnet_dict TEST.api_networks.add(network_dict) TEST.api_subnets.add(subnet_dict) diff --git a/tox.ini b/tox.ini index 84a74008c..108cfc5b9 100644 --- a/tox.ini +++ b/tox.ini @@ -38,7 +38,6 @@ exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,p # E128 continuation line under-indented for visual indent # F401 '' imported but unused # F403 'from import *' used; unable to detect undefined names -# F841 local variable '' is assigned to but never used # F999 syntax error in doctest # H201 no 'except:' at least use 'except Exception:' # H302 import only modules.'from optparse import make_option' does not import a module @@ -46,4 +45,4 @@ exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,p # H4xx docstrings # H701 empty localization string # H702 Formatting operation should be outside of localization method call -ignore = E121,E126,E127,E128,F403,F841,F999,H201,H302,H303,H4,H701,H702 +ignore = E121,E126,E127,E128,F403,F999,H201,H302,H303,H4,H701,H702