[Libvirt-cim] [PATCH] [TEST] Add new tc to verify a MAC address is generated for the domain

Deepti B. Kalakeri deeptik at linux.vnet.ibm.com
Tue Jul 21 08:41:59 UTC 2009


# HG changeset patch
# User Deepti B.Kalakeri <deeptik at linux.vnet.ibm.com>
# Date 1248165703 25200
# Node ID 76407aac7701beedc970f5add3b0c3eeef12c7cb
# Parent  910a44242f106fb6993e94f4431edacf3dedcba3
[TEST] Add new tc to verify a MAC address is generated for the domain.

This test case verifies that, if user does not specify MAC Address,
a MAC address is generated for the domain by the provider.

Verified with KVM  and current sources on F10 and SLES11.
Signed-off-by: Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>

diff -r 910a44242f10 -r 76407aac7701 suites/libvirt-cim/cimtest/VirtualSystemManagementService/21_createVS_verifyMAC.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/21_createVS_verifyMAC.py	Tue Jul 21 01:41:43 2009 -0700
@@ -0,0 +1,96 @@
+#!/usr/bin/python
+#
+# Copyright 2009 IBM Corp.
+#
+# Authors:
+#    Deepti B. Kalakeri <deeptik at linux.vnet.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
+#
+# This test case verifies that, if user does not specify MAC Address, 
+# a MAC address is generated for the domain by the provider.
+#                                                   Date: 21-07-2009                              
+# 
+
+import sys
+from XenKvmLib.const import do_main
+from CimTest.Globals import logger
+from CimTest.ReturnCodes import PASS, FAIL
+from XenKvmLib.vxml import get_class
+from XenKvmLib.enumclass import EnumInstances
+from XenKvmLib.classes import get_typed_class
+
+SUPPORTED_TYPES = ['Xen', 'KVM', 'XenFV', 'LXC']
+default_dom = 'dom_mac_notspecified'
+MAC_ADDR_LEN = 6 
+
+
+def verify_nrasd_mac_value(virt, server):
+    rasd_list   = []
+    classname = get_typed_class(virt, "NetResourceAllocationSettingData")
+    try:
+        rasd_list = EnumInstances(server, classname, ret_cim_inst=True)
+        if len(rasd_list) < 1:
+            logger.error("%s returned %i instances, excepted at least 1.",
+                         classname, len(rasd_list))
+            return FAIL
+
+        for rasd in rasd_list:
+            # Verify the Mac Address for the domain is generated and set
+            if default_dom in rasd['InstanceID']:
+                mac_addr_len = len(rasd['Address'].split(":"))
+                if rasd['Address'] != "" and mac_addr_len == MAC_ADDR_LEN:
+                    logger.info("Mac Address for dom '%s' is set to '%s'", \
+                                 default_dom, rasd['Address'])
+                    return PASS
+
+    except Exception, detail:
+        logger.error("Exception: %s", detail)
+        return FAIL
+
+    logger.error("Mac Address for dom '%s' is not set", default_dom)
+    return FAIL
+
+ at do_main(SUPPORTED_TYPES)
+def main():
+    options = main.options
+
+    cxml = get_class(options.virt)(default_dom, mac=None)
+ 
+    try:
+        ret = cxml.cim_define(options.ip)
+        if not ret:
+            raise Exception("Unable to define %s" % default_dom)
+
+        status = cxml.cim_start(options.ip)
+        if status != PASS:
+            cxml.undefine(options.ip)
+            raise Exception("Failed to start the defined domain: %s" \
+                             % default_dom) 
+
+        status = verify_nrasd_mac_value(options.virt, options.ip)
+
+    except Exception, details:
+        logger.error("Exception details: %s", details)
+        return FAIL
+
+    cxml.cim_destroy(options.ip)
+    cxml.undefine(options.ip)
+
+    return status
+
+if __name__ == "__main__":
+    sys.exit(main())
+
diff -r 910a44242f10 -r 76407aac7701 suites/libvirt-cim/lib/XenKvmLib/vsms.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vsms.py	Mon Jul 20 02:09:38 2009 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/vsms.py	Tue Jul 21 01:41:43 2009 -0700
@@ -159,10 +159,12 @@
 
 class CIM_NetResourceAllocationSettingData(CIMClassMOF):
     def __init__(self, type, mac, name, virt_net=None): 
-        self.Address = mac
         self.NetworkType = type
         self.ResourceType = RASD_TYPE_NET_ETHER
 
+        if mac != None:
+            self.Address = mac
+
         if virt_net != None :
             if type == 'network':
                 self.PoolID = "NetworkPool/%s" % virt_net




More information about the Libvirt-cim mailing list