Commit 8f227489 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Stricter check for OS modifications passed to OpClusterSetParams



Don't just check the first element of each item, but also make sure the
OS name is a string and not empty.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 58f0ce16
......@@ -36,7 +36,6 @@ opcodes.
import logging
import re
from ganeti import compat
from ganeti import constants
from ganeti import errors
from ganeti import ht
......@@ -165,11 +164,13 @@ _PAllowRuntimeChgs = ("allow_runtime_changes", True, ht.TBool,
_OPID_RE = re.compile("([a-z])([A-Z])")
#: Utility function for L{OpClusterSetParams}
_TestClusterOsList = ht.TOr(ht.TNone,
ht.TListOf(ht.TAnd(ht.TList, ht.TIsLength(2),
ht.TMap(ht.WithDesc("GetFirstItem")(compat.fst),
ht.TElemOf(constants.DDMS_VALUES)))))
_TestClusterOsListItem = \
ht.TAnd(ht.TIsLength(2), ht.TItems([
ht.TElemOf(constants.DDMS_VALUES),
ht.TNonEmptyString,
]))
_TestClusterOsList = ht.TOr(ht.TNone, ht.TListOf(_TestClusterOsListItem))
# TODO: Generate check from constants.INIC_PARAMS_TYPES
#: Utility function for testing NIC definitions
......
......@@ -338,5 +338,31 @@ class TestResultChecks(unittest.TestCase):
}))
class TestClusterOsList(unittest.TestCase):
def test(self):
good = [
None,
[],
[(constants.DDM_ADD, "dos"),
(constants.DDM_REMOVE, "linux")],
]
for i in good:
self.assertTrue(opcodes._TestClusterOsList(i))
wrong = ["", 0, "xy", ["Hello World"], object(),
[("foo", "bar")],
[("", "")],
[[constants.DDM_ADD]],
[(constants.DDM_ADD, "")],
[(constants.DDM_REMOVE, "")],
[(constants.DDM_ADD, None)],
[(constants.DDM_REMOVE, None)],
]
for i in wrong:
self.assertFalse(opcodes._TestClusterOsList(i))
if __name__ == "__main__":
testutils.GanetiTestProgram()
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