summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/Bcfg2/Options.py4
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Packages/Source.py2
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Reporting.py3
-rw-r--r--testsuite/Testsrc/test_code_checks.py21
-rw-r--r--testsuite/ext/__init__.py0
-rw-r--r--testsuite/ext/exception_messages.py35
-rw-r--r--testsuite/pylintrc.conf2
7 files changed, 55 insertions, 12 deletions
diff --git a/src/lib/Bcfg2/Options.py b/src/lib/Bcfg2/Options.py
index b418d57b0..aff8c0733 100644
--- a/src/lib/Bcfg2/Options.py
+++ b/src/lib/Bcfg2/Options.py
@@ -331,7 +331,7 @@ def get_bool(val):
elif val in falselist:
return False
else:
- raise ValueError
+ raise ValueError("Not a boolean value", val)
def get_size(value):
@@ -341,7 +341,7 @@ def get_size(value):
return value
mat = re.match("(\d+)([KkMmGg])?", value)
if not mat:
- raise ValueError
+ raise ValueError("Not a valid size", value)
rvalue = int(mat.group(1))
mult = mat.group(2).lower()
if mult == 'k':
diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Source.py b/src/lib/Bcfg2/Server/Plugins/Packages/Source.py
index b98070ca9..985405e65 100644
--- a/src/lib/Bcfg2/Server/Plugins/Packages/Source.py
+++ b/src/lib/Bcfg2/Server/Plugins/Packages/Source.py
@@ -67,7 +67,7 @@ def fetch_url(url):
if '@' in url:
mobj = re.match('(\w+://)([^:]+):([^@]+)@(.*)$', url)
if not mobj:
- raise ValueError
+ raise ValueError("Invalid URL")
user = mobj.group(2)
passwd = mobj.group(3)
url = mobj.group(1) + mobj.group(4)
diff --git a/src/lib/Bcfg2/Server/Plugins/Reporting.py b/src/lib/Bcfg2/Server/Plugins/Reporting.py
index 60f5b1e09..d072f1a33 100644
--- a/src/lib/Bcfg2/Server/Plugins/Reporting.py
+++ b/src/lib/Bcfg2/Server/Plugins/Reporting.py
@@ -1,5 +1,6 @@
""" Unified statistics and reporting plugin """
+import sys
import time
import platform
import traceback
@@ -27,7 +28,7 @@ def _rpc_call(method):
return self.transport.rpc(method, *args, **kwargs)
except TransportError:
# this is needed for Admin.Pull
- raise PluginExecutionError
+ raise PluginExecutionError(sys.exc_info()[1])
return _real_rpc_call
diff --git a/testsuite/Testsrc/test_code_checks.py b/testsuite/Testsrc/test_code_checks.py
index d4ab0aa12..f6b7e991a 100644
--- a/testsuite/Testsrc/test_code_checks.py
+++ b/testsuite/Testsrc/test_code_checks.py
@@ -2,6 +2,7 @@ import os
import re
import sys
import glob
+import copy
from subprocess import Popen, PIPE, STDOUT
# add all parent testsuite directories to sys.path to allow (most)
@@ -15,13 +16,14 @@ while _path != '/':
_path = os.path.dirname(_path)
from common import *
+# path to base testsuite directory
+testdir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
+
# path to Bcfg2 src directory
-srcpath = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..",
- "src"))
+srcpath = os.path.abspath(os.path.join(testdir, "..", "src"))
# path to pylint rc file
-rcfile = os.path.abspath(os.path.join(os.path.dirname(__file__), "..",
- "pylintrc.conf"))
+rcfile = os.path.join(testdir, "pylintrc.conf")
# test for pylint existence
try:
@@ -140,7 +142,7 @@ def blacklist_filter(filelist, blacklist):
class TestPylint(Bcfg2TestCase):
pylint_cmd = ["pylint", "--rcfile", rcfile, "--init-hook",
- "import sys;sys.path.append('%s')" %
+ "import sys;sys.path.extend('%s')" %
os.path.join(srcpath, "lib")]
# regex to find errors and fatal errors
@@ -156,6 +158,11 @@ class TestPylint(Bcfg2TestCase):
full_blacklist = expand_path_dict(error_checks) + contingent_blacklist + \
blacklist
+ def get_env(self):
+ env = copy.copy(os.environ)
+ env['PYTHONPATH'] = '%s:%s' % (env['PYTHONPATH'], testdir)
+ return env
+
@skipIf(not os.path.exists(srcpath), "%s does not exist" % srcpath)
@skipIf(not os.path.exists(rcfile), "%s does not exist" % rcfile)
@skipUnless(HAS_PYLINT, "pylint not found, skipping")
@@ -206,7 +213,7 @@ class TestPylint(Bcfg2TestCase):
extra_args = []
args = self.pylint_cmd + extra_args + \
[os.path.join(srcpath, p) for p in paths]
- pylint = Popen(args, stdout=PIPE, stderr=STDOUT)
+ pylint = Popen(args, stdout=PIPE, stderr=STDOUT, env=self.get_env())
print(pylint.communicate()[0])
self.assertEqual(pylint.wait(), 0)
@@ -260,7 +267,7 @@ class TestPylint(Bcfg2TestCase):
args = self.pylint_cmd + extra_args + \
["-f", "parseable", "-d", "R0801,E1103"] + \
[os.path.join(srcpath, p) for p in paths]
- pylint = Popen(args, stdout=PIPE, stderr=STDOUT)
+ pylint = Popen(args, stdout=PIPE, stderr=STDOUT, env=self.get_env())
output = pylint.communicate()[0]
rv = pylint.wait()
diff --git a/testsuite/ext/__init__.py b/testsuite/ext/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/testsuite/ext/__init__.py
diff --git a/testsuite/ext/exception_messages.py b/testsuite/ext/exception_messages.py
new file mode 100644
index 000000000..877ba42a1
--- /dev/null
+++ b/testsuite/ext/exception_messages.py
@@ -0,0 +1,35 @@
+from logilab import astng
+from pylint.interfaces import IASTNGChecker
+from pylint.checkers import BaseChecker
+from pylint.checkers.utils import safe_infer
+
+
+class ExceptionMessageChecker(BaseChecker):
+ __implements__ = IASTNGChecker
+
+ name = 'Exception Messages'
+ msgs = \
+ {'R9901': ('Exception raised without arguments',
+ 'Used when an exception is raised without any arguments')}
+ options = (
+ ('exceptions-without-args',
+ dict(default=('NotImplementedError',),
+ type='csv',
+ metavar='<exception names>',
+ help='List of exception names that may be raised without arguments')),)
+ # this is important so that your checker is executed before others
+ priority = -1
+
+ def visit_raise(self, node):
+ if node.exc is None:
+ return
+ if isinstance(node.exc, astng.Name):
+ raised = safe_infer(node.exc)
+ if (isinstance(raised, astng.Class) and
+ raised.name not in self.config.exceptions_without_args):
+ self.add_message('R9901', node=node.exc)
+
+
+def register(linter):
+ """required method to auto register this checker"""
+ linter.register_checker(ExceptionMessageChecker(linter))
diff --git a/testsuite/pylintrc.conf b/testsuite/pylintrc.conf
index 63c2873ee..14ccd1d23 100644
--- a/testsuite/pylintrc.conf
+++ b/testsuite/pylintrc.conf
@@ -19,7 +19,7 @@ persistent=no
# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
-load-plugins=
+load-plugins=ext.exception_messages
[MESSAGES CONTROL]