]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tests: ceph_objectstore_tool.py skip if /dev/tty fails
authorLoic Dachary <ldachary@redhat.com>
Fri, 14 Nov 2014 10:00:17 +0000 (11:00 +0100)
committerLoic Dachary <ldachary@redhat.com>
Sat, 15 Nov 2014 22:27:15 +0000 (23:27 +0100)
Some environments do not have a /dev/tty. When opening /dev/tty fails,
skip the test instead of returning an error.

Signed-off-by: Loic Dachary <ldachary@redhat.com>
src/test/ceph_objectstore_tool.py

index dfeb27f582dac6865378313b1e1289be64ded533..407222e135c8f4331ecc02fb0a83b178c0b43ea6 100755 (executable)
@@ -111,9 +111,13 @@ def vstart(new):
     call("MON=1 OSD=4 CEPH_PORT=7400 ./vstart.sh -l {opt} -d mon osd > /dev/null 2>&1".format(opt=OPT), shell=True)
     print "DONE"
 
-
-def test_failure(cmd, errmsg):
-    ttyfd = open("/dev/tty", "rw")
+def test_failure_tty(cmd, errmsg):
+    try:
+        ttyfd = open("/dev/tty", "rw")
+    except Exception, e:
+        logging.info(str(e))
+        logging.info("SKIP " + cmd)
+        return 0
     TMPFILE = r"/tmp/tmp.{pid}".format(pid=os.getpid())
     tmpfd = open(TMPFILE, "w")
 
@@ -133,6 +137,19 @@ def test_failure(cmd, errmsg):
         logging.error("Bad message to stderr \"" + line + "\"")
         return 1
 
+def test_failure(cmd, errmsg):
+    logging.debug(cmd)
+    try:
+        out = check_output(cmd, stderr=subprocess.STDOUT, shell=True)
+        logging.error("Should have failed, but got exit 0")
+        return 1
+    except subprocess.CalledProcessError, e:
+        if errmsg in e.output:
+            logging.info("Correctly failed with message \"" + errmsg + "\"")
+            return 0
+        else:
+            logging.error("Bad message to stderr \"" + e.output + "\"")
+            return 1
 
 def get_nspace(num):
     if num == 0:
@@ -400,7 +417,7 @@ def main(argv):
     print "Test invalid parameters"
     # On export can't use stdout to a terminal
     cmd = (CFSD_PREFIX + "--op export --pgid {pg}").format(osd=ONEOSD, pg=ONEPG)
-    ERRORS += test_failure(cmd, "stdout is a tty and no --file option specified")
+    ERRORS += test_failure_tty(cmd, "stdout is a tty and no --file option specified")
 
     OTHERFILE = "/tmp/foo.{pid}".format(pid=pid)
     foofd = open(OTHERFILE, "w")
@@ -416,7 +433,7 @@ def main(argv):
 
     # On import can't use stdin from a terminal
     cmd = (CFSD_PREFIX + "--op import --pgid {pg}").format(osd=ONEOSD, pg=ONEPG)
-    ERRORS += test_failure(cmd, "stdin is a tty and no --file option specified")
+    ERRORS += test_failure_tty(cmd, "stdin is a tty and no --file option specified")
 
     # Specify a bad --type
     cmd = (CFSD_PREFIX + "--type foobar --op list --pgid {pg}").format(osd=ONEOSD, pg=ONEPG)