]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
python-common: move test_invalid_snmp_gateway_spec from mgr/cephadm
authorSebastian Wagner <sewagner@redhat.com>
Mon, 20 Dec 2021 10:37:40 +0000 (11:37 +0100)
committerSebastian Wagner <sewagner@redhat.com>
Wed, 5 Jan 2022 09:24:42 +0000 (10:24 +0100)
Let's keep the tests in the same package where the class is defined.

Signed-off-by: Sebastian Wagner <sewagner@redhat.com>
src/pybind/mgr/cephadm/tests/test_spec.py
src/python-common/ceph/tests/test_service_spec.py

index f92c6ac10b28cbcc109ccc68e222471988ea9307..436aae5d6f2eeb34c82cbeb9d328889468f6fa00 100644 (file)
@@ -9,7 +9,6 @@ import pytest
 
 from ceph.deployment.service_spec import ServiceSpec, NFSServiceSpec, RGWSpec, \
     IscsiServiceSpec, HostPlacementSpec, CustomContainerSpec
-from ceph.deployment.hostspec import SpecValidationError
 from orchestrator import DaemonDescription, OrchestratorError
 
 
@@ -647,239 +646,3 @@ snmp_version: V3
 def test_valid_snmp_gateway_spec(yaml_doc: YAMLdoc, snmp_type: str):
     spec = ServiceSpec.from_json(yaml_doc.content)
     spec.validate()
-
-
-@pytest.mark.parametrize(
-    "yaml_doc,expected_error", [
-        (YAMLdoc("""
----
-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: V4
-"""), 'snmp_version unsupported. Must be one of V2c, V3'),
-        (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
-"""), 'Missing SNMP version (snmp_version)'),
-        (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
-auth_protocol: wah
-snmp_destination: 192.168.1.42:162
-snmp_version: V3
-"""), 'auth_protocol unsupported. Must be one of MD5, SHA'),
-        (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
-auth_protocol: SHA
-privacy_protocol: weewah
-snmp_destination: 192.168.1.42:162
-snmp_version: V3
-"""), 'privacy_protocol unsupported. Must be one of DES, AES'),
-        (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
-auth_protocol: SHA
-privacy_protocol: AES
-snmp_destination: 192.168.1.42:162
-snmp_version: V3
-"""), 'Must provide an engine_id for SNMP V3 notifications'),
-        (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
-snmp_version: V2c
-"""), 'SNMP destination (snmp_destination) type (IPv4) is invalid. Must be either: IPv4:Port, Name:Port'),
-        (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
-auth_protocol: SHA
-privacy_protocol: AES
-engine_id: bogus
-snmp_destination: 192.168.1.42:162
-snmp_version: V3
-"""), 'engine_id must be a string containing 10-64 hex characters. Its length must be divisible by 2'),
-        (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
-auth_protocol: SHA
-engine_id: 8000C53F0000000000
-snmp_version: V3
-"""), 'SNMP destination (snmp_destination) must be provided'),
-        (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
-auth_protocol: SHA
-privacy_protocol: AES
-engine_id: 8000C53F0000000000
-snmp_destination: my.imaginary.snmp-host
-snmp_version: V3
-"""), 'SNMP destination (snmp_destination) is invalid: DNS lookup failed'),
-        (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
-auth_protocol: SHA
-privacy_protocol: AES
-engine_id: 8000C53F0000000000
-snmp_destination: 10.79.32.10:fred
-snmp_version: V3
-"""), 'SNMP destination (snmp_destination) is invalid: Port must be numeric'),
-        (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
-auth_protocol: SHA
-privacy_protocol: AES
-engine_id: 8000C53
-snmp_destination: 10.79.32.10:162
-snmp_version: V3
-"""), 'engine_id must be a string containing 10-64 hex characters. Its length must be divisible by 2'),
-        (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
-auth_protocol: SHA
-privacy_protocol: AES
-engine_id: 8000C53DOH!
-snmp_destination: 10.79.32.10:162
-snmp_version: V3
-"""), 'engine_id must be a string containing 10-64 hex characters. Its length must be divisible by 2'),
-        (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
-auth_protocol: SHA
-privacy_protocol: AES
-engine_id: 8000C53FCA7344403DC611EC9B985254002537A6C53FCA7344403DC6112537A60
-snmp_destination: 10.79.32.10:162
-snmp_version: V3
-"""), 'engine_id must be a string containing 10-64 hex characters. Its length must be divisible by 2'),
-        (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
-auth_protocol: SHA
-privacy_protocol: AES
-engine_id: 8000C53F00000
-snmp_destination: 10.79.32.10:162
-snmp_version: V3
-"""), 'engine_id must be a string containing 10-64 hex characters. Its length must be divisible by 2'),
-    ])
-def test_invalid_snmp_gateway_spec(yaml_doc: YAMLdoc, expected_error: str):
-    with pytest.raises(SpecValidationError) as e:
-        ServiceSpec.from_json(yaml_doc.content)
-    assert str(e.value) == expected_error
index 555ba9b894115e32c2a62669f36caecddf92fdeb..fd284f481338ccb3aa96cfa59210c663dd998cf4 100644 (file)
@@ -1,5 +1,7 @@
 # flake8: noqa
 import json
+import re
+
 import yaml
 
 import pytest
@@ -589,6 +591,233 @@ spec:
   auth_protocol: BIZARRE
   snmp_version: V3
 """, "auth_protocol unsupported. Must be one of MD5, SHA"),
