Merge "Using neutron-lib hacking rules"

This commit is contained in:
Jenkins
2017年07月24日 10:12:16 +00:00
committed by Gerrit Code Review

View File

@@ -95,7 +95,7 @@ class CommonData(forms.SelfHandlingForm):
bgpvpn = bgpvpn_api.bgpvpn_create(request, **params)
else:
raise Exception(
'Action type %s is not supported' % self.action)
_('Action type %s is not supported') % self.action)
msg = _('BGPVPN {name} was successfully {action}.').format(
name=data['name'],
action=success_action)

View File

@@ -79,7 +79,7 @@ class UpdateAssociations(workflows.MembershipAction):
return api.neutron.network_list_for_tenant(request, tenant_id)
else:
raise Exception(
'Resource type %s is not supported' % resource_type)
_('Resource type %s is not supported') % resource_type)
except Exception:
exceptions.handle(request, err_msg % resource_type)
@@ -235,7 +235,7 @@ class UpdateBgpVpnAssociations(workflows.Workflow):
self._handle_type(request, data, 'router')
action = True
if not action:
raise Exception('Associations type is not supported')
raise Exception(_('Associations type is not supported'))
except Exception:
return False
return True

View File

@@ -18,7 +18,9 @@ from openstack_dashboard.test import helpers
from bgpvpn_dashboard.test.test_data import utils
def create_stubs(stubs_to_create={}):
def create_stubs(stubs_to_create=None):
if stubs_to_create is None:
stubs_to_create = {}
return helpers.create_stubs(stubs_to_create)

View File

