From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 7236574603632443392 X-Received: by 2002:a05:6a00:1a0f:b0:64f:4614:e0b8 with SMTP id g15-20020a056a001a0f00b0064f4614e0b8mr464473pfv.2.1684896322099; Tue, 23 May 2023 19:45:22 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a17:90a:fd96:b0:246:6edd:bdde with SMTP id cx22-20020a17090afd9600b002466eddbddels8381543pjb.0.-pod-prod-07-us; Tue, 23 May 2023 19:45:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7+2PLsmqgxlfcmKNAIQ3RhfpeHqwraJViVcepctt0/8o6knY9Bc/l2Dr9QqEL9P/eSSn7L X-Received: by 2002:a17:90b:3749:b0:247:8ce1:996e with SMTP id ne9-20020a17090b374900b002478ce1996emr13673865pjb.29.1684896321111; Tue, 23 May 2023 19:45:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684896321; cv=none; d=google.com; s=arc-20160816; b=RwskHZxFzQuAEd5LWCxCoOtgdNgOdd0HrRS5fLRfDP+uz0V7Gln/Per98exszur7r+ XhD/CGXJ3n7QOLOEdwRrIVYFIg5BPp6tGE5U4zk64ZKnC1FUFuAom1EDt4s7vKh51EIz pG7VOXv7wmNgREMQbFMzdQuByqi49YRBjAe87gE179o1wcp6kAi7imQiS1AsLr0iEsL6 f/Inj9P1XD4TNhY0Uam0mK7It2Tp297QppirHXnB7URSZF29XI2bF20E896ZcUn4A8Ml fWrBwE6sExhZBX2ZW3EFO/nAYilDUnlt/5IvUiy+E0Qilo9l3fG5Fkb65ykRQrlrppqC OdmA== 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=6foKccPN7jJBFYh+FFtJGCmidVCdhXlibtdxV/AxDG8=; b=mW6jQkYJA6kiHTG7Fhnmr5pKAzBSCdIdhcg/isXJ9h2Nip3BOQ6txzqJgLEb/4/F31 vQuWaa2QtQeRJMSk0hH11jmwv3QH7520DpaSaA4F8MhIRSxL/+GRhR4dd1l5sCIwhQCE MAtSprt791DI+bW0mxwZT9b6iZfsIixXh3TL5P7/vKEbP/KHTo6wFEDHv4pIyeYT5rio 35tMYdnAge1YxWWDGsM93CN5lz6bsHphd5yX9JheKpqNaNpR2P7sHkd91ZwCG7IxCKWS fVqRjX6hZGf8if6kgMHGpbHYneQbOvKUXpzM5CpBIbc4xqk7YhHF6f/kGNTH5lmDI+y5 R41Q== 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 oc11-20020a17090b1c0b00b0024e59d95b82si57002pjb.1.2023.05.23.19.45.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 May 2023 19:45:21 -0700 (PDT) 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 34O2jEc5032413 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 24 May 2023 04:45:15 +0200 From: Uladzimir Bely To: isar-users@googlegroups.com Subject: [PATCH 1/4] cibuilder.py: Refactor vm_start related functions Date: Wed, 24 May 2023 04:45:11 +0200 Message-Id: <20230524024514.17042-2-ubely@ilbers.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230524024514.17042-1-ubely@ilbers.de> References: <20230524024514.17042-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: zygC0Xb55GUB get_ssh_cmd_prefix: Add possibility to specify user and hostname instead of default `ci@localhost`. This allows to run test on hardware targets by their IP address or hostname. prepare_priv_key: Copy private SSH key to build directory before use since it's original location may be readonly. remote_run: carve out ssh-related code from vm_start function. Signed-off-by: Uladzimir Bely --- testsuite/cibuilder.py | 67 ++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/testsuite/cibuilder.py b/testsuite/cibuilder.py index 6aac2279..a4edb578 100755 --- a/testsuite/cibuilder.py +++ b/testsuite/cibuilder.py @@ -226,14 +226,12 @@ 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) + def get_ssh_cmd_prefix(self, user, host, port, priv_key): + cmd_prefix = 'ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no '\ + '-p %s -o IdentityFile=%s %s@%s ' \ + % (port, priv_key, user, host) - cmd_prefix = 'ssh' + port_args + \ - ' -o ConnectTimeout=5 -o IdentityFile=' + priv_key + \ - ' -o StrictHostKeyChecking=no ci@localhost ' + self.log.debug('Connect command:\n' + cmd_prefix) return cmd_prefix @@ -258,6 +256,9 @@ class CIBuilder(Test): def wait_connection(self, proc, cmd_prefix, timeout): + if proc is None: + return 0 + self.log.debug('Waiting for SSH server ready...') rc = None @@ -281,6 +282,35 @@ class CIBuilder(Test): return rc + def prepare_priv_key(self): + # copy private key to build directory (that is writable) + 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) + + return priv_key + + + def remote_run(self, user, host, port, cmd, script, proc=None, timeout=0): + priv_key = self.prepare_priv_key() + cmd_prefix = self.get_ssh_cmd_prefix(user, host, port, priv_key) + + rc = self.wait_connection(proc, cmd_prefix, timeout) + + if rc == 0: + if cmd is not None: + rc = self.exec_cmd(cmd, cmd_prefix) + self.log.debug('`' + cmd + '` returned ' + str(rc)) + elif script is not None: + rc = self.run_script(script, cmd_prefix) + self.log.debug('`' + script + '` returned ' + str(rc)) + else: + return None + + return rc + + def vm_start(self, arch='amd64', distro='buster', enforce_pcbios=False, skip_modulecheck=False, image='isar-image-base', cmd=None, script=None): @@ -342,32 +372,17 @@ class CIBuilder(Test): universal_newlines=True) if cmd is not None or script is not None: - rc = None try: - port = None + user='ci' + host='localhost' + port = 22 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: - if cmd is not None: - rc = self.exec_cmd(cmd, cmd_prefix) - self.log.debug('`' + cmd + '` returned ' + str(rc)) - elif script is not None: - rc = self.run_script(script, cmd_prefix) - self.log.debug('`' + script + '` returned ' + str(rc)) + rc = self.remote_run(user, host, port, cmd, script, p1, timeout) finally: if p1.poll() is None: -- 2.20.1