diff options
author | Randy Witt <randy.e.witt@linux.intel.com> | 2015-08-20 10:55:17 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-08-24 23:45:24 +0100 |
commit | b46d83a848cf23c7f639a6ebafbd0f2c1413584a (patch) | |
tree | ed9ae9818c9c0aaa3db5091d3bf561ed2155dc78 /meta/lib | |
parent | 829a6e521f15bae93d5f1a02dc67bc56a8c606c8 (diff) | |
download | openembedded-core-b46d83a848cf23c7f639a6ebafbd0f2c1413584a.tar.gz openembedded-core-b46d83a848cf23c7f639a6ebafbd0f2c1413584a.tar.bz2 openembedded-core-b46d83a848cf23c7f639a6ebafbd0f2c1413584a.zip |
qemurunner: Make create_socket() return data and use exceptions
So that create_socket() can be called more than once to create sockets,
it now returns the socket and port rather than setting class variables
directly.
create_socket() now only uses exceptions for errors, not the return
value from the function.
Signed-off-by: Randy Witt <randy.e.witt@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Diffstat (limited to 'meta/lib')
-rw-r--r-- | meta/lib/oeqa/utils/qemurunner.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py index c5bb13c878..c8d689900d 100644 --- a/meta/lib/oeqa/utils/qemurunner.py +++ b/meta/lib/oeqa/utils/qemurunner.py @@ -42,20 +42,18 @@ class QemuRunner: self.runqemutime = 60 def create_socket(self): - try: - self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.server_socket.setblocking(0) - self.server_socket.bind(("127.0.0.1",0)) - self.server_socket.listen(2) - self.serverport = self.server_socket.getsockname()[1] - logger.info("Created listening socket for qemu serial console on: 127.0.0.1:%s" % self.serverport) - return True - except socket.error, msg: - self.server_socket.close() - logger.error("Failed to create listening socket: %s" % msg[1]) - return False - + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.setblocking(0) + sock.bind(("127.0.0.1",0)) + sock.listen(2) + port = sock.getsockname()[1] + logger.info("Created listening socket for qemu serial console on: 127.0.0.1:%s" % port) + return (sock, port) + + except socket.error: + sock.close() + raise def log(self, msg): if self.logfile: @@ -82,7 +80,10 @@ class QemuRunner: else: os.environ["DEPLOY_DIR_IMAGE"] = self.deploy_dir_image - if not self.create_socket(): + try: + self.server_socket, self.serverport = self.create_socket() + except socket.error, msg: + logger.error("Failed to create listening socket: %s" % msg[1]) return False # Set this flag so that Qemu doesn't do any grabs as SDL grabs interact |