* [PATCH] [XEND] Fix get_dev_property_by_uuid
@ 2007-01-22 12:21 Stefan Berger
2007-01-22 17:26 ` Alastair Tse
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Berger @ 2007-01-22 12:21 UTC (permalink / raw)
To: Xen-devel; +Cc: ewan
[-- Attachment #1: Type: text/plain, Size: 343 bytes --]
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@us.ibm.com>
[-- Attachment #2: xend-xenapi-get_dev_property-fix.diff --]
[-- Type: text/x-patch, Size: 7724 bytes --]
Index: root/xen-unstable.hg/tools/python/xen/xend/XendAPI.py
===================================================================
--- root.orig/xen-unstable.hg/tools/python/xen/xend/XendAPI.py
+++ root/xen-unstable.hg/tools/python/xen/xend/XendAPI.py
@@ -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
# ----------------------------------------------------------------
@@ -1409,7 +1412,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):
Index: root/xen-unstable.hg/tools/python/xen/xend/XendDomain.py
===================================================================
--- root.orig/xen-unstable.hg/tools/python/xen/xend/XendDomain.py
+++ root/xen-unstable.hg/tools/python/xen/xend/XendDomain.py
@@ -640,18 +640,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
+
+ self.domains_lock.release()
- return None
+ return value
def is_valid_vm(self, vm_ref):
return (self.get_vm_by_uuid(vm_ref) != None)
Index: root/xen-unstable.hg/tools/xm-test/tests/xapi/Makefile.am
===================================================================
--- root.orig/xen-unstable.hg/tools/xm-test/tests/xapi/Makefile.am
+++ root/xen-unstable.hg/tools/xm-test/tests/xapi/Makefile.am
@@ -1,6 +1,7 @@
SUBDIRS =
-TESTS = 01_xapi-vm_basic.test
+TESTS = 01_xapi-vm_basic.test \
+ 02_xapi-vbd_basic.test
XFAIL_TESTS =
Index: root/xen-unstable.hg/tools/xm-test/tests/xapi/02_xapi-vbd_basic.py
===================================================================
--- /dev/null
+++ root/xen-unstable.hg/tools/xm-test/tests/xapi/02_xapi-vbd_basic.py
@@ -0,0 +1,129 @@
+#!/usr/bin/python
+
+# Copyright (C) International Business Machines Corp., 2007
+# Author: Stefan Berger <stefanb@us.ibm.com>
+
+# 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")
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] [XEND] Fix get_dev_property_by_uuid
2007-01-22 12:21 [PATCH] [XEND] Fix get_dev_property_by_uuid Stefan Berger
@ 2007-01-22 17:26 ` Alastair Tse
0 siblings, 0 replies; 2+ messages in thread
From: Alastair Tse @ 2007-01-22 17:26 UTC (permalink / raw)
To: xen-devel
On Mon, 2007-01-22 at 07:21 -0500, Stefan Berger wrote:
> 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@us.ibm.com>
Applied.
Thanks,
Alastair
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-01-22 17:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-22 12:21 [PATCH] [XEND] Fix get_dev_property_by_uuid Stefan Berger
2007-01-22 17:26 ` Alastair Tse
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.