[oe-commits] Stefan Stanacar : lib/oeqa/utils/oeqemuconsole.py: handle qemu serial console connection

git at git.openembedded.org git at git.openembedded.org
Tue Jul 9 09:46:01 UTC 2013


Module: openembedded-core.git
Branch: master
Commit: 1cfec2f0a1a1ee84cc6b2b6ad890688da85c5e81
URL:    http://git.openembedded.org/?p=openembedded-core.git&a=commit;h=1cfec2f0a1a1ee84cc6b2b6ad890688da85c5e81

Author: Stefan Stanacar <stefanx.stanacar at intel.com>
Date:   Fri Jun 28 11:09:28 2013 +0300

lib/oeqa/utils/oeqemuconsole.py: handle qemu serial console connection

Python's telnetlib Telnet class connects only to AF_INET sockets, but we
want to use Unix domain socket for the qemu serial connection, so that's
why we override it.
Also we add a new read_all_timeout method similar to Telnet's read_all,
that read until a match or timeout and logs all output.

Signed-off-by: Stefan Stanacar <stefanx.stanacar at intel.com>

---

 meta/lib/oeqa/utils/oeqemuconsole.py |   45 ++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/meta/lib/oeqa/utils/oeqemuconsole.py b/meta/lib/oeqa/utils/oeqemuconsole.py
new file mode 100644
index 0000000..95a2133
--- /dev/null
+++ b/meta/lib/oeqa/utils/oeqemuconsole.py
@@ -0,0 +1,45 @@
+import socket
+import time
+import re
+from telnetlib import Telnet
+
+class oeQemuConsole(Telnet):
+
+    """
+    Override Telnet class to use unix domain sockets,
+    Telnet uses AF_INET for socket, we don't want that.
+    Also, provide a read_all variant with timeout, that
+    returns whatever output there is.
+    """
+
+    def __init__(self, stream, logfile):
+
+        Telnet.__init__(self, host=None)
+        self.stream = stream
+        self.logfile = logfile
+        self.eof = 0
+        self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+        self.sock.connect(stream)
+
+    def log(self, msg):
+        if self.logfile:
+            with open(self.logfile, "a") as f:
+                f.write("%s\n" % msg)
+
+
+    def read_all_timeout(self, match, timeout=200):
+        """Read until EOF or until timeout or until match.
+        """
+        ret = False
+        self.process_rawq()
+        endtime = time.time() + timeout
+        while not self.eof and time.time() < endtime:
+            self.fill_rawq()
+            self.process_rawq()
+            if re.search(match, self.cookedq):
+                ret = True
+                break
+        buf = self.cookedq
+        self.cookedq = ''
+        self.log(buf)
+        return (ret, buf)



More information about the Openembedded-commits mailing list