source: trunk/packages/xen-3.1/xen-3.1/tools/xm-test/tests/xapi/02_xapi-vbd_basic.py @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

  • Property svn:mime-type set to text/script
File size: 3.3 KB
Line 
1#!/usr/bin/python
2
3# Copyright (C) International Business Machines Corp., 2007
4# Author: Stefan Berger <stefanb@us.ibm.com>
5
6# Tests related to SR, VDI, VBD
7#
8# Used methods:
9# SR: get_by_name_label, get_VDIs
10#
11# VDI: create, get_name_label, destroy
12#
13# VBD: create, get_driver, get_mode, get_VM, get_VDI, get_device
14#
15# VM: get_VBDs
16
17from XmTestLib import xapi
18from XmTestLib.XenAPIDomain import XmTestAPIDomain
19from XmTestLib import *
20from xen.xend import XendAPIConstants
21import commands
22import os
23
24try:
25    # XmTestAPIDomain tries to establish a connection to XenD
26    domain = XmTestAPIDomain()
27except Exception, e:
28    SKIP("Skipping test. Error: %s" % str(e))
29
30vm_uuid = domain.get_uuid()
31
32session = xapi.connect()
33
34# Do something with SR/VDI/VBD
35
36sr_uuid = session.xenapi.SR.get_by_name_label("Local")
37if len(sr_uuid) == 0:
38    FAIL("Could not get a handle on SR 'Local'")
39
40vdi_rec = { 'name_label'  : "My disk",
41            'SR'          : sr_uuid[0],
42            'virtual_size': 1 << 10,
43            'sector_size' : 512,
44            'type'        : 0,
45            'shareable'   : 0,
46            'read-only'   : 0
47}
48
49vdi_ref = session.xenapi.VDI.create(vdi_rec)
50
51res = session.xenapi.SR.get_VDIs(sr_uuid[0])
52if vdi_ref not in res:
53    session.xenapi.VDI.destroy(vdi_ref)
54    FAIL("SR_get_VDI does not show new VDI")
55
56res = session.xenapi.VDI.get_name_label(vdi_ref)
57if res != vdi_rec['name_label']:
58    session.xenapi.VDI.destroy(vdi_ref)
59    FAIL("VDI_get_name_label return wrong information")
60
61#MORE method calls to VDI to add here...
62
63
64
65
66vbd_rec = { 'VM'    : vm_uuid,
67            'VDI'   : vdi_ref,
68            'device': "xvda1",
69            'mode'  : 1,
70            'driver': 1,
71}
72
73vbd_ref = session.xenapi.VBD.create(vbd_rec)
74
75res = session.xenapi.VBD.get_driver(vbd_ref)
76print "VBD driver: %s" % res
77if res != XendAPIConstants.XEN_API_DRIVER_TYPE[int(vbd_rec['driver'])]:
78    session.xenapi.VDI.destroy(vdi_ref)
79    FAIL("VBD_get_driver returned wrong information")
80
81res = session.xenapi.VBD.get_mode(vbd_ref)
82print "VBD mode: %s" % res
83# FIXME: Check this. Should not have to subtract '1'.
84if res != XendAPIConstants.XEN_API_VBD_MODE[int(vbd_rec['mode']) - 1]:
85    session.xenapi.VDI.destroy(vdi_ref)
86    FAIL("VBD_get_mode returned wrong information")
87
88res = session.xenapi.VBD.get_VM(vbd_ref)
89if res != vm_uuid:
90    session.xenapi.VDI.destroy(vdi_ref)
91    FAIL("VBD_get_VM returned wrong result")
92
93res = session.xenapi.VBD.get_VDI(vbd_ref)
94if res != vdi_ref:
95    session.xenapi.VDI.destroy(vdi_ref)
96    FAIL("VBD_get_VDI returned wrong result")
97
98res = session.xenapi.VBD.get_device(vbd_ref)
99print "VBD device: %s" % res
100if res != vbd_rec['device']+":disk":
101    session.xenapi.VDI.destroy(vdi_ref)
102    FAIL("VBD_get_device returned wrong result")
103
104res = session.xenapi.VM.get_VBDs(vm_uuid)
105if vbd_ref not in res:
106    session.xenapi.VDI.destroy(vdi_ref)
107    FAIL("VM_get_VBDS does not show created VBD")
108
109
110rc = domain.start()
111
112console = domain.getConsole()
113
114try:
115    run = console.runCmd("cat /proc/interrupts")
116except ConsoleError, e:
117    saveLog(console.getHistory())
118    session.xenapi.VDI.destroy(vdi_ref)
119    FAIL("Could not access proc-filesystem")
120
121
122domain.stop()
123domain.destroy()
124
125session.xenapi.VDI.destroy(vdi_ref)
126
127res = session.xenapi.SR.get_VDIs(sr_uuid[0])
128if vdi_ref in res:
129    FAIL("SR_get_VDI still shows deleted VDI")
Note: See TracBrowser for help on using the repository browser.