From patchwork Thu Jun 21 06:26:03 2018 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: 139478 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp1691701lji; Wed, 20 Jun 2018 23:53:05 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJh0epXDD6O+rqZVnsqALbMofFzJNcKH1w6Vvbwjb4lg8F8JwJQkjvwZwHN+iJRjmoY7A9v X-Received: by 2002:a37:c3cf:: with SMTP id r76-v6mr226385qkl.150.1529563984921; Wed, 20 Jun 2018 23:53:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529563984; cv=none; d=google.com; s=arc-20160816; b=traH6Nuuf4yTgjlRUJxIIXKCkhgh8E6RWKpNUVNuxS1Qk+6pOm8QRgOx3vNK6oRHbd LFkyoaAhVwLOAzHyeZtM0dw0hlEDdBydUEJmwXbDUa/jKLm3TMdWGx+j0LRJJyg603D3 relywv11/lznn77LkdQ09J+e1Q6PsHZs40x5xmh35ddf39qnC35b73NviTKnndT2JJK7 3vOGSauFAnThO/hWJUW6Cf49Myql4E674vpJAmN9393YPmCsaPZYwccI1K1VOR5YC2dF jvp7xX9eG0yWM+Bi2xJcxnc6uvSWEBxlHOy1CLGcnSRbbjtPzhJPahnyBIChoqV1oEKg XS6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=+fpQ9OpisHqiat2sOGv2GPKHWVwYsiDh4yf4g4yiwdQ=; b=rC6vJR4vryc/fqMEtKHbnpEjam9f6dPcnsEZHac/2VmxF3qTieVNWHiIq2PyNg/55C Xn1aCI++YdjehQhzZz4iG78mfKH85QUDK35uWPUlHKLLOGBJCvKcEoIqOjnSmV8jeez/ fucE4g8L1XmmYqPZ8q36yZIDcX1kwOG9O9UqF2nrlbHNZMbB5KXNYVVOLb81Zrzl9Pyx v8upPXlqmM8xrE3mSqd+ohwKf5PPz/d5OpkvC2fxBiNO9xtE3qDPA8hRpELv8Pztyh1M 94N3yg+oBUa5mlgd5snugvV7groh8t0y0ePGHymQS30r2OPNivI85ZltKxS0SqLauHet etxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=c3Vh4bj5; 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 sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x23-v6si3684201qtj.169.2018.06.20.23.53.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Jun 2018 23:53:04 -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 header.s=google header.b=c3Vh4bj5; 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 sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53376 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVtSq-0004Q7-Bg for patch@linaro.org; Thu, 21 Jun 2018 02:53:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVt8P-0005ef-0s for qemu-devel@nongnu.org; Thu, 21 Jun 2018 02:31:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVt8N-0003im-Eh for qemu-devel@nongnu.org; Thu, 21 Jun 2018 02:31:57 -0400 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]:33816) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fVt8N-0003i1-8Q for qemu-devel@nongnu.org; Thu, 21 Jun 2018 02:31:55 -0400 Received: by mail-wm0-x231.google.com with SMTP id l15-v6so1887232wmc.1 for ; Wed, 20 Jun 2018 23:31:55 -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=+fpQ9OpisHqiat2sOGv2GPKHWVwYsiDh4yf4g4yiwdQ=; b=c3Vh4bj5esESTHAW0a2ZvjU/o7zWpCwv7zBCbkeTxH9H3iTjxz75u52o8zeA3hwNUM pLPLCulZSjxayRxdjBT9NJseFvVnCRSDJeG4rX8wYtBzGf4gjPWGXMV49ZGifWgodfGM 2Lmeps5DQlHE6vmOoyBhPug++/k271hfchxdw= 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:mime-version:content-transfer-encoding; bh=+fpQ9OpisHqiat2sOGv2GPKHWVwYsiDh4yf4g4yiwdQ=; b=HXVMSTrGTKk9Pa3jewgV6tRBlZTHf2yboB1F5yVz+pGFQ9v6j2zxoDaolUivYfydGj h0a32gbIWej5iVIDWAozn6TtAUz8R0cNU0ORnf1bwnmttgDMpmLmhFlKp1yTD5SCrcg8 LwVWDMzbxGsXYtg586s2rCYDmdHrbE41XR1/z0VsxISvxICZjTMVCkaT2VmSwJJHR5Jn qdCUeXiYx5ux+1pE023mrdC8BLHqNTno3fzH+R0EW+BgTv+WmW+ZA2f83CGu0Sx4MKLK VteeELhXpksBaOA+KWs5R8TOh5c9YohRo+fMxVDBaVx4nbkNUTLMPxpMhEGcl4xjdk+w oHNw== X-Gm-Message-State: APt69E2zNUY8pofYHL7cQHv0r5wEqBj0JocjvAQlHOKe+jWrEztBPIld ctPMrEq3xFvieANDk3SC1mTATw== X-Received: by 2002:a1c:8012:: with SMTP id b18-v6mr3722483wmd.13.1529562714163; Wed, 20 Jun 2018 23:31:54 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id o13-v6sm3033405wmc.8.2018.06.20.23.31.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Jun 2018 23:31:51 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 031DC3E1548; Thu, 21 Jun 2018 07:26:10 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Thu, 21 Jun 2018 07:26:03 +0100 Message-Id: <20180621062605.941-56-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180621062605.941-1-alex.bennee@linaro.org> References: <20180621062605.941-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::231 Subject: [Qemu-devel] [PULL v2 55/57] docker: docker.py adding age check 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: agraf@suse.de, =?utf-8?q?Alex_Benn=C3=A9e?= , richard.henderson@linaro.org, qemu-devel@nongnu.org, f4bug@amsat.org, cota@braap.org, famz@redhat.com, aurelien@aurel32.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is useful for querying if an image is too old. Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé -- 2.17.1 diff --git a/tests/docker/docker.py b/tests/docker/docker.py index e4f37820e0..b279836154 100755 --- a/tests/docker/docker.py +++ b/tests/docker/docker.py @@ -32,6 +32,7 @@ except ImportError: from io import StringIO from shutil import copy, rmtree from pwd import getpwuid +from datetime import datetime,timedelta FILTERED_ENV_NAMES = ['ftp_proxy', 'http_proxy', 'https_proxy'] @@ -190,6 +191,9 @@ class Docker(object): except subprocess.CalledProcessError: return None + def get_image_creation_time(self, info): + return json.loads(info)[0]["Created"] + def get_image_dockerfile_checksum(self, tag): resp = self.inspect_tag(tag) labels = json.loads(resp)[0]["Config"].get("Labels", {}) @@ -461,11 +465,14 @@ class CheckCommand(SubCommand): def args(self, parser): parser.add_argument("tag", help="Image Tag") - parser.add_argument("dockerfile", - help="Dockerfile name") + parser.add_argument("dockerfile", default=None, + help="Dockerfile name", nargs='?') + parser.add_argument("--checktype", choices=["checksum", "age"], + default="checksum", help="check type") + parser.add_argument("--olderthan", default=60, type=int, + help="number of minutes") def run(self, args, argv): - dockerfile = open(args.dockerfile, "rb").read() tag = args.tag dkr = Docker() @@ -474,13 +481,32 @@ class CheckCommand(SubCommand): print("Image does not exist") return 1 - if dkr.image_matches_dockerfile(tag, dockerfile): - if not args.quiet: - print("Image is up to date") - return 0 - else: - print("Image needs updating") - return 1 + if args.checktype == "checksum": + if not args.dockerfile: + print("Need a dockerfile for tag:%s" % (tag)) + return 1 + + dockerfile = open(args.dockerfile, "rb").read() + + if dkr.image_matches_dockerfile(tag, dockerfile): + if not args.quiet: + print("Image is up to date") + return 0 + else: + print("Image needs updating") + return 1 + elif args.checktype == "age": + timestr = dkr.get_image_creation_time(info).split(".")[0] + created = datetime.strptime(timestr, "%Y-%m-%dT%H:%M:%S") + past = datetime.now() - timedelta(minutes=args.olderthan) + if created < past: + print ("Image created @ %s more than %d minutes old" % + (timestr, args.olderthan)) + return 1 + else: + if not args.quiet: + print ("Image less than %d minutes old" % (args.olderthan)) + return 0 def main():