Commit b8d51bb2 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

constants: Verify exported names

The “constants” module is a bit special in the sense that we don't want
to export random stuff from it. This unittest checks the naming
convention and removes imported modules from the module's namespace.
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarIustin Pop <>
parent abbf2cd9
......@@ -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
......@@ -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([
def test(self):
wrong = \
wrong -= self._EXCEPTIONS
msg=("Invalid names exported from constants module: %s" %
class TestParameterNames(unittest.TestCase):
"""HV/BE parameter tests"""
VALID_NAME = re.compile("^[a-zA-Z_][a-zA-Z0-9_]*$")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment