From 778704dd23b906c7c2ed50862d2001a01b2c7196 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 5 Feb 2020 17:19:56 -0600 Subject: [PATCH] mgr/orch: HostSpec -> HostPlacementSpec This object is about describing where to place a service on a host: it includes a host name and either an IP or network and possibly even a name for the service. Signed-off-by: Sage Weil --- src/pybind/mgr/cephadm/module.py | 12 ++++++------ src/pybind/mgr/orchestrator.py | 13 +++++++------ src/pybind/mgr/tests/test_orchestrator.py | 10 +++++----- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 319a50e89d6..d8dc967c3e6 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -30,7 +30,7 @@ from ceph.deployment.drive_selection import selector from mgr_module import MgrModule import mgr_util import orchestrator -from orchestrator import OrchestratorError, HostSpec, OrchestratorValidationError +from orchestrator import OrchestratorError, HostPlacementSpec, OrchestratorValidationError from . import remotes @@ -2168,7 +2168,7 @@ class BaseScheduler(object): * requires a placement_spec - `place(host_pool)` needs to return a List[HostSpec, ..] + `place(host_pool)` needs to return a List[HostPlacementSpec, ..] """ def __init__(self, placement_spec): @@ -2176,7 +2176,7 @@ class BaseScheduler(object): self.placement_spec = placement_spec def place(self, host_pool, count=None): - # type: (List, Optional[int]) -> List[HostSpec] + # type: (List, Optional[int]) -> List[HostPlacementSpec] raise NotImplementedError @@ -2190,10 +2190,10 @@ class SimpleScheduler(BaseScheduler): super(SimpleScheduler, self).__init__(placement_spec) def place(self, host_pool, count=None): - # type: (List, Optional[int]) -> List[HostSpec] + # type: (List, Optional[int]) -> List[HostPlacementSpec] if not host_pool: raise Exception('List of host candidates is empty') - host_pool = [HostSpec(x, '', '') for x in host_pool] + host_pool = [HostPlacementSpec(x, '', '') for x in host_pool] # shuffle for pseudo random selection random.shuffle(host_pool) return host_pool[:count] @@ -2241,7 +2241,7 @@ class NodeAssignment(object): # NOTE: This currently queries for all hosts without label restriction if self.spec.placement.label: logger.info("Found labels. Assinging nodes that match the label") - candidates = [HostSpec(x[0], '', '') for x in self.get_hosts_func()] # TODO: query for labels + candidates = [HostPlacementSpec(x[0], '', '') for x in self.get_hosts_func()] # TODO: query for labels logger.info('Assigning nodes to spec: {}'.format(candidates)) self.spec.placement.set_hosts(candidates) diff --git a/src/pybind/mgr/orchestrator.py b/src/pybind/mgr/orchestrator.py index 09fed945d55..d93bc26993d 100644 --- a/src/pybind/mgr/orchestrator.py +++ b/src/pybind/mgr/orchestrator.py @@ -35,7 +35,7 @@ except ImportError: logger = logging.getLogger(__name__) -class HostSpec(namedtuple('HostSpec', ['hostname', 'network', 'name'])): +class HostPlacementSpec(namedtuple('HostPlacementSpec', ['hostname', 'network', 'name'])): def __str__(self): res = '' res += self.hostname @@ -46,7 +46,8 @@ class HostSpec(namedtuple('HostSpec', ['hostname', 'network', 'name'])): return res -def parse_host_specs(host, require_network=True): +def parse_host_placement_specs(host, require_network=True): + # type: (str, Optional[bool]) -> HostPlacementSpec """ Split host into host, network, and (optional) daemon name parts. The network part can be an IP, CIDR, or ceph addrvec like '[v2:1.2.3.4:3300,v1:1.2.3.4:6789]'. @@ -68,7 +69,7 @@ def parse_host_specs(host, require_network=True): name_re = r'=(.*?)$' # assign defaults - host_spec = HostSpec('', '', '') + host_spec = HostPlacementSpec('', '', '') match_host = re.search(host_re, host) if match_host: @@ -1045,10 +1046,10 @@ class PlacementSpec(object): # type: (Optional[str], Optional[List], Optional[int]) -> None self.label = label if hosts: - if all([isinstance(host, HostSpec) for host in hosts]): - self.hosts = hosts # type: List[HostSpec] + if all([isinstance(host, HostPlacementSpec) for host in hosts]): + self.hosts = hosts # type: List[HostPlacementSpec] else: - self.hosts = [parse_host_specs(x, require_network=False) for x in hosts if x] + self.hosts = [parse_host_placement_specs(x, require_network=False) for x in hosts if x] else: self.hosts = [] diff --git a/src/pybind/mgr/tests/test_orchestrator.py b/src/pybind/mgr/tests/test_orchestrator.py index 3687e253d1e..b86e8cb5fe7 100644 --- a/src/pybind/mgr/tests/test_orchestrator.py +++ b/src/pybind/mgr/tests/test_orchestrator.py @@ -9,7 +9,7 @@ from ceph.deployment import inventory from orchestrator import raise_if_exception, RGWSpec, Completion, ProgressReference from orchestrator import InventoryNode, ServiceDescription from orchestrator import OrchestratorValidationError -from orchestrator import parse_host_specs +from orchestrator import parse_host_placement_specs @pytest.mark.parametrize("test_input,expected, require_network", @@ -24,8 +24,8 @@ from orchestrator import parse_host_specs ("myhost:[v1:10.1.1.10:6789,v2:10.1.1.11:3000]", ('myhost', '[v1:10.1.1.10:6789,v2:10.1.1.11:3000]', ''), True), ("myhost:[v1:10.1.1.10:6789,v2:10.1.1.11:3000]=sname", ('myhost', '[v1:10.1.1.10:6789,v2:10.1.1.11:3000]', 'sname'), True), ]) -def test_parse_host_specs(test_input, expected, require_network): - ret = parse_host_specs(test_input, require_network=require_network) +def test_parse_host_placement_specs(test_input, expected, require_network): + ret = parse_host_placement_specs(test_input, require_network=require_network) assert ret == expected assert str(ret) == test_input @@ -37,9 +37,9 @@ def test_parse_host_specs(test_input, expected, require_network): # empty string ("myhost=1"), ]) -def test_parse_host_specs_raises(test_input): +def test_parse_host_placement_specs_raises(test_input): with pytest.raises(ValueError): - ret = parse_host_specs(test_input) + ret = parse_host_placement_specs(test_input) def _test_resource(data, resource_class, extra=None): -- 2.39.5