Kaitlin Rupert wrote:
# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1213147576 25200
# Node ID c6fdcb5088bbe504097625265a0d8fc0c4ed73c9
# Parent 1a4f0bc12b84af40d1ebef71ea3d6d30b300af05
[TEST] Add vsms_util.py
This module is for vsms related utility functions (for AddResource, ModifyResource,
etc).
Add the mod_<> functions. These are identical the code paths in VSMS
08_modifyresource.py except for mod_net_res().
mod_net_res() - In the case of Xen, the bridge name needs to be verified. This is
because the network interface type is converted to a bridge interface by libvirt.
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r 1a4f0bc12b84 -r c6fdcb5088bb suites/libvirt-cim/lib/XenKvmLib/vsms_util.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/suites/libvirt-cim/lib/XenKvmLib/vsms_util.py Tue Jun 10 18:26:16 2008 -0700
@@ -0,0 +1,102 @@
+#!/usr/bin/python
+#
+# Copyright 2008 IBM Corp.
+#
+# Authors:
+# Kaitlin Rupert <karupert(a)us.ibm.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+import pywbem
+from CimTest import Globals
+from CimTest.ReturnCodes import FAIL, PASS
+from CimTest.Globals import logger
+from VirtLib.live import network_by_bridge
+
+def mod_disk_res(server, service, cxml, dasd, ndpath):
+ try:
+ service.ModifyResourceSettings(ResourceSettings = [str(dasd)])
+ cxml.dumpxml(server)
+ dpath = cxml.xml_get_disk_source()
+ if dpath != ndpath:
+ logger.error("Got %s, exp %s." % (dpath, ndpath))
+ raise Exception('Error changing rs for disk path')
+ logger.info('good status for disk path')
+ except Exception, details:
+ logger.error('Error invoking ModifyRS')
+ logger.error(details)
+ return FAIL
+
+ return PASS
+
+def mod_net_res(server, service, virt, cxml, nasd, ntype, net_name):
+ try:
+ service.ModifyResourceSettings(ResourceSettings = [str(nasd)])
+ cxml.dumpxml(server)
+ type = cxml.xml_get_net_type()
+
+ if virt == "KVM":
+ name = cxml.xml_get_net_network()
+ else:
+ if type == "bridge":
+ type = "network"
+ br_name = cxml.xml_get_net_bridge()
+ name = network_by_bridge(br_name, server, virt)
+
+ if type != ntype or name != net_name:
+ logger.error('Got %s, exp %s. Got %s, exp %s' %
+ (type, ntype, name, net_name))
+ raise Exception('Error changing rs for net mac')
+ logger.info('good status for net mac')
+ except Exception, details:
+ logger.error('Error invoking ModifyRS')
+ logger.error(details)
+ return FAIL
+
+ return PASS
+
+def mod_mem_res(server, service, cxml, masd, nmem):
+ try:
+ service.ModifyResourceSettings(ResourceSettings=[str(masd)])
+ cxml.dumpxml(server)
+ mem = cxml.xml_get_mem()
+ if int(mem) != int(nmem) * 1024:
+ logger.error("Got %d, exp %d." % (int(mem), (int(nmem) * 1024)))
+ raise Exception('Error changing rs for mem')
+ logger.info('good status for mem')
+ except Exception, details:
+ logger.error('Error invoking ModifyRS')
+ logger.error(details)
+ return FAIL
+
+ return PASS
+
+def mod_vcpu_res(server, service, cxml, pasd, ncpu):
+ try:
+ service.ModifyResourceSettings(ResourceSettings = [str(pasd)])
+ cxml.dumpxml(server)
+ cpu = cxml.xml_get_vcpu()
+ if int(cpu) != int(ncpu):
+ logger.error("Got %d, exp %d." % (int(cpu), int(ncpu)))
+ raise Exception('Error changing rs for vcpu')
+ logger.info('good status for vcpu')
+ except Exception, details:
+ logger.error('Error invoking ModifyRS')
+ logger.error(details)
+ return FAIL
+
+ return PASS
1) Since the Exception handling is same in all of the above, We can move
it to a function.
2) Also, We can make it more meaningful if we print the fn in which the
exception is occurs.
+
_______________________________________________
Libvirt-cim mailing list
Libvirt-cim(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvirt-cim