From: Sebastian Wagner Date: Tue, 11 Feb 2020 12:22:49 +0000 (+0100) Subject: mgr/cephadm: Bail if we cannot find a host for services X-Git-Tag: v15.1.1~451^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e1ab8304a809e00a4516af92891e839708dd8def;p=ceph.git mgr/cephadm: Bail if we cannot find a host for services This would require tricky manipulation of ports etc. Signed-off-by: Sebastian Wagner --- diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 9c32b2fe4ff4..442da3a5164f 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1776,6 +1776,12 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): ) daemons.append(sd) num_added += 1 + + if (len(our_daemons) + num_added) < spec.count: + missing = spec.count - len(our_daemons) - num_added + available = [p.hostname for p in hosts_without_daemons] + m = f'Cannot find placement for {missing} daemons. available hosts = {available}' + raise orchestrator.OrchestratorError(m) return create_func(args) diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index d7399667c88d..e4a02a170c27 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -2,6 +2,8 @@ import json from contextlib import contextmanager import fnmatch +import pytest + from ceph.deployment.drive_group import DriveGroupSpec, DeviceSelection try: @@ -10,7 +12,7 @@ except ImportError: pass from orchestrator import ServiceDescription, InventoryNode, \ - ServiceSpec, PlacementSpec, RGWSpec, HostSpec + ServiceSpec, PlacementSpec, RGWSpec, HostSpec, OrchestratorError from tests import mock from .fixtures import cephadm_module, wait @@ -186,15 +188,37 @@ class TestCephadm(object): with self._with_host(cephadm_module, 'host1'): with self._with_host(cephadm_module, 'host2'): ps = PlacementSpec(hosts=['host1'], count=1) - c = cephadm_module.add_rgw(RGWSpec('realm', 'zone', placement=ps)) + c = cephadm_module.add_rgw(RGWSpec('realm', 'zone1', placement=ps)) [out] = wait(cephadm_module, c) - match_glob(out, "Deployed rgw.realm.zone.host1.* on host 'host1'") - + match_glob(out, "Deployed rgw.realm.zone1.host1.* on host 'host1'") ps = PlacementSpec(hosts=['host1', 'host2'], count=2) - c = cephadm_module.update_rgw(RGWSpec('realm', 'zone', placement=ps)) + c = cephadm_module.update_rgw(RGWSpec('realm', 'zone1', placement=ps)) [out] = wait(cephadm_module, c) - match_glob(out, "Deployed rgw.realm.zone.host2.* on host 'host2'") + match_glob(out, "Deployed rgw.realm.zone1.host2.* on host 'host2'") + + @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('{}')) + @mock.patch("cephadm.module.CephadmOrchestrator.send_command") + @mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command) + @mock.patch("cephadm.module.CephadmOrchestrator._get_connection") + def test_rgw_update_fail(self, _send_command, _get_connection, cephadm_module): + + with self._with_host(cephadm_module, 'host1'): + with self._with_host(cephadm_module, 'host2'): + ps = PlacementSpec(hosts=['host1'], count=1) + c = cephadm_module.add_rgw(RGWSpec('realm', 'zone1', placement=ps)) + [out] = wait(cephadm_module, c) + match_glob(out, "Deployed rgw.realm.zone1.host1.* on host 'host1'") + + ps = PlacementSpec(hosts=['host2'], count=1) + c = cephadm_module.add_rgw(RGWSpec('realm', 'zone2', placement=ps)) + [out] = wait(cephadm_module, c) + match_glob(out, "Deployed rgw.realm.zone2.host2.* on host 'host2'") + + with pytest.raises(OrchestratorError): + ps = PlacementSpec(hosts=['host1', 'host2'], count=2) + c = cephadm_module.update_rgw(RGWSpec('realm', 'zone1', placement=ps)) + [out] = wait(cephadm_module, c) @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm(