Further pep8 fixes

Fix the following issues in some files:
F401 'XXX' imported but unused
E123 closing bracket does not match indentation of opening bracket's
line
E126 continuation line over-indented for hanging indent
E128 continuation line under-indented for visual indent
E129 visually indented line with same indent as next logical line
H904  Wrap long lines in parentheses instead of a backslash

Partial-Bug: #1333290
Change-Id: Ic9b3a1e47fd24d2835f35f2ef71c4519908ff049
This commit is contained in:
Andreas Jaeger 2014-08-15 10:09:28 +02:00
parent fa24580fcf
commit baad6f7894
13 changed files with 89 additions and 103 deletions

View File

@ -1,17 +1,17 @@
# Copyright 2014 Mirantis Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import oslo.config.cfg

View File

@ -19,7 +19,6 @@ Handles all requests to Nova.
import sys
from novaclient import exceptions as nova_exception
from novaclient import extension
from novaclient import service_catalog
from novaclient.v1_1 import client as nova_client
from novaclient.v1_1.contrib import assisted_volume_snapshots
@ -51,16 +50,16 @@ nova_opts = [
default=False,
help='Allow to perform insecure SSL requests to nova'),
cfg.StrOpt('nova_admin_username',
default='nova',
help='Nova admin username'),
default='nova',
help='Nova admin username'),
cfg.StrOpt('nova_admin_password',
help='Nova admin password'),
cfg.StrOpt('nova_admin_tenant_name',
default='service',
help='Nova admin tenant name'),
default='service',
help='Nova admin tenant name'),
cfg.StrOpt('nova_admin_auth_url',
default='http://localhost:5000/v2.0',
help='Identity service url'),
default='http://localhost:5000/v2.0',
help='Identity service url'),
]
CONF = cfg.CONF
@ -163,14 +162,14 @@ class API(base.Base):
availability_zone=None, instance_count=1,
admin_pass=None):
return _untranslate_server_summary_view(
novaclient(context).servers.create(
name, image, flavor, userdata=user_data,
security_groups=security_groups, key_name=key_name,
block_device_mapping=block_device_mapping,
block_device_mapping_v2=block_device_mapping_v2,
nics=nics, availability_zone=availability_zone,
min_count=instance_count, admin_pass=admin_pass)
)
novaclient(context).servers.create(
name, image, flavor, userdata=user_data,
security_groups=security_groups, key_name=key_name,
block_device_mapping=block_device_mapping,
block_device_mapping_v2=block_device_mapping_v2,
nics=nics, availability_zone=availability_zone,
min_count=instance_count, admin_pass=admin_pass)
)
def server_delete(self, context, instance):
novaclient(context).servers.delete(instance)
@ -178,8 +177,8 @@ class API(base.Base):
@translate_server_exception
def server_get(self, context, instance_id):
return _untranslate_server_summary_view(
novaclient(context).servers.get(instance_id)
)
novaclient(context).servers.get(instance_id)
)
def server_list(self, context, search_opts=None, all_tenants=False):
if search_opts is None:
@ -189,7 +188,8 @@ class API(base.Base):
else:
search_opts['project_id'] = context.project_id
servers = [_untranslate_server_summary_view(s)
for s in novaclient(context).servers.list(True, search_opts)]
for s in novaclient(context).servers.list(True,
search_opts)]
return servers
@ -219,9 +219,9 @@ class API(base.Base):
@translate_server_exception
def server_rebuild(self, context, instance_id, image_id, password=None):
return _untranslate_server_summary_view(
novaclient(context).servers.rebuild(instance_id, image_id,
password)
)
novaclient(context).servers.rebuild(instance_id, image_id,
password)
)
@translate_server_exception
def instance_volume_attach(self, context, instance_id, volume_id,
@ -235,7 +235,7 @@ class API(base.Base):
@translate_server_exception
def instance_volume_detach(self, context, instance_id, att_id):
return novaclient(context).volumes.delete_server_volume(instance_id,
att_id)
att_id)
@translate_server_exception
def instance_volumes_list(self, context, instance_id):
@ -252,8 +252,8 @@ class API(base.Base):
@translate_server_exception
def server_update(self, context, instance_id, name):
return _untranslate_server_summary_view(
novaclient(context).servers.update(instance_id, name=name)
)
novaclient(context).servers.update(instance_id, name=name)
)
def update_server_volume(self, context, instance_id, attachment_id,
new_volume_id):

