From patchwork Fri Apr 13 19:26:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nir Soffer X-Patchwork-Id: 10340723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 89376600D0 for ; Fri, 13 Apr 2018 19:27:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A41028797 for ; Fri, 13 Apr 2018 19:27:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EF09287CF; Fri, 13 Apr 2018 19:27:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1B99328797 for ; Fri, 13 Apr 2018 19:27:47 +0000 (UTC) Received: from localhost ([::1]:47961 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f74MM-0006KW-9R for patchwork-qemu-devel@patchwork.kernel.org; Fri, 13 Apr 2018 15:27:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37415) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f74Ky-000593-Lf for qemu-devel@nongnu.org; Fri, 13 Apr 2018 15:26:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f74Kx-0001v1-Ki for qemu-devel@nongnu.org; Fri, 13 Apr 2018 15:26:20 -0400 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:35942) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f74Kx-0001tp-DJ; Fri, 13 Apr 2018 15:26:19 -0400 Received: by mail-wr0-x241.google.com with SMTP id q13so7306451wre.3; Fri, 13 Apr 2018 12:26:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=l8qL1DhH1cR5eZmb5/tK6tzu3Mcu9S14FRMWd2SBA8A=; b=H9MpIE6WxSC6yTJtAFAKyIvGtZhKoTHBHx9+TtS65z6MCAAzKEF+zQoyq40RDo5cSk Qqj/96Y08DgCOdbMnhtFY1jhYwKOa3p8BoPSEXGLNyLOK1n1Flnr0F8QQEnY9Z1znaq2 U4B6n/opBqcnX8pDY5FvhNjojfXPSIa7MWq4+Td1aDz1Ru4BqVGWy0qfKanx1ziX7CyI YW0dULu9sBoAj9xWYkdmc4BRXYIaTn2cH5IZ8AUvq23JmffW5V7Pi5fKe1AG0c8zNmdM DzM0fCFGcyC7m3HJXTzjIF9bSWGmim3j+2UEHzjX3XjrU9x1YUSqNNoDGkHBzJHzNc0b niLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=l8qL1DhH1cR5eZmb5/tK6tzu3Mcu9S14FRMWd2SBA8A=; b=gLF/mexdfmB0lVhIfJx8gYI1Ld/0cm182+sJQ9le4Wdi38mlszQBp2cV9kQQlTgoE0 bSsGjAvdzCdqU7BWj0evebCQhilxTdvkvMW1fr193Ol2LWVCIg3f0Dwl9mskvprBS0Hw ZAPuNOOOBJfaKuMfZhWzI4SUkHOe36ROvD4VzZjuUS0nCVnJiygiR8BZ7+y77Gjkr4/v 7A4Kq0BEd0U48njwZScMzvxmXCl7HeesQBKtOt/lIWH4UV2VxuxqyYcSJesGg62j9cb0 oGU5Rq+DrGS1WwiZCyCIwIoPPp++VO4srzWMqdPjpM+DyBvv92ieF0GEWnv5rE4dvhCf tMJg== X-Gm-Message-State: ALQs6tDjcn1y0Vi+b1A6kPEHUSn1wOUVdT+FGAbpPh7q2cI9+tW6Rt8j qi4qxY9CcF46M4Ackpk4rY10kkxn9f4= X-Google-Smtp-Source: AIpwx48KkBYOjZYkau/W3K3V08T82Az1nPo9lZPLF5LBsH8GcoY4vBz++SpnFHVwuJjJaIxdJUSbIg== X-Received: by 10.223.226.15 with SMTP id j15mr4399234wri.235.1523647577919; Fri, 13 Apr 2018 12:26:17 -0700 (PDT) Received: from lean.local (93-173-127-3.bb.netvision.net.il. [93.173.127.3]) by smtp.gmail.com with ESMTPSA id r200sm842127wmb.39.2018.04.13.12.26.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Apr 2018 12:26:17 -0700 (PDT) From: Nir Soffer To: qemu-devel@nongnu.org Date: Fri, 13 Apr 2018 22:26:04 +0300 Message-Id: <20180413192605.2145-3-nirsof@gmail.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180413192605.2145-1-nirsof@gmail.com> References: <20180413192605.2145-1-nirsof@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PATCH 2/3] iotests.py: Add helper for running commands X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Nir Soffer , qemu-block@nongnu.org, rjones@redhat.com, mreitz@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add few helpers for running external commands: - CommandFailed: exception, keeping all the info related to a failed command, and providing a useful error message. (Unfortunately subprocess.CalledProcessError does not). - run(): run a command collecting output from the underlying process stdout and stderr, returning the command output or raising CommandFailed. These helpers will be used by new qemu-nbd tests. And later can be used to cleanup helpers for running qemu-* tools in iotests.py. Signed-off-by: Nir Soffer --- tests/qemu-iotests/iotests.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index b25d48a91b..0f8abf99cb 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -64,6 +64,24 @@ luks_default_secret_object = 'secret,id=keysec0,data=' + \ os.environ['IMGKEYSECRET'] luks_default_key_secret_opt = 'key-secret=keysec0' +class CommandFailed(Exception): + + def __init__(self, cmd, rc, out, err): + self.cmd = cmd + self.rc = rc + self.out = out + self.err = err + + def __str__(self): + return ("Command {self.cmd} failed: rc={self.rc}, out={self.out!r}, " + "err={self.err!r}").format(self=self) + +def run(*args): + p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = p.communicate() + if p.returncode != 0: + raise CommandFailed(args, p.returncode, out, err) + return out def qemu_img(*args): '''Run qemu-img and return the exit code'''