From: John Mulligan Date: Wed, 8 Dec 2021 20:37:11 +0000 (-0500) Subject: python-common: add unit test func for invalid yaml inputs X-Git-Tag: v16.2.8~260^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cf160fbc18e0d729f62ba41a58c0b34b912ece02;p=ceph.git python-common: add unit test func for invalid yaml inputs 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 (cherry picked from commit 068d37d95762bce4d11668a838c6e85f6098723a) --- diff --git a/src/python-common/ceph/tests/test_service_spec.py b/src/python-common/ceph/tests/test_service_spec.py index e2e30944ceb..3678585b84e 100644 --- a/src/python-common/ceph/tests/test_service_spec.py +++ b/src/python-common/ceph/tests/test_service_spec.py @@ -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)