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