From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 7008446828784910336 X-Received: by 2002:a05:6512:38a8:: with SMTP id o8mr256500lft.102.1633020365296; Thu, 30 Sep 2021 09:46:05 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a05:6512:324d:: with SMTP id c13ls1167568lfr.0.gmail; Thu, 30 Sep 2021 09:46:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUA9CaAdchjI4JhmFSUmKWn+NDGFUqG5OT+FJ8b9uYof1LrM3k/ldAJmrDzjePgCP0uVa1 X-Received: by 2002:a05:6512:ac2:: with SMTP id n2mr235476lfu.460.1633020364425; Thu, 30 Sep 2021 09:46:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633020364; cv=none; d=google.com; s=arc-20160816; b=OXBBcMAyzcL4MVI9u+F5HKFlLcsZjqiyQCyMD6jCMT+l9x9aFNwVAUjxFdM5nng9TF cHsenncjaKhmuV/QGZIM9u1MzzVXFLI1thH20NErC/Mq6af3GRkSh21Y/2nL963HZGvN IuUaK8HI60wnIe4UQwRM1CaDtt8yGMKWCPRZxgmqfKuId5jhOHv7GO5xu6gL0hUM963e 7f8SabcJ58Y8ImWoavgYhnluQs+fVsJOAwknRxmPw/WbP609CU+14rd0YTt9sR+URRbJ kriLLkJ+U0DmN6qWKWCK31Acwx+g9OIOaRF1QqG4vmBR3qlbs51S48w/l/EDBtbWo5PS F1aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=nx5QaPslJNqF43E7/lXxAFvv7U6gZAAJvLgZkw2F4Ec=; b=OMoqBe26+YeYr+flrH5yuMqaHPK7OYUeiT9T7Yc/VF9P4lsAx5xh6A9arJ8Oxa/AYh ReU6YXoZxCTzzMEks/waFokvBDnCr+jaKWckMHUaMIwbBLe7IrLvW/Z5I+0a3cpLYZ4e IfGNooMNmjaoE5O2WLyWvrkLJdE407uWf3ar/g7CJL3WIg3K5ObzGEvcZtXlBsrDIyiu 8O8DxScIvXKk5aJI3CfA48S0242fRASEeRl8EtOnziUstA+jssW0q0wqYLH6GJQFShaq ZppEEf6CnS51uFg206ofYES5mnZVNJBbkPCpIkba4snGJclGHsb6/5KUhAcFFQ57UlMx YuRg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=softfail (google.com: domain of transitioning anton.mikanovich@promwad.com does not designate 85.214.156.166 as permitted sender) smtp.mailfrom=anton.mikanovich@promwad.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=promwad.com Return-Path: Received: from shymkent.ilbers.de (shymkent.ilbers.de. [85.214.156.166]) by gmr-mx.google.com with ESMTPS id o26si193117lfc.4.2021.09.30.09.46.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 Sep 2021 09:46:04 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning anton.mikanovich@promwad.com does not designate 85.214.156.166 as permitted sender) client-ip=85.214.156.166; Authentication-Results: gmr-mx.google.com; spf=softfail (google.com: domain of transitioning anton.mikanovich@promwad.com does not designate 85.214.156.166 as permitted sender) smtp.mailfrom=anton.mikanovich@promwad.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=promwad.com Received: from ws-323.promwad.corp (leased-line-st-87-252-252-30.telecom.by [87.252.252.30]) (authenticated bits=0) by shymkent.ilbers.de (8.15.2/8.15.2/Debian-8) with ESMTPSA id 18UGjhuf018892 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=NOT); Thu, 30 Sep 2021 18:46:01 +0200 From: Anton Mikanovich To: isar-users@googlegroups.com Cc: Anton Mikanovich Subject: [PATCH v14 07/16] vm_boot_test: Improve QEMU images checking Date: Thu, 30 Sep 2021 19:45:32 +0300 Message-Id: <1633020341-26062-8-git-send-email-anton.mikanovich@promwad.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1633020341-26062-1-git-send-email-anton.mikanovich@promwad.com> References: <1633020341-26062-1-git-send-email-anton.mikanovich@promwad.com> X-TUID: bv++bX2nKInW From: Anton Mikanovich Makes QEMU start test to analyze boot log in real-time. It helps test cases to finish as soon as booting succeeds and do not wasting time on waiting. Get rid of python-subprocess32 backport package. Signed-off-by: Anton Mikanovich --- testsuite/vm_boot_test/vm_boot_test.py | 53 +++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/testsuite/vm_boot_test/vm_boot_test.py b/testsuite/vm_boot_test/vm_boot_test.py index eee14b2..6e580d0 100644 --- a/testsuite/vm_boot_test/vm_boot_test.py +++ b/testsuite/vm_boot_test/vm_boot_test.py @@ -1,7 +1,8 @@ #!/usr/bin/env python3 import os -import subprocess32 +import select +import subprocess import sys import time import tempfile @@ -13,6 +14,9 @@ import start_vm from avocado import Test +class CanBeFinished(Exception): + pass + class VmBase(Test): def vm_start(self, arch='amd64', distro='buster'): @@ -34,18 +38,45 @@ class VmBase(Test): self.log.info('QEMU boot line: ' + str(cmdline)) - devnull = open(os.devnull, 'w') - - p1 = subprocess32.Popen(cmdline, stdout=devnull, stderr=devnull) - time.sleep(int(time_to_wait)) - p1.kill() - p1.wait() + login_prompt = b'isar login:' + service_prompt = b'Just an example' + + timeout = time.time() + int(time_to_wait) + + p1 = subprocess.Popen(cmdline, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + try: + poller = select.poll() + poller.register(p1.stdout, select.POLLIN) + poller.register(p1.stderr, select.POLLIN) + while time.time() < timeout and p1.poll() is None: + events = poller.poll(1000 * (timeout - time.time())) + for fd, event in events: + if fd == p1.stdout.fileno(): + # Wait for the complete string if it is read in chunks + # like "i", "sar", " login:" + time.sleep(0.01) + data = os.read(fd, 1024) + if login_prompt in data: + raise CanBeFinished + if fd == p1.stderr.fileno(): + self.log.error(p1.stderr.readline()) + except CanBeFinished: + self.log.debug('Got login prompt') + finally: + if p1.poll() is None: + p1.kill() + p1.wait() if os.path.exists(output_file): - if 'isar login:' in open(output_file).read(): - return - - self.fail('Test failed') + with open(output_file, "rb") as f1: + data = f1.read() + if service_prompt in data and login_prompt in data: + return + else: + self.log.error(data) + + self.fail('Log ' + output_file) class VmBootTestFast(VmBase): -- 2.7.4