View File

@ -52,7 +52,6 @@ This module provides Manager, a base class for managers.
"""
from oslo.config import cfg
from oslo import messaging
import six
from manila.db import base

View File

@ -394,8 +394,8 @@ class IpNetnsCommand(IpCommandBase):
if addl_env:
env_params = (['env'] +
['%s=%s' % pair for pair in addl_env.items()])
total_cmd = ['ip', 'netns', 'exec', self._parent.namespace] + \
env_params + list(cmds)
total_cmd = (['ip', 'netns', 'exec', self._parent.namespace] +
env_params + list(cmds))
return utils.execute(*total_cmd, run_as_root=True,
check_exit_code=check_exit_code)

View File

@ -69,9 +69,9 @@ neutron_opts = [
deprecated_name='quantum_ovs_bridge',
help='Name of Integration Bridge used by Open vSwitch'),
cfg.StrOpt('neutron_ca_certificates_file',
help='Location of ca certificates file to use for '
'neutron client requests.'),
]
help='Location of ca certificates file to use for '
'neutron client requests.'),
]
CONF = cfg.CONF
CONF.register_opts(neutron_opts)
@ -208,8 +208,8 @@ class API(base.Base):
network_req_body['network']['tenant_id'] = tenant_id
network_req_body['network']['name'] = name
try:
return self.client.create_network(network_req_body).\
get('network', {})
return self.client.create_network(
network_req_body).get('network', {})
except neutron_client_exc.NeutronClientException as e:
raise exception.NetworkException(code=e.status_code,
message=e.message)
@ -222,8 +222,8 @@ class API(base.Base):
subnet_req_body['subnet']['cidr'] = cidr
subnet_req_body['subnet']['ip_version'] = 4
try:
return self.client.create_subnet(subnet_req_body).\
get('subnet', {})
return self.client.create_subnet(
subnet_req_body).get('subnet', {})
except neutron_client_exc.NeutronClientException as e:
raise exception.NetworkException(code=e.status_code,
message=e.message)
@ -262,8 +262,8 @@ class API(base.Base):
def update_port_fixed_ips(self, port_id, fixed_ips):
try:
port_req_body = {'port': fixed_ips}
port = self.client.update_port(port_id, port_req_body).\
get('port', {})
port = self.client.update_port(
port_id, port_req_body).get('port', {})
return port
except neutron_client_exc.NeutronClientException as e:
raise exception.NetworkException(code=e.status_code,
@ -279,8 +279,8 @@ class API(base.Base):
def router_update_routes(self, router_id, routes):
try:
router_req_body = {'router': routes}
port = self.client.update_router(router_id, router_req_body).\
get('router', {})
port = self.client.update_router(
router_id, router_req_body).get('router', {})
return port
except neutron_client_exc.NeutronClientException as e:
raise exception.NetworkException(code=e.status_code,
@ -290,8 +290,8 @@ class API(base.Base):
"""Update specific subnet for client."""
subnet_req_body = {'subnet': {'name': name}}
try:
return self.client.update_subnet(subnet_uuid, subnet_req_body).\
get('subnet', {})
return self.client.update_subnet(
subnet_uuid, subnet_req_body).get('subnet', {})
except neutron_client_exc.NeutronClientException as e:
raise exception.NetworkException(code=e.status_code,
message=e.message)

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import time
from oslo.config import cfg
from manila.common import constants
@ -99,9 +97,8 @@ class NeutronNetworkPlugin(manila_network.NetworkBaseAPI, db_base.Base):
try:
self.neutron_api.delete_port(port['id'])
except exception.NetworkException:
self.db.network_allocation_update(context,
port['id'],
{'status': constants.STATUS_ERROR})
self.db.network_allocation_update(
context, port['id'], {'status': constants.STATUS_ERROR})
raise
else:
self.db.network_allocation_delete(context, port['id'])
@ -112,12 +109,12 @@ class NeutronNetworkPlugin(manila_network.NetworkBaseAPI, db_base.Base):
def _save_neutron_network_data(self, context, share_network):
net_info = self.neutron_api.get_network(
share_network['neutron_net_id'])
share_network['neutron_net_id'])
provider_nw_dict = {
'network_type': net_info['provider:network_type'],
'segmentation_id': net_info['provider:segmentation_id']
}
}
self.db.share_network_update(context,
share_network['id'],
@ -125,12 +122,12 @@ class NeutronNetworkPlugin(manila_network.NetworkBaseAPI, db_base.Base):
def _save_neutron_subnet_data(self, context, share_network):
subnet_info = self.neutron_api.get_subnet(
share_network['neutron_subnet_id'])
share_network['neutron_subnet_id'])
subnet_values = {
'cidr': subnet_info['cidr'],
'ip_version': subnet_info['ip_version']
}
}
self.db.share_network_update(context,
share_network['id'],

View File

@ -142,8 +142,9 @@ class DbQuotaDriver(object):
if not defaults and resource.name not in quotas:
continue
limit = quotas.get(resource.name, class_quotas.get(
resource.name, default_quotas[resource.name]))
limit = quotas.get(
resource.name,
class_quotas.get(resource.name, default_quotas[resource.name]))
modified_quotas[resource.name] = dict(limit=limit)
# Include usages if desired. This is optional because one
@ -154,7 +155,7 @@ class DbQuotaDriver(object):
modified_quotas[resource.name].update(
in_use=usage.get('in_use', 0),
reserved=usage.get('reserved', 0),
)
)
# Initialize remains quotas.
if remains:
modified_quotas[resource.name].update(remains=limit)
@ -163,8 +164,8 @@ class DbQuotaDriver(object):
all_quotas = db.quota_get_all(context, project_id)
for quota in all_quotas:
if quota.resource in modified_quotas:
modified_quotas[quota.resource]['remains'] -= \
quota.hard_limit
modified_quotas[quota.resource]['remains'] -= (
quota.hard_limit)
return modified_quotas
@ -234,9 +235,8 @@ class DbQuotaDriver(object):
user_quotas[key] = value
user_usages = None
if usages:
user_usages = db.quota_usage_get_all_by_project_and_user(context,
project_id,
user_id)
user_usages = db.quota_usage_get_all_by_project_and_user(
context, project_id, user_id)
return self._process_quotas(context, resources, project_id,
user_quotas, quota_class,
defaults=defaults, usages=user_usages)
@ -258,16 +258,14 @@ class DbQuotaDriver(object):
if user_id:
user_quotas = self.get_user_quotas(context, resources,
project_id, user_id)
setted_quotas = db.quota_get_all_by_project_and_user(context,
project_id,
user_id)
setted_quotas = db.quota_get_all_by_project_and_user(
context, project_id, user_id)
for key, value in user_quotas.items():
maximum = project_quotas[key]['remains'] +\
setted_quotas.get(key, 0)
maximum = (project_quotas[key]['remains'] +
setted_quotas.get(key, 0))
settable_quotas[key] = dict(
minimum=value['in_use'] + value['reserved'],
maximum=maximum
)
minimum=value['in_use'] + value['reserved'],
maximum=maximum)
else:
for key, value in project_quotas.items():
minimum = max(int(value['limit'] - value['remains']),
@ -837,14 +835,15 @@ class QuotaEngine(object):
"""
return self._driver.get_project_quotas(context, self._resources,
project_id,
quota_class=quota_class,
defaults=defaults,
usages=usages,
remains=remains)
project_id,
quota_class=quota_class,
defaults=defaults,
usages=usages,
remains=remains)
def get_settable_quotas(self, context, project_id, user_id=None):
"""
"""Get settable quotas.
Given a list of resources, retrieve the range of settable quotas for
the given user or project.

