from ceph.deployment.service_spec import ServiceSpec, NFSServiceSpec, RGWSpec, \
IscsiServiceSpec, HostPlacementSpec, CustomContainerSpec
-from ceph.deployment.hostspec import SpecValidationError
from orchestrator import DaemonDescription, OrchestratorError
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
# flake8: noqa
import json
+import re
+
import yaml
import pytest
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)