WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] [XEND] Fix get_dev_property_by_uuid

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] [XEND] Fix get_dev_property_by_uuid
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 23 Jan 2007 12:05:09 -0800
Delivery-date: Tue, 23 Jan 2007 12:05:07 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Alastair Tse <atse@xxxxxxxxxxxxx>
# Date 1169486633 0
# Node ID bffe672121336051b58d0fdfbf2f05cb056d524e
# Parent  687b1120765e0aebabc1d0a6bfbae2b9c4948aca
[XEND] Fix get_dev_property_by_uuid

This patch replaces calls to get_dev_property() by calls to
get_dev_property_by_uuid() in XenAPI.py and fixes the implementation
of get_dev_property_by_uuid.

I am adding a test case to the xapi grouptests to verify the fixes.
There's a FIXME note in the test case which should be looked at.

Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxx>
---
 tools/python/xen/xend/XendAPI.py              |   22 ++--
 tools/python/xen/xend/XendDomain.py           |   14 +-
 tools/xm-test/tests/xapi/02_xapi-vbd_basic.py |  129 ++++++++++++++++++++++++++
 tools/xm-test/tests/xapi/Makefile.am          |    3 
 4 files changed, 151 insertions(+), 17 deletions(-)

diff -r 687b1120765e -r bffe67212133 tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py  Mon Jan 22 17:10:27 2007 +0000
+++ b/tools/python/xen/xend/XendAPI.py  Mon Jan 22 17:23:53 2007 +0000
@@ -1149,23 +1149,26 @@ class XendAPI:
     # attributes (rw)
     def VBD_get_VM(self, session, vbd_ref):
         xendom = XendDomain.instance()
-        return xen_api_success(xendom.get_dev_property('vbd', vbd_ref, 'VM'))
+        return xen_api_success(xendom.get_dev_property_by_uuid('vbd',
+                                                               vbd_ref, 'VM'))
     
     def VBD_get_VDI(self, session, vbd_ref):
-        return xen_api_todo()
+        xendom = XendDomain.instance()
+        return xen_api_success(xendom.get_dev_property_by_uuid('vbd',
+                                                               vbd_ref, 'VDI'))
     
     def VBD_get_device(self, session, vbd_ref):
         xendom = XendDomain.instance()
-        return xen_api_success(xendom.get_dev_property('vbd', vbd_ref,
-                                                      'device'))
+        return xen_api_success(xendom.get_dev_property_by_uuid('vbd', vbd_ref,
+                                                               'device'))
     def VBD_get_mode(self, session, vbd_ref):
         xendom = XendDomain.instance()
-        return xen_api_success(xendom.get_dev_property('vbd', vbd_ref,
-                                                      'mode'))
+        return xen_api_success(xendom.get_dev_property_by_uuid('vbd', vbd_ref,
+                                                               'mode'))
     def VBD_get_driver(self, session, vbd_ref):
         xendom = XendDomain.instance()
-        return xen_api_success(xendom.get_dev_property('vbd', vbd_ref,
-                                                      'driver'))
+        return xen_api_success(xendom.get_dev_property_by_uuid('vbd', vbd_ref,
+                                                               'driver'))
 
     # Xen API: Class VIF
     # ----------------------------------------------------------------
@@ -1422,7 +1425,8 @@ class XendAPI:
 
     def VTPM_get_VM(self, session, vtpm_ref):
         xendom = XendDomain.instance()
-        return xen_api_success(xendom.get_dev_property('vtpm', vtpm_ref, 'VM'))
+        return xen_api_success(xendom.get_dev_property_by_uuid('vtpm',
+                                                              vtpm_ref, 'VM'))
 
     # class methods
     def VTPM_create(self, session, vtpm_struct):
diff -r 687b1120765e -r bffe67212133 tools/python/xen/xend/XendDomain.py
--- a/tools/python/xen/xend/XendDomain.py       Mon Jan 22 17:10:27 2007 +0000
+++ b/tools/python/xen/xend/XendDomain.py       Mon Jan 22 17:23:53 2007 +0000
@@ -636,18 +636,18 @@ class XendDomain:
             self.domains_lock.release()
 
     def get_dev_property_by_uuid(self, klass, dev_uuid, field):
+        value = None
         self.domains_lock.acquire()
         try:
             dom = self.get_vm_with_dev_uuid(klass, dev_uuid)
-            if not dom:
-                return None
-
-            value = dom.get_device_property(klass, dev_uuid, field)
-            return value
+            if dom:
+                value = dom.get_dev_property(klass, dev_uuid, field)
         except ValueError, e:
             pass
-        
-        return None
+
+        self.domains_lock.release()
+        
+        return value
 
     def is_valid_vm(self, vm_ref):
         return (self.get_vm_by_uuid(vm_ref) != None)
