Enforce log hints in ofagent and oneconvergence

This change enforces log hints use and removes debug level log
translation, modifications are validated through a hacking rule
and the change respects loggging guidelines. Validate that hacking
rules apply to directories:-
    neutron/plugins/ofagent
    neutron/plugins/oneconvergence

Change-Id: I520a36ae53848b828ce33f4050606a7238f4cbce
Partial-bug: #1320867
This commit is contained in:
Gary Kotton 2014-12-02 04:27:07 -08:00 committed by Cedric Brandily
parent 28ecc6a15f
commit e264f14c79
5 changed files with 57 additions and 53 deletions

View File

@ -88,8 +88,8 @@ def _directory_to_check_translation(filename):
"neutron/plugins/mlnx", "neutron/plugins/mlnx",
"neutron/plugins/nec", "neutron/plugins/nec",
"neutron/plugins/nuage", "neutron/plugins/nuage",
#"neutron/plugins/ofagent", "neutron/plugins/ofagent",
#"neutron/plugins/oneconvergence", "neutron/plugins/oneconvergence",
"neutron/plugins/opencontrail", "neutron/plugins/opencontrail",
"neutron/plugins/openvswitch", "neutron/plugins/openvswitch",
"neutron/plugins/plumgrid", "neutron/plugins/plumgrid",

View File

@ -31,6 +31,7 @@ from neutron.common import rpc as n_rpc
from neutron.common import topics from neutron.common import topics
from neutron import context as n_context from neutron import context as n_context
from neutron.extensions import securitygroup as ext_sg from neutron.extensions import securitygroup as ext_sg
from neutron.i18n import _LE, _LI
from neutron.openstack.common import log as logging from neutron.openstack.common import log as logging
from neutron.plugins.oneconvergence.lib import config from neutron.plugins.oneconvergence.lib import config
@ -48,7 +49,7 @@ class NVSDAgentRpcCallback(object):
self.sg_agent = sg_agent self.sg_agent = sg_agent
def port_update(self, context, **kwargs): def port_update(self, context, **kwargs):
LOG.debug(_("port_update received: %s"), kwargs) LOG.debug("port_update received: %s", kwargs)
port = kwargs.get('port') port = kwargs.get('port')
# Validate that port is on OVS # Validate that port is on OVS
vif_port = self.agent.int_br.get_vif_port_by_id(port['id']) vif_port = self.agent.int_br.get_vif_port_by_id(port['id'])
@ -105,7 +106,7 @@ class NVSDNeutronAgent(object):
self.host = socket.gethostname() self.host = socket.gethostname()
self.agent_id = 'nvsd-q-agent.%s' % self.host self.agent_id = 'nvsd-q-agent.%s' % self.host
LOG.info(_("RPC agent_id: %s"), self.agent_id) LOG.info(_LI("RPC agent_id: %s"), self.agent_id)
self.topic = topics.AGENT self.topic = topics.AGENT
self.context = n_context.get_admin_context_without_session() self.context = n_context.get_admin_context_without_session()
@ -150,14 +151,14 @@ class NVSDNeutronAgent(object):
try: try:
port_info = self._update_ports(ports) port_info = self._update_ports(ports)
if port_info: if port_info:
LOG.debug(_("Port list is updated")) LOG.debug("Port list is updated")
self._process_devices_filter(port_info) self._process_devices_filter(port_info)
ports = port_info['current'] ports = port_info['current']
self.ports = ports self.ports = ports
except Exception: except Exception:
LOG.exception(_("Error in agent event loop")) LOG.exception(_LE("Error in agent event loop"))
LOG.debug(_("AGENT looping.....")) LOG.debug("AGENT looping.....")
time.sleep(self.polling_interval) time.sleep(self.polling_interval)
@ -169,7 +170,7 @@ def main():
root_helper = config.AGENT.root_helper root_helper = config.AGENT.root_helper
polling_interval = config.AGENT.polling_interval polling_interval = config.AGENT.polling_interval
agent = NVSDNeutronAgent(integ_br, root_helper, polling_interval) agent = NVSDNeutronAgent(integ_br, root_helper, polling_interval)
LOG.info(_("NVSD Agent initialized successfully, now running... ")) LOG.info(_LI("NVSD Agent initialized successfully, now running... "))
# Start everything. # Start everything.
agent.daemon_loop() agent.daemon_loop()

