diff --git a/HACKING.rst b/HACKING.rst new file mode 100644 index 0000000000..9b7659019c --- /dev/null +++ b/HACKING.rst @@ -0,0 +1,27 @@ +Ceilometer Style Commandments +============================= + +- Step 1: Read the OpenStack Style Commandments + http://docs.openstack.org/developer/hacking/ +- Step 2: Read on + +Ceilometer Specific Commandments +-------------------------------- + +- [C301] LOG.warn() is not allowed. Use LOG.warning() +- [C302] Deprecated library function os.popen() + +Creating Unit Tests +------------------- +For every new feature, unit tests should be created that both test and +(implicitly) document the usage of said feature. If submitting a patch for a +bug that had no unit test, a new passing unit test should be added. If a +submitted bug fix does have a unit test, be sure to add a new one that fails +without the patch and passes with the patch. + +All unittest classes must ultimately inherit from testtools.TestCase. + +All setUp and tearDown methods must upcall using the super() method. +tearDown methods should be avoided and addCleanup calls should be preferred. +Never manually create tempfiles. Always use the tempfile fixtures from +the fixture library to ensure that they are cleaned up. diff --git a/ceilometer/agent/manager.py b/ceilometer/agent/manager.py index 779c1a3bb1..762949fa82 100644 --- a/ceilometer/agent/manager.py +++ b/ceilometer/agent/manager.py @@ -34,7 +34,7 @@ from stevedore import extension from ceilometer.agent import plugin_base from ceilometer import coordination -from ceilometer.i18n import _, _LI, _LE, _LW +from ceilometer.i18n import _, _LE, _LI, _LW from ceilometer import keystone_client from ceilometer import messaging from ceilometer import pipeline diff --git a/ceilometer/collector.py b/ceilometer/collector.py index 05b3530572..8f1140f6f5 100644 --- a/ceilometer/collector.py +++ b/ceilometer/collector.py @@ -25,8 +25,8 @@ from oslo_utils import netutils from oslo_utils import units from ceilometer import dispatcher -from ceilometer import messaging from ceilometer.i18n import _, _LE +from ceilometer import messaging from ceilometer import utils OPTS = [ diff --git a/ceilometer/compute/pollsters/memory.py b/ceilometer/compute/pollsters/memory.py index d920dff8ee..5d6735b6e9 100644 --- a/ceilometer/compute/pollsters/memory.py +++ b/ceilometer/compute/pollsters/memory.py @@ -19,7 +19,7 @@ import ceilometer from ceilometer.compute import pollsters from ceilometer.compute.pollsters import util from ceilometer.compute.virt import inspector as virt_inspector -from ceilometer.i18n import _, _LW, _LE +from ceilometer.i18n import _, _LE, _LW from ceilometer import sample LOG = log.getLogger(__name__) diff --git a/ceilometer/hacking/__init__.py b/ceilometer/hacking/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ceilometer/hacking/checks.py b/ceilometer/hacking/checks.py new file mode 100644 index 0000000000..9474aa5d92 --- /dev/null +++ b/ceilometer/hacking/checks.py @@ -0,0 +1,57 @@ +# Copyright (c) 2016 OpenStack Foundation +# 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. + +""" +Guidelines for writing new hacking checks + + - Use only for Ceilometer specific tests. OpenStack general tests + should be submitted to the common 'hacking' module. + - Pick numbers in the range X3xx. Find the current test with + the highest allocated number and then pick the next value. + - Keep the test method code in the source file ordered based + on the C3xx value. + - List the new rule in the top level HACKING.rst file + +""" + + +def no_log_warn(logical_line): + """Disallow 'LOG.warn(' + + https://bugs.launchpad.net/tempest/+bug/1508442 + + C301 + """ + if logical_line.startswith('LOG.warn('): + yield(0, 'C301 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 + + C302 + """ + + if 'os.popen(' in logical_line: + yield(0, 'C302 Deprecated library function os.popen(). ' + 'Replace it using subprocess module. ') + + +def factory(register): + register(no_log_warn) + register(no_os_popen) diff --git a/ceilometer/notification.py b/ceilometer/notification.py index 908356cdc2..d9e4cafc20 100644 --- a/ceilometer/notification.py +++ b/ceilometer/notification.py @@ -24,8 +24,8 @@ from stevedore import extension from ceilometer.agent import plugin_base as base from ceilometer import coordination from ceilometer.event import endpoint as event_endpoint -from ceilometer.i18n import _, _LI, _LW from ceilometer import exchange_control +from ceilometer.i18n import _, _LI, _LW from ceilometer import messaging from ceilometer import pipeline from ceilometer import service_base diff --git a/ceilometer/publisher/messaging.py b/ceilometer/publisher/messaging.py index 31157ab0ff..f1b59a9310 100644 --- a/ceilometer/publisher/messaging.py +++ b/ceilometer/publisher/messaging.py @@ -27,7 +27,7 @@ from oslo_utils import excutils import six import six.moves.urllib.parse as urlparse -from ceilometer.i18n import _, _LI, _LE +from ceilometer.i18n import _, _LE, _LI from ceilometer import messaging from ceilometer import publisher from ceilometer.publisher import utils diff --git a/doc/source/conf.py b/doc/source/conf.py index 3ddfb710bd..1bbdc90db6 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -11,6 +11,7 @@ # All configuration values have a default; values that are commented out # serve to show the default. +import subprocess import sys import os @@ -150,8 +151,10 @@ html_theme_options = { # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' -git_cmd = "git log --pretty=format:'%ad, commit %h' --date=local -n1" -html_last_updated_fmt = os.popen(git_cmd).read() +git_cmd = ["git", "log", "--pretty=format:'%ad, commit %h'", "--date=local", + "-n1"] +html_last_updated_fmt = subprocess.Popen( + git_cmd, stdout=subprocess.PIPE).communicate()[0] # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. diff --git a/tox.ini b/tox.ini index 111c57aa3f..e5f1952335 100644 --- a/tox.ini +++ b/tox.ini @@ -133,3 +133,4 @@ show-source = True [hacking] import_exceptions = ceilometer.i18n +local-check-factory = ceilometer.hacking.checks.factory