Merge PR #32209 into master

* refs/pull/32209/head:
	mgr/cephadm: Add unittest for service_action

Reviewed-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sage Weil 2019-12-13 20:12:53 -06:00
commit a577292103
2 changed files with 48 additions and 7 deletions

View File

@ -808,6 +808,8 @@ class CephadmOrchestrator(MgrModule, orchestrator.Orchestrator):
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,
@ -858,7 +860,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.Orchestrator):
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):
"""

View File

@ -38,13 +38,25 @@ class TestCephadm(object):
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
@ -79,6 +91,33 @@ class TestCephadm(object):
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)