View File

@ -106,7 +106,7 @@ class NVSDApi(object):
nvsd_net = response.json() nvsd_net = response.json()
LOG.debug(_("Network %(id)s created under tenant %(tenant_id)s"), LOG.debug("Network %(id)s created under tenant %(tenant_id)s",
{'id': nvsd_net['id'], 'tenant_id': tenant_id}) {'id': nvsd_net['id'], 'tenant_id': tenant_id})
return nvsd_net return nvsd_net
@ -123,7 +123,7 @@ class NVSDApi(object):
resource='network', tenant_id=tenant_id, resource='network', tenant_id=tenant_id,
resource_id=network_id) resource_id=network_id)
LOG.debug(_("Network %(id)s updated under tenant %(tenant_id)s"), LOG.debug("Network %(id)s updated under tenant %(tenant_id)s",
{'id': network_id, 'tenant_id': tenant_id}) {'id': network_id, 'tenant_id': tenant_id})
def delete_network(self, network, subnets=[]): def delete_network(self, network, subnets=[]):
@ -144,7 +144,7 @@ class NVSDApi(object):
self.send_request("DELETE", path, resource='network', self.send_request("DELETE", path, resource='network',
tenant_id=tenant_id, resource_id=network_id) tenant_id=tenant_id, resource_id=network_id)
LOG.debug(_("Network %(id)s deleted under tenant %(tenant_id)s"), LOG.debug("Network %(id)s deleted under tenant %(tenant_id)s",
{'id': network_id, 'tenant_id': tenant_id}) {'id': network_id, 'tenant_id': tenant_id})
def create_subnet(self, subnet): def create_subnet(self, subnet):
@ -157,7 +157,7 @@ class NVSDApi(object):
self.send_request("POST", uri, body=jsonutils.dumps(subnet), self.send_request("POST", uri, body=jsonutils.dumps(subnet),
resource='subnet', tenant_id=tenant_id) resource='subnet', tenant_id=tenant_id)
LOG.debug(_("Subnet %(id)s created under tenant %(tenant_id)s"), LOG.debug("Subnet %(id)s created under tenant %(tenant_id)s",
{'id': subnet['id'], 'tenant_id': tenant_id}) {'id': subnet['id'], 'tenant_id': tenant_id})
def delete_subnet(self, subnet): def delete_subnet(self, subnet):
@ -171,7 +171,7 @@ class NVSDApi(object):
self.send_request("DELETE", uri, resource='subnet', self.send_request("DELETE", uri, resource='subnet',
tenant_id=tenant_id, resource_id=subnet_id) tenant_id=tenant_id, resource_id=subnet_id)
LOG.debug(_("Subnet %(id)s deleted under tenant %(tenant_id)s"), LOG.debug("Subnet %(id)s deleted under tenant %(tenant_id)s",
{'id': subnet_id, 'tenant_id': tenant_id}) {'id': subnet_id, 'tenant_id': tenant_id})
def update_subnet(self, subnet, subnet_update): def update_subnet(self, subnet, subnet_update):
@ -187,7 +187,7 @@ class NVSDApi(object):
resource='subnet', tenant_id=tenant_id, resource='subnet', tenant_id=tenant_id,
resource_id=subnet_id) resource_id=subnet_id)
LOG.debug(_("Subnet %(id)s updated under tenant %(tenant_id)s"), LOG.debug("Subnet %(id)s updated under tenant %(tenant_id)s",
{'id': subnet_id, 'tenant_id': tenant_id}) {'id': subnet_id, 'tenant_id': tenant_id})
def create_port(self, tenant_id, port): def create_port(self, tenant_id, port):
@ -219,7 +219,7 @@ class NVSDApi(object):
self.send_request("POST", path, body=jsonutils.dumps(lport), self.send_request("POST", path, body=jsonutils.dumps(lport),
resource='port', tenant_id=tenant_id) resource='port', tenant_id=tenant_id)
LOG.debug(_("Port %(id)s created under tenant %(tenant_id)s"), LOG.debug("Port %(id)s created under tenant %(tenant_id)s",
{'id': port['id'], 'tenant_id': tenant_id}) {'id': port['id'], 'tenant_id': tenant_id})
def update_port(self, tenant_id, port, port_update): def update_port(self, tenant_id, port, port_update):
@ -243,7 +243,7 @@ class NVSDApi(object):
resource='port', tenant_id=tenant_id, resource='port', tenant_id=tenant_id,
resource_id=port_id) resource_id=port_id)
LOG.debug(_("Port %(id)s updated under tenant %(tenant_id)s"), LOG.debug("Port %(id)s updated under tenant %(tenant_id)s",
{'id': port_id, 'tenant_id': tenant_id}) {'id': port_id, 'tenant_id': tenant_id})
def delete_port(self, port_id, port): def delete_port(self, port_id, port):
@ -256,7 +256,7 @@ class NVSDApi(object):
self.send_request("DELETE", uri, resource='port', tenant_id=tenant_id, self.send_request("DELETE", uri, resource='port', tenant_id=tenant_id,
resource_id=port_id) resource_id=port_id)
LOG.debug(_("Port %(id)s deleted under tenant %(tenant_id)s"), LOG.debug("Port %(id)s deleted under tenant %(tenant_id)s",
{'id': port_id, 'tenant_id': tenant_id}) {'id': port_id, 'tenant_id': tenant_id})
def _get_ports(self, tenant_id, network_id): def _get_ports(self, tenant_id, network_id):
@ -278,7 +278,7 @@ class NVSDApi(object):
resource='floating_ip', resource='floating_ip',
tenant_id=tenant_id) tenant_id=tenant_id)
LOG.debug(_("Flatingip %(id)s created under tenant %(tenant_id)s"), LOG.debug("Flatingip %(id)s created under tenant %(tenant_id)s",
{'id': floating_ip['id'], 'tenant_id': tenant_id}) {'id': floating_ip['id'], 'tenant_id': tenant_id})
def update_floatingip(self, floating_ip, floating_ip_update): def update_floatingip(self, floating_ip, floating_ip_update):
@ -296,7 +296,7 @@ class NVSDApi(object):
tenant_id=tenant_id, tenant_id=tenant_id,
resource_id=floating_ip_id) resource_id=floating_ip_id)
LOG.debug(_("Flatingip %(id)s updated under tenant %(tenant_id)s"), LOG.debug("Flatingip %(id)s updated under tenant %(tenant_id)s",
{'id': floating_ip_id, 'tenant_id': tenant_id}) {'id': floating_ip_id, 'tenant_id': tenant_id})
def delete_floatingip(self, floating_ip): def delete_floatingip(self, floating_ip):
@ -310,7 +310,7 @@ class NVSDApi(object):
self.send_request("DELETE", uri, resource='floating_ip', self.send_request("DELETE", uri, resource='floating_ip',
tenant_id=tenant_id, resource_id=floating_ip_id) tenant_id=tenant_id, resource_id=floating_ip_id)
LOG.debug(_("Flatingip %(id)s deleted under tenant %(tenant_id)s"), LOG.debug("Flatingip %(id)s deleted under tenant %(tenant_id)s",
{'id': floating_ip_id, 'tenant_id': tenant_id}) {'id': floating_ip_id, 'tenant_id': tenant_id})
def create_router(self, router): def create_router(self, router):
@ -323,7 +323,7 @@ class NVSDApi(object):
resource='router', resource='router',
tenant_id=tenant_id) tenant_id=tenant_id)
LOG.debug(_("Router %(id)s created under tenant %(tenant_id)s"), LOG.debug("Router %(id)s created under tenant %(tenant_id)s",
{'id': router['id'], 'tenant_id': tenant_id}) {'id': router['id'], 'tenant_id': tenant_id})
def update_router(self, router): def update_router(self, router):
@ -339,7 +339,7 @@ class NVSDApi(object):
resource='router', tenant_id=tenant_id, resource='router', tenant_id=tenant_id,
resource_id=router_id) resource_id=router_id)
LOG.debug(_("Router %(id)s updated under tenant %(tenant_id)s"), LOG.debug("Router %(id)s updated under tenant %(tenant_id)s",
{'id': router_id, 'tenant_id': tenant_id}) {'id': router_id, 'tenant_id': tenant_id})
def delete_router(self, tenant_id, router_id): def delete_router(self, tenant_id, router_id):
@ -349,5 +349,5 @@ class NVSDApi(object):
self.send_request("DELETE", uri, resource='router', self.send_request("DELETE", uri, resource='router',
tenant_id=tenant_id, resource_id=router_id) tenant_id=tenant_id, resource_id=router_id)
LOG.debug(_("Router %(id)s deleted under tenant %(tenant_id)s"), LOG.debug("Router %(id)s deleted under tenant %(tenant_id)s",
{'id': router_id, 'tenant_id': tenant_id}) {'id': router_id, 'tenant_id': tenant_id})

