From: Sage Weil Date: Fri, 9 Apr 2021 18:19:37 +0000 (-0400) Subject: mgr/cephadm: include daemon_type in DaemonPlacement X-Git-Tag: v16.2.2~1^2~54 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=590dcfb3d1dfa1ab0f5dde5d1fb7fe89df1d67a4;p=ceph.git mgr/cephadm: include daemon_type in DaemonPlacement Initially, this will always match the service_type. Signed-off-by: Sage Weil (cherry picked from commit d7b4a51a520d5d720fe784d64ac7864e828dea4a) --- diff --git a/src/pybind/mgr/cephadm/schedule.py b/src/pybind/mgr/cephadm/schedule.py index 7583a2042fa64..45f97d2269611 100644 --- a/src/pybind/mgr/cephadm/schedule.py +++ b/src/pybind/mgr/cephadm/schedule.py @@ -12,6 +12,7 @@ T = TypeVar('T') class DaemonPlacement(NamedTuple): + daemon_type: str hostname: str network: str = '' # for mons only name: str = '' @@ -19,7 +20,7 @@ class DaemonPlacement(NamedTuple): ports: List[int] = [] def __str__(self) -> str: - res = self.hostname + res = self.daemon_type + ':' + self.hostname other = [] if self.network: other.append(f'network={self.network}') @@ -33,6 +34,7 @@ class DaemonPlacement(NamedTuple): def renumber_ports(self, n: int) -> 'DaemonPlacement': return DaemonPlacement( + self.daemon_type, self.hostname, self.network, self.name, @@ -41,6 +43,8 @@ class DaemonPlacement(NamedTuple): ) def matches_daemon(self, dd: DaemonDescription) -> bool: + if self.daemon_type != dd.daemon_type: + return False if self.hostname != dd.hostname: return False # fixme: how to match against network? @@ -63,9 +67,12 @@ class HostAssignment(object): networks: Dict[str, Dict[str, Dict[str, List[str]]]] = {}, filter_new_host=None, # type: Optional[Callable[[str],bool]] allow_colo: bool = False, + primary_daemon_type: Optional[str] = None, + per_host_sidecar: Optional[str] = None, ): assert spec self.spec = spec # type: ServiceSpec + self.primary_daemon_type = primary_daemon_type or spec.service_type self.hosts: List[orchestrator.HostSpec] = hosts self.filter_new_host = filter_new_host self.service_name = spec.service_name() @@ -214,18 +221,21 @@ class HostAssignment(object): def get_candidates(self) -> List[DaemonPlacement]: if self.spec.placement.hosts: ls = [ - DaemonPlacement(hostname=h.hostname, network=h.network, name=h.name, + DaemonPlacement(daemon_type=self.primary_daemon_type, + hostname=h.hostname, network=h.network, name=h.name, ports=self.ports_start) for h in self.spec.placement.hosts ] elif self.spec.placement.label: ls = [ - DaemonPlacement(hostname=x.hostname, ports=self.ports_start) + DaemonPlacement(daemon_type=self.primary_daemon_type, + hostname=x.hostname, ports=self.ports_start) for x in self.hosts_by_label(self.spec.placement.label) ] elif self.spec.placement.host_pattern: ls = [ - DaemonPlacement(hostname=x, ports=self.ports_start) + DaemonPlacement(daemon_type=self.primary_daemon_type, + hostname=x, ports=self.ports_start) for x in self.spec.placement.filter_matching_hostspecs(self.hosts) ] elif ( @@ -233,7 +243,8 @@ class HostAssignment(object): or self.spec.placement.count_per_host is not None ): ls = [ - DaemonPlacement(hostname=x.hostname, ports=self.ports_start) + DaemonPlacement(daemon_type=self.primary_daemon_type, + hostname=x.hostname, ports=self.ports_start) for x in self.hosts ] else: @@ -247,7 +258,8 @@ class HostAssignment(object): for p in orig: ip = self.find_ip_on_host(p.hostname, self.spec.networks) if ip: - ls.append(DaemonPlacement(hostname=p.hostname, network=p.network, + ls.append(DaemonPlacement(daemon_type=self.primary_daemon_type, + hostname=p.hostname, network=p.network, name=p.name, ports=p.ports, ip=ip)) else: logger.debug( diff --git a/src/pybind/mgr/cephadm/tests/test_scheduling.py b/src/pybind/mgr/cephadm/tests/test_scheduling.py index bfcdba906f6c9..bed12651f9437 100644 --- a/src/pybind/mgr/cephadm/tests/test_scheduling.py +++ b/src/pybind/mgr/cephadm/tests/test_scheduling.py @@ -213,17 +213,22 @@ def test_daemon_placement_renumber(dp, n, result): 'dp,dd,result', [ ( - DaemonPlacement(hostname='host1'), + DaemonPlacement(daemon_type='mgr', hostname='host1'), DaemonDescription('mgr', 'a', 'host1'), True ), ( - DaemonPlacement(hostname='host1', name='a'), + DaemonPlacement(daemon_type='mgr', hostname='host1', name='a'), DaemonDescription('mgr', 'a', 'host1'), True ), ( - DaemonPlacement(hostname='host1', name='a'), + DaemonPlacement(daemon_type='mon', hostname='host1', name='a'), + DaemonDescription('mgr', 'a', 'host1'), + False + ), + ( + DaemonPlacement(daemon_type='mgr', hostname='host1', name='a'), DaemonDescription('mgr', 'b', 'host1'), False ), @@ -386,7 +391,7 @@ class NodeAssignmentTest(NamedTuple): PlacementSpec(hosts=['smithi060']), ['smithi060'], [], - ['smithi060'], ['smithi060'], [] + ['mgr:smithi060'], ['mgr:smithi060'], [] ), # all_hosts NodeAssignmentTest( @@ -397,7 +402,9 @@ class NodeAssignmentTest(NamedTuple): DaemonDescription('mgr', 'a', 'host1'), DaemonDescription('mgr', 'b', 'host2'), ], - ['host1', 'host2', 'host3'], ['host3'], [] + ['mgr:host1', 'mgr:host2', 'mgr:host3'], + ['mgr:host3'], + [] ), # all_hosts + count_per_host NodeAssignmentTest( @@ -408,8 +415,8 @@ class NodeAssignmentTest(NamedTuple): DaemonDescription('mds', 'a', 'host1'), DaemonDescription('mds', 'b', 'host2'), ], - ['host1', 'host2', 'host3', 'host1', 'host2', 'host3'], - ['host3', 'host1', 'host2', 'host3'], + ['mds:host1', 'mds:host2', 'mds:host3', 'mds:host1', 'mds:host2', 'mds:host3'], + ['mds:host3', 'mds:host1', 'mds:host2', 'mds:host3'], [] ), # count that is bigger than the amount of hosts. Truncate to len(hosts) @@ -419,7 +426,9 @@ class NodeAssignmentTest(NamedTuple): PlacementSpec(count=4), 'host1 host2 host3'.split(), [], - ['host1', 'host2', 'host3'], ['host1', 'host2', 'host3'], [] + ['mgr:host1', 'mgr:host2', 'mgr:host3'], + ['mgr:host1', 'mgr:host2', 'mgr:host3'], + [] ), # count that is bigger than the amount of hosts; wrap around. NodeAssignmentTest( @@ -427,8 +436,8 @@ class NodeAssignmentTest(NamedTuple): PlacementSpec(count=6), 'host1 host2 host3'.split(), [], - ['host1', 'host2', 'host3', 'host1', 'host2', 'host3'], - ['host1', 'host2', 'host3', 'host1', 'host2', 'host3'], + ['mds:host1', 'mds:host2', 'mds:host3', 'mds:host1', 'mds:host2', 'mds:host3'], + ['mds:host1', 'mds:host2', 'mds:host3', 'mds:host1', 'mds:host2', 'mds:host3'], [] ), # count + partial host list @@ -440,7 +449,9 @@ class NodeAssignmentTest(NamedTuple): DaemonDescription('mgr', 'a', 'host1'), DaemonDescription('mgr', 'b', 'host2'), ], - ['host3'], ['host3'], ['mgr.a', 'mgr.b'] + ['mgr:host3'], + ['mgr:host3'], + ['mgr.a', 'mgr.b'] ), # count + partial host list (with colo) NodeAssignmentTest( @@ -448,10 +459,12 @@ class NodeAssignmentTest(NamedTuple): PlacementSpec(count=3, hosts=['host3']), 'host1 host2 host3'.split(), [ - DaemonDescription('mgr', 'a', 'host1'), - DaemonDescription('mgr', 'b', 'host2'), + DaemonDescription('mds', 'a', 'host1'), + DaemonDescription('mds', 'b', 'host2'), ], - ['host3', 'host3', 'host3'], ['host3', 'host3', 'host3'], ['mgr.a', 'mgr.b'] + ['mds:host3', 'mds:host3', 'mds:host3'], + ['mds:host3', 'mds:host3', 'mds:host3'], + ['mds.a', 'mds.b'] ), # count 1 + partial host list NodeAssignmentTest( @@ -462,7 +475,9 @@ class NodeAssignmentTest(NamedTuple): DaemonDescription('mgr', 'a', 'host1'), DaemonDescription('mgr', 'b', 'host2'), ], - ['host3'], ['host3'], ['mgr.a', 'mgr.b'] + ['mgr:host3'], + ['mgr:host3'], + ['mgr.a', 'mgr.b'] ), # count + partial host list + existing NodeAssignmentTest( @@ -472,7 +487,9 @@ class NodeAssignmentTest(NamedTuple): [ DaemonDescription('mgr', 'a', 'host1'), ], - ['host3'], ['host3'], ['mgr.a'] + ['mgr:host3'], + ['mgr:host3'], + ['mgr.a'] ), # count + partial host list + existing (deterministic) NodeAssignmentTest( @@ -482,7 +499,9 @@ class NodeAssignmentTest(NamedTuple): [ DaemonDescription('mgr', 'a', 'host1'), ], - ['host1'], [], [] + ['mgr:host1'], + [], + [] ), # count + partial host list + existing (deterministic) NodeAssignmentTest( @@ -492,7 +511,9 @@ class NodeAssignmentTest(NamedTuple): [ DaemonDescription('mgr', 'a', 'host2'), ], - ['host1'], ['host1'], ['mgr.a'] + ['mgr:host1'], + ['mgr:host1'], + ['mgr.a'] ), # label only NodeAssignmentTest( @@ -500,7 +521,9 @@ class NodeAssignmentTest(NamedTuple): PlacementSpec(label='foo'), 'host1 host2 host3'.split(), [], - ['host1', 'host2', 'host3'], ['host1', 'host2', 'host3'], [] + ['mgr:host1', 'mgr:host2', 'mgr:host3'], + ['mgr:host1', 'mgr:host2', 'mgr:host3'], + [] ), # label + count (truncate to host list) NodeAssignmentTest( @@ -508,7 +531,9 @@ class NodeAssignmentTest(NamedTuple): PlacementSpec(count=4, label='foo'), 'host1 host2 host3'.split(), [], - ['host1', 'host2', 'host3'], ['host1', 'host2', 'host3'], [] + ['mgr:host1', 'mgr:host2', 'mgr:host3'], + ['mgr:host1', 'mgr:host2', 'mgr:host3'], + [] ), # label + count (with colo) NodeAssignmentTest( @@ -516,8 +541,8 @@ class NodeAssignmentTest(NamedTuple): PlacementSpec(count=6, label='foo'), 'host1 host2 host3'.split(), [], - ['host1', 'host2', 'host3', 'host1', 'host2', 'host3'], - ['host1', 'host2', 'host3', 'host1', 'host2', 'host3'], + ['mds:host1', 'mds:host2', 'mds:host3', 'mds:host1', 'mds:host2', 'mds:host3'], + ['mds:host1', 'mds:host2', 'mds:host3', 'mds:host1', 'mds:host2', 'mds:host3'], [] ), # label only + count_per_hst @@ -526,10 +551,10 @@ class NodeAssignmentTest(NamedTuple): PlacementSpec(label='foo', count_per_host=3), 'host1 host2 host3'.split(), [], - ['host1', 'host2', 'host3', 'host1', 'host2', 'host3', - 'host1', 'host2', 'host3'], - ['host1', 'host2', 'host3', 'host1', 'host2', 'host3', - 'host1', 'host2', 'host3'], + ['mds:host1', 'mds:host2', 'mds:host3', 'mds:host1', 'mds:host2', 'mds:host3', + 'mds:host1', 'mds:host2', 'mds:host3'], + ['mds:host1', 'mds:host2', 'mds:host3', 'mds:host1', 'mds:host2', 'mds:host3', + 'mds:host1', 'mds:host2', 'mds:host3'], [] ), # host_pattern @@ -538,7 +563,9 @@ class NodeAssignmentTest(NamedTuple): PlacementSpec(host_pattern='mgr*'), 'mgrhost1 mgrhost2 datahost'.split(), [], - ['mgrhost1', 'mgrhost2'], ['mgrhost1', 'mgrhost2'], [] + ['mgr:mgrhost1', 'mgr:mgrhost2'], + ['mgr:mgrhost1', 'mgr:mgrhost2'], + [] ), # host_pattern + count_per_host NodeAssignmentTest( @@ -546,8 +573,8 @@ class NodeAssignmentTest(NamedTuple): PlacementSpec(host_pattern='mds*', count_per_host=3), 'mdshost1 mdshost2 datahost'.split(), [], - ['mdshost1', 'mdshost2', 'mdshost1', 'mdshost2', 'mdshost1', 'mdshost2'], - ['mdshost1', 'mdshost2', 'mdshost1', 'mdshost2', 'mdshost1', 'mdshost2'], + ['mds:mdshost1', 'mds:mdshost2', 'mds:mdshost1', 'mds:mdshost2', 'mds:mdshost1', 'mds:mdshost2'], + ['mds:mdshost1', 'mds:mdshost2', 'mds:mdshost1', 'mds:mdshost2', 'mds:mdshost1', 'mds:mdshost2'], [] ), # label + count_per_host + ports @@ -556,10 +583,10 @@ class NodeAssignmentTest(NamedTuple): PlacementSpec(count=6, label='foo'), 'host1 host2 host3'.split(), [], - ['host1(*:80)', 'host2(*:80)', 'host3(*:80)', - 'host1(*:81)', 'host2(*:81)', 'host3(*:81)'], - ['host1(*:80)', 'host2(*:80)', 'host3(*:80)', - 'host1(*:81)', 'host2(*:81)', 'host3(*:81)'], + ['rgw:host1(*:80)', 'rgw:host2(*:80)', 'rgw:host3(*:80)', + 'rgw:host1(*:81)', 'rgw:host2(*:81)', 'rgw:host3(*:81)'], + ['rgw:host1(*:80)', 'rgw:host2(*:80)', 'rgw:host3(*:80)', + 'rgw:host1(*:81)', 'rgw:host2(*:81)', 'rgw:host3(*:81)'], [] ), # label + count_per_host + ports (+ xisting) @@ -572,10 +599,10 @@ class NodeAssignmentTest(NamedTuple): DaemonDescription('rgw', 'b', 'host2', ports=[80]), DaemonDescription('rgw', 'c', 'host1', ports=[82]), ], - ['host1(*:80)', 'host2(*:80)', 'host3(*:80)', - 'host1(*:81)', 'host2(*:81)', 'host3(*:81)'], - ['host1(*:80)', 'host3(*:80)', - 'host2(*:81)', 'host3(*:81)'], + ['rgw:host1(*:80)', 'rgw:host2(*:80)', 'rgw:host3(*:80)', + 'rgw:host1(*:81)', 'rgw:host2(*:81)', 'rgw:host3(*:81)'], + ['rgw:host1(*:80)', 'rgw:host3(*:80)', + 'rgw:host2(*:81)', 'rgw:host3(*:81)'], ['rgw.c'] ), # cephadm.py teuth case @@ -587,7 +614,7 @@ class NodeAssignmentTest(NamedTuple): DaemonDescription('mgr', 'y', 'host1'), DaemonDescription('mgr', 'x', 'host2'), ], - ['host1(name=y)', 'host2(name=x)'], + ['mgr:host1(name=y)', 'mgr:host2(name=x)'], [], [] ), ]) @@ -775,12 +802,12 @@ class NodeAssignmentTest4(NamedTuple): 'host3': {'192.168.0.0/16': {'eth0': ['192.168.0.1']}}, }, [], - ['host1(10.0.0.1:80)', 'host2(10.0.0.2:80)', - 'host1(10.0.0.1:81)', 'host2(10.0.0.2:81)', - 'host1(10.0.0.1:82)', 'host2(10.0.0.2:82)'], - ['host1(10.0.0.1:80)', 'host2(10.0.0.2:80)', - 'host1(10.0.0.1:81)', 'host2(10.0.0.2:81)', - 'host1(10.0.0.1:82)', 'host2(10.0.0.2:82)'], + ['rgw:host1(10.0.0.1:80)', 'rgw:host2(10.0.0.2:80)', + 'rgw:host1(10.0.0.1:81)', 'rgw:host2(10.0.0.2:81)', + 'rgw:host1(10.0.0.1:82)', 'rgw:host2(10.0.0.2:82)'], + ['rgw:host1(10.0.0.1:80)', 'rgw:host2(10.0.0.2:80)', + 'rgw:host1(10.0.0.1:81)', 'rgw:host2(10.0.0.2:81)', + 'rgw:host1(10.0.0.1:82)', 'rgw:host2(10.0.0.2:82)'], [] ), ])