* repos/domain/spice_options.py: add this test for BZ#682237
---
repos/domain/spice_options.py | 138 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 138 insertions(+), 0 deletions(-)
create mode 100644 repos/domain/spice_options.py
diff --git a/repos/domain/spice_options.py b/repos/domain/spice_options.py
new file mode 100644
index 0000000..7e0b027
--- /dev/null
+++ b/repos/domain/spice_options.py
@@ -0,0 +1,138 @@
+#!/usr/bin/env python
+"""For configuring spice compression options testing
+ domain:spice_options
+ guestname
+ xxx
+ image
+ auto_glz|auto_lz|quic|glz|lz|off
+ jpeg
+ auto|never|always
+ zlib
+ auto|never|always
+ playback
+ on|off
+"""
+
+__author__ = 'Nan Zhang: nzhang(a)redhat.com'
+__date__ = 'Thu Sep 8, 2011'
+__version__ = '0.1.0'
+__credits__ = 'Copyright (C) 2011 Red Hat, Inc.'
+__all__ = ['usage', 'spice_config']
+
+import os
+import re
+import sys
+from xml.dom import minidom
+
+def append_path(path):
+ """Append root path of package"""
+ if path in sys.path:
+ pass
+ else:
+ sys.path.append(path)
+
+pwd = os.getcwd()
+result = re.search('(.*)libvirt-test-API', pwd)
+append_path(result.group(0))
+
+from lib import connectAPI
+from lib import domainAPI
+from utils.Python import utils
+from utils.Python import xmlbuilder
+from exception import LibvirtAPI
+
+def check_params(params):
+ """Verify inputing parameter dictionary"""
+ logger = params['logger']
+ keys = ['guestname', 'image', 'jpeg', 'zlib',
'playback']
+ for key in keys:
+ if key not in params:
+ logger.error("%s is required" %key)
+ return 1
+ return 0
+
+def spice_options(params):
+ """check spice options"""
+ # Initiate and check parameters
+ params_check_result = check_params(params)
+ if params_check_result:
+ return 1
+ logger = params['logger']
+ guestname = params['guestname']
+ image = params['image']
+ jpeg = params['jpeg']
+ zlib = params['zlib']
+ playback = params['playback']
+
+ # Connect to local hypervisor connection URI
+ util = utils.Utils()
+ uri = util.get_uri('127.0.0.1')
+ conn = connectAPI.ConnectAPI()
+ virconn = conn.open(uri)
+
+ caps = conn.get_caps()
+ logger.debug(caps)
+
+ # Get domain xml
+ domobj = domainAPI.DomainAPI(virconn)
+ try:
+ if guestname not in domobj.get_defined_list():
+ logger.error("%s doesn't exist or in running state." %
guestname)
+ return 1
+ except LibvirtAPI, e:
+ logger.error("API error message: %s, error code is %s" %
+ (e.response()['message'], e.response()['code']))
+ return 1
+
+ guestxml = domobj.get_xml_desc(guestname)
+ guestobj = minidom.parseString(guestxml)
+ xmlobj = xmlbuilder.XmlBuilder()
+ xmlobj.add_graphics(params, guestobj)
+ guestxml = xmlobj.build_domain(guestobj)
+
+ try:
+ domobj.undefine(guestname)
+ domobj.define(guestxml)
+ domobj.start(guestname)
+ except LibvirtAPI, e:
+ logger.error("API error message: %s, error code is %s" %
+ (e.response()['message'], e.response()['code']))
+ return 1
+
+ xmlobj = domobj.get_xml_desc(guestname)
+ prexml = xmlobj.split('\n')
+ postxml = ''
+ for i in range(len(prexml)):
+ postxml = postxml + prexml[i].lstrip()
+ domxml = minidom.parseString(postxml)
+
+ # Check spice options in 'graphcis' tag
+ graphTag = domxml.getElementsByTagName("graphics")
+ try:
+ try:
+ for graphTag in domxml.getElementsByTagName("graphics"):
+ assert len(graphTag.childNodes) == 4
+ assert graphTag.childNodes[0].getAttribute("compression") \
+ == params['image']
+ assert graphTag.childNodes[1].getAttribute("compression") \
+ == params['jpeg']
+ assert graphTag.childNodes[2].getAttribute("compression") \
+ == params['zlib']
+ assert graphTag.childNodes[3].getAttribute("compression") \
+ == params['playback']
+ except AssertionError:
+ logger.error("Wrong checks happend on spice options.")
+ conn.close()
+ logger.info("closed hypervisor connection")
+ return 1
+ finally:
+ logger.info("spice options were checked successfully.")
+ conn.close()
+ logger.info("closed hypervisor connection")
+
+ return 0
+
+def spice_options_clean():
+ """Clean testing environment"""
+ pass
+
--
1.7.4.4