pyhton-common: move some tests from cephadm/test_spec.py

Cause they don't have any dependencies to cephadm

Signed-off-by: Sebastian Wagner <sewagner@redhat.com>
This commit is contained in:
Sebastian Wagner 2021-07-23 02:36:27 +02:00
parent f3d3dcee87
commit 6f90f0fa2e
No known key found for this signature in database
GPG Key ID: 8D2442807E6979F8
2 changed files with 91 additions and 93 deletions

View File

@ -6,10 +6,8 @@ import json
import pytest
import yaml
from ceph.deployment.service_spec import ServiceSpec, NFSServiceSpec, RGWSpec, \
IscsiServiceSpec, AlertManagerSpec, HostPlacementSpec, CustomContainerSpec
IscsiServiceSpec, HostPlacementSpec, CustomContainerSpec
from orchestrator import DaemonDescription, OrchestratorError
@ -589,92 +587,3 @@ def test_daemon_description_service_name(spec: ServiceSpec,
else:
with pytest.raises(OrchestratorError):
dd.service_name()
def test_alertmanager_spec_1():
spec = AlertManagerSpec()
assert spec.service_type == 'alertmanager'
assert isinstance(spec.user_data, dict)
assert len(spec.user_data.keys()) == 0
def test_alertmanager_spec_2():
spec = AlertManagerSpec(user_data={'default_webhook_urls': ['foo']})
assert isinstance(spec.user_data, dict)
assert 'default_webhook_urls' in spec.user_data.keys()
def test_custom_container_spec():
spec = CustomContainerSpec(service_id='hello-world',
image='docker.io/library/hello-world:latest',
entrypoint='/usr/bin/bash',
uid=1000,
gid=2000,
volume_mounts={'foo': '/foo'},
args=['--foo'],
envs=['FOO=0815'],
bind_mounts=[
[
'type=bind',
'source=lib/modules',
'destination=/lib/modules',
'ro=true'
]
],
ports=[8080, 8443],
dirs=['foo', 'bar'],
files={
'foo.conf': 'foo\nbar',
'bar.conf': ['foo', 'bar']
})
assert spec.service_type == 'container'
assert spec.entrypoint == '/usr/bin/bash'
assert spec.uid == 1000
assert spec.gid == 2000
assert spec.volume_mounts == {'foo': '/foo'}
assert spec.args == ['--foo']
assert spec.envs == ['FOO=0815']
assert spec.bind_mounts == [
[
'type=bind',
'source=lib/modules',
'destination=/lib/modules',
'ro=true'
]
]
assert spec.ports == [8080, 8443]
assert spec.dirs == ['foo', 'bar']
assert spec.files == {
'foo.conf': 'foo\nbar',
'bar.conf': ['foo', 'bar']
}
def test_custom_container_spec_config_json():
spec = CustomContainerSpec(service_id='foo', image='foo', dirs=None)
config_json = spec.config_json()
for key in ['entrypoint', 'uid', 'gid', 'bind_mounts', 'dirs']:
assert key not in config_json
def test_ingress_spec():
yaml_str = """service_type: ingress
service_id: rgw.foo
placement:
hosts:
- host1
- host2
- host3
spec:
virtual_ip: 192.168.20.1/24
backend_service: rgw.foo
frontend_port: 8080
monitor_port: 8081
"""
yaml_file = yaml.safe_load(yaml_str)
spec = ServiceSpec.from_json(yaml_file)
assert spec.service_type == "ingress"
assert spec.service_id == "rgw.foo"
assert spec.virtual_ip == "192.168.20.1/24"
assert spec.frontend_port == 8080
assert spec.monitor_port == 8081

View File

@ -5,7 +5,8 @@ import yaml
import pytest
from ceph.deployment.service_spec import HostPlacementSpec, PlacementSpec, \
ServiceSpec, RGWSpec, NFSServiceSpec, IscsiServiceSpec
ServiceSpec, RGWSpec, NFSServiceSpec, IscsiServiceSpec, AlertManagerSpec, \
CustomContainerSpec
from ceph.deployment.drive_group import DriveGroupSpec
from ceph.deployment.hostspec import SpecValidationError
@ -242,6 +243,19 @@ spec:
assert yaml.dump(object) == y
assert yaml.dump(ServiceSpec.from_json(object.to_json())) == y
def test_alertmanager_spec_1():
spec = AlertManagerSpec()
assert spec.service_type == 'alertmanager'
assert isinstance(spec.user_data, dict)
assert len(spec.user_data.keys()) == 0
def test_alertmanager_spec_2():
spec = AlertManagerSpec(user_data={'default_webhook_urls': ['foo']})
assert isinstance(spec.user_data, dict)
assert 'default_webhook_urls' in spec.user_data.keys()
@pytest.mark.parametrize("spec1, spec2, eq",
[
(
@ -335,3 +349,78 @@ def test_service_id_raises_invalid_char(s_type, s_id):
with pytest.raises(SpecValidationError):
spec = ServiceSpec.from_json(_get_dict_spec(s_type, s_id))
spec.validate()
def test_custom_container_spec():
spec = CustomContainerSpec(service_id='hello-world',
image='docker.io/library/hello-world:latest',
entrypoint='/usr/bin/bash',
uid=1000,
gid=2000,
volume_mounts={'foo': '/foo'},
args=['--foo'],
envs=['FOO=0815'],
bind_mounts=[
[
'type=bind',
'source=lib/modules',
'destination=/lib/modules',
'ro=true'
]
],
ports=[8080, 8443],
dirs=['foo', 'bar'],
files={
'foo.conf': 'foo\nbar',
'bar.conf': ['foo', 'bar']
})
assert spec.service_type == 'container'
assert spec.entrypoint == '/usr/bin/bash'
assert spec.uid == 1000
assert spec.gid == 2000
assert spec.volume_mounts == {'foo': '/foo'}
assert spec.args == ['--foo']
assert spec.envs == ['FOO=0815']
assert spec.bind_mounts == [
[
'type=bind',
'source=lib/modules',
'destination=/lib/modules',
'ro=true'
]
]
assert spec.ports == [8080, 8443]
assert spec.dirs == ['foo', 'bar']
assert spec.files == {
'foo.conf': 'foo\nbar',
'bar.conf': ['foo', 'bar']
}
def test_custom_container_spec_config_json():
spec = CustomContainerSpec(service_id='foo', image='foo', dirs=None)
config_json = spec.config_json()
for key in ['entrypoint', 'uid', 'gid', 'bind_mounts', 'dirs']:
assert key not in config_json
def test_ingress_spec():
yaml_str = """service_type: ingress
service_id: rgw.foo
placement:
hosts:
- host1
- host2
- host3
spec:
virtual_ip: 192.168.20.1/24
backend_service: rgw.foo
frontend_port: 8080
monitor_port: 8081
"""
yaml_file = yaml.safe_load(yaml_str)
spec = ServiceSpec.from_json(yaml_file)
assert spec.service_type == "ingress"
assert spec.service_id == "rgw.foo"
assert spec.virtual_ip == "192.168.20.1/24"
assert spec.frontend_port == 8080
assert spec.monitor_port == 8081