]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: fix placement with label and host pattern 56107/head
authorAdam King <adking@redhat.com>
Wed, 14 Feb 2024 16:28:11 +0000 (11:28 -0500)
committerAdam King <adking@redhat.com>
Sun, 10 Mar 2024 21:04:01 +0000 (17:04 -0400)
Previously, when both the label and host pattern were
provided, only the label was actually used for the placement

Fixes: https://tracker.ceph.com/issues/64428
Signed-off-by: Adam King <adking@redhat.com>
(cherry picked from commit 106f34ba31c82dd87f4c3f9ad82d8ace81e6c689)

src/pybind/mgr/cephadm/schedule.py
src/pybind/mgr/cephadm/tests/test_scheduling.py
src/python-common/ceph/deployment/service_spec.py

index 6666d761ebcf919a07177a7079f851e84217c4ee..98d2fe99897eca6ffc14876bd41673f886083c28 100644 (file)
@@ -413,6 +413,8 @@ class HostAssignment(object):
                                 hostname=x.hostname, ports=self.ports_start)
                 for x in self.hosts_by_label(self.spec.placement.label)
             ]
+            if self.spec.placement.host_pattern:
+                ls = [h for h in ls if h.hostname in self.spec.placement.filter_matching_hostspecs(self.hosts)]
         elif self.spec.placement.host_pattern:
             ls = [
                 DaemonPlacement(daemon_type=self.primary_daemon_type,
index 067cd5028a2cf06b670a6f1471a3688b78fcd675..b58680dd5b3f8cd4fd630a41770c3642adcba0cb 100644 (file)
@@ -631,6 +631,17 @@ class NodeAssignmentTest(NamedTuple):
              'rgw:host2(*:81)', 'rgw:host3(*:81)'],
             ['rgw.c']
         ),
+        # label + host pattern
+        # Note all hosts will get the "foo" label, we are checking
+        # that it also filters on the host pattern when label is provided
+        NodeAssignmentTest(
+            'mgr',
+            PlacementSpec(label='foo', host_pattern='mgr*'),
+            'mgr1 mgr2 osd1'.split(),
+            [],
+            None, None,
+            ['mgr:mgr1', 'mgr:mgr2'], ['mgr:mgr1', 'mgr:mgr2'], []
+        ),
         # cephadm.py teuth case
         NodeAssignmentTest(
             'mgr',
index bcebf23c20822b567cbe27c9fef7b096fe1c0d95..13bf69182054f4cf4ecda0e27c47bcc541f54379 100644 (file)
@@ -190,8 +190,9 @@ class PlacementSpec(object):
             all_hosts = [hs.hostname for hs in hostspecs]
             return [h.hostname for h in self.hosts if h.hostname in all_hosts]
         if self.label:
-            return [hs.hostname for hs in hostspecs if self.label in hs.labels]
-        all_hosts = [hs.hostname for hs in hostspecs]
+            all_hosts = [hs.hostname for hs in hostspecs if self.label in hs.labels]
+        else:
+            all_hosts = [hs.hostname for hs in hostspecs]
         if self.host_pattern:
             return fnmatch.filter(all_hosts, self.host_pattern)
         return all_hosts