Update code for new hacking/pep8/flake8 global requirements

A new hacking version was checked in [1] as a part of global
requirements. [1] ignored the rules, this patch enables the
rules again and fixes the code.

[1] https://review.openstack.org/#/c/100137/

Change-Id: If64cce56e9f1e349f05a4c706bfb28b5e557dab0
Closes-Bug: 1338918
This commit is contained in:
Pritesh Kothari
2014-07-08 00:13:15 -07:00
parent 22a413bcd7
commit adae9ecdbc
20 changed files with 104 additions and 87 deletions

View File

@@ -15,6 +15,7 @@
import json
import logging
import six
LOG = logging.getLogger(__name__)
@@ -136,10 +137,8 @@ class ResourceManager(object):
def get_json(response):
"""This method provided backward compatibility with old versions
of requests library
"""Provide backward compatibility with old versions of requests library."""
"""
json_field_or_function = getattr(response, 'json', None)
if callable(json_field_or_function):
return response.json()

View File

@@ -76,15 +76,16 @@ class Client(object):
self.jobs = jobs.JobsManager(self)
self.job_executions = job_executions.JobExecutionsManager(self)
self.job_binaries = job_binaries.JobBinariesManager(self)
self.job_binary_internals =\
self.job_binary_internals = (
job_binary_internals.JobBinaryInternalsManager(self)
)
def get_keystone_client(self, username=None, api_key=None, auth_url=None,
token=None, project_id=None, project_name=None):
if not auth_url:
raise RuntimeError("No auth url specified")
imported_client = keystone_client_v2 if "v2.0" in auth_url\
else keystone_client_v3
imported_client = (keystone_client_v2 if "v2.0" in auth_url
else keystone_client_v3)
if not getattr(self, "keystone_client", None):
self.keystone_client = imported_client.Client(
username=username,

View File

@@ -17,9 +17,10 @@ import argparse
import datetime
import inspect
import json
import sys
from saharaclient.nova import utils
from saharaclient.openstack.common.apiclient import exceptions
import sys
def _print_list_field(field):
@@ -147,7 +148,7 @@ def do_plugin_list(cs, args):
required=True,
help='Name of the plugin.')
# TODO(mattf) - saharaclient does not support query w/ version
#@utils.arg('--version',
# @utils.arg('--version',
# metavar='<version>',
# help='Optional version')
def do_plugin_show(cs, args):
@@ -314,7 +315,7 @@ def do_cluster_show(cs, args):
help='JSON representation of cluster.')
def do_cluster_create(cs, args):
"""Create a cluster."""
# TODO(mattf): improve template validation, e.g. template w/o name key
# TODO(mattf): improve template validation, e.g. template w/o name key
template = json.loads(args.json.read())
# The neutron_management_network parameter to clusters.create is
# called net_id. Therefore, we must translate before invoking
@@ -383,7 +384,7 @@ def do_node_group_template_show(cs, args):
help='JSON representation of node group template.')
def do_node_group_template_create(cs, args):
"""Create a node group template."""
# TODO(mattf): improve template validation, e.g. template w/o name key
# TODO(mattf): improve template validation, e.g. template w/o name key
template = json.loads(args.json.read())
_filter_call_args(template, cs.node_group_templates.create)
@@ -448,7 +449,7 @@ def do_cluster_template_show(cs, args):
help='JSON representation of cluster template.')
def do_cluster_template_create(cs, args):
"""Create a cluster template."""
# TODO(mattf): improve template validation, e.g. template w/o name key
# TODO(mattf): improve template validation, e.g. template w/o name key
template = json.loads(args.json.read())
remap = {'neutron_management_network': 'net_id'}
_filter_call_args(template, cs.cluster_templates.create, remap)
@@ -559,6 +560,8 @@ def do_job_binary_data_list(cs, args):
help='Data to store.')
def do_job_binary_data_create(cs, args):
"""Store data in the internal DB.
Store data in the internal DB.
Use 'swift upload' instead of this command.
Use this command only if Swift is not available.
"""

View File

