else:
if name != local_name:
raise errors.GenericError("Current cluster name is '%s'" % local_name)
+
+
+def VerifyKeys(keys):
+ """Raises an exception if unknown ssconf keys are given.
+
+ @type keys: sequence
+ @param keys: Key names to verify
+ @raise errors.GenericError: When invalid keys were found
+
+ """
+ invalid = frozenset(keys) - _VALID_KEYS
+ if invalid:
+ raise errors.GenericError("Invalid ssconf keys: %s" %
+ utils.CommaJoin(sorted(invalid)))
"cluster.example.com", _cfg_location=self.tmpdir)
+class TestVerifyKeys(unittest.TestCase):
+ def testNoKeys(self):
+ ssconf.VerifyKeys({})
+
+ def testValidKeys(self):
+ ssconf.VerifyKeys(ssconf._VALID_KEYS)
+
+ for key in ssconf._VALID_KEYS:
+ ssconf.VerifyKeys([key])
+
+ def testInvalidKeys(self):
+ for key in ["", ".", " ", "foo", "bar", "HelloWorld"]:
+ self.assertRaises(errors.GenericError, ssconf.VerifyKeys, [key])
+
+
if __name__ == "__main__":
testutils.GanetiTestProgram()