Initial seed of hacking rules

It is an initial seed of hacking rules based on neutron and
nova-powervm.

Closes-Bug: 1508442

Change-Id: Ie700e86e6bf881ca4174abf56a7ec36e99fcc68e
changes/65/281565/2
kairoaraujo 7 years ago
parent f17e5ebf5e
commit 16af89ab92

@ -9,6 +9,9 @@ Networking-PowerVM Specific Commandments
----------------------------------------
- Follow the Neutron HACKING.rst
- [P301] LOG.warn() is not allowed. Use LOG.warning()
- [P302] Deprecated library function os.popen()
Creating Unit Tests
-------------------
For every new feature, unit tests should be created that both test and

@ -0,0 +1,45 @@
# Copyright 2016 IBM Corp.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from neutron.hacking import checks
def no_log_warn(logical_line):
"""Disallow 'LOG.warn('
"""
if logical_line.startswith('LOG.warn('):
yield(0, 'P301 Use LOG.warning() rather than LOG.warn()')
def no_os_popen(logical_line):
"""Disallow 'os.popen('
Deprecated library function os.popen() Replace it using subprocess
https://bugs.launchpad.net/tempest/+bug/1529836
P302
"""
if 'os.popen(' in logical_line:
yield(0, 'P302 Deprecated library function os.popen(). '
'Replace it using subprocess module. ')
def factory(register):
register(no_log_warn)
register(no_os_popen)
checks.factory(register)

@ -36,6 +36,7 @@ from pypowervm import util as pvm_util
from pypowervm.utils import uuid as pvm_uuid
from networking_powervm.plugins.ibm.agent.powervm.i18n import _
from networking_powervm.plugins.ibm.agent.powervm.i18n import _LE
from networking_powervm.plugins.ibm.agent.powervm.i18n import _LI
from networking_powervm.plugins.ibm.agent.powervm.i18n import _LW
from networking_powervm.plugins.ibm.agent.powervm import utils
@ -173,8 +174,8 @@ class CNAEventHandler(pvm_adpt.EventHandler):
if not pvm_util.is_instance_path(uri):
return []
except Exception:
LOG.warn(_LW('Unable to parse URI %s for provision request '
'assessment.'), uri)
LOG.warning(_LW('Unable to parse URI %s for provision request '
'assessment.'), uri)
return []
# The event queue will only return URI's for 'root like' objects.
@ -307,7 +308,7 @@ class BasePVMNeutronAgent(object):
self.agent_state)
self.agent_state.pop('start_flag', None)
except Exception:
LOG.exception(_("Failed reporting state!"))
LOG.exception(_LE("Failed reporting state!"))
def update_device_up(self, device):
"""Calls back to neutron that a device is alive."""
@ -491,8 +492,8 @@ class BasePVMNeutronAgent(object):
except Exception as e:
LOG.exception(e)
LOG.warn(_LW("Error has been encountered and logged. The "
"agent will retry again."))
LOG.warning(_LW("Error has been encountered and logged. The "
"agent will retry again."))
# sleep for a while and re-loop
time.sleep(ACONF.exception_interval)

@ -155,8 +155,8 @@ class PVIDLooper(object):
return
except Exception as e:
LOG.warn(_LW("An error occurred while attempting to update the "
"PVID of the virtual NIC."))
LOG.warning(_LW("An error occurred while attempting to update the "
"PVID of the virtual NIC."))
LOG.exception(e)
# Increment the request count.
@ -365,9 +365,9 @@ class SharedEthernetNeutronAgent(agent_base.BasePVMNeutronAgent):
# VLANs the ones that are no longer needed.
vlans_to_del = existing_vlans - req_vlans
for vlan_to_del in vlans_to_del:
LOG.warn(_LW("Cleaning up VLAN %(vlan)s from the system. "
"It is no longer in use."),
{'vlan': vlan_to_del})
LOG.warning(_LW("Cleaning up VLAN %(vlan)s from the "
"system. It is no longer in use."),
{'vlan': vlan_to_del})
net_br.remove_vlan_from_nb(self.adapter, self.host_uuid,
nb.uuid, vlan_to_del)
@ -423,10 +423,10 @@ class SharedEthernetNeutronAgent(agent_base.BasePVMNeutronAgent):
"""
nb_uuid = self.br_map.get(dev.get('physical_network'))
if not nb_uuid and emit_warnings:
LOG.warn(_LW("Unable to determine the Network Bridge (Shared "
"Ethernet Adapter) for physical network %s. Will "
"be unable to determine appropriate provisioning "
"action."), dev.get('physical_network'))
LOG.warning(_LW("Unable to determine the Network Bridge (Shared "
"Ethernet Adapter) for physical network %s. Will "
"be unable to determine appropriate provisioning "
"action."), dev.get('physical_network'))
return nb_uuid, dev.get('segmentation_id')

@ -139,10 +139,10 @@ def _parse_empty_bridge_mapping(bridges):
if len(bridges) > 1:
raise np_exc.MultiBridgeNoMapping()
LOG.warn(_LW('The bridge_mappings for the agent was not specified. '
'There was exactly one Network Bridge on the system. '
'Agent is assuming the default network is backed by the '
'single Network Bridge.'))
LOG.warning(_LW('The bridge_mappings for the agent was not specified. '
'There was exactly one Network Bridge on the system. '
'Agent is assuming the default network is backed by the '
'single Network Bridge.'))
return {'default': bridges[0].uuid}
@ -322,7 +322,7 @@ def list_bridges(adapter, host_uuid):
net_bridges = pvm_net.NetBridge.wrap(resp)
if len(net_bridges) == 0:
LOG.warn(_LW('No NetworkBridges detected on the host.'))
LOG.warning(_LW('No NetworkBridges detected on the host.'))
return net_bridges

@ -70,3 +70,6 @@ ignore = H404,H405
show-source = true
builtins = _
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools,.ropeproject,rally-scenarios
[hacking]
local-check-factory = networking_powervm.hacking.checks.factory
Loading…
Cancel
Save