From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 7008446828784910336 X-Received: by 2002:ac2:43b5:: with SMTP id t21mr90998lfl.616.1631781208241; Thu, 16 Sep 2021 01:33:28 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a05:6512:13a9:: with SMTP id p41ls1891285lfa.0.gmail; Thu, 16 Sep 2021 01:33:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwTQpSgnXPZO28bQjpJIs3++iL1Q3BP2XU9vRB6IWhHub8edIqajmlH/ErE8saZRybhyqH X-Received: by 2002:a05:6512:2353:: with SMTP id p19mr3197690lfu.681.1631781207178; Thu, 16 Sep 2021 01:33:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631781207; cv=none; d=google.com; s=arc-20160816; b=h16Gu/l159uC1mdl4OY6FmylsxOe9GU48MJDjO/JAfSJPtKpauKGhOTjoyQtW9SMo5 LkzA6dBJyV4dFXBDZIgfaQIoHpbonpr9UAuHOmbRQSbDRJRo8jt+9IsomL2C96JaPgBi jTMIEvLikdssxp4kLiIGsHOlKZ9MuEXYB+7vF3j9uRPNirQa38arQmH6DGpDvNrWrrwJ IRe0kf+S+uxJxaTKJLuPX9DVLpfn86ESRX5CDz+IgRvMjVMAVKqA15AcPkVhs5c90IVP x7+kpc8hcirtkY48oeUPI+Qch3Qod9QeQkdxovguep4HtxNI8fRkbwgIypWf4WqXPuIK rxbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=E9+kcmsgx/2xjVd+jTSVCmaJdQwAJgiFW9+CX5pLdnc=; b=bBShIefWZvksOcTJVpMtTJeM9KDRmjoqgUvjaV30tG7DEXYtYt694CwCpIVRYudfyP lZv4GdPM4Ekv0fayw2z5bLBWIePF93VPvnqtzs3zZFyxQAMDkVp6AQb/xkA7E+PYGCDp CKxSK1tQJT58i+SRTIZzbuZOr99O4SZpHYQB72cDAGTzBExSWGNMSZqYzMv23DEYBpZe WE6hi5+4YFr9FiJrGf/rp5PwZTMEHD+7a3l2QrhyMaT2QH8G2UDPg+GvinKQ02qkNc8l ppMldnzy6xhHCZd3x/mvGtIAo7cFj0GN+f1fF35pMJcCmi2d7GnU72RNe/5CZwKXtKQE E9QA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of amikan@ilbers.de designates 85.214.156.166 as permitted sender) smtp.mailfrom=amikan@ilbers.de Return-Path: Received: from shymkent.ilbers.de (shymkent.ilbers.de. [85.214.156.166]) by gmr-mx.google.com with ESMTPS id l20si294885lfg.9.2021.09.16.01.33.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 16 Sep 2021 01:33:27 -0700 (PDT) Received-SPF: pass (google.com: domain of amikan@ilbers.de designates 85.214.156.166 as permitted sender) client-ip=85.214.156.166; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of amikan@ilbers.de designates 85.214.156.166 as permitted sender) smtp.mailfrom=amikan@ilbers.de Received: from localhost.localdomain (mm-240-58-214-37.mgts.dynamic.pppoe.byfly.by [37.214.58.240] (may be forged)) (authenticated bits=0) by shymkent.ilbers.de (8.15.2/8.15.2/Debian-8) with ESMTPSA id 18G8X2xK021529 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 Sep 2021 10:33:24 +0200 From: Anton Mikanovich To: isar-users@googlegroups.com Cc: Anton Mikanovich Subject: [PATCH v11 07/16] vm_boot_test: Improve QEMU images checking Date: Thu, 16 Sep 2021 11:32:44 +0300 Message-Id: <20210916083253.53037-8-amikan@ilbers.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210916083253.53037-1-amikan@ilbers.de> References: <20210916083253.53037-1-amikan@ilbers.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUID: LHib7rlMPvxQ 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.25.1