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 <sage@redhat.com>
This commit is contained in:
Sage Weil 2020-03-06 14:53:22 -06:00
parent f0dcf03d5e
commit 6b1d6b3cd4
4 changed files with 27 additions and 27 deletions

View File

@ -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):

View File

@ -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)

View File

@ -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, \

View File

@ -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,