From: Sebastian Wagner Date: Fri, 25 Oct 2019 13:31:07 +0000 (+0200) Subject: mgr/orchestrator: Improve ceph CLI for blink lights X-Git-Tag: v15.1.0~1025^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a70ec42cad0e035ec02459e83991d14935812c6c;p=ceph.git mgr/orchestrator: Improve ceph CLI for blink lights Signed-off-by: Sebastian Wagner --- diff --git a/qa/tasks/mgr/test_orchestrator_cli.py b/qa/tasks/mgr/test_orchestrator_cli.py index 1f5875c9f9d9..80829c38efd1 100644 --- a/qa/tasks/mgr/test_orchestrator_cli.py +++ b/qa/tasks/mgr/test_orchestrator_cli.py @@ -106,7 +106,7 @@ class TestOrchestratorCli(MgrTestCase): for t in ["ident", "fault"]: self.assertNotIn(dev_id, _ls_lights(t)) - self._cmd("device", t + "-light-on", dev_id) + self._cmd("device", "light", "on", dev_id, t) self.assertIn(dev_id, _ls_lights(t)) health = { @@ -115,7 +115,7 @@ class TestOrchestratorCli(MgrTestCase): }[t] self.wait_for_health(health, 30) - self._cmd("device", t + "-light-off", dev_id) + self._cmd("device", "light", "off", dev_id, t) self.assertNotIn(dev_id, _ls_lights(t)) self.wait_for_health_clear(30) diff --git a/src/pybind/mgr/orchestrator.py b/src/pybind/mgr/orchestrator.py index ea0a65066797..d4d39a8dd462 100644 --- a/src/pybind/mgr/orchestrator.py +++ b/src/pybind/mgr/orchestrator.py @@ -6,14 +6,13 @@ Please see the ceph-mgr module developer's guide for more information. """ import sys import time -import fnmatch +from collections import namedtuple from functools import wraps import uuid import string import random import datetime - -import six +import copy from mgr_module import MgrModule, PersistentStoreDict from mgr_util import format_bytes diff --git a/src/pybind/mgr/orchestrator_cli/module.py b/src/pybind/mgr/orchestrator_cli/module.py index a009104c0cb6..ee8cb8735987 100644 --- a/src/pybind/mgr/orchestrator_cli/module.py +++ b/src/pybind/mgr/orchestrator_cli/module.py @@ -5,7 +5,7 @@ from functools import wraps from prettytable import PrettyTable try: - from typing import List, Set + from typing import List, Set, Optional except ImportError: pass # just for type checking. @@ -144,33 +144,21 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): self._refresh_health() raise - - @_write_cli(prefix='device fault-light-on', - cmd_args='name=devid,type=CephString', - desc='Enable device *fault* light') - def _device_fault_on(self, devid): - return self.light_on('fault', devid) - - @_write_cli(prefix='device ident-light-on', - cmd_args='name=devid,type=CephString', - desc='Enable device *ident* light') - def _device_ident_on(self, devid): - return self.light_on('ident', devid) - - - @_write_cli(prefix='device fault-light-off', - cmd_args='name=devid,type=CephString ' + @_write_cli(prefix='device light', + cmd_args='name=enable,type=CephChoices,strings=on|off ' + 'name=devid,type=CephString ' + 'name=light_type,type=CephChoices,strings=ident|fault,req=false ' 'name=force,type=CephBool,req=false', - desc='Disable device *fault* light') - def _device_fault_off(self, devid, force=False): - return self.light_off('fault', devid, force) - - @_write_cli(prefix='device ident-light-off', - cmd_args='name=devid,type=CephString ' - 'name=force,type=CephBool,req=false', - desc='Disable device *ident* light') - def _device_ident_off(self, devid, force=False): - return self.light_off('ident', devid, force) + desc='Enable or disable the device light. Default type is `ident`\n' + 'Usage: device light (on|off) [ident|fault] [--force]') + def _device_light(self, enable, devid, light_type=None, force=False): + # type: (str, str, Optional[str], bool) -> HandleCommandResult + light_type = light_type or 'ident' + on = enable == 'on' + if on: + return self.light_on(light_type, devid) + else: + return self.light_off(light_type, devid, force) def _select_orchestrator(self): return self.get_module_option("orchestrator")