From: Henning Schild <henning.schild@siemens.com>
To: Uladzimir Bely <ubely@ilbers.de>
Cc: isar-users@googlegroups.com
Subject: Re: [PATCH 08/11] testsuite: Support running custom commands in VM
Date: Tue, 24 Jan 2023 08:14:44 +0100 [thread overview]
Message-ID: <20230124081444.717de76a@md1za8fc.ad001.siemens.net> (raw)
In-Reply-To: <20230124081404.25aa167c@md1za8fc.ad001.siemens.net>
Am Tue, 24 Jan 2023 08:14:04 +0100
schrieb Henning Schild <henning.schild@siemens.com>:
> Am Fri, 13 Jan 2023 08:19:39 +0100
> schrieb Uladzimir Bely <ubely@ilbers.de>:
>
> > By specifying `cmd='<command>'` 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 <ubely@ilbers.de>
> > ---
> > 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 '
>
> What is the username? My guess would be root. Let us make that
> explicit and see if we can at some point get away with running this
> as non-root while we root into the VMs.
Forget the comment ... the username is "ci"
Henning
> Henning
>
> > + 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)
>
next prev parent reply other threads:[~2023-01-24 7:14 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-13 7:19 [PATCH 00/11] " Uladzimir Bely
2023-01-13 7:19 ` [PATCH 01/11] testsuite: Fix failing hostname service in qemu guest Uladzimir Bely
2023-01-13 7:19 ` [PATCH 02/11] testsuite: Allow custom image names in start_vm.py Uladzimir Bely
2023-01-24 6:59 ` Henning Schild
2023-01-13 7:19 ` [PATCH 03/11] testsuite: Fix terminal broken after run test executed Uladzimir Bely
2023-01-13 7:19 ` [PATCH 04/11] testsuite: Add SSH key pair for using in CI Uladzimir Bely
2023-01-13 7:19 ` [PATCH 05/11] image-account-extension: Add copy-ci-key flag for user Uladzimir Bely
2023-01-24 7:09 ` Henning Schild
2023-01-24 7:18 ` Henning Schild
2023-01-25 7:36 ` Uladzimir Bely
2023-01-25 8:45 ` Henning Schild
2023-01-13 7:19 ` [PATCH 06/11] meta-isar: Fix PCI bus initialization in qemuarm machine Uladzimir Bely
2023-02-08 13:03 ` Uladzimir Bely
2023-01-13 7:19 ` [PATCH 07/11] testsuite: Use random free port for qemu SSH forwarding Uladzimir Bely
2023-01-24 7:11 ` Henning Schild
2023-02-08 13:04 ` Uladzimir Bely
2023-01-13 7:19 ` [PATCH 08/11] testsuite: Support running custom commands in VM Uladzimir Bely
2023-01-24 7:14 ` Henning Schild
2023-01-24 7:14 ` Henning Schild [this message]
2023-01-13 7:19 ` [PATCH 09/11] meta-isar: Use a separate image recipe in CI Uladzimir Bely
2023-01-13 7:19 ` [PATCH 10/11] isar-image-ci: Make ethernet inerface auto bring up in ubuntu-focal Uladzimir Bely
2023-01-24 7:24 ` Henning Schild
2023-01-24 7:27 ` Henning Schild
2023-01-13 7:19 ` [PATCH 11/11] testsuite: Run custom commands on some qemu targets Uladzimir Bely
2023-01-24 7:39 ` Henning Schild
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230124081444.717de76a@md1za8fc.ad001.siemens.net \
--to=henning.schild@siemens.com \
--cc=isar-users@googlegroups.com \
--cc=ubely@ilbers.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox