Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH 1/2] oeqa/utils/qemurunner: change the serial runner usage
@ 2023-02-16  9:54 Louis Rannou
  2023-02-16  9:54 ` [PATCH 2/2] oeqa/utils/qemurunner: remove deprecated usage of run_serial Louis Rannou
  2023-02-16 22:31 ` [OE-core] [PATCH 1/2] oeqa/utils/qemurunner: change the serial runner usage Alexandre Belloni
  0 siblings, 2 replies; 3+ messages in thread
From: Louis Rannou @ 2023-02-16  9:54 UTC (permalink / raw)
  To: openembedded-core; +Cc: khilman, Louis Rannou

[YOCTO #15021]

Create a new runner run_serial_socket which usage matches the traditional ssh
runner. Its return status is 0 when the command succeeded or 0 when it
failed. If an error is encountered, it raises an Exception.

The previous serial runner is maintained and marked as deprecated.

Signed-off-by: Louis Rannou <lrannou@baylibre.com>
---
 meta/lib/oeqa/targetcontrol.py    |  3 +++
 meta/lib/oeqa/utils/qemurunner.py | 42 ++++++++++++++++++++-----------
 2 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/meta/lib/oeqa/targetcontrol.py b/meta/lib/oeqa/targetcontrol.py
index 1fdff82889..99fbcb5879 100644
--- a/meta/lib/oeqa/targetcontrol.py
+++ b/meta/lib/oeqa/targetcontrol.py
@@ -210,6 +210,9 @@ class QemuTarget(BaseTarget):
     def run_serial(self, command, timeout=60):
         return self.runner.run_serial(command, timeout=timeout)
 
+    def run_serial_socket(self, command, timeout=60):
+        return self.runner.run_serial_socket(command, timeout=timeout)
+
 
 class SimpleRemoteTarget(BaseTarget):
 
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
index c19164e6e7..c8fffd8fd1 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -618,7 +618,13 @@ class QemuRunner:
                 return self.qmp.cmd(command)
 
     def run_serial(self, command, raw=False, timeout=60):
+        # Deprecated
         # Returns (status, output) where status is 1 on success and 0 on error
+        (status, output) = self.run_serial_socket(command, raw, timeout)
+        return (0 if status else 1, output)
+
+    def run_serial_socket(self, command, raw=False, timeout=60):
+        # Returns (status, output) where status is 0 on success and a negative value on error.
 
         # We assume target system have echo to get command status
         if not raw:
@@ -632,7 +638,7 @@ class QemuRunner:
         while True:
             now = time.time()
             if now >= end:
-                data += "<<< run_serial(): command timed out after %d seconds without output >>>\r\n\r\n" % timeout
+                data += "<<< run_serial_socket(): command timed out after %d seconds without output >>>\r\n\r\n" % timeout
                 break
             try:
                 sread, _, _ = select.select([self.server_socket],[],[], end - now)
@@ -650,21 +656,27 @@ class QemuRunner:
                         return (1, "")
                     raise Exception("No data on serial console socket, connection closed?")
 
-        if data:
-            if raw:
-                status = 1
+        if not data:
+            self.logger.error("serial run returned no data")
+            raise subprocess.SubprocessError('serial run failed: no data')
+
+        if raw:
+            status = 0
+        else:
+            # Remove first line (command line) and last line (prompt)
+            data = data[data.find('$?\r\n')+4:data.rfind('\r\n')]
+            index = data.rfind('\r\n')
+            if index == -1:
+                data = ""
+                self.logger.error("serial run returned no result")
+                raise Exception('serial run failed: no result')
             else:
-                # Remove first line (command line) and last line (prompt)
-                data = data[data.find('$?\r\n')+4:data.rfind('\r\n')]
-                index = data.rfind('\r\n')
-                if index == -1:
-                    status_cmd = data
-                    data = ""
-                else:
-                    status_cmd = data[index+2:]
-                    data = data[:index]
-                if (status_cmd == "0"):
-                    status = 1
+                status_cmd = data[index+2:]
+                data = data[:index]
+                try:
+                    status = int(status_cmd)
+                except ValueError as e:
+                    raise Exception('Could not convert to integer: {}'.format(str(e)))
         return (status, str(data))
 
 
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-02-16 22:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-16  9:54 [PATCH 1/2] oeqa/utils/qemurunner: change the serial runner usage Louis Rannou
2023-02-16  9:54 ` [PATCH 2/2] oeqa/utils/qemurunner: remove deprecated usage of run_serial Louis Rannou
2023-02-16 22:31 ` [OE-core] [PATCH 1/2] oeqa/utils/qemurunner: change the serial runner usage Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox