Initial seed of hacking rules

Change-Id: I17ccd8de73c9c5452897cc6f54fddcf1911971e0
This commit is contained in:
Kyle L. Henderson 2016-02-02 10:07:37 -06:00
parent 7dd938d819
commit 18252f3f96
8 changed files with 47 additions and 9 deletions

View File

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

View File

View File

@ -0,0 +1,30 @@
# 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 nova.hacking import checks
def no_log_warn(logical_line, filename):
"""Disallow 'LOG.warn('
"""
if logical_line.startswith('LOG.warn('):
yield(0, 'P301 Use LOG.warning() rather than LOG.warn()')
def factory(register):
register(no_log_warn)
checks.factory(register)

View File

@ -115,7 +115,7 @@ class TestHostCPUStats(test.TestCase):
# Make sure None is returned if there is no data.
host_stats.cur_phyp = None
host_stats._update_internal_metric()
self.assertEqual(None, host_stats.cur_data)
self.assertIsNone(host_stats.cur_data)
# Make the 'prev' the current...for the first pass
host_stats.cur_phyp = self.prev_phyp

View File

@ -222,7 +222,8 @@ class TestConfigDrivePowerVM(test.TestCase):
self.apt.update_by_path.side_effect = validate_update
def validate_remove_stor(vg_w, vopts=[]):
def validate_remove_stor(vg_w, vopts=None):
vopts = {} if vopts is None else vopts
self.assertIsInstance(vg_w, pvm_stor.VG)
self.assertEqual(1, len(vopts))
self.assertIsInstance(vopts[0], pvm_stor.VOptMedia)
@ -253,7 +254,8 @@ class TestConfigDrivePowerVM(test.TestCase):
self.apt.read.side_effect = [self.vio_to_vg, self.vg_to_vio]
mock_vm_id.return_value = '2'
def validate_remove_stor(vg_w, vopts=[]):
def validate_remove_stor(vg_w, vopts=None):
vopts = {} if vopts is None else vopts
self.assertIsInstance(vg_w, pvm_stor.VG)
self.assertEqual(1, len(vopts))
self.assertIsInstance(vopts[0], pvm_stor.VOptMedia)

View File

@ -534,9 +534,10 @@ class FindDisk(task.Task):
LOG.info(_LI('Finding disk for instance: %s'), self.instance.name)
disk = self.disk_dvr.get_disk_ref(self.instance, self.disk_type)
if not disk:
LOG.warn(_LW('Disk not found: %(disk_name)s'),
{'disk_name': self.disk_dvr._get_disk_name(self.disk_type,
self.instance)
LOG.warning(_LW('Disk not found: %(disk_name)s'),
{'disk_name':
self.disk_dvr._get_disk_name(self.disk_type,
self.instance),
}, instance=self.instance)
return disk

View File

@ -14,8 +14,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
from oslo_log import log as logging
from oslo_serialization import jsonutils
import re
import six
@ -470,7 +470,7 @@ def get_vm_qp(adapter, lpar_uuid, qprop=None, log_errors=True):
LOG.exception(e)
raise
return json.loads(resp.body)
return jsonutils.loads(resp.body)
def crt_lpar(adapter, host_wrapper, instance, flavor):

View File

@ -34,3 +34,6 @@ whitelist_externals = bash
[flake8]
ignore = E125,H405
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools
[hacking]
local-check-factory = nova_powervm.hacking.checks.factory