[libvirt-test-API][PATCH 1/2] domain: add open_graphicsfd

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

 



Add test case for API domain.openGraphicsFD.

Signed-off-by: Jincheng Miao <jmiao@xxxxxxxxxx>
---
 repos/domain/open_graphicsfd.py |   89 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 89 insertions(+), 0 deletions(-)
 create mode 100644 repos/domain/open_graphicsfd.py

diff --git a/repos/domain/open_graphicsfd.py b/repos/domain/open_graphicsfd.py
new file mode 100644
index 0000000..ab5b681
--- /dev/null
+++ b/repos/domain/open_graphicsfd.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+# To test domain's openGraphicsFD API
+
+import time
+import os
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+
+required_params = ('guestname', 'idx')
+optional_params = {'flags': ''}
+
+
+def parse_flags(flags):
+    """ parse flags
+    """
+    if flags == 'skipauth':
+        return libvirt.VIR_DOMAIN_OPEN_GRAPHICS_SKIPAUTH
+    elif flags == None:
+        return 0
+    else:
+        return -1
+
+def check_guest_status(domobj):
+    """ check guest current status
+    """
+    state = domobj.info()[0]
+    if state == libvirt.VIR_DOMAIN_SHUTOFF or \
+        state == libvirt.VIR_DOMAIN_SHUTDOWN:
+        return False
+    else:
+        return True
+
+
+def check_graphicsfd(fd):
+    """ check graphicsfd
+    """
+    try:
+        f = os.fdopen(fd)
+        f.close()
+    except:
+        return False
+    return True
+
+
+def open_graphicsfd(params):
+    """ test openGraphicsFD API
+    """
+    logger = params['logger']
+    guestname = params['guestname']
+    idx = int(params['idx'])
+    flags = parse_flags(params.get('flags'))
+
+    if flags == -1:
+        logger.error("invalid flags for openGraphicsFD: %s" % flags)
+        return 1
+
+    logger.info("the guestname is %s" % guestname)
+    logger.info("the idx is %s" % idx)
+    logger.info("the flags is %s" % flags)
+
+    conn = sharedmod.libvirtobj['conn']
+
+    domobj = conn.lookupByName(guestname)
+
+    # Check domain status
+    if check_guest_status(domobj):
+        pass
+    else:
+        domobj.create()
+        time.sleep(90)
+
+    try:
+        fd = domobj.openGraphicsFD(idx)
+
+        if check_graphicsfd(fd):
+            logger.info("check graphicsfd: success.")
+        else:
+            logger.error("check graphicsfd: failed.")
+            return 1
+
+    except libvirtError, e:
+        logger.error("API error message: %s, error code is %s"
+                     % (e.message, e.get_error_code()))
+        return 1
+
+    return 0
-- 
1.7.1

--
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]