]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: allow mon creation without explicit ip or addr
authorSage Weil <sage@redhat.com>
Fri, 6 Mar 2020 20:53:22 +0000 (14:53 -0600)
committerSage Weil <sage@redhat.com>
Sat, 7 Mar 2020 17:22:55 +0000 (11:22 -0600)
Allow mons to be created if the public_network option is defined in the
config database.

Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/tests/test_cephadm.py
src/pybind/mgr/orchestrator/__init__.py
src/pybind/mgr/orchestrator/_interface.py

index 62ff645e012b7aa956fe8198bb7131b57398b676..daf1c04783cefbdc8b7dc0d66b533b8dab052f1f 100644 (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):
index db524617ed8a64a233f9fd30e80d2d78faf876af..6080ee5503b314908a624ad0dbc20858f0d0feeb 100644 (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)
index e0843299f3af051cd6bb04d6067da1aee0114494..05ac4601166d5ea718d455eb92ec214c93d1ce9b 100644 (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, \
index b04eaf97887ffedf6209c945dd7d7b296b8e58de..41c7de325763de81e4e8ee3f257dfb83246acdb6 100644 (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,