[10/23] CI: Fix errors reporting during startvm

Message ID 20240325155540.4162990-11-amikan@ilbers.de
State New
Headers show
Series Additional CI improvements | expand

Commit Message

Anton Mikanovich March 25, 2024, 3:55 p.m. UTC
Test case failure should be triggered by self.fail() API.
It helps to prepare much more correct log output.
So rebuild error handling of startvm related functions.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 testsuite/cibuilder.py | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)

Patch

diff --git a/testsuite/cibuilder.py b/testsuite/cibuilder.py
index fa30c2f5..d282f8ee 100755
--- a/testsuite/cibuilder.py
+++ b/testsuite/cibuilder.py
@@ -475,7 +475,7 @@  BBPATH .= ":${LAYERDIR}"\
         p1 = subprocess.Popen('exec ' + ' '.join(cmdline), shell=True,
                               stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                               universal_newlines=True)
-        self.log.info("Started VM with pid %s" % (p1.pid))
+        self.log.info("Starting VM with pid %s" % (p1.pid))
 
         return p1, cmdline, boot_log
 
@@ -506,8 +506,10 @@  BBPATH .= ":${LAYERDIR}"\
                 if fd == p1.stderr.fileno():
                     app_log.error(p1.stderr.readline().rstrip())
 
-        self.log.error("Didn't get login prompt")
-        return 1
+        rc = 1
+        if time.time() > timeout:
+            rc = 2
+        return rc
 
 
     def vm_parse_output(self, boot_log, multiconfig, skip_modulecheck):
@@ -539,10 +541,8 @@  BBPATH .= ":${LAYERDIR}"\
                 if (module_output in data or skip_modulecheck):
                     if resize_output and not resize_output in data:
                         rc = 1
-                        self.log.error("No resize output while expected")
                 else:
                     rc = 2
-                    self.log.error("No example module output while expected")
         return rc
 
 
@@ -553,13 +553,16 @@  BBPATH .= ":${LAYERDIR}"\
 
 
     def vm_turn_off(self, vm):
-        pid = self.vm_dict[vm][0]
-        os.kill(pid, signal.SIGKILL)
+        try:
+            pid = self.vm_dict[vm][0]
+            os.kill(pid, signal.SIGKILL)
 
-        del(self.vm_dict[vm])
-        self.vm_dump_dict(vm)
+            del(self.vm_dict[vm])
+            self.vm_dump_dict(vm)
 
-        self.log.info("Stopped VM with pid %s" % (pid))
+            self.log.info("Stopped VM with pid %s" % (pid))
+        except ProcessLookupError:
+            self.log.error("Can't stop VM %s" % vm)
 
 
     def vm_start(self, arch='amd64', distro='buster',
@@ -611,7 +614,10 @@  BBPATH .= ":${LAYERDIR}"\
             rc = self.vm_wait_boot(p1, timeout)
             if rc != 0:
                 self.vm_turn_off(vm)
-                self.fail('Failed to boot qemu machine')
+                if rc == 2:
+                    self.fail("Didn't get login prompt")
+                else:
+                    self.fail('Failed to boot qemu machine')
 
         if cmd is not None or script is not None:
             self.ssh_user='ci'
@@ -638,7 +644,12 @@  BBPATH .= ":${LAYERDIR}"\
             if rc != 0:
                 if not keep:
                     self.vm_turn_off(vm)
-                self.fail('Failed to parse output')
+                if rc == 1:
+                    self.fail("No resize output while expected")
+                elif rc == 2:
+                    self.fail("No example module output while expected")
+                else:
+                    self.fail('Failed to parse output')
 
         if not keep:
             self.vm_turn_off(vm)