View File

@ -20,12 +20,9 @@ You can customize this scheduler by specifying your own share Filters and
Weighing Functions.
"""
import operator
from oslo.config import cfg
from manila import exception
from manila.openstack.common import importutils
from manila.openstack.common import log as logging
from manila.scheduler import driver
from manila.scheduler import scheduler_options

View File

@ -49,8 +49,8 @@ class CapacityFilter(filters.BaseHostFilter):
free = math.floor(free_space * (1 - reserved))
if free < volume_size:
LOG.warning(_("Insufficient free space for volume creation "
"(requested / avail): "
"%(requested)s/%(available)s")
"(requested / avail): "
"%(requested)s/%(available)s")
% {'requested': volume_size,
'available': free})

View File

@ -32,9 +32,9 @@ from manila.openstack.common import log as logging
from manila.openstack.common import timeutils
scheduler_json_config_location_opt = cfg.StrOpt(
'scheduler_json_config_location',
default='',
help='Absolute path to scheduler configuration JSON file.')
'scheduler_json_config_location',
default='',
help='Absolute path to scheduler configuration JSON file.')
CONF = cfg.CONF
CONF.register_opt(scheduler_json_config_location_opt)

View File

@ -28,10 +28,10 @@ from oslo.config import cfg
from manila.openstack.common.scheduler import weights
capacity_weight_opts = [
cfg.FloatOpt('capacity_weight_multiplier',
default=1.0,
help='Multiplier used for weighing volume capacity. '
'Negative numbers mean to stack vs spread.'),
cfg.FloatOpt('capacity_weight_multiplier',
default=1.0,
help='Multiplier used for weighing volume capacity. '
'Negative numbers mean to stack vs spread.'),
]
CONF = cfg.CONF

View File

@ -21,7 +21,6 @@ inline callbacks.
"""
import functools
import os
import shutil
import uuid
@ -35,7 +34,6 @@ import testtools
from manila.db import migration
from manila.db.sqlalchemy import api as db_api
from manila.openstack.common import importutils
from manila.openstack.common import log as logging
from manila.openstack.common import timeutils
from manila import rpc
@ -278,7 +276,7 @@ class TestCase(testtools.TestCase):
self.assertEqual(sub_value, super_value)
def assertIn(self, a, b, *args, **kwargs):
"""Python < v2.7 compatibility. Assert 'a' in 'b'"""
"""Python < v2.7 compatibility. Assert 'a' in 'b'."""
try:
f = super(TestCase, self).assertIn
except AttributeError:
@ -287,7 +285,7 @@ class TestCase(testtools.TestCase):
f(a, b, *args, **kwargs)
def assertNotIn(self, a, b, *args, **kwargs):
"""Python < v2.7 compatibility. Assert 'a' NOT in 'b'"""
"""Python < v2.7 compatibility. Assert 'a' NOT in 'b'."""
try:
f = super(TestCase, self).assertNotIn
except AttributeError:

