From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 7188033154287927296 X-Received: by 2002:a5e:c002:0:b0:6e4:e844:22e5 with SMTP id u2-20020a5ec002000000b006e4e84422e5mr6494466iol.63.1673594388073; Thu, 12 Jan 2023 23:19:48 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a6b:510c:0:b0:6bc:6044:840e with SMTP id f12-20020a6b510c000000b006bc6044840els822968iob.0.-pod-prod-gmail; Thu, 12 Jan 2023 23:19:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXuWoBewK0cTLwlRY67MSQgGE/z98af1S0B44Ix0xiIv6bJcaqGvxkrwr4LPVL2Px8rFjoU6 X-Received: by 2002:a6b:dc08:0:b0:704:7ab3:8795 with SMTP id s8-20020a6bdc08000000b007047ab38795mr3360490ioc.17.1673594387469; Thu, 12 Jan 2023 23:19:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673594387; cv=none; d=google.com; s=arc-20160816; b=bHt3nRj9WwVAM9fQ5L4Hf0cAS/kEnp2aJSl4vEIQHmWeMtsNoUjPBwHKoAwk/+rsUL tTtLtmqPmGvUns9d9N6jCc7uNXuwxHigLtOdb0rXkfDxodBEraWHECJDmAy+w6kFn2nE UeMPsWRgNGT4zNrCYNWKz3x4zwJ03X3UQL4X+R3ej9XBjVSQAQaMjDbiUw8za0IvQbyd VldTszktNbyNK/5mDNGH/hY5bqNqjlzRONGWlxbhn4g24cMvjmfKrpb23HUFsUYt5AC+ tG2CEetjoxD1fbG5/7SUjp3gcEVNFiTPfH8Skne7fQnackn5pFQmqkbNoRDWOgLIYT0Q NaDg== 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=j6edAaRWis76G/6jjQKXSr4fUMES0nwl9OoFpB8G4ko=; b=TRc5QFgpwTHcK8NDsu7BCldTX+xMBCj7wnqgy7+n6H277neEsylvpUqoOKaHvE4LV7 TeMgJ0N7MvoIzvnDdQNaid+piO4Hd5sl2BojJSkhWghrLJgELikiSo6CHudo+PnjZjbB XVFeFxrsB++juuslA7a9AIWCiF4ZMQRFCHUEUKlQ9LFhMUpR0vF1np5J4v5WQLvuDv59 4b41sbSAvoD9IXmWU7waAn7CFO+vIOSjHCqboHfH3he2tsp6OHMbxFIzmSb+hzb+/N4k LT931dmpYklhCBraBR388m4V0cx6uxo567Oss4E9k7fkzUo/Yk65ivgRlI+42DAR8Mww gwbg== 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 bl12-20020a056602408c00b006e2d7e57bbfsi1211027iob.1.2023.01.12.23.19.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Jan 2023 23:19:47 -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 30D7JgEw027786 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 13 Jan 2023 08:19:45 +0100 From: Uladzimir Bely To: isar-users@googlegroups.com Subject: [PATCH 08/11] testsuite: Support running custom commands in VM Date: Fri, 13 Jan 2023 08:19:39 +0100 Message-Id: <20230113071942.22506-9-ubely@ilbers.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230113071942.22506-1-ubely@ilbers.de> References: <20230113071942.22506-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: ziN7sudGGyp0 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 | 60 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/testsuite/cibuilder.py b/testsuite/cibuilder.py index 9e9cc8a3..4496b0dd 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 @@ -201,11 +202,44 @@ class CIBuilder(Test): return env['LAYERDIR_' + layer].strip('"') - def vm_start(self, arch='amd64', distro='buster', image='isar-image-base', enforce_pcbios=False): + def vm_exec_cmd(self, cmd='/bin/true', timeout=10, port=None): + spk = os.path.dirname(__file__) + '/keys/ssh/id_rsa' + os.chmod(spk, 0o400) + + port_args = '' + if port: + port_args = ' -p ' + str(port) + + cmd_prefix = 'ssh' + port_args + \ + ' -o ConnectTimeout=5 -o IdentityFile=' + spk + \ + ' -o StrictHostKeyChecking=no ci@localhost ' + self.log.debug('Waiting for SSH server ready...') + + rc = None + while time.time() < timeout and rc != 0: + rc = subprocess.call('exec ' + cmd_prefix + '/bin/true', + shell=True, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + time.sleep(1) + if rc != 0: + self.log.error('SSH server is not ready') + return -1 + + rc = subprocess.call('exec ' + cmd_prefix + cmd, shell=True, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + time.sleep(1) + + return rc + + def vm_start(self, arch='amd64', distro='buster', image='isar-image-base', + enforce_pcbios=False, 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('===================================================') @@ -256,6 +290,30 @@ 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 + + rc = self.vm_exec_cmd(cmd, timeout, port) + 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