From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 7197811629045579776 X-Received: by 2002:a05:6e02:4b2:b0:313:d1b4:d9b1 with SMTP id e18-20020a056e0204b200b00313d1b4d9b1mr4249233ils.61.1675871116056; Wed, 08 Feb 2023 07:45:16 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a6b:cd4c:0:b0:71b:37da:bd45 with SMTP id d73-20020a6bcd4c000000b0071b37dabd45ls3787587iog.10.-pod-prod-gmail; Wed, 08 Feb 2023 07:45:15 -0800 (PST) X-Google-Smtp-Source: AK7set+NaqxvE/sVEthkMsnk6U0qpRUSChb1mNblkyyaSlVFZmbTjQDCT+I3jP++i/OMa0ZExzjx X-Received: by 2002:a6b:5c01:0:b0:738:b3d:271 with SMTP id z1-20020a6b5c01000000b007380b3d0271mr2563783ioh.13.1675871115565; Wed, 08 Feb 2023 07:45:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675871115; cv=none; d=google.com; s=arc-20160816; b=O406GSH9R2IMnCGhD/0TM+ZHsIRoMuufy5S4NZ7ys7VnZRuoXDlyWTp03T6UjdL7aQ SaM7FdPekZnlwkPO+tlZ05xcfKlcF0oKHZ4tVVh9RjKppvO91RcV5pZwozvZ+i+gjGLk poIW3TSBdJMsbaFKMyuqUrJwjr9SDD3TaSnwwKnJRsdJ5KaE9lEqdzXal80otOkRa9uY bkUWgooNJi4lZbHWKeCkUFIhJ5U5+kUrGqGtcicSOB2nMypK2GAb3vO85iMz/0X7KRB1 zheFl9ZYfYLTKrXL52VbjwkVjUYc6QPDw35vLidSOcbf16YD9KDNqQHHgm+zVcraQfGp iJuA== 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:to:from; bh=gUdhyyUSjQlOEjFeoYa1S5v7S69MDTucvfqOwqcJvew=; b=W/3KsDuQP8HgNl6yHePnqjLjSOo+hqIIGCIhC+6Kugwh+wAC2bYJlK8N1QmemR5jxD +eWCjhQk2+pSQQTw+kE71ETowZgflRcN9xYgOARpUrqZkME9is2GsUX+djdLUmQ1rt0X mylkWa+I3mbuQChuhmOrRcMk7NqIARRILACGK0Hznh8aPJ40/sE/Nqm4fiw++YY5KbMI tzW2dmlGe0Ksxs0vj5LnAhK3HR5MEUYwApm/8vURJCtquAliRxSIK5sFgbeUzpvT4mp8 6apZjbD1ytejgvnVjlvsEZ3SWhF7e8z7vcKv5R0wQTHiA7Mw7oSW82J2j2WX356nF09f 46rw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of ubely@ilbers.de designates 85.214.156.166 as permitted sender) smtp.mailfrom=ubely@ilbers.de Return-Path: Received: from shymkent.ilbers.de (shymkent.ilbers.de. [85.214.156.166]) by gmr-mx.google.com with ESMTPS id o184-20020a6bbec1000000b00722c80c69d5si1166621iof.4.2023.02.08.07.45.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 Feb 2023 07:45:15 -0800 (PST) Received-SPF: pass (google.com: domain of ubely@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 ubely@ilbers.de designates 85.214.156.166 as permitted sender) smtp.mailfrom=ubely@ilbers.de Received: from baighyz.m.ilbers.de (host-80-81-17-52.static.customer.m-online.net [80.81.17.52]) (authenticated bits=0) by shymkent.ilbers.de (8.15.2/8.15.2/Debian-8+deb9u1) with ESMTPSA id 318FjB4x015298 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 8 Feb 2023 16:45:13 +0100 From: Uladzimir Bely To: isar-users@googlegroups.com Subject: [PATCH v2 6/9] testsuite: Support running custom commands in VM Date: Wed, 8 Feb 2023 16:45:08 +0100 Message-Id: <20230208154511.1884-7-ubely@ilbers.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230208154511.1884-1-ubely@ilbers.de> References: <20230208154511.1884-1-ubely@ilbers.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on shymkent.ilbers.de X-TUID: eLFTxLsrZjgG By specifying `cmd=''` it's now possible to run VM and execute the command over SSH connection. If this is not specified, tests uses previous approach, with parsing output log and searching some specific fragments. Signed-off-by: Uladzimir Bely --- testsuite/cibuilder.py | 81 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 2 deletions(-) diff --git a/testsuite/cibuilder.py b/testsuite/cibuilder.py index 247b998b..9b64af90 100755 --- a/testsuite/cibuilder.py +++ b/testsuite/cibuilder.py @@ -2,6 +2,7 @@ import logging import os +import re import select import shutil import subprocess @@ -209,13 +210,54 @@ class CIBuilder(Test): return env['LAYERDIR_' + layer].strip('"') + def get_ssh_cmd_prefix(self, port, priv_key): + port_args = '' + if port: + port_args = ' -p ' + str(port) + + cmd_prefix = 'ssh' + port_args + \ + ' -o ConnectTimeout=5 -o IdentityFile=' + priv_key + \ + ' -o StrictHostKeyChecking=no ci@localhost ' + + return cmd_prefix + + + def exec_cmd(self, cmd, cmd_prefix): + rc = subprocess.call('exec ' + str(cmd_prefix) + ' "' + str(cmd) + '"', shell=True, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + return rc + + + def wait_connection(self, proc, cmd_prefix, timeout): + self.log.debug('Waiting for SSH server ready...') + + rc = None + while time.time() < timeout: + if proc.poll() is not None: + self.log.error('Machine is not running') + return rc + + rc = self.exec_cmd('/bin/true', cmd_prefix) + time.sleep(1) + + if rc == 0: + self.log.debug('SSH server is ready') + break + + if rc != 0: + self.log.error('SSH server is not ready') + + return rc + + def vm_start(self, arch='amd64', distro='buster', enforce_pcbios=False, skip_modulecheck=False, - image='isar-image-base'): + image='isar-image-base', cmd=None): time_to_wait = self.params.get('time_to_wait', default=60) self.log.info('===================================================') self.log.info('Running Isar VM boot test for (' + distro + '-' + arch + ')') + self.log.info('Remote command is ' + str(cmd)) self.log.info('Isar build folder is: ' + self.build_dir) self.log.info('===================================================') @@ -238,7 +280,7 @@ class CIBuilder(Test): output_file, None, enforce_pcbios) cmdline.insert(1, '-nographic') - self.log.info('QEMU boot line: ' + str(cmdline)) + self.log.info('QEMU boot line:\n' + ' '.join(cmdline)) login_prompt = b'isar login:' # the printk of recipes-kernel/example-module @@ -266,6 +308,41 @@ class CIBuilder(Test): p1 = subprocess.Popen('exec ' + ' '.join(cmdline), shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + + if cmd is not None: + rc = None + try: + port = None + for arg in cmdline: + match = re.match(r".*hostfwd=tcp::(\d*).*", arg) + if match: + port = match.group(1) + break + + # copy private key to build directory + priv_key = '%s/ci_priv_key' % self.build_dir + if not os.path.exists(priv_key): + shutil.copy(os.path.dirname(__file__) + '/keys/ssh/id_rsa', priv_key) + os.chmod(priv_key, 0o400) + + cmd_prefix = self.get_ssh_cmd_prefix(port, priv_key) + self.log.debug('Connect command:\n' + cmd_prefix) + rc = self.wait_connection(p1, cmd_prefix, timeout) + + if rc == 0: + rc = self.exec_cmd(cmd, cmd_prefix) + self.log.debug('`' + cmd + '` returned ' + str(rc)) + finally: + if p1.poll() is None: + self.log.debug('Killing qemu...') + p1.kill() + p1.wait() + + if rc != 0: + self.fail('Log ' + output_file) + + return + try: poller = select.poll() poller.register(p1.stdout, select.POLLIN) -- 2.20.1