View File

@ -22,6 +22,7 @@ from oslo.serialization import jsonutils
import requests import requests
from six.moves.urllib import parse from six.moves.urllib import parse
from neutron.i18n import _LE, _LW
from neutron.openstack.common import log as logging from neutron.openstack.common import log as logging
import neutron.plugins.oneconvergence.lib.exception as exception import neutron.plugins.oneconvergence.lib.exception as exception
@ -85,20 +86,20 @@ class NVSDController(object):
headers=headers, data=data) headers=headers, data=data)
break break
except Exception as e: except Exception as e:
LOG.error(_("Login Failed: %s"), e) LOG.error(_LE("Login Failed: %s"), e)
LOG.error(_("Unable to establish connection" LOG.error(_LE("Unable to establish connection"
" with Controller %s"), self.api_url) " with Controller %s"), self.api_url)
LOG.error(_("Retrying after 1 second...")) LOG.error(_LE("Retrying after 1 second..."))
time.sleep(1) time.sleep(1)
if response.status_code == requests.codes.ok: if response.status_code == requests.codes.ok:
LOG.debug(_("Login Successful %(uri)s " LOG.debug("Login Successful %(uri)s "
"%(status)s"), {'uri': self.api_url, "%(status)s", {'uri': self.api_url,
'status': response.status_code}) 'status': response.status_code})
self.auth_token = jsonutils.loads(response.content)["session_uuid"] self.auth_token = jsonutils.loads(response.content)["session_uuid"]
LOG.debug(_("AuthToken = %s"), self.auth_token) LOG.debug("AuthToken = %s", self.auth_token)
else: else:
LOG.error(_("login failed")) LOG.error(_LE("login failed"))
return return
@ -106,7 +107,7 @@ class NVSDController(object):
"""Issue a request to NVSD controller.""" """Issue a request to NVSD controller."""
if self.auth_token is None: if self.auth_token is None:
LOG.warning(_("No Token, Re-login")) LOG.warning(_LW("No Token, Re-login"))
self.login() self.login()
headers = {"Content-Type": content_type} headers = {"Content-Type": content_type}
@ -122,19 +123,19 @@ class NVSDController(object):
response = self.do_request(method, url=url, response = self.do_request(method, url=url,
headers=headers, data=body) headers=headers, data=body)
LOG.debug(_("request: %(method)s %(uri)s successful"), LOG.debug("request: %(method)s %(uri)s successful",
{'method': method, 'uri': self.api_url + uri}) {'method': method, 'uri': self.api_url + uri})
request_ok = True request_ok = True
except httplib.IncompleteRead as e: except httplib.IncompleteRead as e:
response = e.partial response = e.partial
request_ok = True request_ok = True
except Exception as e: except Exception as e:
LOG.error(_("request: Request failed from " LOG.error(_LE("request: Request failed from "
"Controller side :%s"), e) "Controller side :%s"), e)
if response is None: if response is None:
# Timeout. # Timeout.
LOG.error(_("Response is Null, Request timed out: %(method)s to " LOG.error(_LE("Response is Null, Request timed out: %(method)s to "
"%(uri)s"), {'method': method, 'uri': uri}) "%(uri)s"), {'method': method, 'uri': uri})
self.auth_token = None self.auth_token = None
raise exception.RequestTimeout() raise exception.RequestTimeout()
@ -146,25 +147,26 @@ class NVSDController(object):
raise exception.UnAuthorizedException() raise exception.UnAuthorizedException()
if status in self.error_codes: if status in self.error_codes:
LOG.error(_("Request %(method)s %(uri)s body = %(body)s failed " LOG.error(_LE("Request %(method)s %(uri)s body = %(body)s failed "
"with status %(status)s"), {'method': method, "with status %(status)s. Reason: %(reason)s)"),
{'method': method,
'uri': uri, 'body': body, 'uri': uri, 'body': body,
'status': status}) 'status': status,
LOG.error(_("%s"), response.reason) 'reason': response.reason})
raise self.error_codes[status]() raise self.error_codes[status]()
elif status not in (requests.codes.ok, requests.codes.created, elif status not in (requests.codes.ok, requests.codes.created,
requests.codes.no_content): requests.codes.no_content):
LOG.error(_("%(method)s to %(url)s, unexpected response code: " LOG.error(_LE("%(method)s to %(url)s, unexpected response code: "
"%(status)d"), {'method': method, 'url': url, "%(status)d"), {'method': method, 'url': url,
'status': status}) 'status': status})
return return
if not request_ok: if not request_ok:
LOG.error(_("Request failed from Controller side with " LOG.error(_LE("Request failed from Controller side with "
"Status=%s"), status) "Status=%s"), status)
raise exception.ServerException() raise exception.ServerException()
else: else:
LOG.debug(_("Success: %(method)s %(url)s status=%(status)s"), LOG.debug("Success: %(method)s %(url)s status=%(status)s",
{'method': method, 'url': self.api_url + uri, {'method': method, 'url': self.api_url + uri,
'status': status}) 'status': status})
response.body = response.content response.body = response.content

