From patchwork Mon Feb 22 21:02:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Mayhew X-Patchwork-Id: 8383181 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8AAC6C0553 for ; Mon, 22 Feb 2016 21:02:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AFE95204A0 for ; Mon, 22 Feb 2016 21:02:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 863DE2038E for ; Mon, 22 Feb 2016 21:02:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752254AbcBVVCN (ORCPT ); Mon, 22 Feb 2016 16:02:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60051 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752159AbcBVVCM (ORCPT ); Mon, 22 Feb 2016 16:02:12 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id AC746C0005DB; Mon, 22 Feb 2016 21:02:12 +0000 (UTC) Received: from tonberry.usersys.redhat.com (dhcp145-110.rdu.redhat.com [10.13.145.110]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1ML2CY2011117 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 22 Feb 2016 16:02:12 -0500 Received: from tonberry.usersys.redhat.com (localhost [127.0.0.1]) by tonberry.usersys.redhat.com (8.15.2/8.14.5) with ESMTP id u1ML2CMn061556; Mon, 22 Feb 2016 16:02:12 -0500 Received: (from smayhew@localhost) by tonberry.usersys.redhat.com (8.15.2/8.15.2/Submit) id u1ML2BYL061555; Mon, 22 Feb 2016 16:02:11 -0500 From: Scott Mayhew To: dros@monkey.org Cc: linux-nfs@vger.kernel.org Subject: [nfsometer PATCH 1/2] cmd.py: redefine CmdErrorCode Date: Mon, 22 Feb 2016 16:02:10 -0500 Message-Id: <1456174931-61514-1-git-send-email-smayhew@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Redefine CmdErrorCode so the error code itself can be checked. Signed-off-by: Scott Mayhew --- nfsometerlib/cmd.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/nfsometerlib/cmd.py b/nfsometerlib/cmd.py index 9b6dbdd..a2ebcef 100644 --- a/nfsometerlib/cmd.py +++ b/nfsometerlib/cmd.py @@ -25,7 +25,15 @@ class CmdError(Exception): pass class CmdErrorCode(CmdError): - pass + def __init__(self, cmd, code, errstr): + self.cmd = cmd + self.code = code + self.errstr = errstr + + def __str__(self): + return str.format( + 'command "{:s}" exited with non-zero status: {:d}{:s}', + self.cmd, self.code, self.errstr) class CmdErrorOut(CmdError): pass @@ -67,8 +75,7 @@ def cmd(args, raiseerrorcode=True, raiseerrorout=True, instr='', errstr = '\n%s' % errstr if raiseerrorcode and ret != 0: - raise CmdErrorCode('command "%s" exited with non-zero status: %u%s' % - (args, ret, errstr)) + raise CmdErrorCode(args, ret, errstr) if raiseerrorout and errstr: raise CmdErrorOut('command "%s" has output to stderr: %s' %