From 303843b476b442d0d398680b23aa244633768f29 Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Mon, 20 Dec 2021 11:48:43 +0100 Subject: [PATCH] python-common: move test_valid_snmp_gateway_spec from mgr/cephadm We have to validate to_json() now as well, as we have spcial enums. Otherwiese we might end up with !!python... representations. Signed-off-by: Sebastian Wagner --- src/pybind/mgr/cephadm/tests/test_spec.py | 60 ------------------- .../ceph/tests/test_service_spec.py | 38 ++++++++++++ 2 files changed, 38 insertions(+), 60 deletions(-) diff --git a/src/pybind/mgr/cephadm/tests/test_spec.py b/src/pybind/mgr/cephadm/tests/test_spec.py index 436aae5d6f2..c89d3b6c1ca 100644 --- a/src/pybind/mgr/cephadm/tests/test_spec.py +++ b/src/pybind/mgr/cephadm/tests/test_spec.py @@ -3,7 +3,6 @@ # fmt: off import json -import yaml import pytest @@ -587,62 +586,3 @@ def test_daemon_description_service_name(spec: ServiceSpec, else: with pytest.raises(OrchestratorError): dd.service_name() - - -class YAMLdoc: - def __init__(self, text): - self.content = yaml.safe_load(text) - - -@pytest.mark.parametrize( - "yaml_doc,snmp_type", [ - (YAMLdoc(""" ---- -service_type: snmp-gateway -service_name: snmp-gateway -placement: - count: 1 -spec: - credentials: - snmp_community: public -port: 9464 -snmp_destination: 192.168.1.42:162 -snmp_version: V2c -"""), 'snmp V2c'), - (YAMLdoc(""" ---- -service_type: snmp-gateway -service_name: snmp-gateway -placement: - count: 1 -spec: - credentials: - snmp_v3_auth_username: myuser - snmp_v3_auth_password: mypassword -port: 9464 -engine_id: 8000C53F00000000 -auth_protocol: MD5 -snmp_destination: 192.168.1.42:162 -snmp_version: V3 -"""), 'SNMP V3 authNoPriv'), - (YAMLdoc(""" ---- -service_type: snmp-gateway -service_name: snmp-gateway -placement: - count: 1 -spec: - credentials: - snmp_v3_auth_username: myuser - snmp_v3_auth_password: mypassword - snmp_v3_priv_password: mysecret -port: 9464 -engine_id: 8000C53F00000000 -privacy_protocol: AES -snmp_destination: 192.168.1.42:162 -snmp_version: V3 -"""), 'SNMP V3 authPriv'), - ]) -def test_valid_snmp_gateway_spec(yaml_doc: YAMLdoc, snmp_type: str): - spec = ServiceSpec.from_json(yaml_doc.content) - spec.validate() diff --git a/src/python-common/ceph/tests/test_service_spec.py b/src/python-common/ceph/tests/test_service_spec.py index fd284f48133..080e5773217 100644 --- a/src/python-common/ceph/tests/test_service_spec.py +++ b/src/python-common/ceph/tests/test_service_spec.py @@ -321,6 +321,44 @@ spec: uid: 1000 volume_mounts: foo: /foo +--- +service_type: snmp-gateway +service_name: snmp-gateway +placement: + count: 1 +spec: + credentials: + snmp_community: public + snmp_destination: 192.168.1.42:162 + snmp_version: V2c +--- +service_type: snmp-gateway +service_name: snmp-gateway +placement: + count: 1 +spec: + auth_protocol: MD5 + credentials: + snmp_v3_auth_password: mypassword + snmp_v3_auth_username: myuser + engine_id: 8000C53F00000000 + port: 9464 + snmp_destination: 192.168.1.42:162 + snmp_version: V3 +--- +service_type: snmp-gateway +service_name: snmp-gateway +placement: + count: 1 +spec: + credentials: + snmp_v3_auth_password: mypassword + snmp_v3_auth_username: myuser + snmp_v3_priv_password: mysecret + engine_id: 8000C53F00000000 + privacy_protocol: AES + snmp_destination: 192.168.1.42:162 + snmp_version: V3 """.split('---\n')) def test_yaml(y): data = yaml.safe_load(y)