[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [test-API PATCH 3/3] repo: Add test for console input and output operations



This test checks if the console input and output work as desired. The
test takes as an argument a string, that is sent to the console and
another string that is expected to be read from the console. When those
two compare successfuly the test succeeds.
---
 repos/domain/console_io.py |   76 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 76 insertions(+), 0 deletions(-)
 create mode 100644 repos/domain/console_io.py

diff --git a/repos/domain/console_io.py b/repos/domain/console_io.py
new file mode 100644
index 0000000..6af206a
--- /dev/null
+++ b/repos/domain/console_io.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+""" A test case to test console mutual exclusivity
+    mandatory arguments: guestname
+                         device
+                         data
+                         expect
+"""
+import libvirt
+from libvirt import libvirtError
+
+from utils.Python import utils
+from utils.Python.testError import TestError
+
+def usage(params):
+    """Verify parameter dictionary"""
+    logger = params['logger']
+    keys = ['guestname', 'device', 'data', 'expect']
+    for key in keys:
+        if key not in params:
+            logger.error("%s is required" %key)
+            return 1
+
+def console_io(params):
+    """Attach to console"""
+    logger = params['logger']
+    guest = params['guestname']
+    device = params['device']
+    data = params['data']
+    expect = params['expect']
+
+    util = utils.Utils()
+    uri = params['uri']
+    reply = ""
+
+    ret = 1
+
+    try:
+        logger.info("Connecting to hypervisor: " + uri)
+        conn = libvirt.open(uri)
+        dom = conn.lookupByName(guest)
+
+        logger.info("Creating stream object")
+        stream = conn.newStream(0)
+
+        logger.info("Forcibly open console on domain")
+        dom.openConsole(device, stream, libvirt.VIR_DOMAIN_CONSOLE_FORCE);
+
+        logger.info("Sending data: '" + data + "'")
+        stream.send(data)
+
+        while len(reply) < len(expect):
+            recv = stream.recv(10);
+            reply += recv
+            logger.info("Recieved data: '" + recv + "'")
+
+        if expect != reply:
+            raise TestError("Recieved data don't match expected string")
+
+    except libvirtError, e:
+        logger.error("Libvirt call failed")
+        raise e;
+
+    except TestError, e:
+        logger.error("Test failed: " + str(e));
+
+    else:
+        logger.info("All tests succeeded")
+        ret = 0
+
+    finally:
+        logger.info("Closing hypervisor connection")
+        conn.close()
+
+        logger.info("Done")
+
+    return ret
-- 
1.7.3.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]