ia64/xen-unstable

changeset 13570:bffe67212133

[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@us.ibm.com>
author Alastair Tse <atse@xensource.com>
date Mon Jan 22 17:23:53 2007 +0000 (2007-01-22)
parents 687b1120765e
children b75af612851c
files tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendDomain.py tools/xm-test/tests/xapi/02_xapi-vbd_basic.py tools/xm-test/tests/xapi/Makefile.am
line diff
     1.1 --- a/tools/python/xen/xend/XendAPI.py	Mon Jan 22 17:10:27 2007 +0000
     1.2 +++ b/tools/python/xen/xend/XendAPI.py	Mon Jan 22 17:23:53 2007 +0000
     1.3 @@ -1149,23 +1149,26 @@ class XendAPI:
     1.4      # attributes (rw)
     1.5      def VBD_get_VM(self, session, vbd_ref):
     1.6          xendom = XendDomain.instance()
     1.7 -        return xen_api_success(xendom.get_dev_property('vbd', vbd_ref, 'VM'))
     1.8 +        return xen_api_success(xendom.get_dev_property_by_uuid('vbd',
     1.9 +                                                               vbd_ref, 'VM'))
    1.10      
    1.11      def VBD_get_VDI(self, session, vbd_ref):
    1.12 -        return xen_api_todo()
    1.13 +        xendom = XendDomain.instance()
    1.14 +        return xen_api_success(xendom.get_dev_property_by_uuid('vbd',
    1.15 +                                                               vbd_ref, 'VDI'))
    1.16      
    1.17      def VBD_get_device(self, session, vbd_ref):
    1.18          xendom = XendDomain.instance()
    1.19 -        return xen_api_success(xendom.get_dev_property('vbd', vbd_ref,
    1.20 -                                                      'device'))
    1.21 +        return xen_api_success(xendom.get_dev_property_by_uuid('vbd', vbd_ref,
    1.22 +                                                               'device'))
    1.23      def VBD_get_mode(self, session, vbd_ref):
    1.24          xendom = XendDomain.instance()
    1.25 -        return xen_api_success(xendom.get_dev_property('vbd', vbd_ref,
    1.26 -                                                      'mode'))
    1.27 +        return xen_api_success(xendom.get_dev_property_by_uuid('vbd', vbd_ref,
    1.28 +                                                               'mode'))
    1.29      def VBD_get_driver(self, session, vbd_ref):
    1.30          xendom = XendDomain.instance()
    1.31 -        return xen_api_success(xendom.get_dev_property('vbd', vbd_ref,
    1.32 -                                                      'driver'))
    1.33 +        return xen_api_success(xendom.get_dev_property_by_uuid('vbd', vbd_ref,
    1.34 +                                                               'driver'))
    1.35  
    1.36      # Xen API: Class VIF
    1.37      # ----------------------------------------------------------------
    1.38 @@ -1422,7 +1425,8 @@ class XendAPI:
    1.39  
    1.40      def VTPM_get_VM(self, session, vtpm_ref):
    1.41          xendom = XendDomain.instance()
    1.42 -        return xen_api_success(xendom.get_dev_property('vtpm', vtpm_ref, 'VM'))
    1.43 +        return xen_api_success(xendom.get_dev_property_by_uuid('vtpm',
    1.44 +                                                              vtpm_ref, 'VM'))
    1.45  
    1.46      # class methods
    1.47      def VTPM_create(self, session, vtpm_struct):
     2.1 --- a/tools/python/xen/xend/XendDomain.py	Mon Jan 22 17:10:27 2007 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomain.py	Mon Jan 22 17:23:53 2007 +0000
     2.3 @@ -636,18 +636,18 @@ class XendDomain:
     2.4              self.domains_lock.release()
     2.5  
     2.6      def get_dev_property_by_uuid(self, klass, dev_uuid, field):
     2.7 +        value = None
     2.8          self.domains_lock.acquire()
     2.9          try:
    2.10              dom = self.get_vm_with_dev_uuid(klass, dev_uuid)
    2.11 -            if not dom:
    2.12 -                return None
    2.13 -
    2.14 -            value = dom.get_device_property(klass, dev_uuid, field)
    2.15 -            return value
    2.16 +            if dom:
    2.17 +                value = dom.get_dev_property(klass, dev_uuid, field)
    2.18          except ValueError, e:
    2.19              pass
    2.20 +
    2.21 +        self.domains_lock.release()
    2.22          
    2.23 -        return None
    2.24 +        return value
    2.25  
    2.26      def is_valid_vm(self, vm_ref):
    2.27          return (self.get_vm_by_uuid(vm_ref) != None)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/xm-test/tests/xapi/02_xapi-vbd_basic.py	Mon Jan 22 17:23:53 2007 +0000
     3.3 @@ -0,0 +1,129 @@
     3.4 +#!/usr/bin/python
     3.5 +
     3.6 +# Copyright (C) International Business Machines Corp., 2007
     3.7 +# Author: Stefan Berger <stefanb@us.ibm.com>
     3.8 +
     3.9 +# Tests related to SR, VDI, VBD
    3.10 +#
    3.11 +# Used methods:
    3.12 +# SR: get_by_name_label, get_VDIs
    3.13 +#
    3.14 +# VDI: create, get_name_label, destroy
    3.15 +#
    3.16 +# VBD: create, get_driver, get_mode, get_VM, get_VDI, get_device
    3.17 +#
    3.18 +# VM: get_VBDs
    3.19 +
    3.20 +from XmTestLib import xapi
    3.21 +from XmTestLib.XenAPIDomain import XmTestAPIDomain
    3.22 +from XmTestLib import *
    3.23 +from xen.xend import XendAPIConstants
    3.24 +import commands
    3.25 +import os
    3.26 +
    3.27 +try:
    3.28 +    # XmTestAPIDomain tries to establish a connection to XenD
    3.29 +    domain = XmTestAPIDomain()
    3.30 +except Exception, e:
    3.31 +    SKIP("Skipping test. Error: %s" % str(e))
    3.32 +
    3.33 +vm_uuid = domain.get_uuid()
    3.34 +
    3.35 +session = xapi.connect()
    3.36 +
    3.37 +# Do something with SR/VDI/VBD
    3.38 +
    3.39 +sr_uuid = session.xenapi.SR.get_by_name_label("Local")
    3.40 +if len(sr_uuid) == 0:
    3.41 +    FAIL("Could not get a handle on SR 'Local'")
    3.42 +
    3.43 +vdi_rec = { 'name_label'  : "My disk",
    3.44 +            'SR'          : sr_uuid[0],
    3.45 +            'virtual_size': 1 << 10,
    3.46 +            'sector_size' : 512,
    3.47 +            'type'        : 0,
    3.48 +            'shareable'   : 0,
    3.49 +            'read-only'   : 0
    3.50 +}
    3.51 +
    3.52 +vdi_ref = session.xenapi.VDI.create(vdi_rec)
    3.53 +
    3.54 +res = session.xenapi.SR.get_VDIs(sr_uuid[0])
    3.55 +if vdi_ref not in res:
    3.56 +    session.xenapi.VDI.destroy(vdi_ref)
    3.57 +    FAIL("SR_get_VDI does not show new VDI")
    3.58 +
    3.59 +res = session.xenapi.VDI.get_name_label(vdi_ref)
    3.60 +if res != vdi_rec['name_label']:
    3.61 +    session.xenapi.VDI.destroy(vdi_ref)
    3.62 +    FAIL("VDI_get_name_label return wrong information")
    3.63 +
    3.64 +#MORE method calls to VDI to add here...
    3.65 +
    3.66 +
    3.67 +
    3.68 +
    3.69 +vbd_rec = { 'VM'    : vm_uuid,
    3.70 +            'VDI'   : vdi_ref,
    3.71 +            'device': "xvda1",
    3.72 +            'mode'  : 1,
    3.73 +            'driver': 1,
    3.74 +}
    3.75 +
    3.76 +vbd_ref = session.xenapi.VBD.create(vbd_rec)
    3.77 +
    3.78 +res = session.xenapi.VBD.get_driver(vbd_ref)
    3.79 +print "VBD driver: %s" % res
    3.80 +if res != XendAPIConstants.XEN_API_DRIVER_TYPE[int(vbd_rec['driver'])]:
    3.81 +    session.xenapi.VDI.destroy(vdi_ref)
    3.82 +    FAIL("VBD_get_driver returned wrong information")
    3.83 +
    3.84 +res = session.xenapi.VBD.get_mode(vbd_ref)
    3.85 +print "VBD mode: %s" % res
    3.86 +# FIXME: Check this. Should not have to subtract '1'.
    3.87 +if res != XendAPIConstants.XEN_API_VBD_MODE[int(vbd_rec['mode']) - 1]:
    3.88 +    session.xenapi.VDI.destroy(vdi_ref)
    3.89 +    FAIL("VBD_get_mode returned wrong information")
    3.90 +
    3.91 +res = session.xenapi.VBD.get_VM(vbd_ref)
    3.92 +if res != vm_uuid:
    3.93 +    session.xenapi.VDI.destroy(vdi_ref)
    3.94 +    FAIL("VBD_get_VM returned wrong result")
    3.95 +
    3.96 +res = session.xenapi.VBD.get_VDI(vbd_ref)
    3.97 +if res != vdi_ref:
    3.98 +    session.xenapi.VDI.destroy(vdi_ref)
    3.99 +    FAIL("VBD_get_VDI returned wrong result")
   3.100 +
   3.101 +res = session.xenapi.VBD.get_device(vbd_ref)
   3.102 +print "VBD device: %s" % res
   3.103 +if res != vbd_rec['device']+":disk":
   3.104 +    session.xenapi.VDI.destroy(vdi_ref)
   3.105 +    FAIL("VBD_get_device returned wrong result")
   3.106 +
   3.107 +res = session.xenapi.VM.get_VBDs(vm_uuid)
   3.108 +if vbd_ref not in res:
   3.109 +    session.xenapi.VDI.destroy(vdi_ref)
   3.110 +    FAIL("VM_get_VBDS does not show created VBD")
   3.111 +
   3.112 +
   3.113 +rc = domain.start()
   3.114 +
   3.115 +console = domain.getConsole()
   3.116 +
   3.117 +try:
   3.118 +    run = console.runCmd("cat /proc/interrupts")
   3.119 +except ConsoleError, e:
   3.120 +    saveLog(console.getHistory())
   3.121 +    session.xenapi.VDI.destroy(vdi_ref)
   3.122 +    FAIL("Could not access proc-filesystem")
   3.123 +
   3.124 +
   3.125 +domain.stop()
   3.126 +domain.destroy()
   3.127 +
   3.128 +session.xenapi.VDI.destroy(vdi_ref)
   3.129 +
   3.130 +res = session.xenapi.SR.get_VDIs(sr_uuid[0])
   3.131 +if vdi_ref in res:
   3.132 +    FAIL("SR_get_VDI still shows deleted VDI")
     4.1 --- a/tools/xm-test/tests/xapi/Makefile.am	Mon Jan 22 17:10:27 2007 +0000
     4.2 +++ b/tools/xm-test/tests/xapi/Makefile.am	Mon Jan 22 17:23:53 2007 +0000
     4.3 @@ -1,6 +1,7 @@
     4.4  SUBDIRS =
     4.5  
     4.6 -TESTS = 01_xapi-vm_basic.test
     4.7 +TESTS = 01_xapi-vm_basic.test \
     4.8 +	02_xapi-vbd_basic.test
     4.9  
    4.10  XFAIL_TESTS =
    4.11