From: Sebastian Wagner Date: Fri, 23 Jul 2021 07:05:59 +0000 (+0200) Subject: python-common: test_yaml(): add a few tests X-Git-Tag: v16.2.8~273^2~6 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=8d6e779add015b9a42599db9b24d04d611c5e49d;p=ceph.git python-common: test_yaml(): add a few tests Signed-off-by: Sebastian Wagner (cherry picked from commit e7035f1a54c8b48d918c7579dfcf5665ae351dbc) --- diff --git a/src/python-common/ceph/tests/test_service_spec.py b/src/python-common/ceph/tests/test_service_spec.py index 9cb85bb24cb9b..373809b3c41f1 100644 --- a/src/python-common/ceph/tests/test_service_spec.py +++ b/src/python-common/ceph/tests/test_service_spec.py @@ -194,8 +194,9 @@ def test_osd_unmanaged(): dg_spec = ServiceSpec.from_json(osd_spec) assert dg_spec.unmanaged == True -def test_yaml(): - y = """service_type: crash + +@pytest.mark.parametrize("y", +"""service_type: crash service_name: crash placement: host_pattern: '*' @@ -247,14 +248,79 @@ service_type: grafana service_name: grafana spec: port: 1234 -""" - - for y in y.split('---\n'): - data = yaml.safe_load(y) - object = ServiceSpec.from_json(data) +--- +service_type: ingress +service_id: rgw.foo +service_name: ingress.rgw.foo +placement: + hosts: + - host1 + - host2 + - host3 +spec: + backend_service: rgw.foo + frontend_port: 8080 + monitor_port: 8081 + virtual_ip: 192.168.20.1/24 +--- +service_type: nfs +service_id: mynfs +service_name: nfs.mynfs +spec: + port: 1234 +--- +service_type: iscsi +service_id: iscsi +service_name: iscsi.iscsi +networks: +- ::0/8 +spec: + api_user: api_user + pool: pool + trusted_ip_list: + - ::1 + - ::2 +--- +service_type: container +service_id: hello-world +service_name: container.hello-world +spec: + args: + - --foo + bind_mounts: + - - type=bind + - source=lib/modules + - destination=/lib/modules + - ro=true + dirs: + - foo + - bar + entrypoint: /usr/bin/bash + envs: + - FOO=0815 + files: + bar.conf: + - foo + - bar + foo.conf: 'foo + + bar' + gid: 2000 + image: docker.io/library/hello-world:latest + ports: + - 8080 + - 8443 + uid: 1000 + volume_mounts: + foo: /foo +""".split('---\n')) +def test_yaml(y): + data = yaml.safe_load(y) + object = ServiceSpec.from_json(data) + + assert yaml.dump(object) == y + assert yaml.dump(ServiceSpec.from_json(object.to_json())) == y - assert yaml.dump(object) == y - assert yaml.dump(ServiceSpec.from_json(object.to_json())) == y def test_alertmanager_spec_1(): spec = AlertManagerSpec()