Enforce log hints in neutron.services.l3_router

This change enforces log hints use and removes debug level log
translation, modifications are validated through a hacking rule.

Validate that hacking rules apply to directories:
    - neutron/services/l3_router

Change-Id: I2a832c5e0c4ed2a944d199d6a2d6233b8cf838dd
Partial-bug: #1320867
This commit is contained in:
Cedric Brandily 2014-11-11 15:26:14 +01:00
parent 25d3e0114a
commit fa70c4011f
3 changed files with 34 additions and 31 deletions

View File

@ -56,7 +56,8 @@ def _directory_to_check_translation(filename):
"neutron/notifiers",
"neutron/openstack",
"neutron/scheduler",
"neutron/server"]
"neutron/server",
"neutron/services/l3_router"]
return any([dir in filename for dir in dirs])

View File

@ -21,6 +21,7 @@ from oslo.config import cfg
from neutron.common import constants as l3_constants
from neutron.openstack.common import excutils
from neutron.openstack.common.gettextutils import _LE, _LI
from neutron.openstack.common import log as logging
from neutron.plugins.ml2 import db
from neutron.plugins.ml2.drivers.brocade.db import models as brocade_db
@ -70,7 +71,7 @@ class BrocadeSVIPlugin(router.L3RouterPlugin):
'rbridge_id': cfg.CONF.ml2_brocade.rbridge_id
}
self._driver = driver.NOSdriver()
LOG.info(_("rbridge id %s"), self._switch['rbridge_id'])
LOG.info(_LI("rbridge id %s"), self._switch['rbridge_id'])
def create_router(self, context, router):
""" creates a vrf on NOS device."""
@ -149,7 +150,8 @@ class BrocadeSVIPlugin(router.L3RouterPlugin):
'device_owner': [DEVICE_OWNER_ROUTER_INTF]}
port_count = self._core_plugin.get_ports_count(context,
port_filters)
LOG.info(_("BrocadeSVIPlugin.add_router_interface ports_count %d"),
LOG.info(_LI("BrocadeSVIPlugin.add_router_interface ports_count "
"%d"),
port_count)
# port count is checked against 2 since the current port is already
@ -157,10 +159,10 @@ class BrocadeSVIPlugin(router.L3RouterPlugin):
if port_count == 2:
# This subnet is already part of some router
# (this is not supported in this version of brocade svi plugin)
LOG.error(_("BrocadeSVIPlugin: adding redundant router "
"interface is not supported"))
raise Exception(_("BrocadeSVIPlugin:adding redundant router "
"interface is not supported"))
msg = _("BrocadeSVIPlugin: adding redundant router interface "
"is not supported")
LOG.error(msg)
raise Exception(msg)
try:
switch = self._switch
@ -172,8 +174,8 @@ class BrocadeSVIPlugin(router.L3RouterPlugin):
gateway_ip_cidr,
str(router_id))
except Exception:
LOG.error(_("Failed to create Brocade resources to add router "
"interface. info=%(info)s, router_id=%(router_id)s"),
LOG.error(_LE("Failed to create Brocade resources to add router "
"interface. info=%(info)s, router_id=%(router_id)s"),
{"info": info, "router_id": router_id})
with excutils.save_and_reraise_exception():
with context.session.begin(subtransactions=True):
@ -218,10 +220,10 @@ class BrocadeSVIPlugin(router.L3RouterPlugin):
str(router_id))
except Exception:
with excutils.save_and_reraise_exception():
LOG.error(_("Fail remove of interface from brocade router "
"interface. info=%(info)s, "
"router_id=%(router_id)s") %
({"info": info, "router_id": router_id}))
LOG.error(_LE("Fail remove of interface from brocade "
"router interface. info=%(info)s, "
"router_id=%(router_id)s"),
{"info": info, "router_id": router_id})
return True
@staticmethod

View File

