From 4fc6c74858e66c4e40afd51e09ce69293319ae51 Mon Sep 17 00:00:00 2001 From: Jakub Libosvar Date: Fri, 18 Apr 2014 15:22:45 +0200 Subject: [PATCH] Fix H302 violations in db package and services Change-Id: If5e07fa4529430ba90d9c7dd81d28ceeee00ebe0 Partial-Bug: #1291032 --- neutron/db/l3_agentschedulers_db.py | 7 ++++--- neutron/db/loadbalancer/loadbalancer_db.py | 3 +-- neutron/db/migration/alembic_migrations/env.py | 4 ++-- neutron/db/sqlalchemyutils.py | 4 ++-- neutron/db/vpn/vpn_db.py | 3 +-- neutron/service.py | 4 ++-- .../loadbalancer/drivers/embrane/agent/lb_operations.py | 4 ++-- neutron/services/loadbalancer/drivers/embrane/models.py | 2 +- neutron/services/loadbalancer/drivers/haproxy/cfg.py | 4 ++-- neutron/services/vpn/device_drivers/cisco_ipsec.py | 5 +++-- neutron/tests/unit/test_wsgi.py | 2 +- neutron/wsgi.py | 4 ++-- 12 files changed, 23 insertions(+), 23 deletions(-) diff --git a/neutron/db/l3_agentschedulers_db.py b/neutron/db/l3_agentschedulers_db.py index 698a786fa6..19969cb600 100644 --- a/neutron/db/l3_agentschedulers_db.py +++ b/neutron/db/l3_agentschedulers_db.py @@ -22,7 +22,7 @@ from sqlalchemy.orm import joinedload from neutron.common import constants from neutron.db import agents_db -from neutron.db.agentschedulers_db import AgentSchedulerDbMixin +from neutron.db import agentschedulers_db from neutron.db import model_base from neutron.db import models_v2 from neutron.extensions import l3agentscheduler @@ -52,7 +52,7 @@ class RouterL3AgentBinding(model_base.BASEV2, models_v2.HasId): class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase, - AgentSchedulerDbMixin): + agentschedulers_db.AgentSchedulerDbMixin): """Mixin class to add l3 agent scheduler extension to plugins using the l3 agent for routing. """ @@ -237,7 +237,8 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase, return [l3_agent for l3_agent in query - if AgentSchedulerDbMixin.is_eligible_agent(active, l3_agent)] + if agentschedulers_db.AgentSchedulerDbMixin.is_eligible_agent( + active, l3_agent)] def get_l3_agent_candidates(self, sync_router, l3_agents): """Get the valid l3 agents for the router from a list of l3_agents.""" diff --git a/neutron/db/loadbalancer/loadbalancer_db.py b/neutron/db/loadbalancer/loadbalancer_db.py index 9f1c9b6157..9c81a0664b 100644 --- a/neutron/db/loadbalancer/loadbalancer_db.py +++ b/neutron/db/loadbalancer/loadbalancer_db.py @@ -27,7 +27,6 @@ from neutron.db import model_base from neutron.db import models_v2 from neutron.db import servicetype_db as st_db from neutron.extensions import loadbalancer -from neutron.extensions.loadbalancer import LoadBalancerPluginBase from neutron import manager from neutron.openstack.common.db import exception from neutron.openstack.common import excutils @@ -177,7 +176,7 @@ class PoolMonitorAssociation(model_base.BASEV2, primary_key=True) -class LoadBalancerPluginDb(LoadBalancerPluginBase, +class LoadBalancerPluginDb(loadbalancer.LoadBalancerPluginBase, base_db.CommonDbMixin): """Wraps loadbalancer with SQLAlchemy models. diff --git a/neutron/db/migration/alembic_migrations/env.py b/neutron/db/migration/alembic_migrations/env.py index 92fe6b45fd..98352ffb75 100644 --- a/neutron/db/migration/alembic_migrations/env.py +++ b/neutron/db/migration/alembic_migrations/env.py @@ -14,7 +14,7 @@ # # @author: Mark McClain, DreamHost -from logging.config import fileConfig +from logging import config as logging_config from alembic import context from sqlalchemy import create_engine, pool @@ -32,7 +32,7 @@ neutron_config = config.neutron_config # Interpret the config file for Python logging. # This line sets up loggers basically. -fileConfig(config.config_file_name) +logging_config.fileConfig(config.config_file_name) plugin_class_path = neutron_config.core_plugin active_plugins = [plugin_class_path] diff --git a/neutron/db/sqlalchemyutils.py b/neutron/db/sqlalchemyutils.py index e1d525391a..adf0344326 100644 --- a/neutron/db/sqlalchemyutils.py +++ b/neutron/db/sqlalchemyutils.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -from six.moves import xrange +from six import moves import sqlalchemy from sqlalchemy.orm.properties import RelationshipProperty @@ -88,7 +88,7 @@ def paginate_query(query, model, limit, sorts, marker_obj=None): criteria_list = [] for i, sort in enumerate(sorts): crit_attrs = [(getattr(model, sorts[j][0]) == marker_values[j]) - for j in xrange(i)] + for j in moves.xrange(i)] model_attr = getattr(model, sort[0]) if sort[1]: crit_attrs.append((model_attr > marker_values[i])) diff --git a/neutron/db/vpn/vpn_db.py b/neutron/db/vpn/vpn_db.py index 056d956f39..a434b26bab 100644 --- a/neutron/db/vpn/vpn_db.py +++ b/neutron/db/vpn/vpn_db.py @@ -30,7 +30,6 @@ from neutron.db import l3_db from neutron.db import model_base from neutron.db import models_v2 from neutron.extensions import vpnaas -from neutron.extensions.vpnaas import VPNPluginBase from neutron import manager from neutron.openstack.common import excutils from neutron.openstack.common import log as logging @@ -163,7 +162,7 @@ class VPNService(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): cascade="all, delete-orphan") -class VPNPluginDb(VPNPluginBase, base_db.CommonDbMixin): +class VPNPluginDb(vpnaas.VPNPluginBase, base_db.CommonDbMixin): """VPN plugin database class using SQLAlchemy models.""" def __init__(self): diff --git a/neutron/service.py b/neutron/service.py index 3258245d10..8e4d5f5147 100644 --- a/neutron/service.py +++ b/neutron/service.py @@ -30,7 +30,7 @@ from neutron.openstack.common import importutils from neutron.openstack.common import log as logging from neutron.openstack.common import loopingcall from neutron.openstack.common.rpc import service -from neutron.openstack.common.service import ProcessLauncher +from neutron.openstack.common import service as common_service from neutron import wsgi @@ -153,7 +153,7 @@ def serve_rpc(): rpc.start() return rpc else: - launcher = ProcessLauncher(wait_interval=1.0) + launcher = common_service.ProcessLauncher(wait_interval=1.0) launcher.launch_service(rpc, workers=cfg.CONF.rpc_workers) return launcher except Exception: diff --git a/neutron/services/loadbalancer/drivers/embrane/agent/lb_operations.py b/neutron/services/loadbalancer/drivers/embrane/agent/lb_operations.py index 15ac419f58..f31caf7777 100644 --- a/neutron/services/loadbalancer/drivers/embrane/agent/lb_operations.py +++ b/neutron/services/loadbalancer/drivers/embrane/agent/lb_operations.py @@ -15,7 +15,7 @@ # # @author: Ivar Lazzaro, Embrane, Inc. ivar@embrane.com -from functools import wraps +import functools from heleosapi import exceptions as h_exc @@ -34,7 +34,7 @@ def handler(event, handler): else: handler[event].append(f) - @wraps(f) + @functools.wraps(f) def wrapped_f(*args, **kwargs): return f(*args, **kwargs) diff --git a/neutron/services/loadbalancer/drivers/embrane/models.py b/neutron/services/loadbalancer/drivers/embrane/models.py index e092c00310..51adfcf248 100644 --- a/neutron/services/loadbalancer/drivers/embrane/models.py +++ b/neutron/services/loadbalancer/drivers/embrane/models.py @@ -17,7 +17,7 @@ import sqlalchemy as sql -from neutron.db.models_v2 import model_base +from neutron.db import model_base class PoolPort(model_base.BASEV2): diff --git a/neutron/services/loadbalancer/drivers/haproxy/cfg.py b/neutron/services/loadbalancer/drivers/haproxy/cfg.py index 2944e456a6..d740cb6c02 100644 --- a/neutron/services/loadbalancer/drivers/haproxy/cfg.py +++ b/neutron/services/loadbalancer/drivers/haproxy/cfg.py @@ -17,7 +17,7 @@ # @author: Mark McClain, DreamHost import itertools -from six.moves import xrange +from six import moves from neutron.agent.linux import utils from neutron.plugins.common import constants as qconstants @@ -231,7 +231,7 @@ def _expand_expected_codes(codes): continue elif '-' in code: low, hi = code.split('-')[:2] - retval.update(str(i) for i in xrange(int(low), int(hi) + 1)) + retval.update(str(i) for i in moves.xrange(int(low), int(hi) + 1)) else: retval.add(code) return retval diff --git a/neutron/services/vpn/device_drivers/cisco_ipsec.py b/neutron/services/vpn/device_drivers/cisco_ipsec.py index 63eb9c0945..a7d38ba504 100644 --- a/neutron/services/vpn/device_drivers/cisco_ipsec.py +++ b/neutron/services/vpn/device_drivers/cisco_ipsec.py @@ -15,7 +15,7 @@ # @author: Paul Michali, Cisco Systems, Inc. import abc -from collections import namedtuple +import collections import requests import netaddr @@ -46,7 +46,8 @@ cfg.CONF.register_opts(ipsec_opts, 'cisco_csr_ipsec') LOG = logging.getLogger(__name__) -RollbackStep = namedtuple('RollbackStep', ['action', 'resource_id', 'title']) +RollbackStep = collections.namedtuple('RollbackStep', + ['action', 'resource_id', 'title']) class CsrResourceCreateFailure(exceptions.NeutronException): diff --git a/neutron/tests/unit/test_wsgi.py b/neutron/tests/unit/test_wsgi.py index 4e1101ba3a..1de0d53f85 100644 --- a/neutron/tests/unit/test_wsgi.py +++ b/neutron/tests/unit/test_wsgi.py @@ -47,7 +47,7 @@ class TestWSGIServer(base.BaseTestCase): server.stop() server.wait() - @mock.patch('neutron.wsgi.ProcessLauncher') + @mock.patch('neutron.openstack.common.service.ProcessLauncher') def test_start_multiple_workers(self, ProcessLauncher): launcher = ProcessLauncher.return_value diff --git a/neutron/wsgi.py b/neutron/wsgi.py index 5895eee9d0..e3b5262405 100644 --- a/neutron/wsgi.py +++ b/neutron/wsgi.py @@ -44,7 +44,7 @@ from neutron.openstack.common import excutils from neutron.openstack.common import gettextutils from neutron.openstack.common import jsonutils from neutron.openstack.common import log as logging -from neutron.openstack.common.service import ProcessLauncher +from neutron.openstack.common import service as common_service socket_opts = [ cfg.IntOpt('backlog', @@ -216,7 +216,7 @@ class Server(object): else: # Minimize the cost of checking for child exit by extending the # wait interval past the default of 0.01s. - self._launcher = ProcessLauncher(wait_interval=1.0) + self._launcher = common_service.ProcessLauncher(wait_interval=1.0) self._server = WorkerService(self, application) self._launcher.launch_service(self._server, workers=workers)