import fnmatch
from contextlib import contextmanager
+from ceph.deployment.service_spec import PlacementSpec, ServiceSpec
from cephadm.module import CEPH_DATEFMT
try:
wait(m, m.add_host(HostSpec(hostname=name)))
yield
wait(m, m.remove_host(name))
+
+
+def assert_rm_service(cephadm, srv_name):
+ assert wait(cephadm, cephadm.remove_service(srv_name)) == f'Removed service {srv_name}'
+ cephadm._apply_all_services()
+
+
+@contextmanager
+def with_service(cephadm_module: CephadmOrchestrator, spec: ServiceSpec, meth, host: str):
+ if spec.placement.is_empty():
+ spec.placement = PlacementSpec(hosts=[host], count=1)
+ c = meth(cephadm_module, spec)
+ assert wait(cephadm_module, c) == f'Scheduled {spec.service_name()} update...'
+ specs = [d.spec for d in wait(cephadm_module, cephadm_module.describe_service())]
+ assert spec in specs
+
+ cephadm_module._apply_all_services()
+
+ dds = wait(cephadm_module, cephadm_module.list_daemons())
+ names = {dd.service_name() for dd in dds}
+ assert spec.service_name() in names, dds
+
+ yield
+
+ assert_rm_service(cephadm_module, spec.service_name())
\ No newline at end of file
HostSpec, OrchestratorError
from tests import mock
from .fixtures import cephadm_module, wait, _run_cephadm, match_glob, with_host, \
- with_cephadm_module
+ with_cephadm_module, with_service, assert_rm_service
from cephadm.module import CephadmOrchestrator, CEPH_DATEFMT
"""
"""
-def assert_rm_service(cephadm, srv_name):
- assert wait(cephadm, cephadm.remove_service(srv_name)) == f'Removed service {srv_name}'
- cephadm._apply_all_services()
-
-
def assert_rm_daemon(cephadm: CephadmOrchestrator, prefix, host):
dds: List[DaemonDescription] = wait(cephadm, cephadm.list_daemons(host=host))
d_names = [dd.name() for dd in dds if dd.name().startswith(prefix)]
assert False, 'Daemon not found'
-@contextmanager
-def with_service(cephadm_module: CephadmOrchestrator, spec: ServiceSpec, meth, host: str):
- if spec.placement.is_empty():
- spec.placement = PlacementSpec(hosts=[host], count=1)
- c = meth(cephadm_module, spec)
- assert wait(cephadm_module, c) == f'Scheduled {spec.service_name()} update...'
- specs = [d.spec for d in wait(cephadm_module, cephadm_module.describe_service())]
- assert spec in specs
-
- cephadm_module._apply_all_services()
-
- dds = wait(cephadm_module, cephadm_module.list_daemons())
- names = {dd.service_name() for dd in dds}
- assert spec.service_name() in names
-
- yield
-
- assert_rm_service(cephadm_module, spec.service_name())
-
-
class TestCephadm(object):
def test_get_unique_name(self, cephadm_module):