return trivial_result(["Reload is a no-op"])
def _proc_daemons(daemons):
+ if service_name is None and service_id is None:
+ raise ValueError('service_name or service_id required')
args = []
for d in daemons:
args.append((d.service_type, d.service_instance,
error_ok=True)
self.service_cache.invalidate(host)
self.log.debug('_service_action code %s out %s' % (code, out))
- return trivial_result("{} {} from host '{}'".format(action, name, host))
+ return "{} {} from host '{}'".format(action, name, host)
def get_inventory(self, node_filter=None, refresh=False):
"""
def _wait(self, m, c):
# type: (CephadmOrchestrator, Completion) -> Any
m.process([c])
- m.process([c])
- for _ in range(30):
- if c.is_finished:
- raise_if_exception(c)
- return c.result
- time.sleep(0.1)
+ try:
+ import pydevd # if in debugger
+ while True: # don't timeout
+ if c.is_finished:
+ raise_if_exception(c)
+ return c.result
+ time.sleep(0.1)
+ except ImportError: # not in debugger
+ for i in range(30):
+ if i % 10 == 0:
+ m.process([c])
+ if c.is_finished:
+ raise_if_exception(c)
+ return c.result
+ time.sleep(0.1)
+ assert False, "timeout" + str(c._state)
+
+ m.process([c])
assert False, "timeout" + str(c._state)
@contextmanager
c = cephadm_module.get_inventory()
assert self._wait(cephadm_module, c) == [InventoryNode('test')]
+ @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm(
+ json.dumps([
+ dict(
+ name='rgw.myrgw.foobar',
+ style='cephadm',
+ fsid='fsid',
+ container_id='container_id',
+ version='version',
+ state='running',
+ )
+ ])
+ ))
+ @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_service_action(self, _send_command, _get_connection, cephadm_module):
+ cephadm_module._cluster_fsid = "fsid"
+ cephadm_module.service_cache_timeout = 10
+ with self._with_host(cephadm_module, 'test'):
+ c = cephadm_module.service_action('redeploy', 'rgw', service_id='myrgw.foobar')
+ assert self._wait(cephadm_module, c) == ["(Re)deployed rgw.myrgw.foobar on host 'test'"]
+
+ for what in ('start', 'stop', 'restart'):
+ c = cephadm_module.service_action(what, 'rgw', service_id='myrgw.foobar')
+ assert self._wait(cephadm_module, c) == [what + " rgw.myrgw.foobar from 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)