From 4803edd1385b83bdd71a840b78ae562f8db6c93d Mon Sep 17 00:00:00 2001 From: Giuseppe Di Natale Date: Fri, 15 Dec 2017 13:26:43 -0800 Subject: [PATCH] Handle broken pipes in arc_summary Using a command similar to 'arc_summary.py | head' causes a broken pipe exception. Gracefully exit in the case of a broken pipe in arc_summary.py. Requires-Builders: test style Signed-off-by: Giuseppe Di Natale Closes #6965 --- TEST | 12 ++++++------ cmd/arc_summary/arc_summary.py | 13 +++++++++---- .../cli_user/misc/arc_summary_001_pos.ksh | 3 +++ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/TEST b/TEST index 4c593a457078..36059aa8b709 100644 --- a/TEST +++ b/TEST @@ -5,25 +5,25 @@ #TEST_PREPARE_SHARES="yes" ### SPLAT -#TEST_SPLAT_SKIP="yes" +TEST_SPLAT_SKIP="yes" #TEST_SPLAT_OPTIONS="-acvx" ### ztest -#TEST_ZTEST_SKIP="yes" +TEST_ZTEST_SKIP="yes" #TEST_ZTEST_TIMEOUT=1800 #TEST_ZTEST_DIR="/var/tmp/" #TEST_ZTEST_OPTIONS="-V" #TEST_ZTEST_CORE_DIR="/mnt/zloop" ### zimport -#TEST_ZIMPORT_SKIP="yes" +TEST_ZIMPORT_SKIP="yes" #TEST_ZIMPORT_DIR="/var/tmp/zimport" #TEST_ZIMPORT_VERSIONS="master installed" #TEST_ZIMPORT_POOLS="zol-0.6.1 zol-0.6.2 master installed" #TEST_ZIMPORT_OPTIONS="-c" ### xfstests -#TEST_XFSTESTS_SKIP="yes" +TEST_XFSTESTS_SKIP="yes" #TEST_XFSTESTS_URL="https://github.com/behlendorf/xfstests/archive/" #TEST_XFSTESTS_VER="zfs.tar.gz" #TEST_XFSTESTS_POOL="tank" @@ -39,10 +39,10 @@ #TEST_ZFSTESTS_ITERS="1" #TEST_ZFSTESTS_OPTIONS="-vx" #TEST_ZFSTESTS_RUNFILE="linux.run" -#TEST_ZFSTESTS_TAGS="functional" +TEST_ZFSTESTS_TAGS="misc" ### zfsstress -#TEST_ZFSSTRESS_SKIP="yes" +TEST_ZFSSTRESS_SKIP="yes" #TEST_ZFSSTRESS_URL="https://github.com/nedbass/zfsstress/archive/" #TEST_ZFSSTRESS_VER="master.tar.gz" #TEST_ZFSSTRESS_RUNTIME=300 diff --git a/cmd/arc_summary/arc_summary.py b/cmd/arc_summary/arc_summary.py index 5da81347cc29..4cd63958c741 100755 --- a/cmd/arc_summary/arc_summary.py +++ b/cmd/arc_summary/arc_summary.py @@ -47,6 +47,7 @@ import os import sys import time +#import errno from subprocess import Popen, PIPE from decimal import Decimal as D @@ -1010,10 +1011,14 @@ def main(): else: pages = unSub - zfs_header() - for page in pages: - page(Kstat) - sys.stdout.write("\n") + try: + zfs_header() + for page in pages: + page(Kstat) + sys.stdout.write("\n") + except IOError as e: + if e.errno == errno.EPIPE: + sys.exit() if __name__ == '__main__': diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/arc_summary_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/arc_summary_001_pos.ksh index 67c11c8ab673..55ace4fe167a 100755 --- a/tests/zfs-tests/tests/functional/cli_user/misc/arc_summary_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_user/misc/arc_summary_001_pos.ksh @@ -37,4 +37,7 @@ while [[ $i -lt ${#args[*]} ]]; do ((i = i + 1)) done +log_must eval "arc_summary.py | head" +log_must eval "arc_summary.py | head -1" + log_pass "arc_summary.py generates output and doesn't return an error code"