From e1ab8304a809e00a4516af92891e839708dd8def Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Tue, 11 Feb 2020 13:22:49 +0100 Subject: [PATCH] mgr/cephadm: Bail if we cannot find a host for services This would require tricky manipulation of ports etc. Signed-off-by: Sebastian Wagner --- src/pybind/mgr/cephadm/module.py | 6 ++++ src/pybind/mgr/cephadm/tests/test_cephadm.py | 36 ++++++++++++++++---- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 9c32b2fe4ff4b..442da3a5164fe 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 d7399667c88d4..e4a02a170c27c 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( -- 2.39.5