@@ -26,8 +26,6 @@ from neutron.db import common_db_mixin
from neutron_lib.db import constants as db_const
from neutron_lib.db import model_base
from networking_bgpvpn._i18n import _LI
from networking_bgpvpn._i18n import _LW
from networking_bgpvpn.neutron.extensions import bgpvpn as bgpvpn_ext
from networking_bgpvpn.neutron.services.common import utils
@@ -245,8 +243,8 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
context.session.add(net_assoc_db)
return self._make_net_assoc_dict(net_assoc_db)
except db_exc.DBDuplicateEntry:
LOG.warning(_LW("network %(net_id)s is already associated to "
"BGPVPN %(bgpvpn_id)s"),
LOG.warning("network %(net_id)s is already associated to "
"BGPVPN %(bgpvpn_id)s",
{'net_id': net_assoc['network_id'],
'bgpvpn_id': bgpvpn_id})
raise bgpvpn_ext.BGPVPNNetAssocAlreadyExists(
@@ -265,9 +263,9 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
filters, fields)
def delete_net_assoc(self, context, assoc_id, bgpvpn_id):
LOG.info(_LI("deleting network association %(id)s for "
"BGPVPN %(bgpvpn)s"), {'id': assoc_id,
'bgpvpn': bgpvpn_id})
LOG.info("deleting network association %(id)s for "
"BGPVPN %(bgpvpn)s", {'id': assoc_id,
'bgpvpn': bgpvpn_id})
with context.session.begin(subtransactions=True):
net_assoc_db = self._get_net_assoc(context, assoc_id, bgpvpn_id)
net_assoc = self._make_net_assoc_dict(net_assoc_db)
@@ -302,8 +300,8 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
context.session.add(router_assoc_db)
return self._make_router_assoc_dict(router_assoc_db)
except db_exc.DBDuplicateEntry:
LOG.warning(_LW("router %(router_id)s is already associated to "
"BGPVPN %(bgpvpn_id)s"),
LOG.warning("router %(router_id)s is already associated to "
"BGPVPN %(bgpvpn_id)s",
{'router_id': router_id,
'bgpvpn_id': bgpvpn_id})
raise bgpvpn_ext.BGPVPNRouterAssocAlreadyExists(
@@ -322,8 +320,8 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
filters, fields)
def delete_router_assoc(self, context, assoc_id, bgpvpn_id):
LOG.info(_LI("deleting router association %(id)s for "
"BGPVPN %(bgpvpn)s"),
LOG.info("deleting router association %(id)s for "
"BGPVPN %(bgpvpn)s",
{'id': assoc_id, 'bgpvpn': bgpvpn_id})
with context.session.begin(subtransactions=True):
router_assoc_db = self._get_router_assoc(context, assoc_id,

View File

@@ -29,8 +29,6 @@ from neutron_lib.plugins import directory
from oslo_log import log
from networking_bgpvpn._i18n import _
from networking_bgpvpn._i18n import _LI
from networking_bgpvpn._i18n import _LW
from networking_bgpvpn.neutron.extensions import bgpvpn
from networking_bgpvpn.neutron.services.common import constants
@@ -55,14 +53,14 @@ class BGPVPNPlugin(bgpvpn.BGPVPNPluginBase):
# Load the default driver
drivers, default_provider = service_base.load_drivers(bgpvpn_def.LABEL,
self)
LOG.info(_LI("BGP VPN Service Plugin using Service Driver: %s"),
LOG.info("BGP VPN Service Plugin using Service Driver: %s",
default_provider)
self.driver = drivers[default_provider]
if len(drivers) > 1:
LOG.warning(_LW("Multiple drivers configured for BGPVPN, although"
"running multiple drivers in parallel is not yet"
"supported"))
LOG.warning("Multiple drivers configured for BGPVPN, although"
"running multiple drivers in parallel is not yet"
"supported")
registry.subscribe(self._notify_adding_interface_to_router,
resources.ROUTER_INTERFACE,
events.BEFORE_CREATE)

View File

@@ -33,8 +33,6 @@ from oslo_log import log as logging
from networking_bagpipe.agent.bgpvpn import rpc_client
from networking_bgpvpn._i18n import _LE
from networking_bgpvpn.neutron.db import bgpvpn_db
from networking_bgpvpn.neutron.extensions import bgpvpn as bgpvpn_ext
from networking_bgpvpn.neutron.services.common import constants
@@ -166,9 +164,9 @@ def network_is_external(context, net_id):
def _log_callback_processing_exception(resource, event, trigger, kwargs, e):
LOG.exception(_LE("Error during notification processing "
"%(resource)s%(event)s, %(trigger)s, "
"%(kwargs)s: %(exc)s"),
LOG.exception("Error during notification processing "
"%(resource)s%(event)s, %(trigger)s, "
"%(kwargs)s: %(exc)s",
{'trigger': trigger,
'resource': resource,
'event': event,

View File

@@ -13,16 +13,14 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import uuid
from oslo_log import log
from oslo_serialization import jsonutils
from oslo_utils import uuidutils
from neutron_lib import exceptions as n_exc
from networking_bgpvpn._i18n import _LI
from networking_bgpvpn.neutron.extensions import bgpvpn as bgpvpn_ext
from networking_bgpvpn.neutron.services.common import constants
from networking_bgpvpn.neutron.services.common import utils
@@ -105,12 +103,14 @@ class OpenContrailBGPVPNDriver(driver_api.BGPVPNDriverBase):
raise n_exc.NetworkNotFound(net_id=network_id)
def _set_bgpvpn_association(self, oc_client, operation, bgpvpn,
networks=[]):
networks=None):
if networks is None:
networks = []
for network_id in networks:
try:
net_ri_id = self._get_ri_id_of_network(oc_client, network_id)
except n_exc.NetworkNotFound:
LOG.info(_LI("Network %s not found, cleanup route targets"),
LOG.info("Network %s not found, cleanup route targets",
network_id)
rts_fq_name = (bgpvpn['route_targets'] +
bgpvpn['import_targets'] +
@@ -184,7 +184,7 @@ class OpenContrailBGPVPNDriver(driver_api.BGPVPNDriverBase):
bgpvpns = []
for kv_dict in oc_client.kv_store('RETRIEVE'):
try:
value = json.loads(kv_dict['value'])
value = jsonutils.loads(kv_dict['value'])
except ValueError:
continue
if (isinstance(value, dict) and
@@ -202,7 +202,7 @@ class OpenContrailBGPVPNDriver(driver_api.BGPVPNDriverBase):
def _clean_bgpvpn_assoc(self, oc_client, bgpvpn_id):
for kv_dict in oc_client.kv_store('RETRIEVE'):
try:
value = json.loads(kv_dict['value'])
value = jsonutils.loads(kv_dict['value'])
except ValueError:
continue
if (isinstance(value, dict) and
@@ -218,7 +218,7 @@ class OpenContrailBGPVPNDriver(driver_api.BGPVPNDriverBase):
oc_client = self._get_opencontrail_api_client(context)
try:
bgpvpn = json.loads(oc_client.kv_store('RETRIEVE', key=id))
bgpvpn = jsonutils.loads(oc_client.kv_store('RETRIEVE', key=id))
except (oc_exc.OpenContrailAPINotFound, ValueError):
raise bgpvpn_ext.BGPVPNNotFound(id=id)
@@ -307,7 +307,7 @@ class OpenContrailBGPVPNDriver(driver_api.BGPVPNDriverBase):
oc_client = self._get_opencontrail_api_client(context)
try:
net_assoc = json.loads(
net_assoc = jsonutils.loads(
oc_client.kv_store('RETRIEVE', key=assoc_id))
except (oc_exc.OpenContrailAPINotFound, ValueError):
raise bgpvpn_ext.BGPVPNNetAssocNotFound(id=assoc_id,
@@ -365,7 +365,7 @@ class OpenContrailBGPVPNDriver(driver_api.BGPVPNDriverBase):
bgpvpn_net_assocs = []
for kv_dict in oc_client.kv_store('RETRIEVE'):
try:
value = json.loads(kv_dict['value'])
value = jsonutils.loads(kv_dict['value'])
except ValueError:
continue
if (isinstance(value, dict) and

View File

@@ -13,12 +13,15 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
from networking_bgpvpn._i18n import _
from networking_bgpvpn.neutron.services.service_drivers.opencontrail import \
exceptions as oc_exc
from oslo_config import cfg
from oslo_log import log
from oslo_serialization import jsonutils
from oslo_utils import uuidutils
import requests
from six.moves import http_client as httplib
from six.moves.urllib import parse as urlparse
@@ -74,15 +77,17 @@ def get_auth_token():
auth_port = "35357"
auth_url = "%s://%s:%s" % (auth_protocol, auth_host, auth_port)
url = auth_url + '/v2.0/tokens'
response = requests.post(url, data=json.dumps(auth_body),
response = requests.post(url, data=jsonutils.dumps(auth_body),
headers=DEFAULT_HEADERS)
if response.status_code == 200:
auth_content = json.loads(response.text)
auth_content = jsonutils.loads(response.text)
return auth_content['access']['token']['id']
else:
raise RuntimeError("Authentication failure. Code: %d, reason: %s"
% (response.status_code, response.reason))
raise RuntimeError(_("Authentication failure. Code: %(code)d, "
"reason: %(reason)s")
% {'code': response.status_code,
'reason': response.reason})
class RequestHandler(object):
@@ -173,7 +178,7 @@ class RequestHandler(object):
}
if data:
req_params.update({'data': json.dumps(data)})
req_params.update({'data': jsonutils.dumps(data)})
return req_params
@@ -347,7 +352,7 @@ class OpenContrailAPIBaseClient(RequestHandler):
elif operation in ['RETRIEVE', 'DELETE'] and key:
body.update({'key': key})
elif operation == 'STORE' and key and value:
body.update({'key': key, 'value': json.dumps(value)})
body.update({'key': key, 'value': jsonutils.dumps(value)})
else:
raise oc_exc.OpenContrailAPIBadKVAttributes

View File

@@ -22,8 +22,6 @@ from oslo_utils import excutils
from networking_odl.common import client as odl_client
from networking_bgpvpn._i18n import _LW
from networking_bgpvpn.neutron.extensions import bgpvpn as bgpvpn_ext
from networking_bgpvpn.neutron.services.service_drivers import driver_api
@@ -43,10 +41,10 @@ class OpenDaylightBgpvpnDriver(driver_api.BGPVPNDriver):
"""
def __init__(self, service_plugin):
LOG.warning(_LW("This OpenDaylight BGPVPN driver has been deprecated"
"and will be removed. Switch to new v2 Driver: "
"BGPVPN:OpenDaylight:networking_odl.bgpvpn.odl_v2."
"OpenDaylightBgpvpnDriver:default"))
LOG.warning("This OpenDaylight BGPVPN driver has been deprecated"
"and will be removed. Switch to new v2 Driver: "
"BGPVPN:OpenDaylight:networking_odl.bgpvpn.odl_v2."
"OpenDaylightBgpvpnDriver:default")
super(OpenDaylightBgpvpnDriver, self).__init__(service_plugin)
self.service_plugin = service_plugin

View File

@@ -18,7 +18,7 @@ import subprocess
import netaddr
from oslo_log import log
from oslo_serialization import jsonutils as json
from oslo_serialization import jsonutils
from oslo_utils import netutils
from tempest.common import compute
@@ -472,7 +472,7 @@ class ScenarioTest(tempest.test.BaseTestCase):
bdm = image_props.get('block_device_mapping')
if bdm:
bdm = json.loads(bdm)
bdm = jsonutils.loads(bdm)
if bdm and 'snapshot_id' in bdm[0]:
snapshot_id = bdm[0]['snapshot_id']
self.addCleanup(

View File

@@ -90,9 +90,12 @@ commands = python setup.py build_sphinx
commands = oslo_debug_helper -t networking_bgpvpn/tests/unit {posargs}
[flake8]
# E123, E125 skipped as they are invalid PEP-8.
show-source = True
ignore = E123,E125
# E123,E125 skipped as they are invalid PEP-8.
# N530 direct neutron imports not allowed
ignore = E123,E125,N530
builtins = _
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools,.tmp
[hacking]
local-check-factory = neutron_lib.hacking.checks.factory
Reference in New Issue
openstack/networking-bgpvpn
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.

The note is not visible to the blocked user.