On 09/09/2011 02:41 AM, Nan Zhang wrote:
---
repos/domain/spice_options.py | 113 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 113 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..660805c
--- /dev/null
+++ b/repos/domain/spice_options.py
@@ -0,0 +1,113 @@
+#!/usr/bin/evn python
s/evn/env/.
+"""Configuring spice compression options
+"""
+
+__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
Unused import xmlbuilder.
+from exception import LibvirtAPI
Unused import LibvirtAPI.
+
+def usage():
+ print '''usage: mandatory arguments:
+ guestname
+ image
+ jpeg
+ zlib
+ playback
+ '''
+
+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)
+ usage()
+ 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']
Unused variable 'image',
'jpeg', 'zlib' and '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)
+ 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"):
Remove useless
":", this will hit a syntax error.
Alex
+ 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
+