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
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
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
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",
[
(
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