On 11/28/2012 08:10 PM, Wayne Sun wrote:
v2: break down the case to small cases with separate flags
* Use setVcpusFlags API to set domain vcpus with flags
* 3 cases added, each only deal with one set flag value as in
config, live or maximum
* cases are independent on domain states, API will report error
if not suitable for certain states
* the sample conf is only one scenario of hotplug domain vcpus
Signed-off-by: Wayne Sun <gsun(a)redhat.com>
---
cases/set_vcpus_flags.conf | 64 +++++++++++++++++++++++
repos/setVcpus/set_vcpus_config.py | 69 +++++++++++++++++++++++++
repos/setVcpus/set_vcpus_live.py | 96 +++++++++++++++++++++++++++++++++++
repos/setVcpus/set_vcpus_maximum.py | 62 ++++++++++++++++++++++
4 files changed, 291 insertions(+), 0 deletions(-)
create mode 100644 cases/set_vcpus_flags.conf
create mode 100644 repos/setVcpus/__init__.py
create mode 100644 repos/setVcpus/set_vcpus_config.py
create mode 100644 repos/setVcpus/set_vcpus_live.py
create mode 100644 repos/setVcpus/set_vcpus_maximum.py
diff --git a/cases/set_vcpus_flags.conf b/cases/set_vcpus_flags.conf
new file mode 100644
index 0000000..d346735
--- /dev/null
+++ b/cases/set_vcpus_flags.conf
@@ -0,0 +1,64 @@
+domain:install_linux_cdrom
+ guestname
+ $defaultname
+ guestos
+ $defaultos
+ guestarch
+ $defaultarch
+ vcpu
+ $defaultvcpu
+ memory
+ $defaultmem
+ hddriver
+ $defaulthd
+ nicdriver
+ $defaultnic
+ imageformat
+ qcow2
+
+
+domain:destroy
+ guestname
+ $defaultname
+
+setVcpus:set_vcpus_maximum
+ guestname
+ $defaultname
+ vcpu
+ 4
+
+setVcpus:set_vcpus_config
+ guestname
+ $defaultname
+ vcpu
+ 1
It's better to merge "set_vcpus_maximum" and "set_vcpus_config
"
into one testcase
setVcpus:set_vcpus_config
guestname
$defaultname
maxvcpu(optional)
4
vcpu(or optional)
1
+
+domain:start
+ guestname
+ $defaultname
+
+setVcpus:set_vcpus_live
+ guestname
+ $defaultname
+ vcpu
+ 3
+ username
+ $username
+ password
+ $password
+
+setVcpus:set_vcpus_config
+ guestname
+ $defaultname
+ vcpu
+ 2
+
+domain:destroy
+ guestname
+ $defaultname
+
+domain:undefine
+ guestname
+ $defaultname
+
+options cleanup=enable
diff --git a/repos/setVcpus/__init__.py b/repos/setVcpus/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/repos/setVcpus/set_vcpus_config.py b/repos/setVcpus/set_vcpus_config.py
new file mode 100644
index 0000000..2b8f5e7
--- /dev/null
+++ b/repos/setVcpus/set_vcpus_config.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+# Test set domain vcpu with flag VIR_DOMAIN_AFFECT_CONFIG. Check
+# domain config xml to get 'current' vcpu number.
+
+from xml.dom import minidom
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+
+required_params = ('guestname', 'vcpu', )
+optional_params = {}
+
+def get_current_vcpu(domobj):
+ """dump domain config xml description to get current vcpu number
+ """
+ try:
+ guestxml = domobj.XMLDesc(2)
+ logger.debug("domain %s xml is :\n%s" %(domobj.name(), guestxml))
+ xml = minidom.parseString(guestxml)
+ vcpu = xml.getElementsByTagName('vcpu')[0]
+
+ if vcpu.hasAttribute('current'):
+ attr = vcpu.getAttributeNode('current')
+ current = int(attr.nodeValue)
+ else:
+ logger.info("no 'current' atrribute for element vcpu")
+ current = int(vcpu.childNodes[0].data)
+
+ logger.info("domain current vcpu number is: %s" % current)
+
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return False
+
+ return current
+
+def set_vcpus_config(params):
+ """set domain vcpu with config flag and check
+ """
+ global logger
+ logger = params['logger']
+ params.pop('logger')
+ guestname = params['guestname']
+ vcpu = int(params['vcpu'])
+
+ logger.info("the name of virtual machine is %s" % guestname)
+ logger.info("the given vcpu number is %s" % vcpu)
+
+ conn = sharedmod.libvirtobj['conn']
+
+ try:
+ domobj = conn.lookupByName(guestname)
+ logger.info("set domain vcpu as %s with flag: %s" %
+ (vcpu, libvirt.VIR_DOMAIN_AFFECT_CONFIG))
+ domobj.setVcpusFlags(vcpu, libvirt.VIR_DOMAIN_AFFECT_CONFIG)
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return 1
+
+ logger.info("check domain config xml to get current vcpu")
+ ret = get_current_vcpu(domobj)
+ if ret == vcpu:
+ logger.info("domain current vcpu is equal as set")
+ return 0
+ else:
+ logger.error("domain current vcpu is not equal as set")
+ return 1
diff --git a/repos/setVcpus/set_vcpus_live.py b/repos/setVcpus/set_vcpus_live.py
new file mode 100644
index 0000000..35a2976
--- /dev/null
+++ b/repos/setVcpus/set_vcpus_live.py
@@ -0,0 +1,96 @@
+#!/usr/bin/env python
+# Test set domain vcpu with flag VIR_DOMAIN_VCPU_LIVE. Check
+# domain xml and inside domain to get current vcpu number. The
+# live flag only work on running domain, so test on shutoff
+# domain will fail.
+
+from xml.dom import minidom
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+from utils import utils
+
+required_params = ('guestname', 'vcpu', 'username',
'password', )
+optional_params = {}
+
+def get_current_vcpu(domobj, username, password):
+ """dump domain live xml description to get current vcpu number
+ and check in domain to confirm
+ """
+ try:
+ guestxml = domobj.XMLDesc(1)
+ guestname = domobj.name()
+ logger.debug("domain %s xml is :\n%s" %(guestname, guestxml))
+ xml = minidom.parseString(guestxml)
+ vcpu = xml.getElementsByTagName('vcpu')[0]
+
+ if vcpu.hasAttribute('current'):
+ attr = vcpu.getAttributeNode('current')
+ current = int(attr.nodeValue)
+ else:
+ logger.info("no 'current' atrribute for element vcpu")
+ current = int(vcpu.childNodes[0].data)
+
+ logger.info("domain current vcpu number in live xml is: %s" %
current)
+
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return False
+
+ logger.debug("get the mac address of vm %s" % guestname)
+ mac = utils.get_dom_mac_addr(guestname)
+ logger.debug("the mac address of vm %s is %s" % (guestname, mac))
+
+ logger.info("check cpu number in domain")
+ ip = utils.mac_to_ip(mac, 180)
+
+ cmd = "cat /proc/cpuinfo | grep processor | wc -l"
+ ret, output = utils.remote_exec_pexpect(ip, username, password, cmd)
+ if not ret:
+ logger.info("cpu number in domain is %s" % output)
+ if int(output) == current:
+ logger.info("cpu in domain is equal to current vcpu value")
+ else:
+ logger.error("current vcpu is not equal as check in domain")
+ return False
+ else:
+ logger.error("check in domain fail")
+ return False
+
+ return current
+
+def set_vcpus_live(params):
+ """set domain vcpu with live flag and check
+ """
+ global logger
+ logger = params['logger']
+ params.pop('logger')
+ guestname = params['guestname']
+ vcpu = int(params['vcpu'])
+ username = params['username']
+ password = params['password']
+
+ logger.info("the name of virtual machine is %s" % guestname)
+ logger.info("the given vcpu number is %s" % vcpu)
+
+ conn = sharedmod.libvirtobj['conn']
+
+ try:
+ domobj = conn.lookupByName(guestname)
+ logger.info("set domain vcpu as %s with flag: %s" %
+ (vcpu, libvirt.VIR_DOMAIN_VCPU_LIVE))
+ domobj.setVcpusFlags(vcpu, libvirt.VIR_DOMAIN_VCPU_LIVE)
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return 1
+
+ logger.info("check domain vcpu")
+ ret = get_current_vcpu(domobj, username, password)
+ if ret == vcpu:
+ logger.info("domain vcpu is equal as set")
+ return 0
+ else:
+ logger.error("domain vcpu is not equal as set")
+ return 1
diff --git a/repos/setVcpus/set_vcpus_maximum.py b/repos/setVcpus/set_vcpus_maximum.py
new file mode 100644
index 0000000..389a214
--- /dev/null
+++ b/repos/setVcpus/set_vcpus_maximum.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+# Test set domain vcpu with flag VIR_DOMAIN_VCPU_MAXIMUM. Check
+# domain xml to get max vcpu number. The maxinum flag only work
+# on shutoff domain, so test on running domain will fail.
+
+from xml.dom import minidom
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+
+required_params = ('guestname', 'vcpu', )
+optional_params = {}
+
+def get_max_vcpu(domobj):
+ """dump domain xml description to get max vcpu number
+ """
+ try:
+ guestxml = domobj.XMLDesc(1)
+ logger.debug("domain %s xml is :\n%s" %(domobj.name(), guestxml))
+ xml = minidom.parseString(guestxml)
+ vcpu = xml.getElementsByTagName('vcpu')[0]
+ max = int(vcpu.childNodes[0].data)
max is a python built-in function, we try to avoid naming such
a variable.
+ logger.info("domain maximum vcpu number in xml is:
%s" % max)
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return False
+
+ return max
+
+def set_vcpus_maximum(params):
+ """set domain vcpu with maximum flag and check
+ """
+ global logger
+ logger = params['logger']
+ params.pop('logger')
+ guestname = params['guestname']
+ vcpu = int(params['vcpu'])
+
+ logger.info("the name of virtual machine is %s" % guestname)
+ logger.info("the given vcpu number is %s" % vcpu)
+
+ conn = sharedmod.libvirtobj['conn']
+
+ try:
+ domobj = conn.lookupByName(guestname)
+ logger.info("set domain maximum vcpu as %s with flag: %s" %
+ (vcpu, libvirt.VIR_DOMAIN_VCPU_MAXIMUM))
+ domobj.setVcpusFlags(vcpu, libvirt.VIR_DOMAIN_VCPU_MAXIMUM)
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return 1
+
+ logger.info("check domain xml to get max vcpu")
+ ret = get_max_vcpu(domobj)
+ if ret == vcpu:
+ logger.info("domain max vcpu is equal as set")
+ return 0
+ else:
+ logger.error("domain max vcpu is not equal as set")
+ return 1
After I set vcpu with --live, my libvirtd crash, I need to figure
it out before using
these testcases again, please try to run them on RHEL to see if the
same problem
exists too.
Guannan Ren