diff --git a/HACKING.rst b/HACKING.rst index cf274bf0..fb9832f3 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -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 diff --git a/nova_powervm/hacking/__init__.py b/nova_powervm/hacking/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/nova_powervm/hacking/checks.py b/nova_powervm/hacking/checks.py new file mode 100644 index 00000000..63d47652 --- /dev/null +++ b/nova_powervm/hacking/checks.py @@ -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) diff --git a/nova_powervm/tests/virt/powervm/test_host.py b/nova_powervm/tests/virt/powervm/test_host.py index 8cc04e04..0f60287e 100644 --- a/nova_powervm/tests/virt/powervm/test_host.py +++ b/nova_powervm/tests/virt/powervm/test_host.py @@ -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 diff --git a/nova_powervm/tests/virt/powervm/test_media.py b/nova_powervm/tests/virt/powervm/test_media.py index 0ed1c144..1440ed26 100644 --- a/nova_powervm/tests/virt/powervm/test_media.py +++ b/nova_powervm/tests/virt/powervm/test_media.py @@ -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) diff --git a/nova_powervm/virt/powervm/tasks/storage.py b/nova_powervm/virt/powervm/tasks/storage.py index e5f8a3fe..28d3aa84 100644 --- a/nova_powervm/virt/powervm/tasks/storage.py +++ b/nova_powervm/virt/powervm/tasks/storage.py @@ -534,10 +534,11 @@ 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) - }, instance=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 diff --git a/nova_powervm/virt/powervm/vm.py b/nova_powervm/virt/powervm/vm.py index f56538ba..8d6b7e91 100644 --- a/nova_powervm/virt/powervm/vm.py +++ b/nova_powervm/virt/powervm/vm.py @@ -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): diff --git a/tox.ini b/tox.ini index 6a9189e9..6ee93c9b 100644 --- a/tox.ini +++ b/tox.ini @@ -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 \ No newline at end of file