diff -r 687b1120765e -r bffe67212133 
tools/xm-test/tests/xapi/02_xapi-vbd_basic.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/xm-test/tests/xapi/02_xapi-vbd_basic.py     Mon Jan 22 17:23:53 
2007 +0000
@@ -0,0 +1,129 @@
+#!/usr/bin/python
+
+# Copyright (C) International Business Machines Corp., 2007
+# Author: Stefan Berger <stefanb@xxxxxxxxxx>
+
+# Tests related to SR, VDI, VBD
+#
+# Used methods:
+# SR: get_by_name_label, get_VDIs
+#
+# VDI: create, get_name_label, destroy
+#
+# VBD: create, get_driver, get_mode, get_VM, get_VDI, get_device
+#
+# VM: get_VBDs
+
+from XmTestLib import xapi
+from XmTestLib.XenAPIDomain import XmTestAPIDomain
+from XmTestLib import *
+from xen.xend import XendAPIConstants
+import commands
+import os
+
+try:
+    # XmTestAPIDomain tries to establish a connection to XenD
+    domain = XmTestAPIDomain()
+except Exception, e:
+    SKIP("Skipping test. Error: %s" % str(e))
+
+vm_uuid = domain.get_uuid()
+
+session = xapi.connect()
+
+# Do something with SR/VDI/VBD
+
+sr_uuid = session.xenapi.SR.get_by_name_label("Local")
+if len(sr_uuid) == 0:
+    FAIL("Could not get a handle on SR 'Local'")
+
+vdi_rec = { 'name_label'  : "My disk",
+            'SR'          : sr_uuid[0],
+            'virtual_size': 1 << 10,
+            'sector_size' : 512,
+            'type'        : 0,
+            'shareable'   : 0,
+            'read-only'   : 0
+}
+
+vdi_ref = session.xenapi.VDI.create(vdi_rec)
+
+res = session.xenapi.SR.get_VDIs(sr_uuid[0])
+if vdi_ref not in res:
+    session.xenapi.VDI.destroy(vdi_ref)
+    FAIL("SR_get_VDI does not show new VDI")
+
+res = session.xenapi.VDI.get_name_label(vdi_ref)
+if res != vdi_rec['name_label']:
+    session.xenapi.VDI.destroy(vdi_ref)
+    FAIL("VDI_get_name_label return wrong information")
+
+#MORE method calls to VDI to add here...
+
+
+
+
+vbd_rec = { 'VM'    : vm_uuid,
+            'VDI'   : vdi_ref,
+            'device': "xvda1",
+            'mode'  : 1,
+            'driver': 1,
+}
+
+vbd_ref = session.xenapi.VBD.create(vbd_rec)
+
+res = session.xenapi.VBD.get_driver(vbd_ref)
+print "VBD driver: %s" % res
+if res != XendAPIConstants.XEN_API_DRIVER_TYPE[int(vbd_rec['driver'])]:
+    session.xenapi.VDI.destroy(vdi_ref)
+    FAIL("VBD_get_driver returned wrong information")
+
+res = session.xenapi.VBD.get_mode(vbd_ref)
+print "VBD mode: %s" % res
+# FIXME: Check this. Should not have to subtract '1'.
+if res != XendAPIConstants.XEN_API_VBD_MODE[int(vbd_rec['mode']) - 1]:
+    session.xenapi.VDI.destroy(vdi_ref)
+    FAIL("VBD_get_mode returned wrong information")
+
+res = session.xenapi.VBD.get_VM(vbd_ref)
+if res != vm_uuid:
+    session.xenapi.VDI.destroy(vdi_ref)
+    FAIL("VBD_get_VM returned wrong result")
+
+res = session.xenapi.VBD.get_VDI(vbd_ref)
+if res != vdi_ref:
+    session.xenapi.VDI.destroy(vdi_ref)
+    FAIL("VBD_get_VDI returned wrong result")
+
+res = session.xenapi.VBD.get_device(vbd_ref)
+print "VBD device: %s" % res
+if res != vbd_rec['device']+":disk":
+    session.xenapi.VDI.destroy(vdi_ref)
+    FAIL("VBD_get_device returned wrong result")
+
+res = session.xenapi.VM.get_VBDs(vm_uuid)
+if vbd_ref not in res:
+    session.xenapi.VDI.destroy(vdi_ref)
+    FAIL("VM_get_VBDS does not show created VBD")
+
+
+rc = domain.start()
+
+console = domain.getConsole()
+
+try:
+    run = console.runCmd("cat /proc/interrupts")
+except ConsoleError, e:
+    saveLog(console.getHistory())
+    session.xenapi.VDI.destroy(vdi_ref)
+    FAIL("Could not access proc-filesystem")
+
+
+domain.stop()
+domain.destroy()
+
+session.xenapi.VDI.destroy(vdi_ref)
+
+res = session.xenapi.SR.get_VDIs(sr_uuid[0])
+if vdi_ref in res:
+    FAIL("SR_get_VDI still shows deleted VDI")
diff -r 687b1120765e -r bffe67212133 tools/xm-test/tests/xapi/Makefile.am
--- a/tools/xm-test/tests/xapi/Makefile.am      Mon Jan 22 17:10:27 2007 +0000
+++ b/tools/xm-test/tests/xapi/Makefile.am      Mon Jan 22 17:23:53 2007 +0000
@@ -1,6 +1,7 @@ SUBDIRS =
 SUBDIRS =
 
-TESTS = 01_xapi-vm_basic.test
+TESTS = 01_xapi-vm_basic.test \
+       02_xapi-vbd_basic.test
 
 XFAIL_TESTS =
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] [XEND] Fix get_dev_property_by_uuid, Xen patchbot-unstable <=