From patchwork Fri Oct 28 16:33:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 79990 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp1277255qge; Fri, 28 Oct 2016 09:59:56 -0700 (PDT) X-Received: by 10.31.50.204 with SMTP id y195mr13527612vky.29.1477673996908; Fri, 28 Oct 2016 09:59:56 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id h201si3193679vkd.78.2016.10.28.09.59.56 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 28 Oct 2016 09:59:56 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50703 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c0AVX-000352-O0 for patch@linaro.org; Fri, 28 Oct 2016 12:59:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51671) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c0A6I-0004kt-Gw for qemu-devel@nongnu.org; Fri, 28 Oct 2016 12:33:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c0A6H-0003Ha-9q for qemu-devel@nongnu.org; Fri, 28 Oct 2016 12:33:50 -0400 Received: from mail-wm0-x230.google.com ([2a00:1450:400c:c09::230]:35962) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c0A6H-0003H0-2M for qemu-devel@nongnu.org; Fri, 28 Oct 2016 12:33:49 -0400 Received: by mail-wm0-x230.google.com with SMTP id p190so22492867wmp.1 for ; Fri, 28 Oct 2016 09:33:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pPUJZZbq7k1VDs4qokzUXqoYZTedugIJBtZqOUTQJxU=; b=iO+Pt45VRBtJuzSP5KqunkPcqdH1AFzXTtEU4ee5STwEUXjJT4T+vIfAOBQKSA/WIW tYtOgrLoM5MqjNuxrnKjc4b98e1p137RcF6Iu4gDJh70Zi11s4DO6fuokOqXFEfAEssL zxqYA2+crOibW1pLDk/0ehSedG9rGZuRWuXuo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pPUJZZbq7k1VDs4qokzUXqoYZTedugIJBtZqOUTQJxU=; b=jcDg7wT0Cyn8N/MMOJJD37/lYKnQ/Yowrco07jiS+XuPatA67XwRMy8A01cX9rQ6ye rpBXiblX5v5KUtEklze9EDK5gJx1y1NtivSbwn+rfjX6oh04nGxxzMVq3uu9XgcGgDxa 2zE5vghoPD+iLhLBFolecHZwlc1/6W4rEvSLOl5oaePLuBndFJiLot6xtcy+TpXRTzxe zbgoQn97lnuZzo8tCHuU/gM1L95FgSx4uEaaqtlg9qwaplKj6QDX498P14fRlwWBZAiD njEauvZKp16rtTN4zqL7LGjJYo0D8QxxGAm97zLfcaX5/jWfS502qgAqJelQXkRcMr+5 pQlA== X-Gm-Message-State: ABUngvehH1axvxZpFYxEaOLalwzV/ZL85crUPIoRFMuIpn2uJS/9FoprrvHTm77CXuUHbWig X-Received: by 10.194.86.34 with SMTP id m2mr12150917wjz.90.1477672427213; Fri, 28 Oct 2016 09:33:47 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id hy10sm7173589wjb.10.2016.10.28.09.33.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Oct 2016 09:33:44 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 082903E02E1; Fri, 28 Oct 2016 17:33:43 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: famz@redhat.com Date: Fri, 28 Oct 2016 17:33:38 +0100 Message-Id: <20161028163339.31096-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161028163339.31096-1-alex.bennee@linaro.org> References: <20161028163339.31096-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::230 Subject: [Qemu-devel] [PATCH 5/6] tests/docker/docker.py: expand images command 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Modern docker cli commands can filter by repository but as we want to work on all instances do this by hand in python: /tests/docker/docker.py images --repo qemu Will return a space delimited list for the benefit of our Makefile recipes. Signed-off-by: Alex Bennée --- tests/docker/docker.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) -- 2.10.1 diff --git a/tests/docker/docker.py b/tests/docker/docker.py index 37d8319..03c0238 100755 --- a/tests/docker/docker.py +++ b/tests/docker/docker.py @@ -105,12 +105,15 @@ class Docker(object): signal.signal(signal.SIGTERM, self._kill_instances) signal.signal(signal.SIGHUP, self._kill_instances) - def _do(self, cmd, quiet=True, infile=None, **kwargs): + def _do(self, cmd, quiet=True, infile=None, output=False, **kwargs): if quiet: kwargs["stdout"] = DEVNULL if infile: kwargs["stdin"] = infile - return subprocess.call(self._command + cmd, **kwargs) + if output: + return subprocess.check_output(self._command + cmd, **kwargs) + else: + return subprocess.call(self._command + cmd, **kwargs) def _do_kill_instances(self, only_known, only_active=True): cmd = ["ps", "-q"] @@ -188,8 +191,8 @@ class Docker(object): self._instances.remove(label) return ret - def command(self, cmd, argv, quiet): - return self._do([cmd] + argv, quiet=quiet) + def command(self, cmd, argv, quiet, output=False): + return self._do([cmd] + argv, quiet=quiet, output=output) class SubCommand(object): """A SubCommand template base class""" @@ -325,8 +328,22 @@ class CleanCommand(SubCommand): class ImagesCommand(SubCommand): """Run "docker images" command""" name = "images" + def args(self, parser): + parser.add_argument("--repo", + help="List images in the given repository") + def run(self, args, argv): - return Docker().command("images", argv, args.quiet) + if args.repo: + images=[] + image_re = re.compile(r"^"+re.escape(args.repo)+r"\s+(\S*)") + output = Docker().command("images", argv, args.quiet, output=True) + for line in output.split("\n"): + search = image_re.search(line) + if search: + images.append(search.group(1)) + print ' '.join(map(str,images)) + else: + return Docker().command("images", argv, args.quiet) def main(): parser = argparse.ArgumentParser(description="A Docker helper",