]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: fix placement with label and host pattern 56088/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 19:23:42 +0000 (15:23 -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 eabdedf95103fa8050b3d80027ecc65a03b54fd1..e9b2078786dca5d3b07e2998a0a9f457a5969912 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 11beffd158e6d77735dd8dfcac29392e71c7aebe..dadc6a4c0d8b6cc7af82853b155d5789b19b0db5 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 55963053106119d72d12651245718bcd8fade6f5..09e8fd1a765bfc74e9c485d5a2ef9f429a7be76b 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