From 900b6606184c9054b441c3bbec56cf3559e712e5 Mon Sep 17 00:00:00 2001 From: vponomaryov Date: Mon, 7 Jul 2014 17:28:58 +0300 Subject: [PATCH] Fix and enable E12 pep8 rule (indentation issues) Change-Id: I500d2cacba09f2a4337ff325ae658f61b64e4b7a Related-Bug: #1333290 --- manilaclient/shell.py | 22 ++++++++-------- manilaclient/utils.py | 7 ++--- tests/test_service_catalog.py | 4 +-- tests/test_shell.py | 2 +- tests/v1/fakes.py | 13 ++++----- tests/v1/test_auth.py | 6 ++--- tests/v1/test_security_services.py | 13 ++++----- tests/v1/test_share_networks.py | 2 +- tests/v1/test_shell.py | 42 +++++++++++++++++++----------- tools/install_venv.py | 10 ++++--- tox.ini | 2 +- 11 files changed, 68 insertions(+), 55 deletions(-) diff --git a/manilaclient/shell.py b/manilaclient/shell.py index 18531ffdf..7d40e1f50 100644 --- a/manilaclient/shell.py +++ b/manilaclient/shell.py @@ -148,7 +148,7 @@ class SecretsHelper(object): tenant_id. """ if (auth_token == self.auth_token and - management_url == self.management_url): + management_url == self.management_url): # Nothing changed.... return if not all([management_url, auth_token, tenant_id]): @@ -166,8 +166,8 @@ class SecretsHelper(object): self.keyring.delete_password(args) def save_password(self): - self.keyring.set_password('openstack', - self.args.os_username, self.password) + self.keyring.set_password('openstack', self.args.os_username, + self.password) def check_cached_password(self): """Check if os_password is equal to cached password.""" @@ -214,7 +214,7 @@ class SecretsHelper(object): return None management_url = None block = self.keyring.get_password('manilaclient_auth', - self._make_key()) + self._make_key()) if block: _token, management_url, _tenant_id = block.split('|', 2) return management_url @@ -230,7 +230,7 @@ class SecretsHelper(object): return None token = None block = self.keyring.get_password('manilaclient_auth', - self._make_key()) + self._make_key()) if block: token, _management_url, _tenant_id = block.split('|', 2) return token @@ -246,7 +246,7 @@ class SecretsHelper(object): return None tenant_id = None block = self.keyring.get_password('manilaclient_auth', - self._make_key()) + self._make_key()) if block: _token, _management_url, tenant_id = block.split('|', 2) return tenant_id @@ -536,11 +536,11 @@ class OpenStackManilaShell(object): os_region_name, os_tenant_id, endpoint_type, insecure, service_type, service_name, share_service_name, cacert, os_cache, os_reset_cache) = ( - args.os_username, args.os_password, args.os_tenant_name, - args.os_auth_url, args.os_region_name, args.os_tenant_id, - args.endpoint_type, args.insecure, args.service_type, - args.service_name, args.share_service_name, - args.os_cacert, args.os_cache, args.os_reset_cache) + args.os_username, args.os_password, args.os_tenant_name, + args.os_auth_url, args.os_region_name, args.os_tenant_id, + args.endpoint_type, args.insecure, args.service_type, + args.service_name, args.share_service_name, + args.os_cacert, args.os_cache, args.os_reset_cache) if not endpoint_type: endpoint_type = DEFAULT_MANILA_ENDPOINT_TYPE diff --git a/manilaclient/utils.py b/manilaclient/utils.py index 2dfd900e7..ec629cc94 100644 --- a/manilaclient/utils.py +++ b/manilaclient/utils.py @@ -73,11 +73,8 @@ def get_resource_manager_extra_kwargs(f, args, allow_conflicts=False): conflicting_keys = set(list(hook_kwargs)) & set(list(extra_kwargs)) if conflicting_keys and not allow_conflicts: - msg = ("Hook '%(hook_name)s' is attempting to redefine attributes " - "'%(conflicting_keys)s'" % { - 'hook_name': hook_name, - 'conflicting_keys': conflicting_keys, - }) + msg = ("Hook '%s' is attempting to redefine " + "attributes '%s'" % (hook_name, conflicting_keys)) raise Exception(msg) extra_kwargs.update(hook_kwargs) diff --git a/tests/test_service_catalog.py b/tests/test_service_catalog.py index f064eecd5..03103b813 100644 --- a/tests/test_service_catalog.py +++ b/tests/test_service_catalog.py @@ -106,9 +106,9 @@ class ServiceCatalogTest(utils.TestCase): self.assertRaises(exceptions.AmbiguousEndpoints, sc.url_for, service_type='compute') self.assertEqual(sc.url_for('tenantId', '1', service_type='compute'), - "https://compute1.host/v1/1234") + "https://compute1.host/v1/1234") self.assertEqual(sc.url_for('tenantId', '2', service_type='compute'), - "https://compute1.host/v1/3456") + "https://compute1.host/v1/3456") self.assertRaises(exceptions.EndpointNotFound, sc.url_for, "region", "South", service_type='compute') diff --git a/tests/test_shell.py b/tests/test_shell.py index c1090be5f..40cf06472 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -50,7 +50,7 @@ class ShellTest(utils.TestCase): '.*?^usage: ', '.*?^\s+create\s+Creates new NAS storage \(NFS or CIFS\).', '.*?(?m)^See "manila help COMMAND" for help ' - 'on a specific command.', + 'on a specific command.', ] help_text = self.shell('help') for r in required: diff --git a/tests/v1/fakes.py b/tests/v1/fakes.py index facc5522e..310fc0fdb 100644 --- a/tests/v1/fakes.py +++ b/tests/v1/fakes.py @@ -123,12 +123,13 @@ class FakeHTTPClient(fakes.FakeHTTPClient): return (200, {}, share_nw) def get_share_networks_detail(self, **kw): - share_nw = {'share_networks': [{'id': 1234, - 'name': 'fake_share_nw'}, - {'id': 4321, - 'name': 'duplicated_name'}, - {'id': 4322, - 'name': 'duplicated_name'}]} + share_nw = { + 'share_networks': [ + {'id': 1234, 'name': 'fake_share_nw'}, + {'id': 4321, 'name': 'duplicated_name'}, + {'id': 4322, 'name': 'duplicated_name'}, + ] + } return (200, {}, share_nw) def get_security_services(self, **kw): diff --git a/tests/v1/test_auth.py b/tests/v1/test_auth.py index 752d5ee9d..4417afa78 100644 --- a/tests/v1/test_auth.py +++ b/tests/v1/test_auth.py @@ -35,7 +35,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase): "id": "FAKE_ID", "tenant": { "id": "FAKE_TENANT_ID" - }, + }, }, "serviceCatalog": [ { @@ -195,7 +195,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase): "id": "FAKE_ID", "tenant": { "id": "FAKE_TENANT_ID" - }, + }, }, "serviceCatalog": [ { @@ -282,7 +282,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase): "id": "FAKE_ID", "tenant": { "id": "FAKE_TENANT_ID" - }, + }, }, "serviceCatalog": [ { diff --git a/tests/v1/test_security_services.py b/tests/v1/test_security_services.py index 28f4b539d..766592ce4 100644 --- a/tests/v1/test_security_services.py +++ b/tests/v1/test_security_services.py @@ -114,12 +114,13 @@ class SecurityServiceTest(utils.TestCase): def test_update(self): security_service = 'fake service' - values = {'dns_ip': 'new dns ip', - 'server': 'new.ldap.server', - 'domain': 'new.ldap.domain', - 'sid': 'new sid', - 'password': 'fake password', - } + values = { + 'dns_ip': 'new dns ip', + 'server': 'new.ldap.server', + 'domain': 'new.ldap.domain', + 'sid': 'new sid', + 'password': 'fake password', + } with mock.patch.object(self.manager, '_update', fakes.fake_update): result = self.manager.update(security_service, **values) diff --git a/tests/v1/test_share_networks.py b/tests/v1/test_share_networks.py index 37cbc1c90..01cecbcde 100644 --- a/tests/v1/test_share_networks.py +++ b/tests/v1/test_share_networks.py @@ -91,7 +91,7 @@ class ShareNetworkTest(utils.TestCase): def test_list_with_filters(self): filters = OrderedDict([('all_tenants', 1), ('status', 'ERROR')]) expected_path = share_networks.RESOURCES_PATH + '/detail' + \ - '?all_tenants=1&status=ERROR' + '?all_tenants=1&status=ERROR' with mock.patch.object(self.manager, '_list', mock.Mock(return_value=None)): diff --git a/tests/v1/test_shell.py b/tests/v1/test_shell.py index 76d9e818e..c0617a94a 100644 --- a/tests/v1/test_shell.py +++ b/tests/v1/test_shell.py @@ -214,12 +214,18 @@ class ShellTest(utils.TestCase): self.assert_called('GET', '/security-services?share_network_id=1234') def test_share_network_security_service_list_by_name_not_found(self): - self.assertRaises(exceptions.CommandError, self.run_command, - 'share-network-security-service-list inexistent_share_nw') + self.assertRaises( + exceptions.CommandError, + self.run_command, + 'share-network-security-service-list inexistent_share_nw', + ) def test_share_network_security_service_list_by_name_multiple(self): - self.assertRaises(exceptions.CommandError, self.run_command, - 'share-network-security-service-list duplicated_name') + self.assertRaises( + exceptions.CommandError, + self.run_command, + 'share-network-security-service-list duplicated_name', + ) def test_share_network_security_service_list_by_id(self): self.run_command('share-network-security-service-list 1111') @@ -371,17 +377,17 @@ class ShellTest(utils.TestCase): return utils.TestResponse({ "status_code": 200, "text": jsonutils.dumps(resp_text), - }) + }) elif url == 'fake/shares/detail': resp_text = {"unauthorized": {"message": "Unauthorized", "code": "401"}} return utils.TestResponse({ "status_code": 401, "text": jsonutils.dumps(resp_text), - }) + }) else: headers = { - 'x-server-management-url': 'new_url', + 'x-server-management-url': 'new_url', 'x-auth-token': 'new_token', } resp_text = 'some_text' @@ -389,7 +395,7 @@ class ShellTest(utils.TestCase): "status_code": 200, "text": jsonutils.dumps(resp_text), "headers": headers - }) + }) client.get_client_class = lambda *_: client_v1.Client shell.SecretsHelper.tenant_id = \ @@ -405,8 +411,12 @@ class ShellTest(utils.TestCase): 'User-Agent': 'python-manilaclient', 'Accept': 'application/json', 'X-Auth-Token': 'new_token'} - requests.request.assert_called_with('GET', 'new_url/shares/detail', - headers=expected_headers, verify=True) + requests.request.assert_called_with( + 'GET', + 'new_url/shares/detail', + headers=expected_headers, + verify=True, + ) class SecretsHelperTestCase(utils.TestCase): @@ -455,9 +465,11 @@ class SecretsHelperTestCase(utils.TestCase): expected_key = 'http://111.11.11.11:5000/user/project/region/' \ 'publicURL/share/fake/fake' self.helper.save('fake_token', 'fake_url', 'fake_tenant_id') - shell.ManilaKeyring.set_password. \ - assert_called_once_with('manilaclient_auth', - expected_key, 'fake_token|fake_url|fake_tenant_id') + shell.ManilaKeyring.set_password.assert_called_once_with( + 'manilaclient_auth', + expected_key, + 'fake_token|fake_url|fake_tenant_id', + ) def test_save_params_already_cached(self): self.helper.save('fake_token', 'fake_url', 'fake_tenant_id') @@ -490,8 +502,8 @@ class SecretsHelperTestCase(utils.TestCase): self.assertEqual(self.helper.management_url, 'fake_url') expected_key = 'http://111.11.11.11:5000/user/project/region/' \ 'publicURL/share/fake/fake' - shell.ManilaKeyring.get_password. \ - assert_called_once_with('manilaclient_auth', expected_key) + shell.ManilaKeyring.get_password.assert_called_once_with( + 'manilaclient_auth', expected_key) def test_auth_token_os_cache_false(self): self.args.os_cache = False diff --git a/tools/install_venv.py b/tools/install_venv.py index 269b4a843..dc28089aa 100644 --- a/tools/install_venv.py +++ b/tools/install_venv.py @@ -195,8 +195,8 @@ def install_dependencies(venv=VENV): pip_install('-r', PIP_REQUIRES) pip_install('-r', TEST_REQUIRES) # Tell the virtual env how to "import manila" - pthfile = os.path.join(venv, "lib", PY_VERSION, "site-packages", - "manilaclient.pth") + pthfile = os.path.join( + venv, "lib", PY_VERSION, "site-packages", "manilaclient.pth") f = open(pthfile, 'w') f.write("%s\n" % ROOT) @@ -230,9 +230,11 @@ def print_help(): def parse_args(): """Parse command-line arguments.""" parser = optparse.OptionParser() - parser.add_option("-n", "--no-site-packages", dest="no_site_packages", + parser.add_option( + "-n", "--no-site-packages", dest="no_site_packages", default=False, action="store_true", - help="Do not inherit packages from global Python install") + help="Do not inherit packages from global Python install", + ) return parser.parse_args() diff --git a/tox.ini b/tox.ini index 2eaf3f411..d3fbed5b5 100644 --- a/tox.ini +++ b/tox.ini @@ -28,6 +28,6 @@ commands = python setup.py testr --coverage --testr-args='{posargs}' downloadcache = ~/cache/pip [flake8] -ignore = E12,H102,F811,F821 +ignore = H102,F811,F821 builtins = _ exclude = .venv,.tox,dist,doc,openstack,*egg