diff --git a/lib/constants.py b/lib/constants.py index d30aeb7d9e59602e1ed407b4c1e9553ce4cf46d1..79d0b2fed0d3921cc3ba71d3c2a781702d804aa8 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -1703,3 +1703,6 @@ BLOCKDEV_DRIVER_MANUAL = "manual" HTOOLS = _autoconf.HTOOLS # The hail iallocator IALLOC_HAIL = "hail" + +# Do not re-export imported modules +del re, _vcsversion, _autoconf diff --git a/test/ganeti.constants_unittest.py b/test/ganeti.constants_unittest.py index 9aab10fa1db2c565e01a4e32cad6e95eb71366d7..c0d834ccebb9f531e8644f533b3dc5d9bb8ea4ad 100755 --- a/test/ganeti.constants_unittest.py +++ b/test/ganeti.constants_unittest.py @@ -24,9 +24,11 @@ import unittest import re +import itertools from ganeti import constants from ganeti import locking +from ganeti import utils import testutils @@ -78,6 +80,25 @@ class TestConstants(unittest.TestCase): self.failUnless(constants.OP_PRIO_HIGH > constants.OP_PRIO_HIGHEST) +class TestExportedNames(unittest.TestCase): + _VALID_NAME_RE = re.compile(r"^[A-Z][A-Z0-9_]+$") + _BUILTIN_NAME_RE = re.compile(r"^__\w+__$") + _EXCEPTIONS = frozenset([ + "SplitVersion", + "BuildVersion", + ]) + + def test(self): + wrong = \ + set(itertools.ifilterfalse(self._BUILTIN_NAME_RE.match, + itertools.ifilterfalse(self._VALID_NAME_RE.match, + dir(constants)))) + wrong -= self._EXCEPTIONS + self.assertFalse(wrong, + msg=("Invalid names exported from constants module: %s" % + utils.CommaJoin(sorted(wrong)))) + + class TestParameterNames(unittest.TestCase): """HV/BE parameter tests""" VALID_NAME = re.compile("^[a-zA-Z_][a-zA-Z0-9_]*$")