]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pyhton-common: move some tests from cephadm/test_spec.py
authorSebastian Wagner <sewagner@redhat.com>
Fri, 23 Jul 2021 00:36:27 +0000 (02:36 +0200)
committerSebastian Wagner <sewagner@redhat.com>
Fri, 26 Nov 2021 10:19:50 +0000 (11:19 +0100)
Cause they don't have any dependencies to cephadm

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 7566aa99dd821b4e614918ea4d267bfa4d595131..458958973c84fe65be64bfd3e24c0e2e14ebc3c8 100644 (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
index a360f12632324d5e9ce6b25ca95a3fea5e8643a1..e8620b017339f6dc369e5a45f234e1be6a87c9fb 100644 (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