@ -29,6 +29,7 @@ from neutron.db import extraroute_db
from neutron.db import l3_agentschedulers_db
from neutron.db import l3_gwmode_db
from neutron.openstack.common import excutils
from neutron.openstack.common.gettextutils import _LE, _LI
from neutron.openstack.common import log as logging
from neutron.plugins.common import constants
from neutron.plugins.ml2.driver_context import NetworkContext # noqa
@ -109,8 +110,8 @@ class AristaL3ServicePlugin(db_base_plugin_v2.NeutronDbPluginV2,
return new_router
except Exception:
with excutils.save_and_reraise_exception():
LOG.error(_("Error creating router on Arista HW "
"router=%s ") % new_router)
LOG.error(_LE("Error creating router on Arista HW router=%s "),
new_router)
super(AristaL3ServicePlugin, self).delete_router(context,
new_router['id'])
@ -132,8 +133,8 @@ class AristaL3ServicePlugin(db_base_plugin_v2.NeutronDbPluginV2,
original_router, new_router)
return new_router
except Exception:
LOG.error(_("Error updating router on Arista HW "
"router=%s ") % new_router)
LOG.error(_LE("Error updating router on Arista HW router=%s "),
new_router)
@log.log
def delete_router(self, context, router_id):
@ -147,8 +148,8 @@ class AristaL3ServicePlugin(db_base_plugin_v2.NeutronDbPluginV2,
try:
self.driver.delete_router(context, tenant_id, router_id, router)
except Exception as e:
LOG.error(_("Error deleting router on Arista HW "
"router %(r)s exception=%(e)s") %
LOG.error(_LE("Error deleting router on Arista HW "
"router %(r)s exception=%(e)s"),
{'r': router, 'e': e})
with context.session.begin(subtransactions=True):
@ -193,8 +194,8 @@ class AristaL3ServicePlugin(db_base_plugin_v2.NeutronDbPluginV2,
return new_router
except Exception:
with excutils.save_and_reraise_exception():
LOG.error(_("Error Adding subnet %(subnet)s to "
"router %(router_id)s on Arista HW") %
LOG.error(_LE("Error Adding subnet %(subnet)s to "
"router %(router_id)s on Arista HW"),
{'subnet': subnet, 'router_id': router_id})
super(AristaL3ServicePlugin, self).remove_router_interface(
context,
@ -227,11 +228,11 @@ class AristaL3ServicePlugin(db_base_plugin_v2.NeutronDbPluginV2,
self.driver.remove_router_interface(context, router_info)
return new_router
except Exception as exc:
LOG.error(_("Error removing interface %(interface)s from "
"router %(router_id)s on Arista HW"
"Exception =(exc)s") % {'interface': interface_info,
'router_id': router_id,
'exc': exc})
LOG.error(_LE("Error removing interface %(interface)s from "
"router %(router_id)s on Arista HW"
"Exception =(exc)s"),
{'interface': interface_info, 'router_id': router_id,
'exc': exc})
def synchronize(self):
"""Synchronizes Router DB from Neturon DB with EOS.
@ -242,7 +243,7 @@ class AristaL3ServicePlugin(db_base_plugin_v2.NeutronDbPluginV2,
Uses idempotent properties of EOS configuration, which means
same commands can be repeated.
"""
LOG.info(_('Syncing Neutron Router DB <-> EOS'))
LOG.info(_LI('Syncing Neutron Router DB <-> EOS'))
ctx = nctx.get_admin_context()
routers = super(AristaL3ServicePlugin, self).get_routers(ctx)
@ -273,10 +274,9 @@ class AristaL3ServicePlugin(db_base_plugin_v2.NeutronDbPluginV2,
try:
self.driver.add_router_interface(self, r)
except Exception:
LOG.error(_("Error Adding interface %(subnet_id)s to "
"router %(router_id)s on Arista HW") %
{'subnet_id': subnet_id,
'router_id': r})
LOG.error(_LE("Error Adding interface %(subnet_id)s "
"to router %(router_id)s on Arista HW"),
{'subnet_id': subnet_id, 'router_id': r})
def _validate_interface_info(self, interface_info):
port_id_specified = interface_info and 'port_id' in interface_info