From f61f8e4d790fabf7fbd87c2b938a93eb2340aff1 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sun, 8 Mar 2020 12:01:09 -0500 Subject: [PATCH] mgr/cephadm: allow count == 0 Scale a service down to 0 without removing the spec. Signed-off-by: Sage Weil --- src/pybind/mgr/cephadm/module.py | 5 +++++ .../mgr/cephadm/tests/test_scheduling.py | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index dab91bed559..362dbeb8db1 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -2980,6 +2980,10 @@ class HostAssignment(object): """ Load hosts into the spec.placement.hosts container. """ + # count == 0 + if self.spec.placement.count == 0: + return [] + # respect any explicit host list if self.spec.placement.hosts and not self.spec.placement.count: logger.debug('Provided hosts: %s' % self.spec.placement.hosts) @@ -2994,6 +2998,7 @@ class HostAssignment(object): logger.debug('All hosts: {}'.format(candidates)) return candidates + count = 0 if self.spec.placement.hosts and \ self.spec.placement.count and \ diff --git a/src/pybind/mgr/cephadm/tests/test_scheduling.py b/src/pybind/mgr/cephadm/tests/test_scheduling.py index 7c6132c098d..abd3b3e4e2d 100644 --- a/src/pybind/mgr/cephadm/tests/test_scheduling.py +++ b/src/pybind/mgr/cephadm/tests/test_scheduling.py @@ -22,6 +22,15 @@ class NodeAssignmentTest(NamedTuple): [], ['smithi060'] ), + # zero count + NodeAssignmentTest( + 'mon', + PlacementSpec(count=0), + ['smithi060'], + [], + [] + ), + # all_hosts NodeAssignmentTest( 'mon', @@ -44,6 +53,17 @@ class NodeAssignmentTest(NamedTuple): ], ['host1', 'host2', 'host3'] ), + # zero count + partial host list + NodeAssignmentTest( + 'mon', + PlacementSpec(count=0, hosts=['host3']), + 'host1 host2 host3'.split(), + [ + DaemonDescription('mon', 'a', 'host1'), + DaemonDescription('mon', 'b', 'host2'), + ], + [] + ), # count + partial host list + existing NodeAssignmentTest( 'mon', -- 2.39.5