Finish up flake8 conversion.

Change-Id: I5034f19d5f9b20ad2b4569455273c730b1efec08
This commit is contained in:
Monty Taylor 2013-04-28 18:00:21 -07:00
parent 76ca57c52d
commit b2ca5cad74
24 changed files with 57 additions and 78 deletions

View File

@ -109,7 +109,7 @@ function run_tests {
function run_pep8 {
echo "Running pep8 ..."
${wrapper} tools/check_source.sh
${wrapper} flake8
}
function run_coverage_start {

View File

@ -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)

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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:

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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,

View File

@ -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)

View File

@ -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()

View File

@ -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 != '/':

View File

@ -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

View File

@ -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")

View File

@ -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))

View File

@ -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'

View File

@ -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'])

View File

@ -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)

View File

@ -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(

View File

@ -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

View File

@ -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.
#

View File

@ -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

View File

@ -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