[test-API PATCH 2/3] repo: Add test for mutualy exclusive console access

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

 



This test case checks if the console connection code works in a safe way
that the connection don't get messed up.
---
 repos/domain/console_mutex.py |   89 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 89 insertions(+), 0 deletions(-)
 create mode 100644 repos/domain/console_mutex.py

diff --git a/repos/domain/console_mutex.py b/repos/domain/console_mutex.py
new file mode 100644
index 0000000..f9df815
--- /dev/null
+++ b/repos/domain/console_mutex.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+""" A test case to test console mutual exclusivity
+    mandatory arguments: guestname
+"""
+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']
+    for key in keys:
+        if key not in params:
+            logger.error("%s is required" %key)
+            return 1
+
+def console_mutex(params):
+    """Attach to console"""
+    logger = params['logger']
+    guest = params['guestname']
+    if "device" not in  params:
+        device = "serial0"
+    else:
+        device = params['device']
+
+    util = utils.Utils()
+    uri = params['uri']
+
+    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("Creating another stream object")
+        stream2 = conn.newStream(0)
+
+        logger.info("Open safe console connection while an existing one is open");
+        failed = False
+        try:
+            dom.openConsole(device, stream2, libvirt.VIR_DOMAIN_CONSOLE_SAFE);
+        except libvirtError, e:
+            logger.info("Opening failed - OK")
+            failed = True
+
+        if not failed:
+            raise TestError("Opening of console succeeded although shoud fail")
+
+        logger.info("Abort the existing stream")
+        stream.abort()
+
+        logger.info("Re-try connecting to the console")
+        dom.openConsole(device, stream2, libvirt.VIR_DOMAIN_CONSOLE_SAFE);
+
+        logger.info("Re-try forcibly on already open console")
+
+        logger.info("Creating stream object")
+        stream = conn.newStream(0)
+
+        dom.openConsole(device, stream, libvirt.VIR_DOMAIN_CONSOLE_FORCE);
+
+    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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]