View File

@ -41,6 +41,7 @@ from neutron.db import portbindings_base
from neutron.db import quota_db # noqa from neutron.db import quota_db # noqa
from neutron.db import securitygroups_rpc_base as sg_db_rpc from neutron.db import securitygroups_rpc_base as sg_db_rpc
from neutron.extensions import portbindings from neutron.extensions import portbindings
from neutron.i18n import _LE
from neutron.openstack.common import log as logging from neutron.openstack.common import log as logging
from neutron.plugins.common import constants as svc_constants from neutron.plugins.common import constants as svc_constants
import neutron.plugins.oneconvergence.lib.config # noqa import neutron.plugins.oneconvergence.lib.config # noqa
@ -233,7 +234,7 @@ class OneConvergencePluginV2(db_base_plugin_v2.NeutronDbPluginV2,
#Log the message and delete the subnet from the neutron #Log the message and delete the subnet from the neutron
super(OneConvergencePluginV2, super(OneConvergencePluginV2,
self).delete_subnet(context, neutron_subnet['id']) self).delete_subnet(context, neutron_subnet['id'])
LOG.error(_("Failed to create subnet, " LOG.error(_LE("Failed to create subnet, "
"deleting it from neutron")) "deleting it from neutron"))
return neutron_subnet return neutron_subnet
@ -297,7 +298,7 @@ class OneConvergencePluginV2(db_base_plugin_v2.NeutronDbPluginV2,
self.nvsdlib.create_port(tenant_id, neutron_port) self.nvsdlib.create_port(tenant_id, neutron_port)
except nvsdexception.NVSDAPIException: except nvsdexception.NVSDAPIException:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
LOG.error(_("Deleting newly created " LOG.error(_LE("Deleting newly created "
"neutron port %s"), port_id) "neutron port %s"), port_id)
super(OneConvergencePluginV2, self).delete_port(context, super(OneConvergencePluginV2, self).delete_port(context,
port_id) port_id)
@ -370,7 +371,7 @@ class OneConvergencePluginV2(db_base_plugin_v2.NeutronDbPluginV2,
self.nvsdlib.create_floatingip(neutron_floatingip) self.nvsdlib.create_floatingip(neutron_floatingip)
except nvsdexception.NVSDAPIException: except nvsdexception.NVSDAPIException:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
LOG.error(_("Failed to create floatingip")) LOG.error(_LE("Failed to create floatingip"))
super(OneConvergencePluginV2, super(OneConvergencePluginV2,
self).delete_floatingip(context, self).delete_floatingip(context,
neutron_floatingip['id']) neutron_floatingip['id'])
@ -409,7 +410,7 @@ class OneConvergencePluginV2(db_base_plugin_v2.NeutronDbPluginV2,
self.nvsdlib.create_router(neutron_router) self.nvsdlib.create_router(neutron_router)
except nvsdexception.NVSDAPIException: except nvsdexception.NVSDAPIException:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
LOG.error(_("Failed to create router")) LOG.error(_LE("Failed to create router"))
super(OneConvergencePluginV2, super(OneConvergencePluginV2,
self).delete_router(context, neutron_router['id']) self).delete_router(context, neutron_router['id'])