From 6b1d6b3cd40d8945c7d61a667ef257bb79f0a16a Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 6 Mar 2020 14:53:22 -0600 Subject: [PATCH] mgr/cephadm: allow mon creation without explicit ip or addr Allow mons to be created if the public_network option is defined in the config database. Signed-off-by: Sage Weil --- src/pybind/mgr/cephadm/module.py | 34 ++++++++++++++------ src/pybind/mgr/cephadm/tests/test_cephadm.py | 4 +-- src/pybind/mgr/orchestrator/__init__.py | 2 +- src/pybind/mgr/orchestrator/_interface.py | 14 -------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 62ff645e012..daf1c04783c 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -2362,16 +2362,32 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): 'entity': 'mon.', }) - # infer whether this is a CIDR network, addrvec, or plain IP extra_config = '[mon.%s]\n' % name - if '/' in network: - extra_config += 'public network = %s\n' % network - elif network.startswith('[v') and network.endswith(']'): - extra_config += 'public addrv = %s\n' % network - elif ':' not in network: - extra_config += 'public addr = %s\n' % network + if network: + # infer whether this is a CIDR network, addrvec, or plain IP + if '/' in network: + extra_config += 'public network = %s\n' % network + elif network.startswith('[v') and network.endswith(']'): + extra_config += 'public addrv = %s\n' % network + elif ':' not in network: + extra_config += 'public addr = %s\n' % network + else: + raise OrchestratorError('Must specify a CIDR network, ceph addrvec, or plain IP: \'%s\'' % network) else: - raise RuntimeError('Must specify a CIDR network, ceph addrvec, or plain IP: \'%s\'' % network) + # try to get the public_network from the config + ret, network, err = self.mon_command({ + 'prefix': 'config get', + 'who': 'mon', + 'key': 'public_network', + }) + network = network.strip() # type: ignore + if ret: + raise RuntimeError('Unable to fetch cluster_network config option') + if not network: + raise OrchestratorError('Must set public_network config option or specify a CIDR network, ceph addrvec, or plain IP') + if '/' not in network: + raise OrchestratorError('public_network is set but does not look like a CIDR network: \'%s\'' % network) + extra_config += 'public network = %s\n' % network return self._create_daemon('mon', name, host, keyring=keyring, @@ -2379,8 +2395,6 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): def add_mon(self, spec): # type: (orchestrator.ServiceSpec) -> orchestrator.Completion - # current support requires a network to be specified - orchestrator.servicespec_validate_hosts_have_network_spec(spec) return self._add_daemon('mon', spec, self._create_mon) def _create_mgr(self, mgr_id, host): diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index db524617ed8..6080ee5503b 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -99,13 +99,13 @@ class TestCephadm(object): assert wait(cephadm_module, c) == [what + " rgw.myrgw.foobar from host 'test'"] - def test_mon_update(self, cephadm_module): + def test_mon_add(self, cephadm_module): with self._with_host(cephadm_module, 'test'): ps = PlacementSpec(hosts=['test:0.0.0.0=a'], count=1) c = cephadm_module.add_mon(ServiceSpec('mon', placement=ps)) assert wait(cephadm_module, c) == ["Deployed mon.a on host 'test'"] - with pytest.raises(OrchestratorError, match="is missing a network spec"): + with pytest.raises(OrchestratorError, match="Must set public_network config option or specify a CIDR network,"): ps = PlacementSpec(hosts=['test'], count=1) c = cephadm_module.add_mon(ServiceSpec('mon', placement=ps)) wait(cephadm_module, c) diff --git a/src/pybind/mgr/orchestrator/__init__.py b/src/pybind/mgr/orchestrator/__init__.py index e0843299f3a..05ac4601166 100644 --- a/src/pybind/mgr/orchestrator/__init__.py +++ b/src/pybind/mgr/orchestrator/__init__.py @@ -9,7 +9,7 @@ from ._interface import \ Orchestrator, OrchestratorClientMixin, \ OrchestratorValidationError, OrchestratorError, NoOrchestrator, \ ServiceSpec, NFSServiceSpec, RGWSpec, HostPlacementSpec, \ - servicespec_validate_add, servicespec_validate_hosts_have_network_spec, \ + servicespec_validate_add, \ ServiceDescription, InventoryFilter, PlacementSpec, HostSpec, \ DaemonDescription, \ InventoryHost, DeviceLightLoc, \ diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index b04eaf97887..41c7de32576 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -1651,20 +1651,6 @@ def servicespec_validate_add(self: ServiceSpec): raise OrchestratorValidationError('Cannot add Service: id required') -def servicespec_validate_hosts_have_network_spec(self: ServiceSpec): - # This must not be a method of ServiceSpec, otherwise you'll hunt - # sub-interpreter affinity bugs. - if not self.placement.hosts: - raise OrchestratorValidationError('Service specification: no hosts provided') - - for host, network, _ in self.placement.hosts: - if not network: - m = "Host '{host}' is missing a network spec\nE.g. {host}:1.2.3.0/24".format( - host=host) - logger.error( - f'validate_hosts_have_network_spec: id(OrchestratorValidationError)={id(OrchestratorValidationError)}') - raise OrchestratorValidationError(m) - class NFSServiceSpec(ServiceSpec): def __init__(self, service_id, pool=None, namespace=None, placement=None, -- 2.39.5