From nobody Wed Nov 12 16:27:14 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1571498187; cv=none; d=zoho.com; s=zohoarc; b=E7jTTKnl2o3NuUidkM9VSEcteBHtpTGa1jejwNiF1UmI/yzFXZfsnsdECn4h3zFoFvBKFwqEEkr1wt0Rn7dDjj7LdQbjx3qLzjKphIfHa2VJuKaI61NZ7hQTTxd/4D+FXOIQT9HeXaQpGlhXRgvNLJTNEu6brmhf/Kql0+K6GEc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571498187; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=w2ENnodrkebcANajyxBbU6bIiMWLNySDu9Cotb19W1w=; b=fe1+yK1cnZhK2KnSTa9B95/A/5ri95IYLhIQ/PdPbtw9YdBVVFojNS4GL5x8qMJWWg1cNc1ZKx21eSCSQJI9iXSRPR0JzBVvESjfT43MFeZstFik/pKS283uNAVij9CchSSSka81pweI4B3kt8i3fMKPrqRYkvoEmQBCY7NbkCc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571498187097890.9493122178716; Sat, 19 Oct 2019 08:16:27 -0700 (PDT) Received: from localhost ([::1]:56572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iLqSv-0006KU-QP for importer@patchew.org; Sat, 19 Oct 2019 11:16:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45651) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iLqNn-0001BW-S2 for qemu-devel@nongnu.org; Sat, 19 Oct 2019 11:11:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iLqNm-0006wZ-Dz for qemu-devel@nongnu.org; Sat, 19 Oct 2019 11:11:07 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:35006) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iLqNl-0006tx-UH for qemu-devel@nongnu.org; Sat, 19 Oct 2019 11:11:06 -0400 Received: by mail-wm1-x329.google.com with SMTP id 14so2069870wmu.0 for ; Sat, 19 Oct 2019 08:11:03 -0700 (PDT) Received: from x1w.redhat.com (14.red-88-21-201.staticip.rima-tde.net. [88.21.201.14]) by smtp.gmail.com with ESMTPSA id t13sm10753964wra.70.2019.10.19.08.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Oct 2019 08:11:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w2ENnodrkebcANajyxBbU6bIiMWLNySDu9Cotb19W1w=; b=abiqNl25RX3y8Pe4qxEujhmQkC+ZRwdCye23N7LWvU7tmXrmB0M3G361o3KHxWL0aO RYGBRMf7GzoVpYblyASAOmM/zz9xX8YA0JhlLOAodBMnJOwCdbI9uE+rXdhD2kmpfaw9 +mtNcfzyuKFe4hrrIVY5y8EZ2A+j75jI/59iwQL+HxUnxiTJClp1OAUX+X01jPt04Z7P W/LySH1AsU12XGEEmZLeKLZjW8LhnEltOeRWh6U8vPeETMjh1uNJFU6fGi+Ny/WGLOTn 0Cc6FKKYU1FJZbe+NnJILow3KO4Rhe7hymTs/DbtklF1EGNSROad7GTAwwAsbo1c9821 4aUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=w2ENnodrkebcANajyxBbU6bIiMWLNySDu9Cotb19W1w=; b=aTaR2olOqno7GfJPKRh857w1D7aLZ3KnBL9mf7UAnduKBmG8Vst5s3XEVCpmWvIVif W3K+a3t5h0URLlgpwLivyWpmsExO+lwuXY1kumant81Rg5qtfdKB+l4usttsSBX//bbg dtZC0BA2o2/g00zZsRCIjfuldCkztE9GajmPJfqgSWjaZgn8PNdXkDQk26MEDdYlaTo7 82odnNkXMnP3UCVFmToqPNta2wA9dtjFzjvhrClp9B/mk8RQCgteA9ez0ik6QB1Hgz6B DROy+sWyrRbtA3GO2wrFB4MHlzHHb2uWofcOaSEKWl0fGwoDH6T6mmZFukQC9wU2pvYc woVQ== X-Gm-Message-State: APjAAAXgWbHA/5TXa+P1cHV5H1TQ3vcZrQPIEMy3AicQBHL1U0BPF/cW +FBkClEFTB0avI94NuEWrAxNIUnA X-Google-Smtp-Source: APXvYqzO6IX/iBoc7c2OnYnAbmq6nBSOJ2X0MuUVnVsiO5/eolUNoSn98q6XfvGMhPOZQmnOL5714Q== X-Received: by 2002:a1c:7401:: with SMTP id p1mr6712090wmc.144.1571497862235; Sat, 19 Oct 2019 08:11:02 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 01/11] Acceptance tests: refactor wait_for_console_pattern Date: Sat, 19 Oct 2019 17:10:48 +0200 Message-Id: <20191019151058.31733-2-f4bug@amsat.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191019151058.31733-1-f4bug@amsat.org> References: <20191019151058.31733-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::329 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Aleksandar Markovic , Cleber Rosa , Aleksandar Rikalo , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Cleber Rosa The same utility method is already present in two different test files, so let's consolidate it into a single utility function. Signed-off-by: Cleber Rosa Message-Id: <20190916164011.7653-1-crosa@redhat.com> Reviewed-by: Philippe Mathieu-Daud=C3=A9 [PMD: failure_message is optional] Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- tests/acceptance/avocado_qemu/__init__.py | 25 +++++++++++++++++++++ tests/acceptance/boot_linux_console.py | 27 +++++------------------ tests/acceptance/linux_ssh_mips_malta.py | 18 +++------------ 3 files changed, 33 insertions(+), 37 deletions(-) diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/a= vocado_qemu/__init__.py index bd41e0443c..e3101cba30 100644 --- a/tests/acceptance/avocado_qemu/__init__.py +++ b/tests/acceptance/avocado_qemu/__init__.py @@ -8,6 +8,7 @@ # This work is licensed under the terms of the GNU GPL, version 2 or # later. See the COPYING file in the top-level directory. =20 +import logging import os import sys import uuid @@ -53,6 +54,30 @@ def pick_default_qemu_bin(arch=3DNone): return qemu_bin_from_src_dir_path =20 =20 +def wait_for_console_pattern(test, success_message, failure_message=3DNone= ): + """ + Waits for messages to appear on the console, while logging the content + + :param test: an Avocado test containing a VM that will have its console + read and probed for a success or failure message + :type test: :class:`avocado_qemu.Test` + :param success_message: if this message appears, test succeeds + :param failure_message: if this message appears, test fails + """ + console =3D test.vm.console_socket.makefile() + console_logger =3D logging.getLogger('console') + while True: + msg =3D console.readline().strip() + if not msg: + continue + console_logger.debug(msg) + if success_message in msg: + break + if failure_message and failure_message in msg: + fail =3D 'Failure message found in console: %s' % failure_mess= age + test.fail(fail) + + class Test(avocado.Test): def setUp(self): self._vms =3D {} diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot= _linux_console.py index 8a9a314ab4..8897e0c253 100644 --- a/tests/acceptance/boot_linux_console.py +++ b/tests/acceptance/boot_linux_console.py @@ -9,12 +9,12 @@ # later. See the COPYING file in the top-level directory. =20 import os -import logging import lzma import gzip import shutil =20 from avocado_qemu import Test +from avocado_qemu import wait_for_console_pattern from avocado.utils import process from avocado.utils import archive =20 @@ -29,31 +29,14 @@ class BootLinuxConsole(Test): =20 KERNEL_COMMON_COMMAND_LINE =3D 'printk.time=3D0 ' =20 - def wait_for_console_pattern(self, success_message, - failure_message=3D'Kernel panic - not syn= cing'): - """ - Waits for messages to appear on the console, while logging the con= tent - - :param success_message: if this message appears, test succeeds - :param failure_message: if this message appears, test fails - """ - console =3D self.vm.console_socket.makefile() - console_logger =3D logging.getLogger('console') - while True: - msg =3D console.readline().strip() - if not msg: - continue - console_logger.debug(msg) - if success_message in msg: - break - if failure_message in msg: - fail =3D 'Failure message found in console: %s' % failure_= message - self.fail(fail) + def wait_for_console_pattern(self, success_message): + wait_for_console_pattern(self, success_message, + failure_message=3D'Kernel panic - not syn= cing') =20 def exec_command_and_wait_for_pattern(self, command, success_message): command +=3D '\n' self.vm.console_socket.sendall(command.encode()) - self.wait_for_console_pattern(success_message) + wait_for_console_pattern(self, success_message) =20 def extract_from_deb(self, deb, path): """ diff --git a/tests/acceptance/linux_ssh_mips_malta.py b/tests/acceptance/li= nux_ssh_mips_malta.py index 25a1df5098..ffbb06f846 100644 --- a/tests/acceptance/linux_ssh_mips_malta.py +++ b/tests/acceptance/linux_ssh_mips_malta.py @@ -13,6 +13,7 @@ import time =20 from avocado import skipUnless from avocado_qemu import Test +from avocado_qemu import wait_for_console_pattern from avocado.utils import process from avocado.utils import archive from avocado.utils import ssh @@ -40,19 +41,6 @@ class LinuxSSH(Test): def setUp(self): super(LinuxSSH, self).setUp() =20 - def wait_for_console_pattern(self, success_message, - failure_message=3D'Oops'): - console =3D self.vm.console_socket.makefile() - console_logger =3D logging.getLogger('console') - while True: - msg =3D console.readline() - console_logger.debug(msg.strip()) - if success_message in msg: - break - if failure_message in msg: - fail =3D 'Failure message found in console: %s' % failure_= message - self.fail(fail) - def get_portfwd(self): res =3D self.vm.command('human-monitor-command', command_line=3D'info usernet') @@ -109,7 +97,7 @@ class LinuxSSH(Test): =20 self.log.info('VM launched, waiting for sshd') console_pattern =3D 'Starting OpenBSD Secure Shell server: sshd' - self.wait_for_console_pattern(console_pattern) + wait_for_console_pattern(self, console_pattern, 'Oops') self.log.info('sshd ready') =20 self.ssh_connect('root', 'root') @@ -117,7 +105,7 @@ class LinuxSSH(Test): def shutdown_via_ssh(self): self.ssh_command('poweroff') self.ssh_disconnect_vm() - self.wait_for_console_pattern('Power down') + wait_for_console_pattern(self, 'Power down', 'Oops') =20 def ssh_command_output_contains(self, cmd, exp): stdout, _ =3D self.ssh_command(cmd) --=20 2.21.0