]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/orchestrator: Improve ceph CLI for blink lights
authorSebastian Wagner <sebastian.wagner@suse.com>
Fri, 25 Oct 2019 13:31:07 +0000 (15:31 +0200)
committerSebastian Wagner <sebastian.wagner@suse.com>
Tue, 5 Nov 2019 12:55:12 +0000 (13:55 +0100)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
qa/tasks/mgr/test_orchestrator_cli.py
src/pybind/mgr/orchestrator.py
src/pybind/mgr/orchestrator_cli/module.py

index 1f5875c9f9d9d5290eb932c5797b4427646a4f59..80829c38efd121e807e1acbaf0e92596f0da047d 100644 (file)
@@ -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)
index ea0a650667970d8ebbfe76b09d75375e76458047..d4d39a8dd462977c3774451987036942b39ec814 100644 (file)
@@ -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
index a009104c0cb6b961d16d90fd7f941b50e0a7b9ed..ee8cb8735987d400efbf6aec6ffec50616ee75d9 100644 (file)
@@ -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) <devid> [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")