From nobody Mon Feb 9 12:43:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1618203228; cv=none; d=zohomail.com; s=zohoarc; b=O8hdm1yOkmMefD/BogTJQQyUwgagIIHWGiCRzd7D3qbQjS8WTtQeHoAmmL1rIJAL9yb2HErqVzcic2gRONgpWmitgHdy4XDGgJsWmC45bO7Kg2gRksr4uDFXRKnsahlJJQIEIi+cB3DkA7C4FdOt+jW03f22UzZycVfBC6IfX14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618203228; 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=gKyj9LHUvfRmHHbGTT09vsDcFvrBYo3p5V8ZvtpnNbY=; b=GRKlse7xGkNiqn0N+OAY/K5ORomkjD7FRdVEFme/uTpiUtmgfxxst2sSGzFYAocd0FRwgmWdyWh3b+yNvzbh73V3PKVbsgVGBmOsVIXoseYpv/96yHBjapDLIVjyJZwYGIqIClgyLs/jYRAcqF1AiZAmTpumf4KHWh6UaXSum3g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1618203228216715.6662301635215; Sun, 11 Apr 2021 21:53:48 -0700 (PDT) Received: from localhost ([::1]:35552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lVoa3-00026l-4s for importer@patchew.org; Mon, 12 Apr 2021 00:53:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44874) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVoUK-0002FD-Dz for qemu-devel@nongnu.org; Mon, 12 Apr 2021 00:47:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:20843) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVoUH-0003gr-JJ for qemu-devel@nongnu.org; Mon, 12 Apr 2021 00:47:52 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-452-bEsxxsoJPkurW9kzc9NeSA-1; Mon, 12 Apr 2021 00:47:45 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EA60987504F; Mon, 12 Apr 2021 04:47:44 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-113-108.rdu2.redhat.com [10.10.113.108]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C9DD10016FD; Mon, 12 Apr 2021 04:47:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618202868; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gKyj9LHUvfRmHHbGTT09vsDcFvrBYo3p5V8ZvtpnNbY=; b=Lvor4w1sbcLrXPSLZ/UR5VOzbnNkLMjsZ1iQqfs0LrvUs0/lHvmkJeQU8wiAHhouSGi941 OipTMr9sOiy1TVLlQt+P+G16vLQyQp4EqdAZHUYMicos80YyoxhZPfJwZRWPLmZxnQoNjz YKVcKLe+WXgik5StQO2cXzaDOkpcqWA= X-MC-Unique: bEsxxsoJPkurW9kzc9NeSA-1 From: Cleber Rosa To: qemu-devel@nongnu.org Subject: [PATCH v3 04/11] Acceptance Tests: move useful ssh methods to base class Date: Mon, 12 Apr 2021 00:46:37 -0400 Message-Id: <20210412044644.55083-5-crosa@redhat.com> In-Reply-To: <20210412044644.55083-1-crosa@redhat.com> References: <20210412044644.55083-1-crosa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=crosa@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=crosa@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Thomas Huth , Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Willian Rampazzo , Eric Auger , John Snow , Willian Rampazzo , Cleber Rosa , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Aurelien Jarno , Beraldo Leal Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Both the virtiofs submounts and the linux ssh mips malta tests contains useful methods related to ssh that deserve to be made available to other tests. Let's move them to an auxiliary, mix-in class that will be used on the base LinuxTest class. The method that helps with setting up an ssh connection will now support both key and password based authentication, defaulting to key based. Signed-off-by: Cleber Rosa Reviewed-by: Wainer dos Santos Moschetta Reviewed-by: Willian Rampazzo Reviewed-by: Eric Auger Signed-off-by: Cleber Rosa --- tests/acceptance/avocado_qemu/__init__.py | 48 ++++++++++++++++++++++- tests/acceptance/linux_ssh_mips_malta.py | 40 ++----------------- tests/acceptance/virtiofs_submounts.py | 37 ----------------- 3 files changed, 50 insertions(+), 75 deletions(-) diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/a= vocado_qemu/__init__.py index 83b1741ec85..67f75f66e56 100644 --- a/tests/acceptance/avocado_qemu/__init__.py +++ b/tests/acceptance/avocado_qemu/__init__.py @@ -20,6 +20,7 @@ from avocado.utils import cloudinit from avocado.utils import datadrainer from avocado.utils import network +from avocado.utils import ssh from avocado.utils import vmimage from avocado.utils.path import find_command =20 @@ -43,6 +44,8 @@ from qemu.accel import kvm_available from qemu.accel import tcg_available from qemu.machine import QEMUMachine +from qemu.utils import get_info_usernet_hostfwd_port + =20 def is_readable_executable_file(path): return os.path.isfile(path) and os.access(path, os.R_OK | os.X_OK) @@ -253,7 +256,50 @@ def fetch_asset(self, name, cancel_on_missing=3Dcancel_on_missing) =20 =20 -class LinuxTest(Test): +class LinuxSSHMixIn: + """Contains utility methods for interacting with a guest via SSH.""" + + def ssh_connect(self, username, credential, credential_is_key=3DTrue): + self.ssh_logger =3D logging.getLogger('ssh') + res =3D self.vm.command('human-monitor-command', + command_line=3D'info usernet') + port =3D get_info_usernet_hostfwd_port(res) + self.assertIsNotNone(port) + self.assertGreater(port, 0) + self.log.debug('sshd listening on port: %d', port) + if credential_is_key: + self.ssh_session =3D ssh.Session('127.0.0.1', port=3Dport, + user=3Dusername, key=3Dcredenti= al) + else: + self.ssh_session =3D ssh.Session('127.0.0.1', port=3Dport, + user=3Dusername, password=3Dcre= dential) + for i in range(10): + try: + self.ssh_session.connect() + return + except: + time.sleep(4) + pass + self.fail('ssh connection timeout') + + def ssh_command(self, command): + self.ssh_logger.info(command) + result =3D self.ssh_session.cmd(command) + stdout_lines =3D [line.rstrip() for line + in result.stdout_text.splitlines()] + for line in stdout_lines: + self.ssh_logger.info(line) + stderr_lines =3D [line.rstrip() for line + in result.stderr_text.splitlines()] + for line in stderr_lines: + self.ssh_logger.warning(line) + + self.assertEqual(result.exit_status, 0, + f'Guest command failed: {command}') + return stdout_lines, stderr_lines + + +class LinuxTest(Test, LinuxSSHMixIn): """Facilitates having a cloud-image Linux based available. =20 For tests that indend to interact with guests, this is a better choice diff --git a/tests/acceptance/linux_ssh_mips_malta.py b/tests/acceptance/li= nux_ssh_mips_malta.py index 052008f02d4..61c9079d047 100644 --- a/tests/acceptance/linux_ssh_mips_malta.py +++ b/tests/acceptance/linux_ssh_mips_malta.py @@ -12,16 +12,14 @@ import time =20 from avocado import skipUnless -from avocado_qemu import Test +from avocado_qemu import Test, LinuxSSHMixIn from avocado_qemu import wait_for_console_pattern from avocado.utils import process from avocado.utils import archive from avocado.utils import ssh =20 -from qemu.utils import get_info_usernet_hostfwd_port =20 - -class LinuxSSH(Test): +class LinuxSSH(Test, LinuxSSHMixIn): =20 timeout =3D 150 # Not for 'configure --enable-debug --enable-debug-tcg' =20 @@ -72,41 +70,9 @@ def get_kernel_info(self, endianess, wordsize): def setUp(self): super(LinuxSSH, self).setUp() =20 - def ssh_connect(self, username, password): - self.ssh_logger =3D logging.getLogger('ssh') - res =3D self.vm.command('human-monitor-command', - command_line=3D'info usernet') - port =3D get_info_usernet_hostfwd_port(res) - if not port: - self.cancel("Failed to retrieve SSH port") - self.log.debug("sshd listening on port:" + port) - self.ssh_session =3D ssh.Session(self.VM_IP, port=3Dint(port), - user=3Dusername, password=3Dpasswor= d) - for i in range(10): - try: - self.ssh_session.connect() - return - except: - time.sleep(4) - pass - self.fail("ssh connection timeout") - def ssh_disconnect_vm(self): self.ssh_session.quit() =20 - def ssh_command(self, command, is_root=3DTrue): - self.ssh_logger.info(command) - result =3D self.ssh_session.cmd(command) - stdout_lines =3D [line.rstrip() for line - in result.stdout_text.splitlines()] - for line in stdout_lines: - self.ssh_logger.info(line) - stderr_lines =3D [line.rstrip() for line - in result.stderr_text.splitlines()] - for line in stderr_lines: - self.ssh_logger.warning(line) - return stdout_lines, stderr_lines - def boot_debian_wheezy_image_and_ssh_login(self, endianess, kernel_pat= h): image_url, image_hash =3D self.get_image_info(endianess) image_path =3D self.fetch_asset(image_url, asset_hash=3Dimage_hash) @@ -127,7 +93,7 @@ def boot_debian_wheezy_image_and_ssh_login(self, endiane= ss, kernel_path): wait_for_console_pattern(self, console_pattern, 'Oops') self.log.info('sshd ready') =20 - self.ssh_connect('root', 'root') + self.ssh_connect('root', 'root', False) =20 def shutdown_via_ssh(self): self.ssh_command('poweroff') diff --git a/tests/acceptance/virtiofs_submounts.py b/tests/acceptance/virt= iofs_submounts.py index 57a7047342f..bed8ce44dfc 100644 --- a/tests/acceptance/virtiofs_submounts.py +++ b/tests/acceptance/virtiofs_submounts.py @@ -9,8 +9,6 @@ from avocado_qemu import wait_for_console_pattern from avocado.utils import ssh =20 -from qemu.utils import get_info_usernet_hostfwd_port - =20 def run_cmd(args): subp =3D subprocess.Popen(args, @@ -75,41 +73,6 @@ class VirtiofsSubmountsTest(LinuxTest): :avocado: tags=3Daccel:kvm """ =20 - def ssh_connect(self, username, keyfile): - self.ssh_logger =3D logging.getLogger('ssh') - res =3D self.vm.command('human-monitor-command', - command_line=3D'info usernet') - port =3D get_info_usernet_hostfwd_port(res) - self.assertIsNotNone(port) - self.assertGreater(port, 0) - self.log.debug('sshd listening on port: %d', port) - self.ssh_session =3D ssh.Session('127.0.0.1', port=3Dport, - user=3Dusername, key=3Dkeyfile) - for i in range(10): - try: - self.ssh_session.connect() - return - except: - time.sleep(4) - pass - self.fail('ssh connection timeout') - - def ssh_command(self, command): - self.ssh_logger.info(command) - result =3D self.ssh_session.cmd(command) - stdout_lines =3D [line.rstrip() for line - in result.stdout_text.splitlines()] - for line in stdout_lines: - self.ssh_logger.info(line) - stderr_lines =3D [line.rstrip() for line - in result.stderr_text.splitlines()] - for line in stderr_lines: - self.ssh_logger.warning(line) - - self.assertEqual(result.exit_status, 0, - f'Guest command failed: {command}') - return stdout_lines, stderr_lines - def run(self, args, ignore_error=3DFalse): stdout, stderr, ret =3D run_cmd(args) =20 --=20 2.30.2