]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph.in: improve the interactive mode
authorKefu Chai <kchai@redhat.com>
Thu, 23 Apr 2015 17:27:44 +0000 (01:27 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 27 May 2015 04:20:46 +0000 (12:20 +0800)
* if ceph is not reading from a tty, expect EOF instead of "quit"
  as the end of input.
* do not panic at seeing the EOF
* update the test case test_mon_injectargs_SI(). since we disables
  "ceph injectargs <args,...>" in a458bd83, in which the arguments
  of "injectargs" are supposed to be consumed by "tell" instead.
  so "ceph injectargs ..." is taken as an incomplete command, and
  this command will bring ceph cli into the interactive mode,
  redirecting its stdin to /dev/null helps ceph cli quit the loop,
  but in a way of throwing EOFError exception. this change handles
  the EOF, so the "ceph injectargs ..." does not throws anymore.
  but the side effect is that the test fails since it expects a
  non-zero return code. so replace it with an equivalent "tell"
  command which also fails but due to the non-SI postfix.

Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit da9d2b4077ab1dceeed979ab71f0d9ed59b14266)

qa/workunits/cephtool/test.sh
src/ceph.in

index 1af5e4b5f695166df3036647e2faab8104a8db40..38f485d7becaf1fa79d0cf62fb7aaeacf7b8a7fa 100755 (executable)
@@ -230,10 +230,7 @@ function test_mon_injectargs_SI()
   expect_config_value "mon.a" "mon_pg_warn_min_objects" 10240
   ceph tell mon.a injectargs '--mon_pg_warn_min_objects 1G'
   expect_config_value "mon.a" "mon_pg_warn_min_objects" 1073741824
-  # < /dev/null accounts for the fact that ceph will go in interactive mode
-  # because injectargs is discarded (actually saved for the benefit of 
-  # a tell command that never comes)
-  expect_false ceph injectargs mon.a '--mon_pg_warn_min_objects 10F' < /dev/null 2> /dev/null
+  expect_false ceph tell mon.a injectargs '--mon_pg_warn_min_objects 10F'
   $SUDO ceph daemon mon.a config set mon_pg_warn_min_objects $initial_value
 }
 
@@ -438,7 +435,9 @@ function test_auth()
   # (almost) interactive mode
   echo -e 'auth add client.xx mon allow osd "allow *"\n' | ceph
   ceph auth get client.xx
-  ceph auth del client.xx
+  # script mode
+  echo 'auth del client.xx' | ceph
+  expect_false ceph auth get client.xx
 
   #
   # get / set auid
index 017efbca9359051ed58f30c7a83222063b2c7e23..8de12324655cb9a2d4b68c95c6731585d77fb91b 100755 (executable)
@@ -385,6 +385,25 @@ def ceph_conf(parsed_args, field, name):
 
 PROMPT = 'ceph> '
 
+if sys.stdin.isatty():
+    def read_input():
+        while True:
+            line = raw_input(PROMPT).rstrip()
+            if line in ['q', 'quit', 'Q']:
+                return None
+            if line:
+                return line
+else:
+    def read_input():
+        while True:
+            line = sys.stdin.readline()
+            if not line:
+                return None
+            line = line.rstrip()
+            if line:
+                return line
+
+
 def new_style_command(parsed_args, cmdargs, target, sigdict, inbuf, verbose):
     """
     Do new-style command dance.
@@ -412,18 +431,14 @@ def new_style_command(parsed_args, cmdargs, target, sigdict, inbuf, verbose):
             else:
                 return -errno.EINVAL, '', 'invalid command'
         else:
-            # do the command-interpreter looping
-            # for raw_input to do readline cmd editing
-            import readline
-
             if sys.stdin.isatty():
-                prompt = PROMPT
-            else:
-                prompt = ''
+                # do the command-interpreter looping
+                # for raw_input to do readline cmd editing
+                import readline
 
             while True:
-                interactive_input = raw_input(prompt)
-                if interactive_input in ['q', 'quit', 'Q']:
+                interactive_input = read_input()
+                if interactive_input is None:
                     return 0, '', ''
                 cmdargs = parse_cmdargs(shlex.split(interactive_input))[2]
                 try: