summaryrefslogtreecommitdiff
path: root/ironic/tests
diff options
context:
space:
mode:
authorSteve Baker <sbaker@redhat.com>2020-08-12 16:01:11 +1200
committerSteve Baker <sbaker@redhat.com>2020-11-16 10:39:40 +1300
commit8677be53b7cffb30544633c060e8650a3935726f (patch)
tree16519b18d4a45f8f04c1e2a348ae6e6a3333a41b /ironic/tests
parent3846965e9c7407c6b92dcf12dec586ce478c6e60 (diff)
downloadironic-8677be53b7cffb30544633c060e8650a3935726f.tar.gz
Duplicate trait validation with jsonschema
This change implements the same validation rules as the validate_trait function, but with jsonschema. When the 3 uses of validate_trait are converted to using jsonschema for post (and patch) calls, this function can be deleted. Change-Id: Ie2c0f32f254275007b491748e2a63fa94aa09434 Story: 1651346 Task: 10551
Diffstat (limited to 'ironic/tests')
-rw-r--r--ironic/tests/unit/api/controllers/v1/test_utils.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/ironic/tests/unit/api/controllers/v1/test_utils.py b/ironic/tests/unit/api/controllers/v1/test_utils.py
index 75200d7f8..a1d2efcbc 100644
--- a/ironic/tests/unit/api/controllers/v1/test_utils.py
+++ b/ironic/tests/unit/api/controllers/v1/test_utils.py
@@ -26,6 +26,7 @@ from ironic import api
from ironic.api.controllers.v1 import node as api_node
from ironic.api.controllers.v1 import utils
from ironic.api import types as atypes
+from ironic.common import args
from ironic.common import exception
from ironic.common import policy
from ironic.common import states
@@ -87,6 +88,30 @@ class TestApiUtils(base.TestCase):
"spongebob",
utils.validate_trait, "invalid", "spongebob")
+ def test_validate_trait_jsonschema(self):
+
+ validate_trait = args.schema(utils.TRAITS_SCHEMA)
+ validate_trait('foo', os_traits.HW_CPU_X86_AVX2)
+ validate_trait('foo', "CUSTOM_1")
+ validate_trait('foo', "CUSTOM_TRAIT_GOLD")
+ self.assertRaises(exception.InvalidParameterValue,
+ validate_trait, 'foo', "A" * 256)
+ self.assertRaises(exception.InvalidParameterValue,
+ validate_trait, 'foo', "CuSTOM_1")
+ self.assertRaises(exception.InvalidParameterValue,
+ validate_trait, 'foo', "")
+ self.assertRaises(exception.InvalidParameterValue,
+ validate_trait, 'foo', "CUSTOM_bob")
+ self.assertRaises(exception.InvalidParameterValue,
+ validate_trait, 'foo', "CUSTOM_1-BOB")
+ self.assertRaises(exception.InvalidParameterValue,
+ validate_trait, 'foo', "aCUSTOM_1a")
+ large = "CUSTOM_" + ("1" * 248)
+ self.assertEqual(255, len(large))
+ validate_trait('foo', large)
+ self.assertRaises(exception.InvalidParameterValue,
+ validate_trait, 'foo', large + "1")
+
def test_apply_jsonpatch(self):
doc = {"foo": {"bar": "baz"}}
patch = [{"op": "add", "path": "/foo/answer", "value": 42}]