- use pinEmulator to pin domain emulator to host cpu
- 2 cases cover config and live flags
- cpulist with '^', '-' and ',' is supported to give multiple
host cpus
Related bug 916493:
pinEmulator and emulatorPinInfo should be simple with required params
https://bugzilla.redhat.com/show_bug.cgi?id=916493
is fixed, so the test can run successfully now.
Signed-off-by: Wayne Sun <gsun(a)redhat.com>
---
repos/setVcpus/emulatorpin_config.py | 97 +++++++++++++++++++++++++++++++++++
repos/setVcpus/emulatorpin_live.py | 98 ++++++++++++++++++++++++++++++++++++
2 files changed, 195 insertions(+)
create mode 100644 repos/setVcpus/emulatorpin_config.py
create mode 100644 repos/setVcpus/emulatorpin_live.py
diff --git a/repos/setVcpus/emulatorpin_config.py b/repos/setVcpus/emulatorpin_config.py
new file mode 100644
index 0000000..9b94f98
--- /dev/null
+++ b/repos/setVcpus/emulatorpin_config.py
@@ -0,0 +1,97 @@
+#!/usr/bin/env python
+# Test domain emulator pin with flag VIR_DOMAIN_AFFECT_CONFIG, check
+# domain config xml with emulatorpin configuration.
+
+import re
+from xml.dom import minidom
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+from utils import utils
+
+required_params = ('guestname', 'cpulist',)
+optional_params = {}
+
+def emulatorpin_check(domobj, cpumap):
+ """check domain config xml with emulatorpin element
+ """
+ guestxml = domobj.XMLDesc(2)
+ logger.debug("domain %s xml :\n%s" %(domobj.name(), guestxml))
+
+ doc = minidom.parseString(guestxml)
+ emulatorpin = doc.getElementsByTagName('emulatorpin')
+ if not emulatorpin:
+ logger.error("no emulatorpin element in domain xml")
+ return 1
+
+ if not emulatorpin[0].hasAttribute('cpuset'):
+ logger.error("no cpuset attribute with emulatorpin in domain xml")
+ return 1
+ else:
+ emulator_attr = emulatorpin[0].getAttributeNode('cpuset')
+ cpulist = emulator_attr.nodeValue
+ cpumap_tmp = utils.param_to_tuple(cpulist, maxcpu)
+
+ if cpumap_tmp == cpumap:
+ logger.info("cpuset is as expected in domain xml")
+ return 0
+ else:
+ logger.error("cpuset is not as expected in domain xml")
+ return 1
+
+def emulatorpin_config(params):
+ """pin domain emulator to host cpu with config flag
+ """
+ global logger
+ logger = params['logger']
+ params.pop('logger')
+ guestname = params['guestname']
+ cpulist = params['cpulist']
+
+ logger.info("the name of virtual machine is %s" % guestname)
+ logger.info("the given cpulist is %s" % cpulist)
+
+ global maxcpu
+ maxcpu = utils.get_host_cpus()
+ logger.info("%s physical cpu on host" % maxcpu)
+
+ conn = sharedmod.libvirtobj['conn']
+
+ try:
+ domobj = conn.lookupByName(guestname)
+ cpumap = utils.param_to_tuple(cpulist, maxcpu)
+
+ if not cpumap:
+ logger.error("cpulist: Invalid format")
+ return 1
+
+ logger.debug("cpumap for emulator pin is:")
+ logger.debug(cpumap)
+
+ logger.info("pin domain emulator to host cpulist %s with flag: %s" %
+ (cpulist, libvirt.VIR_DOMAIN_AFFECT_CONFIG))
+ domobj.pinEmulator(cpumap, libvirt.VIR_DOMAIN_AFFECT_CONFIG)
+
+ logger.info("check emulator pin info")
+ ret = domobj.emulatorPinInfo(libvirt.VIR_DOMAIN_AFFECT_CONFIG)
+ logger.debug("emulator pin info is:")
+ logger.debug(ret)
+ if ret == cpumap:
+ logger.info("emulator pin info is expected")
+ else:
+ logger.error("emulator pin info is not expected")
+ return 1
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return 1
+
+ logger.info("check domain emulatorpin configuration in xml")
+ ret = emulatorpin_check(domobj, cpumap)
+ if ret:
+ logger.error("domain emulator pin check failed")
+ return 1
+ else:
+ logger.info("domain emulator pin check succeed")
+ return 0
diff --git a/repos/setVcpus/emulatorpin_live.py b/repos/setVcpus/emulatorpin_live.py
new file mode 100644
index 0000000..08b7073
--- /dev/null
+++ b/repos/setVcpus/emulatorpin_live.py
@@ -0,0 +1,98 @@
+#!/usr/bin/env python
+# Test domain emulator pin with flag VIR_DOMAIN_AFFECT_LIVE, check
+# emulator process status under domain task list on host.
+
+import re
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+from utils import utils
+
+required_params = ('guestname', 'cpulist',)
+optional_params = {}
+
+def emulatorpin_check(guestname, cpumap):
+ """check emulator process status of the running virtual machine
+ grep Cpus_allowed_list /proc/PID/status
+ """
+ tmp_str = ''
+ cmd = "cat /var/run/libvirt/qemu/%s.pid" % guestname
+ status, pid = utils.exec_cmd(cmd, shell=True)
+ if status:
+ logger.error("failed to get the pid of domain %s" % guestname)
+ return 1
+
+ cmd = "grep Cpus_allowed_list /proc/%s/status" % pid[0]
+ status, output = utils.exec_cmd(cmd, shell=True)
+ if status:
+ logger.error("failed to run command: %s" % cmd)
+ return 1
+
+ logger.debug("command '%s' output is:\n%s" % (cmd, output[0]))
+
+ cpulist = output[0].split('\t')[1]
+ ret = utils.param_to_tuple(cpulist, maxcpu)
+
+ if ret == cpumap:
+ logger.info("emulator process cpus allowed list is expected")
+ return 0
+ else:
+ logger.error("emulator process cpus allowed list is not expected")
+ return 1
+
+def emulatorpin_live(params):
+ """pin domain emulator to host cpu with live flag
+ """
+ global logger
+ logger = params['logger']
+ params.pop('logger')
+ guestname = params['guestname']
+ cpulist = params['cpulist']
+
+ logger.info("the name of virtual machine is %s" % guestname)
+ logger.info("the given cpulist is %s" % cpulist)
+
+ global maxcpu
+ maxcpu = utils.get_host_cpus()
+ logger.info("%s physical cpu on host" % maxcpu)
+
+ conn = sharedmod.libvirtobj['conn']
+
+ try:
+ domobj = conn.lookupByName(guestname)
+ cpumap = utils.param_to_tuple(cpulist, maxcpu)
+ if not cpumap:
+ logger.error("cpulist: Invalid format")
+ return 1
+
+ logger.debug("cpumap for emulator pin is:")
+ logger.debug(cpumap)
+
+ logger.info("pin domain emulator to host cpu %s with flag: %s" %
+ (cpulist, libvirt.VIR_DOMAIN_AFFECT_LIVE))
+ domobj.pinEmulator(cpumap, libvirt.VIR_DOMAIN_AFFECT_LIVE)
+
+ logger.info("check emulator info")
+ ret = domobj.emulatorPinInfo()
+ logger.debug("emulator info is:")
+ logger.debug(ret)
+ if ret == cpumap:
+ logger.info("emulator info is expected")
+ else:
+ logger.error("emulator info is not expected")
+ return 1
+
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return 1
+
+ logger.info("check emulator pin status on host")
+ ret = emulatorpin_check(guestname, cpumap)
+ if ret:
+ logger.error("domain emulator pin failed")
+ return 1
+ else:
+ logger.info("domain emulator pin succeed")
+ return 0
--
1.8.2.1