View File

@ -22,7 +22,6 @@
import contextlib
import datetime
import errno
import functools
import hashlib
import inspect
import os
@ -31,17 +30,14 @@ import random
import re
import shutil
import socket
import struct
import sys
import tempfile
import time
from xml.dom import minidom
from xml.parsers import expat
from xml import sax
from xml.sax import expatreader
from xml.sax import saxutils
from eventlet import event
from eventlet import pools
import netaddr
from oslo.config import cfg
@ -477,7 +473,7 @@ def utf8(value):
def delete_if_exists(pathname):
"""delete a file, but ignore file not found error"""
"""Delete a file, but ignore file not found error."""
try:
os.unlink(pathname)
@ -540,7 +536,7 @@ def get_from_path(items, path):
def is_valid_boolstr(val):
"""Check if the provided string is a valid bool string or not. """
"""Check if the provided string is a valid bool string or not."""
val = str(val).lower()
return (val == 'true' or val == 'false' or
val == 'yes' or val == 'no' or
@ -825,7 +821,7 @@ def strcmp_const_time(s1, s2):
def walk_class_hierarchy(clazz, encountered=None):
"""Walk class hierarchy, yielding most derived classes first"""
"""Walk class hierarchy, yielding most derived classes first."""
if not encountered:
encountered = []
for subclass in clazz.__subclasses__():