Enforce log hints in neutron.plugins.hyperv

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/hyperv

Change-Id: Iea2d63a4e74bf824ee308057570c980c50e937bc
Partial-bug: #1320867
This commit is contained in:
Cedric Brandily 2014-11-25 12:56:50 +00:00
parent 1049fd657e
commit 8bc7f5aff3
9 changed files with 77 additions and 76 deletions

View File

@ -79,7 +79,7 @@ def _directory_to_check_translation(filename):
"neutron/plugins/cisco",
"neutron/plugins/common",
#"neutron/plugins/embrane",
#"neutron/plugins/hyperv",
"neutron/plugins/hyperv",
#"neutron/plugins/ibm",
"neutron/plugins/linuxbridge",
#"neutron/plugins/metaplugin",

View File

@ -33,6 +33,7 @@ from neutron.common import constants as n_const
from neutron.common import rpc as n_rpc
from neutron.common import topics
from neutron import context
from neutron.i18n import _LE, _LI
from neutron.openstack.common import log as logging
from neutron.openstack.common import loopingcall
from neutron.plugins.common import constants as p_const
@ -146,8 +147,8 @@ class HyperVNeutronAgent(object):
self.state_rpc.report_state(self.context,
self.agent_state)
self.agent_state.pop('start_flag', None)
except Exception as ex:
LOG.exception(_("Failed reporting state! %s"), ex)
except Exception:
LOG.exception(_LE("Failed reporting state!"))
def _setup_rpc(self):
self.agent_id = 'hyperv_%s' % platform.node()
@ -182,7 +183,7 @@ class HyperVNeutronAgent(object):
for mapping in CONF.AGENT.physical_network_vswitch_mappings:
parts = mapping.split(':')
if len(parts) != 2:
LOG.debug(_('Invalid physical network mapping: %s'), mapping)
LOG.debug('Invalid physical network mapping: %s', mapping)
else:
pattern = re.escape(parts[0].strip()).replace('\\*', '.*')
vswitch = parts[1].strip()
@ -203,21 +204,21 @@ class HyperVNeutronAgent(object):
return (network_id, map)
def network_delete(self, context, network_id=None):
LOG.debug(_("network_delete received. "
"Deleting network %s"), network_id)
LOG.debug("network_delete received. "
"Deleting network %s", network_id)
# The network may not be defined on this agent
if network_id in self._network_vswitch_map:
self._reclaim_local_network(network_id)
else:
LOG.debug(_("Network %s not defined on agent."), network_id)
LOG.debug("Network %s not defined on agent.", network_id)
def port_delete(self, context, port_id=None):
LOG.debug(_("port_delete received"))
LOG.debug("port_delete received")
self._port_unbound(port_id)
def port_update(self, context, port=None, network_type=None,
segmentation_id=None, physical_network=None):
LOG.debug(_("port_update received"))
LOG.debug("port_update received")
if CONF.SECURITYGROUP.enable_security_group:
if 'security_groups' in port:
self.sec_groups_agent.refresh_firewall()
@ -239,7 +240,7 @@ class HyperVNeutronAgent(object):
net_uuid, network_type,
physical_network,
segmentation_id):
LOG.info(_("Provisioning network %s"), net_uuid)
LOG.info(_LI("Provisioning network %s"), net_uuid)
vswitch_name = self._get_vswitch_name(network_type, physical_network)
@ -264,7 +265,7 @@ class HyperVNeutronAgent(object):
self._network_vswitch_map[net_uuid] = map
def _reclaim_local_network(self, net_uuid):
LOG.info(_("Reclaiming local network %s"), net_uuid)
LOG.info(_LI("Reclaiming local network %s"), net_uuid)
del self._network_vswitch_map[net_uuid]
def _port_bound(self, port_id,
@ -272,7 +273,7 @@ class HyperVNeutronAgent(object):
network_type,
physical_network,
segmentation_id):
LOG.debug(_("Binding port %s"), port_id)
LOG.debug("Binding port %s", port_id)
if net_uuid not in self._network_vswitch_map:
self._provision_network(
@ -285,8 +286,8 @@ class HyperVNeutronAgent(object):
self._utils.connect_vnic_to_vswitch(map['vswitch_name'], port_id)
if network_type == p_const.TYPE_VLAN:
LOG.info(_('Binding VLAN ID %(segmentation_id)s '
'to switch port %(port_id)s'),
LOG.info(_LI('Binding VLAN ID %(segmentation_id)s '
'to switch port %(port_id)s'),
dict(segmentation_id=segmentation_id, port_id=port_id))
self._utils.set_vswitch_port_vlan_id(
segmentation_id,
@ -298,7 +299,7 @@ class HyperVNeutronAgent(object):
#Nothing to do
pass
else:
LOG.error(_('Unsupported network type %s'), network_type)
LOG.error(_LE('Unsupported network type %s'), network_type)
if CONF.AGENT.enable_metrics_collection:
self._utils.enable_port_metrics_collection(port_id)
@ -307,11 +308,11 @@ class HyperVNeutronAgent(object):
def _port_unbound(self, port_id):
(net_uuid, map) = self._get_network_vswitch_map_by_port_id(port_id)
if net_uuid not in self._network_vswitch_map:
LOG.info(_('Network %s is not avalailable on this agent'),
LOG.info(_LI('Network %s is not avalailable on this agent'),
net_uuid)
return
LOG.debug(_("Unbinding port %s"), port_id)
LOG.debug("Unbinding port %s", port_id)
self._utils.disconnect_switch_port(map['vswitch_name'], port_id, True)
if not map['ports']:
@ -324,11 +325,12 @@ class HyperVNeutronAgent(object):
for port_id in self._port_metric_retries.keys():
if self._utils.can_enable_control_metrics(port_id):
self._utils.enable_control_metrics(port_id)
LOG.info(_('Port metrics enabled for port: %s'), port_id)
LOG.info(_LI('Port metrics enabled for port: %s'), port_id)
del self._port_metric_retries[port_id]
elif self._port_metric_retries[port_id] < 1:
self._utils.enable_control_metrics(port_id)
LOG.error(_('Port metrics raw enabling for port: %s'), port_id)
LOG.error(_LE('Port metrics raw enabling for port: %s'),
port_id)
del self._port_metric_retries[port_id]
else:
self._port_metric_retries[port_id] -= 1
@ -353,7 +355,7 @@ class HyperVNeutronAgent(object):
else:
self._port_unbound(port_id)
else:
LOG.debug(_("No port %s defined on agent."), port_id)
LOG.debug("No port %s defined on agent.", port_id)
def _treat_devices_added(self, devices):
try:
@ -370,11 +372,11 @@ class HyperVNeutronAgent(object):
for device_details in devices_details_list:
device = device_details['device']
LOG.info(_("Adding port %s"), device)
LOG.info(_LI("Adding port %s"), device)
if 'port_id' in device_details:
LOG.info(
_("Port %(device)s updated. Details: %(device_details)s"),
{'device': device, 'device_details': device_details})
LOG.info(_LI("Port %(device)s updated. Details: "
"%(device_details)s"),
{'device': device, 'device_details': device_details})
self._treat_vif_port(
device_details['port_id'],
device_details['network_id'],
@ -399,16 +401,15 @@ class HyperVNeutronAgent(object):
def _treat_devices_removed(self, devices):
resync = False
for device in devices:
LOG.info(_("Removing port %s"), device)
LOG.info(_LI("Removing port %s"), device)
try:
self.plugin_rpc.update_device_down(self.context,
device,
self.agent_id,
cfg.CONF.host)
except Exception as e:
LOG.debug(
_("Removing port failed for device %(device)s: %(e)s"),
dict(device=device, e=e))
LOG.debug("Removing port failed for device %(device)s: %(e)s",
dict(device=device, e=e))
resync = True
continue
self._port_unbound(device)
@ -432,7 +433,7 @@ class HyperVNeutronAgent(object):
try:
start = time.time()
if sync:
LOG.info(_("Agent out of sync with plugin!"))
LOG.info(_LI("Agent out of sync with plugin!"))
ports.clear()
sync = False
@ -440,14 +441,14 @@ class HyperVNeutronAgent(object):
# notify plugin about port deltas
if port_info:
LOG.debug(_("Agent loop has new devices!"))
LOG.debug("Agent loop has new devices!")
# If treat devices fails - must resync with plugin
sync = self._process_network_ports(port_info)
ports = port_info['current']
self._port_enable_control_metrics()
except Exception as e:
LOG.exception(_("Error in agent event loop: %s"), e)
except Exception:
LOG.exception(_LE("Error in agent event loop"))
sync = True
# sleep till end of polling interval
@ -455,8 +456,8 @@ class HyperVNeutronAgent(object):
if (elapsed < self._polling_interval):
time.sleep(self._polling_interval - elapsed)
else:
LOG.debug(_("Loop iteration exceeded interval "
"(%(polling_interval)s vs. %(elapsed)s)"),
LOG.debug("Loop iteration exceeded interval "
"(%(polling_interval)s vs. %(elapsed)s)",
{'polling_interval': self._polling_interval,
'elapsed': elapsed})
@ -468,5 +469,5 @@ def main():
plugin = HyperVNeutronAgent()
# Start everything.
LOG.info(_("Agent initialized successfully, now running... "))
LOG.info(_LI("Agent initialized successfully, now running... "))
plugin.daemon_loop()

View File

@ -14,6 +14,7 @@
# under the License.
from neutron.agent import firewall
from neutron.i18n import _LE, _LI
from neutron.openstack.common import log as logging
from neutron.plugins.hyperv.agent import utilsfactory
from neutron.plugins.hyperv.agent import utilsv2
@ -42,7 +43,7 @@ class HyperVSecurityGroupsDriver(firewall.FirewallDriver):
self._security_ports = {}
def prepare_port_filter(self, port):
LOG.debug('Creating port %s rules' % len(port['security_group_rules']))
LOG.debug('Creating port %s rules', len(port['security_group_rules']))
# newly created port, add default rules.
if port['device'] not in self._security_ports:
@ -58,8 +59,8 @@ class HyperVSecurityGroupsDriver(firewall.FirewallDriver):
try:
self._utils.create_security_rule(port_id, **param_map)
except Exception as ex:
LOG.error(_('Hyper-V Exception: %(hyperv_exeption)s while '
'adding rule: %(rule)s'),
LOG.error(_LE('Hyper-V Exception: %(hyperv_exeption)s while '
'adding rule: %(rule)s'),
dict(hyperv_exeption=ex, rule=rule))
def _remove_port_rules(self, port_id, rules):
@ -68,8 +69,8 @@ class HyperVSecurityGroupsDriver(firewall.FirewallDriver):
try:
self._utils.remove_security_rule(port_id, **param_map)
except Exception as ex:
LOG.error(_('Hyper-V Exception: %(hyperv_exeption)s while '
'removing rule: %(rule)s'),
LOG.error(_LE('Hyper-V Exception: %(hyperv_exeption)s while '
'removing rule: %(rule)s'),
dict(hyperv_exeption=ex, rule=rule))
def _create_param_map(self, rule):
@ -88,10 +89,10 @@ class HyperVSecurityGroupsDriver(firewall.FirewallDriver):
}
def apply_port_filter(self, port):
LOG.info(_('Aplying port filter.'))
LOG.info(_LI('Aplying port filter.'))
def update_port_filter(self, port):
LOG.info(_('Updating port rules.'))
LOG.info(_LI('Updating port rules.'))
if port['device'] not in self._security_ports:
self.prepare_port_filter(port)
@ -104,10 +105,9 @@ class HyperVSecurityGroupsDriver(firewall.FirewallDriver):
new_rules = [r for r in param_port_rules if r not in rules]
remove_rules = [r for r in rules if r not in param_port_rules]
LOG.info(_("Creating %(new)s new rules, removing %(old)s "
"old rules."),
{'new': len(new_rules),
'old': len(remove_rules)})
LOG.info(_LI("Creating %(new)s new rules, removing %(old)s "
"old rules."),
{'new': len(new_rules), 'old': len(remove_rules)})
self._remove_port_rules(old_port['id'], remove_rules)
self._create_port_rules(port['id'], new_rules)
@ -115,7 +115,7 @@ class HyperVSecurityGroupsDriver(firewall.FirewallDriver):
self._security_ports[port['device']] = port
def remove_port_filter(self, port):
LOG.info(_('Removing port filter'))
LOG.info(_LI('Removing port filter'))
self._security_ports.pop(port['device'], None)
@property

View File

@ -148,7 +148,7 @@ class HyperVUtils(object):
desc = job.Description
elap = job.ElapsedTime
LOG.debug(_("WMI job succeeded: %(desc)s, Elapsed=%(elap)s"),
LOG.debug("WMI job succeeded: %(desc)s, Elapsed=%(elap)s",
{'desc': desc, 'elap': elap})
def _create_switch_port(self, vswitch_name, switch_port_name):

View File

@ -17,6 +17,7 @@ import sys
from oslo.config import cfg
from neutron.i18n import _LW
from neutron.openstack.common import log as logging
from neutron.plugins.hyperv.agent import utils
from neutron.plugins.hyperv.agent import utilsv2
@ -57,13 +58,14 @@ def get_hypervutils():
force_v1_flag = CONF.hyperv.force_hyperv_utils_v1
if _check_min_windows_version(6, 3):
if force_v1_flag:
LOG.warning(_('V1 virtualization namespace no longer supported on '
'Windows Server / Hyper-V Server 2012 R2 or above.'))
LOG.warning(_LW('V1 virtualization namespace no longer supported '
'on Windows Server / Hyper-V Server 2012 R2 or '
'above.'))
cls = utilsv2.HyperVUtilsV2R2
elif not force_v1_flag and _check_min_windows_version(6, 2):
cls = utilsv2.HyperVUtilsV2
else:
cls = utils.HyperVUtils
LOG.debug(_("Loading class: %(module_name)s.%(class_name)s"),
LOG.debug("Loading class: %(module_name)s.%(class_name)s",
{'module_name': cls.__module__, 'class_name': cls.__name__})
return cls()

View File

@ -17,11 +17,8 @@ from oslo import messaging
from neutron.common import rpc as n_rpc
from neutron.common import topics
from neutron.openstack.common import log as logging
from neutron.plugins.hyperv.common import constants
LOG = logging.getLogger(__name__)
class AgentNotifierApi(object):
'''Agent side of the openvswitch rpc API.

View File

@ -19,6 +19,7 @@ from sqlalchemy.orm import exc
from neutron.common import exceptions as n_exc
import neutron.db.api as db_api
from neutron.db import models_v2
from neutron.i18n import _LW
from neutron.openstack.common import log as logging
from neutron.plugins.hyperv.common import constants
from neutron.plugins.hyperv import model as hyperv_model
@ -34,8 +35,8 @@ class HyperVPluginDB(object):
alloc_q = alloc_q.filter_by(allocated=False)
alloc = alloc_q.first()
if alloc:
LOG.debug(_("Reserving vlan %(vlan_id)s on physical network "
"%(physical_network)s from pool"),
LOG.debug("Reserving vlan %(vlan_id)s on physical network "
"%(physical_network)s from pool",
{'vlan_id': alloc.vlan_id,
'physical_network': alloc.physical_network})
alloc.allocated = True
@ -49,8 +50,8 @@ class HyperVPluginDB(object):
vlan_id=constants.FLAT_VLAN_ID)
alloc = alloc_q.first()
if alloc:
LOG.debug(_("Reserving flat physical network "
"%(physical_network)s from pool"),
LOG.debug("Reserving flat physical network "
"%(physical_network)s from pool",
{'physical_network': alloc.physical_network})
alloc.allocated = True
return alloc.physical_network
@ -72,8 +73,8 @@ class HyperVPluginDB(object):
raise n_exc.VlanIdInUse(
vlan_id=vlan_id,
physical_network=physical_network)
LOG.debug(_("Reserving specific vlan %(vlan_id)s on physical "
"network %(physical_network)s from pool"),
LOG.debug("Reserving specific vlan %(vlan_id)s on physical "
"network %(physical_network)s from pool",
{'vlan_id': vlan_id,
'physical_network': physical_network})
alloc.allocated = True
@ -129,13 +130,13 @@ class HyperVPluginDB(object):
alloc = alloc_q.one()
alloc.allocated = False
#session.delete(alloc)
LOG.debug(_("Releasing vlan %(vlan_id)s on physical network "
"%(physical_network)s"),
LOG.debug("Releasing vlan %(vlan_id)s on physical network "
"%(physical_network)s",
{'vlan_id': vlan_id,
'physical_network': physical_network})
except exc.NoResultFound:
LOG.warning(_("vlan_id %(vlan_id)s on physical network "
"%(physical_network)s not found"),
LOG.warning(_LW("vlan_id %(vlan_id)s on physical network "
"%(physical_network)s not found"),
{'vlan_id': vlan_id,
'physical_network': physical_network})
@ -159,10 +160,9 @@ class HyperVPluginDB(object):
# it's not allocatable, so check if its allocated
if not alloc.allocated:
# it's not, so remove it from table
LOG.debug(_(
"Removing vlan %(vlan_id)s on "
"physical network "
"%(physical_network)s from pool"),
LOG.debug(
"Removing vlan %(vlan_id)s on physical network "
"%(physical_network)s from pool",
{'vlan_id': alloc.vlan_id,
'physical_network': physical_network})
session.delete(alloc)
@ -172,8 +172,8 @@ class HyperVPluginDB(object):
for allocs in allocations.itervalues():
for alloc in allocs:
if not alloc.allocated:
LOG.debug(_("Removing vlan %(vlan_id)s on physical "
"network %(physical_network)s from pool"),
LOG.debug("Removing vlan %(vlan_id)s on physical "
"network %(physical_network)s from pool",
{'vlan_id': alloc.vlan_id,
'physical_network': alloc.physical_network})
session.delete(alloc)

View File

@ -30,6 +30,7 @@ from neutron.db import portbindings_base
from neutron.db import quota_db # noqa
from neutron.extensions import portbindings
from neutron.extensions import providernet as provider
from neutron.i18n import _LI
from neutron.openstack.common import log as logging
from neutron.plugins.common import constants as svc_constants
from neutron.plugins.common import utils as plugin_utils
@ -202,7 +203,7 @@ class HyperVNeutronPlugin(agents_db.AgentDbMixin,
def _parse_network_vlan_ranges(self):
self._network_vlan_ranges = plugin_utils.parse_network_vlan_ranges(
cfg.CONF.HYPERV.network_vlan_ranges)
LOG.info(_("Network VLAN ranges: %s"), self._network_vlan_ranges)
LOG.info(_LI("Network VLAN ranges: %s"), self._network_vlan_ranges)
def _check_vlan_id_in_range(self, physical_network, vlan_id):
for r in self._network_vlan_ranges[physical_network]:
@ -253,7 +254,7 @@ class HyperVNeutronPlugin(agents_db.AgentDbMixin,
self._process_l3_create(context, net, network['network'])
self._extend_network_dict_provider(context, net)
LOG.debug(_("Created network: %s"), net['id'])
LOG.debug("Created network: %s", net['id'])
return net
def _extend_network_dict_provider(self, context, network):

View File

@ -39,7 +39,7 @@ class HyperVRpcCallbacks(object):
"""Agent requests device details."""
agent_id = kwargs.get('agent_id')
device = kwargs.get('device')
LOG.debug(_("Device %(device)s details requested from %(agent_id)s"),
LOG.debug("Device %(device)s details requested from %(agent_id)s",
{'device': device, 'agent_id': agent_id})
port = self._db.get_port(device)
if port:
@ -55,7 +55,7 @@ class HyperVRpcCallbacks(object):
self._db.set_port_status(port['id'], q_const.PORT_STATUS_ACTIVE)
else:
entry = {'device': device}
LOG.debug(_("%s can not be found in database"), device)
LOG.debug("%s can not be found in database", device)
return entry
def get_devices_details_list(self, rpc_context, **kwargs):
@ -73,7 +73,7 @@ class HyperVRpcCallbacks(object):
# TODO(garyk) - live migration and port status
agent_id = kwargs.get('agent_id')
device = kwargs.get('device')
LOG.debug(_("Device %(device)s no longer exists on %(agent_id)s"),
LOG.debug("Device %(device)s no longer exists on %(agent_id)s",
{'device': device, 'agent_id': agent_id})
port = self._db.get_port(device)
if port:
@ -84,7 +84,7 @@ class HyperVRpcCallbacks(object):
else:
entry = {'device': device,
'exists': False}
LOG.debug(_("%s can not be found in database"), device)
LOG.debug("%s can not be found in database", device)
return entry
def tunnel_sync(self, rpc_context, **kwargs):