]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: implement prometheus add/update
authorSage Weil <sage@redhat.com>
Thu, 13 Feb 2020 15:11:25 +0000 (09:11 -0600)
committerSage Weil <sage@redhat.com>
Thu, 13 Feb 2020 19:59:36 +0000 (13:59 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/tests/test_cephadm.py

index bb0d420e8118a3f06f36e7ff3c87c572318208e4..66d9ccad1988accdd975c7436a2895fcb1d97be9 100644 (file)
@@ -2167,6 +2167,40 @@ scrape_configs:
         })
         return j
 
+    def add_prometheus(self, spec):
+        spec = NodeAssignment(spec=spec, get_hosts_func=self._get_hosts, service_type='prometheus').load()
+        self.log.debug('nodes %s' % spec.placement.hosts)
+
+        def _add(daemons):
+            args = []
+            num_added = 0
+            for host, _, name in spec.placement.hosts:
+                if num_added >= spec.count:
+                    break
+                daemon_id = self.get_unique_name(host, daemons, None, name)
+                self.log.debug('placing prometheus.%s on host %s' % (daemon_id,
+                                                                     host))
+                args.append((daemon_id, host))
+
+                # add to daemon list so next name(s) will also be unique
+                sd = orchestrator.ServiceDescription()
+                sd.service_instance = daemon_id
+                sd.service_type = 'prometheus'
+                sd.nodename = host
+                daemons.append(sd)
+                num_added += 1
+            return self._create_prometheus(args)
+
+        return self._get_daemons('prometheus').then(_add)
+
+    @async_map_completion
+    def _create_prometheus(self, daemon_id, host):
+        return self._create_daemon('prometheus', daemon_id, host)
+
+    def apply_prometheus(self, spec):
+        spec = NodeAssignment(spec=spec, get_hosts_func=self._get_hosts, service_type='prometheus').load()
+        return self._update_service('prometheus', self.add_prometheus, spec)
+
     def _get_container_image_id(self, image_name):
         # pick a random host...
         host = None
index 929edf3c5990426e9f82f28bb22f13752d311fbb..cf9b1bfe3c23d6206533dea9d986e573e011fb7c 100644 (file)
@@ -273,6 +273,25 @@ class TestCephadm(object):
             match_glob(out, "Deployed rbd-mirror.* on host 'test'")
 
 
+    @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('{}'))
+    @mock.patch("cephadm.module.CephadmOrchestrator.send_command")
+    @mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command)
+    @mock.patch("cephadm.module.CephadmOrchestrator._get_connection")
+    def test_prometheus(self, _send_command, _get_connection, cephadm_module):
+        with self._with_host(cephadm_module, 'test'):
+            ps = PlacementSpec(hosts=['test'], count=1)
+
+            c = cephadm_module.add_prometheus(ServiceSpec(placement=ps))
+            [out] = wait(cephadm_module, c)
+            assert "Deployed prometheus." in out
+            assert " on host 'test'" in out
+
+            ps = PlacementSpec(hosts=['test'], count=2)
+            c = cephadm_module.apply_prometheus(ServiceSpec(placement=ps))
+            [out] = wait(cephadm_module, c)
+            assert "Deployed prometheus." in out
+            assert " on host 'test'" in out
+
     @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('{}'))
     @mock.patch("cephadm.module.CephadmOrchestrator.send_command")
     @mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command)