From b2ca5cad740e56c507664668952d471ecb8ca2f8 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sun, 28 Apr 2013 18:00:21 -0700 Subject: [PATCH] Finish up flake8 conversion. Change-Id: I5034f19d5f9b20ad2b4569455273c730b1efec08 --- run_tests.sh | 2 +- stress/driver.py | 4 ++-- stress/test_floating_ips.py | 4 ++-- stress/test_server_actions.py | 4 ++-- stress/test_servers.py | 4 ++-- tempest/common/glance_http.py | 2 +- tempest/common/ssh.py | 6 ++--- .../identity/v3/json/endpoints_client.py | 6 ++--- .../identity/v3/xml/endpoints_client.py | 6 ++--- .../services/object_storage/object_client.py | 8 +++---- tempest/testboto.py | 5 ++-- tempest/tests/boto/test_s3_objects.py | 6 ++--- tempest/tests/boto/utils/s3.py | 8 +++---- tempest/tests/boto/utils/wait.py | 4 ++-- tempest/tests/compute/test_authorization.py | 6 ++--- tempest/tests/identity/admin/test_users.py | 4 ++-- .../tests/identity/admin/v3/test_endpoints.py | 1 - tempest/tests/network/common.py | 6 +---- .../object_storage/test_object_expiry.py | 4 ++-- .../object_storage/test_object_services.py | 4 ++-- tools/check_source.sh | 24 ------------------- tools/install_venv.py | 2 +- tools/test-requires | 8 +++++-- tox.ini | 7 +++++- 24 files changed, 57 insertions(+), 78 deletions(-) delete mode 100755 tools/check_source.sh diff --git a/run_tests.sh b/run_tests.sh index 6fcdd9069c..56a6e6e568 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -109,7 +109,7 @@ function run_tests { function run_pep8 { echo "Running pep8 ..." - ${wrapper} tools/check_source.sh + ${wrapper} flake8 } function run_coverage_start { diff --git a/stress/driver.py b/stress/driver.py index 96043181e8..533c0005d6 100644 --- a/stress/driver.py +++ b/stress/driver.py @@ -18,7 +18,7 @@ to the bash_openstack function call""" import datetime import random import time -from urlparse import urlparse +import urlparse from config import StressConfig from state import ClusterState @@ -174,7 +174,7 @@ def bash_openstack(manager, keypath = stress_config.host_private_key_path user = stress_config.host_admin_user logdir = stress_config.nova_logdir - host = urlparse(manager.config.identity.uri).hostname + host = urlparse.urlparse(manager.config.identity.uri).hostname computes = _get_compute_nodes(keypath, user, host) stress.utils.execute_on_all(keypath, user, computes, "rm -f %s/*.log" % logdir) diff --git a/stress/test_floating_ips.py b/stress/test_floating_ips.py index 6774e815ff..c5bad9526a 100755 --- a/stress/test_floating_ips.py +++ b/stress/test_floating_ips.py @@ -15,8 +15,8 @@ import random import telnetlib -import pending_action -import test_case +from stress import pending_action +from stress import test_case class TestChangeFloatingIp(test_case.StressTestCase): diff --git a/stress/test_server_actions.py b/stress/test_server_actions.py index f4ddf2379c..3a7094d7f5 100644 --- a/stress/test_server_actions.py +++ b/stress/test_server_actions.py @@ -19,10 +19,10 @@ actions veriy that the API call was successful or not.""" import random -import pending_action +from stress import pending_action +from stress import test_case import stress.utils from tempest.exceptions import Duplicate -import test_case class TestRebootVM(test_case.StressTestCase): diff --git a/stress/test_servers.py b/stress/test_servers.py index 25cbbb07e7..1dd72f1e9b 100644 --- a/stress/test_servers.py +++ b/stress/test_servers.py @@ -19,8 +19,8 @@ actions veriy that the API call was successful or not.""" import random -import pending_action -import test_case +from stress import pending_action +from stress import test_case class TestCreateVM(test_case.StressTestCase): diff --git a/tempest/common/glance_http.py b/tempest/common/glance_http.py index 0902239a21..4ddaf17540 100644 --- a/tempest/common/glance_http.py +++ b/tempest/common/glance_http.py @@ -136,7 +136,7 @@ class HTTPClient(object): # Read body into string if it isn't obviously image data if resp.getheader('content-type', None) != 'application/octet-stream': - body_str = ''.join([chunk for chunk in body_iter]) + body_str = ''.join([body_chunk for body_chunk in body_iter]) body_iter = StringIO.StringIO(body_str) self._log_response(resp, None) else: diff --git a/tempest/common/ssh.py b/tempest/common/ssh.py index 263cf3f15c..448708e37c 100644 --- a/tempest/common/ssh.py +++ b/tempest/common/ssh.py @@ -16,7 +16,7 @@ # under the License. -from cStringIO import StringIO +import cStringIO import select import socket import time @@ -28,7 +28,6 @@ from tempest import exceptions with warnings.catch_warnings(): warnings.simplefilter("ignore") import paramiko - from paramiko import RSAKey class Client(object): @@ -39,7 +38,8 @@ class Client(object): self.username = username self.password = password if isinstance(pkey, basestring): - pkey = RSAKey.from_private_key(StringIO(str(pkey))) + pkey = paramiko.RSAKey.from_private_key( + cStringIO.StringIO(str(pkey))) self.pkey = pkey self.look_for_keys = look_for_keys self.key_filename = key_filename diff --git a/tempest/services/identity/v3/json/endpoints_client.py b/tempest/services/identity/v3/json/endpoints_client.py index 3cb8f90bf5..cf26d0a1e4 100755 --- a/tempest/services/identity/v3/json/endpoints_client.py +++ b/tempest/services/identity/v3/json/endpoints_client.py @@ -16,7 +16,7 @@ # under the License. import json -from urlparse import urlparse +import urlparse from tempest.common.rest_client import RestClient @@ -33,8 +33,8 @@ class EndPointClientJSON(RestClient): def request(self, method, url, headers=None, body=None, wait=None): """Overriding the existing HTTP request in super class rest_client.""" self._set_auth() - self.base_url = self.base_url.replace(urlparse(self.base_url).path, - "/v3") + self.base_url = self.base_url.replace( + urlparse.urlparse(self.base_url).path, "/v3") return super(EndPointClientJSON, self).request(method, url, headers=headers, body=body) diff --git a/tempest/services/identity/v3/xml/endpoints_client.py b/tempest/services/identity/v3/xml/endpoints_client.py index 840097673e..f81fccf297 100755 --- a/tempest/services/identity/v3/xml/endpoints_client.py +++ b/tempest/services/identity/v3/xml/endpoints_client.py @@ -14,7 +14,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from urlparse import urlparse +import urlparse import httplib2 from lxml import etree @@ -52,8 +52,8 @@ class EndPointClientXML(RestClientXML): dscv = self.config.identity.disable_ssl_certificate_validation self.http_obj = httplib2.Http(disable_ssl_certificate_validation=dscv) self._set_auth() - self.base_url = self.base_url.replace(urlparse(self.base_url).path, - "/v3") + self.base_url = self.base_url.replace( + urlparse.urlparse(self.base_url).path, "/v3") return super(EndPointClientXML, self).request(method, url, headers=headers, body=body) diff --git a/tempest/services/object_storage/object_client.py b/tempest/services/object_storage/object_client.py index 9626b6bf95..69df472e51 100644 --- a/tempest/services/object_storage/object_client.py +++ b/tempest/services/object_storage/object_client.py @@ -15,10 +15,10 @@ # License for the specific language governing permissions and limitations # under the License. -from hashlib import sha1 +import hashlib import hmac import httplib2 -from urlparse import urlparse +import urlparse from tempest.common.rest_client import RestClient from tempest import exceptions @@ -127,10 +127,10 @@ class ObjectClient(RestClient): self._set_auth() method = 'GET' - path = "%s/%s/%s" % (urlparse(self.base_url).path, container, + path = "%s/%s/%s" % (urlparse.urlparse(self.base_url).path, container, object_name) hmac_body = '%s\n%s\n%s' % (method, expires, path) - sig = hmac.new(key, hmac_body, sha1).hexdigest() + sig = hmac.new(key, hmac_body, hashlib.sha1).hexdigest() url = "%s/%s?temp_url_sig=%s&temp_url_expires=%s" % (container, object_name, diff --git a/tempest/testboto.py b/tempest/testboto.py index 8b819d980e..9e652cb843 100644 --- a/tempest/testboto.py +++ b/tempest/testboto.py @@ -15,7 +15,7 @@ # License for the specific language governing permissions and limitations # under the License. -from contextlib import closing +import contextlib import logging import os import re @@ -413,7 +413,8 @@ class BotoTestCase(tempest.test.BaseTestCase): """Destroys the bucket and its content, just for teardown.""" exc_num = 0 try: - with closing(boto.connect_s3(**connection_data)) as conn: + with contextlib.closing( + boto.connect_s3(**connection_data)) as conn: if isinstance(bucket, basestring): bucket = conn.lookup(bucket) assert isinstance(bucket, s3.bucket.Bucket) diff --git a/tempest/tests/boto/test_s3_objects.py b/tempest/tests/boto/test_s3_objects.py index dcb7c86559..9d4d79cfb6 100644 --- a/tempest/tests/boto/test_s3_objects.py +++ b/tempest/tests/boto/test_s3_objects.py @@ -15,9 +15,9 @@ # License for the specific language governing permissions and limitations # under the License. -from contextlib import closing +import contextlib -from boto.s3.key import Key +import boto.s3.key from tempest import clients from tempest.common.utils.data_utils import rand_name @@ -46,7 +46,7 @@ class S3BucketsTest(BotoTestCase): bucket_name) self.assertTrue(bucket.name == bucket_name) - with closing(Key(bucket)) as key: + with contextlib.closing(boto.s3.key.Key(bucket)) as key: key.key = object_name key.set_contents_from_string(content) readback = key.get_contents_as_string() diff --git a/tempest/tests/boto/utils/s3.py b/tempest/tests/boto/utils/s3.py index 4c3229b4e5..ea9869b37e 100644 --- a/tempest/tests/boto/utils/s3.py +++ b/tempest/tests/boto/utils/s3.py @@ -15,24 +15,24 @@ # License for the specific language governing permissions and limitations # under the License. -from contextlib import closing +import contextlib import logging import os import re import boto -from boto.s3.key import Key +import boto.s3.key LOG = logging.getLogger(__name__) def s3_upload_dir(bucket, path, prefix="", connection_data=None): if isinstance(bucket, basestring): - with closing(boto.connect_s3(**connection_data)) as conn: + with contextlib.closing(boto.connect_s3(**connection_data)) as conn: bucket = conn.lookup(bucket) for root, dirs, files in os.walk(path): for fil in files: - with closing(Key(bucket)) as key: + with contextlib.closing(boto.s3.key.Key(bucket)) as key: source = root + os.sep + fil target = re.sub("^" + re.escape(path) + "?/", prefix, source) if os.sep != '/': diff --git a/tempest/tests/boto/utils/wait.py b/tempest/tests/boto/utils/wait.py index c2d4ea3734..6cd17a9f11 100644 --- a/tempest/tests/boto/utils/wait.py +++ b/tempest/tests/boto/utils/wait.py @@ -19,7 +19,7 @@ import logging import re import time -from boto.exception import BotoServerError +import boto.exception from testtools import TestCase import tempest.config @@ -87,7 +87,7 @@ def wait_no_exception(lfunction, exc_class=None, exc_matcher=None): """Stops waiting on success.""" start_time = time.time() if exc_matcher is not None: - exc_class = BotoServerError + exc_class = boto.exception.BotoServerError if exc_class is None: exc_class = BaseException diff --git a/tempest/tests/compute/test_authorization.py b/tempest/tests/compute/test_authorization.py index 91cf39fd5d..6edc94669f 100644 --- a/tempest/tests/compute/test_authorization.py +++ b/tempest/tests/compute/test_authorization.py @@ -234,8 +234,7 @@ class AuthorizationTestJSON(base.BaseComputeTest): # Reset the base_url... self.alt_security_client.base_url = self.saved_base_url if resp['status'] is not None: - #TODO(afazekas): body not defined - self.alt_security_client.delete_security_group(body['id']) + self.alt_security_client.delete_security_group(resp['id']) self.fail("Create Security Group request should not happen if" "the tenant id does not match the current user") @@ -274,8 +273,7 @@ class AuthorizationTestJSON(base.BaseComputeTest): # Reset the base_url... self.alt_security_client.base_url = self.saved_base_url if resp['status'] is not None: - self.alt_security_client.delete_security_group_rule( - body['id']) # BUG + self.alt_security_client.delete_security_group_rule(resp['id']) self.fail("Create security group rule request should not " "happen if the tenant id does not match the" " current user") diff --git a/tempest/tests/identity/admin/test_users.py b/tempest/tests/identity/admin/test_users.py index 0573b2189c..f9772ac47e 100644 --- a/tempest/tests/identity/admin/test_users.py +++ b/tempest/tests/identity/admin/test_users.py @@ -309,8 +309,8 @@ class UsersTestJSON(base.BaseIdentityAdminTest): for i in body: fetched_user_ids.append(i['id']) #verifying the user Id in the list - missing_users =\ - [user for user in user_ids if user not in fetched_user_ids] + missing_users = [missing_user for missing_user in user_ids + if missing_user not in fetched_user_ids] self.assertEqual(0, len(missing_users), "Failed to find user %s in fetched list" % ', '.join(m_user for m_user in missing_users)) diff --git a/tempest/tests/identity/admin/v3/test_endpoints.py b/tempest/tests/identity/admin/v3/test_endpoints.py index 98fab5784a..3ad9b289a1 100755 --- a/tempest/tests/identity/admin/v3/test_endpoints.py +++ b/tempest/tests/identity/admin/v3/test_endpoints.py @@ -126,7 +126,6 @@ class EndPointsTestJSON(base.BaseIdentityAdminTest): description=s_description) self.service_ids.append(self.service2['id']) #Updating endpoint with new values - service_id = self.service2['id'] region2 = rand_name('region') url2 = rand_name('url') interface2 = 'internal' diff --git a/tempest/tests/network/common.py b/tempest/tests/network/common.py index 8c8d518dd7..6246f545fd 100644 --- a/tempest/tests/network/common.py +++ b/tempest/tests/network/common.py @@ -125,7 +125,6 @@ class TestNetworkSmokeCommon(test.DefaultClientSmokeTest): @classmethod def setUpClass(cls): super(TestNetworkSmokeCommon, cls).setUpClass() - cfg = cls.config.network cls.tenant_id = cls.manager._get_identity_client( cls.config.identity.username, cls.config.identity.password, @@ -246,10 +245,7 @@ class TestNetworkSmokeCommon(test.DefaultClientSmokeTest): port=dict(name=name, network_id=network.id, tenant_id=network.tenant_id)) - try: - result = self.network_client.create_port(body=body) - except Exception as e: - raise + result = self.network_client.create_port(body=body) self.assertIsNotNone(result, 'Unable to allocate port') port = DeletablePort(client=self.network_client, **result['port']) diff --git a/tempest/tests/object_storage/test_object_expiry.py b/tempest/tests/object_storage/test_object_expiry.py index c12ec3dd7b..e1b1dbd984 100644 --- a/tempest/tests/object_storage/test_object_expiry.py +++ b/tempest/tests/object_storage/test_object_expiry.py @@ -21,7 +21,7 @@ from tempest import exceptions from tempest.test import attr from tempest.tests.object_storage import base import testtools -from time import sleep +import time class ObjectExpiryTest(base.BaseObjectTest): @@ -88,7 +88,7 @@ class ObjectExpiryTest(base.BaseObjectTest): # Check data self.assertEqual(body, data) # Sleep for over 5 seconds, so that object is expired - sleep(5) + time.sleep(5) # Verification of raised exception after object gets expired self.assertRaises(exceptions.NotFound, self.object_client.get_object, self.container_name, object_name) diff --git a/tempest/tests/object_storage/test_object_services.py b/tempest/tests/object_storage/test_object_services.py index 1edce92c2c..4fcc6174b1 100644 --- a/tempest/tests/object_storage/test_object_services.py +++ b/tempest/tests/object_storage/test_object_services.py @@ -21,7 +21,7 @@ from tempest import exceptions from tempest.test import attr from tempest.tests.object_storage import base import testtools -from time import time +import time class ObjectTest(base.BaseObjectTest): @@ -617,7 +617,7 @@ class ObjectTest(base.BaseObjectTest): self.object_client.create_object(self.container_name, object_name, data) - expires = int(time() + 10) + expires = int(time.time() + 10) #Trying to GET object using temp URL with in expiry time _, body = self.object_client.get_object_using_temp_url( diff --git a/tools/check_source.sh b/tools/check_source.sh deleted file mode 100755 index 01724fa3f0..0000000000 --- a/tools/check_source.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -flake8 --ignore=E125,H302,H304,H404,F --show-source --exclude=.git,.venv,.tox,dist,doc,openstack,*egg . -pep8_ret=$? - -pyflakes tempest stress setup.py tools cli bin | grep "imported but unused" -unused_ret=$? - -ret=0 -if [ $pep8_ret != 0 ]; then - echo "hacking.py/pep8 test FAILED!" >&2 - (( ret += 1 )) -else - echo "hacking.py/pep8 test OK!" >&2 -fi - -if [ $unused_ret == 0 ]; then - echo "Unused import test FAILED!" >&2 - (( ret += 2 )) -else - echo "Unused import test OK!" >&2 -fi - -exit $ret diff --git a/tools/install_venv.py b/tools/install_venv.py index ef7b0a8fc8..5d4b290db9 100644 --- a/tools/install_venv.py +++ b/tools/install_venv.py @@ -3,7 +3,7 @@ # Copyright 2010 United States Government as represented by the # Administrator of the National Aeronautics and Space Administration. # All Rights Reserved. -# +# flake8: noqa # Copyright 2010 OpenStack, LLC # Copyright 2013 IBM Corp. # diff --git a/tools/test-requires b/tools/test-requires index 3d4c2d6331..cba42a4c41 100644 --- a/tools/test-requires +++ b/tools/test-requires @@ -1,4 +1,8 @@ -flake8 -hacking +# Install bounded pep8/pyflakes first, then let flake8 install +pep8==1.4.5 +pyflakes==0.7.2 +flake8==2.0 +hacking>=0.5.3,<0.6 +# #TODO(afazekas): ensure pg_config installed psycopg2 diff --git a/tox.ini b/tox.ini index 85a0d86374..4a2f80e872 100644 --- a/tox.ini +++ b/tox.ini @@ -19,4 +19,9 @@ commands = python -m tools/tempest_coverage -c start --combine python -m tools/tempest_coverage -c report --html [testenv:pep8] -commands = bash tools/check_source.sh +commands = flake8 + +[flake8] +ignore = E125,H302,H404 +show-source = True +exclude = .git,.venv,.tox,dist,doc,openstack,*egg