@@ -17,7 +17,9 @@ from saharaclient.openstack.common import importutils
class UnsupportedVersion(Exception):
"""Indicates that the user is trying to use an unsupported
"""Indication for using an unsupported version of the API.
Indicates that the user is trying to use an unsupported
version of the API.
"""
pass

View File

@@ -15,8 +15,8 @@
# under the License.
import logging
import pkg_resources
import pkg_resources
import six
from saharaclient.nova import utils

View File

@@ -35,7 +35,9 @@ from saharaclient.openstack.common import strutils
def getid(obj):
"""Abstracts the common pattern of allowing both an object or an object's
"""Abstracts the common pattern of allowing an object or ID as parameter.
Abstracts the common pattern of allowing both an object or an object's
ID as a parameter when dealing with relationships.
"""
try:
@@ -45,7 +47,9 @@ def getid(obj):
class Manager(utils.HookableMixin):
"""Managers interact with a particular type of API (servers, flavors,
"""Managers interact with API and provide CRUD operations for them.
Managers interact with a particular type of API (servers, flavors,
images, etc.) and provide CRUD operations for them.
"""
resource_class = None
@@ -79,7 +83,9 @@ class Manager(utils.HookableMixin):
@contextlib.contextmanager
def completion_cache(self, cache_type, obj_class, mode):
"""The completion cache store items that can be used for bash
"""Completion cache store items used for bash autocompletion.
The completion cache store items that can be used for bash
autocompletion, like UUIDs or human-friendly IDs.
A resource listing will clear and repopulate the cache.
@@ -168,8 +174,7 @@ class Manager(utils.HookableMixin):
@six.add_metaclass(abc.ABCMeta)
class ManagerWithFind(Manager):
"""Like a `Manager`, but with additional `find()`/`findall()` methods.
"""
"""Like a `Manager`, but with additional `find()`/`findall()` methods."""
@abc.abstractmethod
def list(self):
@@ -342,8 +347,9 @@ class BootingManagerWithFind(ManagerWithFind):
body["server"]["max_count"] = max_count
if security_groups:
body["server"]["security_groups"] =\
body["server"]["security_groups"] = (
[{'name': sg} for sg in security_groups]
)
# Files are a slight bit tricky. They're passed in a "personality"
# list to the POST. Each item is a dict giving a file name and the
@@ -367,8 +373,9 @@ class BootingManagerWithFind(ManagerWithFind):
# Block device mappings are passed as a list of dictionaries
if block_device_mapping:
body['server']['block_device_mapping'] = \
body['server']['block_device_mapping'] = (
self._parse_block_device_mapping(block_device_mapping)
)
elif block_device_mapping_v2:
# Append the image to the list only if we have new style BDMs
if image:
@@ -402,7 +409,9 @@ class BootingManagerWithFind(ManagerWithFind):
class Resource(object):
"""A resource represents a particular instance of an object (server,
"""A resource represents a particular instance of an object.
A resource represents a particular instance of an object (server,
flavor, etc). This is pretty much just a bag for attributes.
:param manager: Manager object
@@ -430,9 +439,8 @@ class Resource(object):
@property
def human_id(self):
"""Subclasses may override this provide a pretty ID which can be used
for bash completion.
"""
"""Provide a pretty ID which can be used for bash completion."""
if self.NAME_ATTR in self.__dict__ and self.HUMAN_ID:
return strutils.to_slug(getattr(self, self.NAME_ATTR))
return None
@@ -448,7 +456,7 @@ class Resource(object):
def __getattr__(self, k):
if k not in self.__dict__:
#NOTE(bcwaldon): disallow lazy-loading if already loaded once
# NOTE(bcwaldon): disallow lazy-loading if already loaded once
if not self.is_loaded():
self.get()
return self.__getattr__(k)

View File

@@ -13,11 +13,11 @@
import json
import os
import pkg_resources
import sys
import textwrap
import uuid
import pkg_resources
import prettytable
import six
@@ -35,6 +35,7 @@ def arg(*args, **kwargs):
def env(*args, **kwargs):
"""returns the first environment variable set
if none are non-empty, defaults to '' or keyword arg default
"""
for arg in args:
@@ -92,6 +93,7 @@ def add_resource_manager_extra_kwargs_hook(f, hook):
def unauthenticated(f):
"""Adds 'unauthenticated' attribute to decorated function.
Usage:
@unauthenticated
def mymethod(f):
@@ -102,7 +104,9 @@ def unauthenticated(f):
def isunauthenticated(f):
"""Checks to see if the function is marked as not requiring authentication
"""Checks to see if the function is marked as not requiring authentication.
Checks to see if the function is marked as not requiring authentication
with the @unauthenticated decorator. Returns True if decorator is
set to True, False otherwise.
"""
@@ -111,6 +115,7 @@ def isunauthenticated(f):
def service_type(stype):
"""Adds 'service_type' attribute to decorated function.
Usage:
@service_type('volume')
def mymethod(f):
@@ -123,8 +128,7 @@ def service_type(stype):
def get_service_type(f):
"""Retrieves service type from function
"""
"""Retrieves service type from function."""
return getattr(f, 'service_type', None)
@@ -185,7 +189,9 @@ def _flatten(data, prefix=None):
def flatten_dict(data):
"""Return a new dict whose sub-dicts have been merged into the
"""Return a new flattened dict.
Return a new dict whose sub-dicts have been merged into the
original. Each of the parents keys are prepended to the child's
to prevent collisions. Any string elements will be JSON parsed
before flattening.
@@ -269,8 +275,8 @@ def find_resource(manager, name_or_id, **find_args):
kwargs.update(find_args)
return manager.find(**kwargs)
except exceptions.NotFound:
msg = "No %s with a name or ID of '%s' exists." % \
(manager.resource_class.__name__.lower(), name_or_id)
msg = ("No %s with a name or ID of '%s' exists." %
(manager.resource_class.__name__.lower(), name_or_id))
raise exceptions.CommandError(msg)
except exceptions.NoUniqueMatch:
msg = ("Multiple %s matches found for '%s', use an ID to be more"
@@ -308,7 +314,9 @@ def _format_field_name(attr):
def _make_field_formatter(attr, filters=None):
"""Given an object attribute, return a formatted field name and a
"""Return a field name & formatter suitable for passing to print_list.
Given an object attribute, return a formatted field name and a
formatter suitable for passing to print_list.
Optionally pass a dict mapping attribute names to a function. The function

View File

@@ -15,7 +15,7 @@
# under the License.
###
### This code is taken from python-novaclient. Goal is minimal modification.
# This code is taken from python-novaclient. Goal is minimal modification.
###
"""
@@ -136,8 +136,8 @@ class SecretsHelper(object):
def save(self, auth_token, management_url, tenant_id):
if not HAS_KEYRING or not self.args.os_cache:
return
if auth_token == self.auth_token and \
management_url == self.management_url:
if (auth_token == self.auth_token and
management_url == self.management_url):
# Nothing changed....
return
if not all([management_url, auth_token, tenant_id]):
@@ -151,8 +151,9 @@ class SecretsHelper(object):
def password(self):
if self._validate_string(self.args.os_password):
return self.args.os_password
verify_pass = \
verify_pass = (
strutils.bool_from_string(cliutils.env("OS_VERIFY_PASSWORD"))
)
return self._prompt_password(verify_pass)
@property
@@ -214,7 +215,7 @@ class SaharaClientArgumentParser(argparse.ArgumentParser):
exits.
"""
self.print_usage(sys.stderr)
#FIXME(lzyeval): if changes occur in argparse.ArgParser._check_value
# FIXME(lzyeval): if changes occur in argparse.ArgParser._check_value
choose_from = ' (choose from'
progparts = self.prog.partition(' ')
self.exit(2, "error: %(errmsg)s\nTry '%(mainp)s help %(subp)s'"
@@ -355,7 +356,7 @@ class OpenStackSaharaShell(object):
# thinking usage-list --end is ambiguous; but it
# works fine with only --endpoint-type present
# Go figure. I'm leaving this here for doc purposes.
#parser.add_argument('--endpoint_type',
# parser.add_argument('--endpoint_type',
# help=argparse.SUPPRESS)
parser.add_argument('--sahara-api-version',
@@ -470,10 +471,11 @@ class OpenStackSaharaShell(object):
yield name, module
def _add_bash_completion_subparser(self, subparsers):
subparser = \
subparser = (
subparsers.add_parser('bash_completion',
add_help=False,
formatter_class=OpenStackHelpFormatter)
)
self.subcommands['bash_completion'] = subparser
subparser.set_defaults(func=self.do_bash_completion)
@@ -486,12 +488,13 @@ class OpenStackSaharaShell(object):
action_help = desc.strip()
arguments = getattr(callback, 'arguments', [])
subparser = \
subparser = (
subparsers.add_parser(command,
help=action_help,
description=desc,
add_help=False,
formatter_class=OpenStackHelpFormatter)
)
subparser.add_argument('-h', '--help',
action='help',
help=argparse.SUPPRESS,)
@@ -521,8 +524,9 @@ class OpenStackSaharaShell(object):
nova_auth_plugin.discover_auth_systems()
# build available subcommands based on version
self.extensions = \
self.extensions = (
self._discover_extensions(options.sahara_api_version)
)
self._run_extension_hooks('__pre_parse_args__')
# NOTE(dtroyer): Hackery to handle --endpoint_type due to argparse
@@ -533,8 +537,9 @@ class OpenStackSaharaShell(object):
spot = argv.index('--endpoint_type')
argv[spot] = '--endpoint-type'
subcommand_parser = \
subcommand_parser = (
self.get_subcommand_parser(options.sahara_api_version)
)
self.parser = subcommand_parser
if options.help or not argv:
@@ -568,12 +573,11 @@ class OpenStackSaharaShell(object):
# args.os_cacert, args.timeout)
(os_username, os_tenant_name, os_tenant_id,
os_auth_url, os_auth_system, endpoint_type,
service_type, bypass_url, os_cache,
cacert) = \
service_type, bypass_url) = (
(args.os_username, args.os_tenant_name, args.os_tenant_id,
args.os_auth_url, args.os_auth_system, args.endpoint_type,
args.service_type, args.bypass_url, args.os_cache,
args.os_cacert)
args.service_type, args.bypass_url)
)
if os_auth_system and os_auth_system != "keystone":
auth_plugin = nova_auth_plugin.load_plugin(os_auth_system)
@@ -591,7 +595,7 @@ class OpenStackSaharaShell(object):
# NA - there is only one service this CLI accesses
# service_type = utils.get_service_type(args.func) or service_type
#FIXME(usrleon): Here should be restrict for project id same as
# FIXME(usrleon): Here should be restrict for project id same as
# for os_username or os_password but for compatibility it is not.
if not cliutils.isunauthenticated(args.func):
if auth_plugin:
@@ -641,8 +645,8 @@ class OpenStackSaharaShell(object):
# Now check for the password/token of which pieces of the
# identifying keyring key can come from the underlying client
if not cliutils.isunauthenticated(args.func):
# NA - Client can't be used with SecretsHelper
# helper = SecretsHelper(args, self.cs.client)
# NA - Client can't be used with SecretsHelper
# helper = SecretsHelper(args, self.cs.client)
if (auth_plugin and auth_plugin.opts and
"os_password" not in auth_plugin.opts):
use_pw = False
@@ -665,7 +669,7 @@ class OpenStackSaharaShell(object):
# at all, so now switch to password mode and save
# the token when its gotten... using our keyring
# saver
# os_password = helper.password
# os_password = helper.password
os_password = args.os_password
if not os_password:
raise exc.CommandError(
@@ -715,7 +719,9 @@ class OpenStackSaharaShell(object):
extension.run_hooks(hook_type, *args, **kwargs)
def do_bash_completion(self, _args):
"""Prints all of the commands and options to stdout so that the
"""Prints all of the commands to stdout to support bash completion.
Prints all of the commands and options to stdout so that the
sahara.bash_completion script doesn't have to hard code them.
"""
commands = set()

View File

@@ -183,10 +183,10 @@ class ITConfig:
config_files = []
config_path = '%s/saharaclient/tests/integration/configs/%s'
if not os.path.exists(config_path % (os.getcwd(), config)):
message = '\n**************************************************' \
'\nINFO: Configuration file "%s" not found *\n' \
'**************************************************' \
% config
message = ('\n**************************************************'
'\nINFO: Configuration file "%s" not found *\n'
'**************************************************'
% config)
print(message, file=sys.stderr)
else:
config = os.path.join(

View File

@@ -15,9 +15,10 @@
import logging
import shlex
import six
import subprocess
import six
from saharaclient.tests.integration.configs import config as cfg
cfg = cfg.ITConfig()
@@ -27,7 +28,7 @@ LOG = logging.getLogger(__name__)
# This is modeled after the client interface in tempest cli tests.2
class CommandBase(object):
def sahara(self, action, flags='', params='', fail_ok=False):
def sahara(self, action, flags='', params='', fail_ok=False):
return self.cmd_with_bypass('sahara', action, flags, params, fail_ok)
def cmd_with_bypass(self, cmd, action, flags='', params='', fail_ok=False):

View File

@@ -16,13 +16,13 @@
import os
import time
from neutronclient.v2_0 import client as neutron_client
import novaclient.exceptions
from novaclient.v1_1 import client as nova_client
import saharaclient.api.base as api_base
from saharaclient.tests.integration.configs import config as cfg
import saharaclient.tests.integration.tests.base as base
from neutronclient.v2_0 import client as neutron_client
import novaclient.exceptions
from novaclient.v1_1 import client as nova_client
cfg = cfg.ITConfig()
@@ -275,7 +275,7 @@ class ClusterTest(base.ITestBase):
self.teardown_via_client()
raise(e)
# A delay here seems necessary to make sure Oozie is active
time.sleep(common.DELAY_AFTER_ACTIVE*60)
time.sleep(common.DELAY_AFTER_ACTIVE * 60)
return skip_teardown
def teardown_cluster(self):

View File

@@ -14,6 +14,7 @@
# limitations under the License.
import os
import saharaclient.api.base as api_base
from saharaclient.tests.integration.configs import config as cfg
import saharaclient.tests.integration.tests.base as base

View File

@@ -31,7 +31,7 @@ class FullTestDriver(edp.EDPTest, cluster.ClusterTest):
except Exception as e:
# Oops. Teardown via CLI is part of the test,
# but something went wrong early. Try tear down via the client.
#TODO(tmckay): use excutils from openstack/common
# TODO(tmckay): use excutils from openstack/common
import traceback
traceback.print_exc()
if not skip_teardown:

View File

@@ -14,6 +14,7 @@
# limitations under the License.
import os
import testtools
from saharaclient.tests.integration.configs import config as cfg

View File

@@ -14,6 +14,7 @@
# limitations under the License.
import os
import testtools
from saharaclient.tests.integration.configs import config as cfg

View File

@@ -14,6 +14,7 @@
# limitations under the License.
import os
import testtools
from saharaclient.tests.integration.configs import config as cfg

View File

@@ -16,13 +16,15 @@
import json
import random
import re
import six
import string
import tempfile
import time
import six
import saharaclient.api.client as client
from saharaclient.tests.integration.configs import config as cfg
from swiftclient import client as swift_client
cfg = cfg.ITConfig()
@@ -115,8 +117,8 @@ class Utils(object):
def poll_cluster_state(self, id):
cluster = self.client.clusters.get(id)
#TODO(tmckay): this should use timeutils but we need
#to add it to openstack/common
# TODO(tmckay): this should use timeutils but we need
# to add it to openstack/common
timeout = common['CLUSTER_CREATION_TIMEOUT'] * 60
while str(cluster.status) != 'Active':
if str(cluster.status) == 'Error' or timeout <= 0:
@@ -127,8 +129,8 @@ class Utils(object):
return str(cluster.status)
def poll_job_execution(self, id):
#TODO(tmckay): this should use timeutils but we need
#to add it to openstack/common
# TODO(tmckay): this should use timeutils but we need
# to add it to openstack/common
timeout = common['JOB_LAUNCH_TIMEOUT'] * 60
status = self.client.job_executions.get(id).info['status']
while status != 'SUCCEEDED':

View File

@@ -11,15 +11,12 @@
# License for the specific language governing permissions and limitations
# under the License.
#import prettytable
import re
import six
import sys
#from distutils.version import StrictVersion
import fixtures
import mock
import six
from testtools import matchers
import saharaclient.api.client

View File

@@ -36,9 +36,7 @@ class TestCase(testtools.TestCase):
class TestResponse(requests.Response):
"""Class used to wrap requests.Response and provide some
convenience to initialize with a dict
"""
"""Wrap requests.Response and provide a way to initialize with a dict."""
def __init__(self, data):
self._text = None

12
tox.ini
View File

@@ -42,18 +42,6 @@ commands =
python setup.py build_sphinx
[flake8]
# E111 indentation is not a multiple of four
# E112 expected an indented block
# E113 unexpected indentation
# E226 missing whitespace around arithmetic operator
# E241 multiple spaces after ':'
# E265 block comment should start with '# '
# F841 local variable is assigned to but never used
# H305 imports not grouped correctly (re: stdlib, six: third-party)
# H307 like imports should be grouped together (six and oslo.config.cfg from third-party are separated by whitespace)
# H405 multi line docstring summary not separated with an empty line
# H904 Wrap long lines in parentheses instead of a backslash
ignore = E111,E112,E113,E226,E241,E265,F841,H305,H307,H405,H904
show-source = true
builtins = _
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools