Customized blink a device light. By default running something like:
lsmcli local-disk-ident-led-on --path $path
If you must, you can customize this via:
ceph config-key set mgr/cephadm/lsmcli_blink_lights_cmd '<my jinja2 template>'
where my jinja2 template is something like:
lsmcli local-disk-{{ ident_fault }}-led-{{'on' if on else 'off'}} --path '{{ path or dev }}'
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
(cherry picked from commit
dc2dd8b19242d7b8da1f881ae128b2746d8ff398)
import json
import errno
import logging
+import shlex
from collections import defaultdict
from contextlib import contextmanager
from functools import wraps
return '\n'.join(out + err)
@trivial_completion
- def blink_device_light(self, ident_fault, on, locs) -> List[str]:
+ def blink_device_light(self, ident_fault: str, on: bool, locs: List[orchestrator.DeviceLightLoc]) -> List[str]:
+ """
+ Blink a device light. Calling something like::
+
+ lsmcli local-disk-ident-led-on --path $path
+
+ If you must, you can customize this via::
+
+ ceph config-key set mgr/cephadm/lsmcli_blink_lights_cmd '<my jinja2 template>'
+
+ See templates/lsmcli_blink_lights_cmd.j2
+ """
@forall_hosts
def blink(host, dev, path):
- cmd = [
- 'lsmcli',
- 'local-disk-%s-led-%s' % (
- ident_fault,
- 'on' if on else 'off'),
- '--path', path or dev,
- ]
+ j2_ctx = {
+ 'on': on,
+ 'ident_fault': ident_fault,
+ 'dev': dev,
+ 'path': path
+ }
+
+ custom_template = self.get_store('lsmcli_blink_lights_cmd', None)
+ if custom_template:
+ lsmcli_blink_lights_cmd = self.template.engine.render_plain(custom_template, j2_ctx)
+ else:
+ lsmcli_blink_lights_cmd = self.template.render('lsmcli_blink_lights_cmd.j2', j2_ctx)
+
+ cmd = shlex.split(lsmcli_blink_lights_cmd)
+
out, err, code = self._run_cephadm(
host, 'osd', 'shell', ['--'] + cmd,
error_ok=True)
import copy
from typing import Optional
-from jinja2 import Environment, PackageLoader, select_autoescape, StrictUndefined
+from jinja2 import Environment, PackageLoader, select_autoescape, StrictUndefined, Template
from jinja2 import exceptions as j2_exceptions
except j2_exceptions.TemplateNotFound as e:
raise TemplateNotFoundError(e.message)
+ def render_plain(self, source, context):
+ try:
+ template = self.env.from_string(source)
+ if context is None:
+ return template.render()
+ return template.render(context)
+ except j2_exceptions.UndefinedError as e:
+ raise UndefinedError(e.message)
+ except j2_exceptions.TemplateNotFound as e:
+ raise TemplateNotFoundError(e.message)
+
class TemplateMgr:
def __init__(self):
if context is not None:
ctx = {**ctx, **context}
return self.engine.render(name, ctx)
+
--- /dev/null
+lsmcli local-disk-{{ ident_fault }}-led-{{'on' if on else 'off'}} --path '{{ path or dev }}'
_run_cephadm.assert_called_with('test', 'osd', 'shell', [
'--', 'lsmcli', f'local-disk-{fault_ident}-led-{on_off}', '--path', 'dev'], error_ok=True)
+ @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm")
+ def test_blink_device_light_custom(self, _run_cephadm, cephadm_module):
+ _run_cephadm.return_value = '{}', '', 0
+ with with_host(cephadm_module, 'test'):
+ cephadm_module.set_store('lsmcli_blink_lights_cmd', 'echo hello')
+ c = cephadm_module.blink_device_light('ident', True, [('test', '', 'dev')])
+ assert wait(cephadm_module, c) == ['Set ident light for test: on']
+ _run_cephadm.assert_called_with('test', 'osd', 'shell', [
+ '--', 'echo', 'hello'], error_ok=True)
+
@pytest.mark.parametrize(
"spec, meth",
[