+    ("""
+---
+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: V4
+""", 'snmp_version unsupported. Must be one of V2c, V3'),
+        ("""
+---
+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
+""", re.escape('Missing SNMP version (snmp_version)')),
+        ("""
+---
+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
+  auth_protocol: wah
+  snmp_destination: 192.168.1.42:162
+  snmp_version: V3
+""", 'auth_protocol unsupported. Must be one of MD5, SHA'),
+        ("""
+---
+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
+  auth_protocol: SHA
+  privacy_protocol: weewah
+  snmp_destination: 192.168.1.42:162
+  snmp_version: V3
+""", 'privacy_protocol unsupported. Must be one of DES, AES'),
+        ("""
+---
+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
+  auth_protocol: SHA
+  privacy_protocol: AES
+  snmp_destination: 192.168.1.42:162
+  snmp_version: V3
+""", 'Must provide an engine_id for SNMP V3 notifications'),
+        ("""
+---
+service_type: snmp-gateway
+service_name: snmp-gateway
+placement:
+  count: 1
+spec:
+  credentials:
+    snmp_community: public
+  port: 9464
+  snmp_destination: 192.168.1.42
+  snmp_version: V2c
+""", re.escape('SNMP destination (snmp_destination) type (IPv4) is invalid. Must be either: IPv4:Port, Name:Port')),
+        ("""
+---
+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
+  auth_protocol: SHA
+  privacy_protocol: AES
+  engine_id: bogus
+  snmp_destination: 192.168.1.42:162
+  snmp_version: V3
+""", 'engine_id must be a string containing 10-64 hex characters. Its length must be divisible by 2'),
+        ("""
+---
+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
+  auth_protocol: SHA
+  engine_id: 8000C53F0000000000
+  snmp_version: V3
+""", re.escape('SNMP destination (snmp_destination) must be provided')),
+        ("""
+---
+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
+  auth_protocol: SHA
+  privacy_protocol: AES
+  engine_id: 8000C53F0000000000
+  snmp_destination: my.imaginary.snmp-host
+  snmp_version: V3
+""", re.escape('SNMP destination (snmp_destination) is invalid: DNS lookup failed')),
+        ("""
+---
+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
+  auth_protocol: SHA
+  privacy_protocol: AES
+  engine_id: 8000C53F0000000000
+  snmp_destination: 10.79.32.10:fred
+  snmp_version: V3
+""", re.escape('SNMP destination (snmp_destination) is invalid: Port must be numeric')),
+        ("""
+---
+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
+  auth_protocol: SHA
+  privacy_protocol: AES
+  engine_id: 8000C53
+  snmp_destination: 10.79.32.10:162
+  snmp_version: V3
+""", 'engine_id must be a string containing 10-64 hex characters. Its length must be divisible by 2'),
+        ("""
+---
+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
+  auth_protocol: SHA
+  privacy_protocol: AES
+  engine_id: 8000C53DOH!
+  snmp_destination: 10.79.32.10:162
+  snmp_version: V3
+""", 'engine_id must be a string containing 10-64 hex characters. Its length must be divisible by 2'),
+        ("""
+---
+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
+  auth_protocol: SHA
+  privacy_protocol: AES
+  engine_id: 8000C53FCA7344403DC611EC9B985254002537A6C53FCA7344403DC6112537A60
+  snmp_destination: 10.79.32.10:162
+  snmp_version: V3
+""", 'engine_id must be a string containing 10-64 hex characters. Its length must be divisible by 2'),
+        ("""
+---
+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
+  auth_protocol: SHA
+  privacy_protocol: AES
+  engine_id: 8000C53F00000
+  snmp_destination: 10.79.32.10:162
+  snmp_version: V3
+""", 'engine_id must be a string containing 10-64 hex characters. Its length must be divisible by 2'),
     ])
 def test_service_spec_validation_error(y, error_match):
     data = yaml.safe_load(y)