From e264f14c797bf0a218b66e2dfdf88175f431ede9 Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Tue, 2 Dec 2014 04:27:07 -0800 Subject: [PATCH] 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 --- neutron/hacking/checks.py | 4 +- .../agent/nvsd_neutron_agent.py | 13 ++--- neutron/plugins/oneconvergence/lib/nvsdlib.py | 30 +++++------ .../oneconvergence/lib/plugin_helper.py | 50 ++++++++++--------- neutron/plugins/oneconvergence/plugin.py | 13 ++--- 5 files changed, 57 insertions(+), 53 deletions(-) diff --git a/neutron/hacking/checks.py b/neutron/hacking/checks.py index 6ac6dd7f90..998f345a91 100644 --- a/neutron/hacking/checks.py +++ b/neutron/hacking/checks.py @@ -88,8 +88,8 @@ def _directory_to_check_translation(filename): "neutron/plugins/mlnx", "neutron/plugins/nec", "neutron/plugins/nuage", - #"neutron/plugins/ofagent", - #"neutron/plugins/oneconvergence", + "neutron/plugins/ofagent", + "neutron/plugins/oneconvergence", "neutron/plugins/opencontrail", "neutron/plugins/openvswitch", "neutron/plugins/plumgrid", diff --git a/neutron/plugins/oneconvergence/agent/nvsd_neutron_agent.py b/neutron/plugins/oneconvergence/agent/nvsd_neutron_agent.py index 02baa42401..8baf24de55 100644 --- a/neutron/plugins/oneconvergence/agent/nvsd_neutron_agent.py +++ b/neutron/plugins/oneconvergence/agent/nvsd_neutron_agent.py @@ -31,6 +31,7 @@ from neutron.common import rpc as n_rpc from neutron.common import topics from neutron import context as n_context from neutron.extensions import securitygroup as ext_sg +from neutron.i18n import _LE, _LI from neutron.openstack.common import log as logging from neutron.plugins.oneconvergence.lib import config @@ -48,7 +49,7 @@ class NVSDAgentRpcCallback(object): self.sg_agent = sg_agent def port_update(self, context, **kwargs): - LOG.debug(_("port_update received: %s"), kwargs) + LOG.debug("port_update received: %s", kwargs) port = kwargs.get('port') # Validate that port is on OVS 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.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.context = n_context.get_admin_context_without_session() @@ -150,14 +151,14 @@ class NVSDNeutronAgent(object): try: port_info = self._update_ports(ports) if port_info: - LOG.debug(_("Port list is updated")) + LOG.debug("Port list is updated") self._process_devices_filter(port_info) ports = port_info['current'] self.ports = ports 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) @@ -169,7 +170,7 @@ def main(): root_helper = config.AGENT.root_helper polling_interval = config.AGENT.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. agent.daemon_loop() diff --git a/neutron/plugins/oneconvergence/lib/nvsdlib.py b/neutron/plugins/oneconvergence/lib/nvsdlib.py index d66abe7953..1b7b243fe2 100644 --- a/neutron/plugins/oneconvergence/lib/nvsdlib.py +++ b/neutron/plugins/oneconvergence/lib/nvsdlib.py @@ -106,7 +106,7 @@ class NVSDApi(object): 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}) return nvsd_net @@ -123,7 +123,7 @@ class NVSDApi(object): resource='network', tenant_id=tenant_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}) def delete_network(self, network, subnets=[]): @@ -144,7 +144,7 @@ class NVSDApi(object): self.send_request("DELETE", path, resource='network', 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}) def create_subnet(self, subnet): @@ -157,7 +157,7 @@ class NVSDApi(object): self.send_request("POST", uri, body=jsonutils.dumps(subnet), 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}) def delete_subnet(self, subnet): @@ -171,7 +171,7 @@ class NVSDApi(object): self.send_request("DELETE", uri, resource='subnet', 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}) def update_subnet(self, subnet, subnet_update): @@ -187,7 +187,7 @@ class NVSDApi(object): resource='subnet', tenant_id=tenant_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}) def create_port(self, tenant_id, port): @@ -219,7 +219,7 @@ class NVSDApi(object): self.send_request("POST", path, body=jsonutils.dumps(lport), 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}) def update_port(self, tenant_id, port, port_update): @@ -243,7 +243,7 @@ class NVSDApi(object): resource='port', tenant_id=tenant_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}) 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, 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}) def _get_ports(self, tenant_id, network_id): @@ -278,7 +278,7 @@ class NVSDApi(object): resource='floating_ip', 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}) def update_floatingip(self, floating_ip, floating_ip_update): @@ -296,7 +296,7 @@ class NVSDApi(object): tenant_id=tenant_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}) def delete_floatingip(self, floating_ip): @@ -310,7 +310,7 @@ class NVSDApi(object): self.send_request("DELETE", uri, resource='floating_ip', 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}) def create_router(self, router): @@ -323,7 +323,7 @@ class NVSDApi(object): resource='router', 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}) def update_router(self, router): @@ -339,7 +339,7 @@ class NVSDApi(object): resource='router', tenant_id=tenant_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}) def delete_router(self, tenant_id, router_id): @@ -349,5 +349,5 @@ class NVSDApi(object): self.send_request("DELETE", uri, resource='router', 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}) diff --git a/neutron/plugins/oneconvergence/lib/plugin_helper.py b/neutron/plugins/oneconvergence/lib/plugin_helper.py index f0eb70b84b..9506f89b1f 100644 --- a/neutron/plugins/oneconvergence/lib/plugin_helper.py +++ b/neutron/plugins/oneconvergence/lib/plugin_helper.py @@ -22,6 +22,7 @@ from oslo.serialization import jsonutils import requests from six.moves.urllib import parse +from neutron.i18n import _LE, _LW from neutron.openstack.common import log as logging import neutron.plugins.oneconvergence.lib.exception as exception @@ -85,20 +86,20 @@ class NVSDController(object): headers=headers, data=data) break except Exception as e: - LOG.error(_("Login Failed: %s"), e) - LOG.error(_("Unable to establish connection" - " with Controller %s"), self.api_url) - LOG.error(_("Retrying after 1 second...")) + LOG.error(_LE("Login Failed: %s"), e) + LOG.error(_LE("Unable to establish connection" + " with Controller %s"), self.api_url) + LOG.error(_LE("Retrying after 1 second...")) time.sleep(1) if response.status_code == requests.codes.ok: - LOG.debug(_("Login Successful %(uri)s " - "%(status)s"), {'uri': self.api_url, - 'status': response.status_code}) + LOG.debug("Login Successful %(uri)s " + "%(status)s", {'uri': self.api_url, + 'status': response.status_code}) self.auth_token = jsonutils.loads(response.content)["session_uuid"] - LOG.debug(_("AuthToken = %s"), self.auth_token) + LOG.debug("AuthToken = %s", self.auth_token) else: - LOG.error(_("login failed")) + LOG.error(_LE("login failed")) return @@ -106,7 +107,7 @@ class NVSDController(object): """Issue a request to NVSD controller.""" if self.auth_token is None: - LOG.warning(_("No Token, Re-login")) + LOG.warning(_LW("No Token, Re-login")) self.login() headers = {"Content-Type": content_type} @@ -122,20 +123,20 @@ class NVSDController(object): response = self.do_request(method, url=url, 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}) request_ok = True except httplib.IncompleteRead as e: response = e.partial request_ok = True except Exception as e: - LOG.error(_("request: Request failed from " + LOG.error(_LE("request: Request failed from " "Controller side :%s"), e) if response is None: # Timeout. - LOG.error(_("Response is Null, Request timed out: %(method)s to " - "%(uri)s"), {'method': method, 'uri': uri}) + LOG.error(_LE("Response is Null, Request timed out: %(method)s to " + "%(uri)s"), {'method': method, 'uri': uri}) self.auth_token = None raise exception.RequestTimeout() @@ -146,25 +147,26 @@ class NVSDController(object): raise exception.UnAuthorizedException() if status in self.error_codes: - LOG.error(_("Request %(method)s %(uri)s body = %(body)s failed " - "with status %(status)s"), {'method': method, - 'uri': uri, 'body': body, - 'status': status}) - LOG.error(_("%s"), response.reason) + LOG.error(_LE("Request %(method)s %(uri)s body = %(body)s failed " + "with status %(status)s. Reason: %(reason)s)"), + {'method': method, + 'uri': uri, 'body': body, + 'status': status, + 'reason': response.reason}) raise self.error_codes[status]() elif status not in (requests.codes.ok, requests.codes.created, requests.codes.no_content): - LOG.error(_("%(method)s to %(url)s, unexpected response code: " - "%(status)d"), {'method': method, 'url': url, - 'status': status}) + LOG.error(_LE("%(method)s to %(url)s, unexpected response code: " + "%(status)d"), {'method': method, 'url': url, + 'status': status}) return if not request_ok: - LOG.error(_("Request failed from Controller side with " + LOG.error(_LE("Request failed from Controller side with " "Status=%s"), status) raise exception.ServerException() 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, 'status': status}) response.body = response.content diff --git a/neutron/plugins/oneconvergence/plugin.py b/neutron/plugins/oneconvergence/plugin.py index 990753032c..f0daa004af 100644 --- a/neutron/plugins/oneconvergence/plugin.py +++ b/neutron/plugins/oneconvergence/plugin.py @@ -41,6 +41,7 @@ from neutron.db import portbindings_base from neutron.db import quota_db # noqa from neutron.db import securitygroups_rpc_base as sg_db_rpc from neutron.extensions import portbindings +from neutron.i18n import _LE from neutron.openstack.common import log as logging from neutron.plugins.common import constants as svc_constants import neutron.plugins.oneconvergence.lib.config # noqa @@ -233,8 +234,8 @@ class OneConvergencePluginV2(db_base_plugin_v2.NeutronDbPluginV2, #Log the message and delete the subnet from the neutron super(OneConvergencePluginV2, self).delete_subnet(context, neutron_subnet['id']) - LOG.error(_("Failed to create subnet, " - "deleting it from neutron")) + LOG.error(_LE("Failed to create subnet, " + "deleting it from neutron")) return neutron_subnet @@ -297,8 +298,8 @@ class OneConvergencePluginV2(db_base_plugin_v2.NeutronDbPluginV2, self.nvsdlib.create_port(tenant_id, neutron_port) except nvsdexception.NVSDAPIException: with excutils.save_and_reraise_exception(): - LOG.error(_("Deleting newly created " - "neutron port %s"), port_id) + LOG.error(_LE("Deleting newly created " + "neutron port %s"), port_id) super(OneConvergencePluginV2, self).delete_port(context, port_id) @@ -370,7 +371,7 @@ class OneConvergencePluginV2(db_base_plugin_v2.NeutronDbPluginV2, self.nvsdlib.create_floatingip(neutron_floatingip) except nvsdexception.NVSDAPIException: with excutils.save_and_reraise_exception(): - LOG.error(_("Failed to create floatingip")) + LOG.error(_LE("Failed to create floatingip")) super(OneConvergencePluginV2, self).delete_floatingip(context, neutron_floatingip['id']) @@ -409,7 +410,7 @@ class OneConvergencePluginV2(db_base_plugin_v2.NeutronDbPluginV2, self.nvsdlib.create_router(neutron_router) except nvsdexception.NVSDAPIException: with excutils.save_and_reraise_exception(): - LOG.error(_("Failed to create router")) + LOG.error(_LE("Failed to create router")) super(OneConvergencePluginV2, self).delete_router(context, neutron_router['id'])