]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
python-common: add unit test func for invalid yaml inputs
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 8 Dec 2021 20:37:11 +0000 (15:37 -0500)
committerSebastian Wagner <sewagner@redhat.com>
Tue, 11 Jan 2022 12:23:03 +0000 (13:23 +0100)
I didn't find a preexisting test function for this so I added a
new test that is fed yaml snippets and expected error messages.
This verifies some of the recently added validation for
count and cound_per_host under the placement spec.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
(cherry picked from commit 068d37d95762bce4d11668a838c6e85f6098723a)

src/python-common/ceph/tests/test_service_spec.py

index e2e30944cebbf230eedbb6fa57480d88938fccce..3678585b84e3658b71fb490247be307867d94524 100644 (file)
@@ -510,3 +510,48 @@ spec:
     assert spec.virtual_ip == "192.168.20.1/24"
     assert spec.frontend_port == 8080
     assert spec.monitor_port == 8081
+
+
+@pytest.mark.parametrize("y, error_match", [
+    ("""
+service_type: rgw
+service_id: foo
+placement:
+  count_per_host: "twelve"
+""", "count-per-host must be a numeric value",),
+    ("""
+service_type: rgw
+service_id: foo
+placement:
+  count_per_host: "2"
+""", "count-per-host must be an integer value",),
+    ("""
+service_type: rgw
+service_id: foo
+placement:
+  count_per_host: 7.36
+""", "count-per-host must be an integer value",),
+    ("""
+service_type: rgw
+service_id: foo
+placement:
+  count: "fifteen"
+""", "num/count must be a numeric value",),
+    ("""
+service_type: rgw
+service_id: foo
+placement:
+  count: "4"
+""", "num/count must be an integer value",),
+    ("""
+service_type: rgw
+service_id: foo
+placement:
+  count: 7.36
+""", "num/count must be an integer value",),
+    ])
+def test_service_spec_validation_error(y, error_match):
+    data = yaml.safe_load(y)
+    with pytest.raises(SpecValidationError) as err:
+        specObj = ServiceSpec.from_json(data)
+    assert err.match(error_match)