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 | |
---|
17 | from XmTestLib import xapi |
---|
18 | from XmTestLib.XenAPIDomain import XmTestAPIDomain |
---|
19 | from XmTestLib import * |
---|
20 | from xen.xend import XendAPIConstants |
---|
21 | import commands |
---|
22 | import os |
---|
23 | |
---|
24 | try: |
---|
25 | # XmTestAPIDomain tries to establish a connection to XenD |
---|
26 | domain = XmTestAPIDomain() |
---|
27 | except Exception, e: |
---|
28 | SKIP("Skipping test. Error: %s" % str(e)) |
---|
29 | |
---|
30 | vm_uuid = domain.get_uuid() |
---|
31 | |
---|
32 | session = xapi.connect() |
---|
33 | |
---|
34 | # Do something with SR/VDI/VBD |
---|
35 | |
---|
36 | sr_uuid = session.xenapi.SR.get_by_name_label("Local") |
---|
37 | if len(sr_uuid) == 0: |
---|
38 | FAIL("Could not get a handle on SR 'Local'") |
---|
39 | |
---|
40 | vdi_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 | |
---|
49 | vdi_ref = session.xenapi.VDI.create(vdi_rec) |
---|
50 | |
---|
51 | res = session.xenapi.SR.get_VDIs(sr_uuid[0]) |
---|
52 | if vdi_ref not in res: |
---|
53 | session.xenapi.VDI.destroy(vdi_ref) |
---|
54 | FAIL("SR_get_VDI does not show new VDI") |
---|
55 | |
---|
56 | res = session.xenapi.VDI.get_name_label(vdi_ref) |
---|
57 | if 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 | |
---|
66 | vbd_rec = { 'VM' : vm_uuid, |
---|
67 | 'VDI' : vdi_ref, |
---|
68 | 'device': "xvda1", |
---|
69 | 'mode' : 1, |
---|
70 | 'driver': 1, |
---|
71 | } |
---|
72 | |
---|
73 | vbd_ref = session.xenapi.VBD.create(vbd_rec) |
---|
74 | |
---|
75 | res = session.xenapi.VBD.get_driver(vbd_ref) |
---|
76 | print "VBD driver: %s" % res |
---|
77 | if 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 | |
---|
81 | res = session.xenapi.VBD.get_mode(vbd_ref) |
---|
82 | print "VBD mode: %s" % res |
---|
83 | # FIXME: Check this. Should not have to subtract '1'. |
---|
84 | if 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 | |
---|
88 | res = session.xenapi.VBD.get_VM(vbd_ref) |
---|
89 | if res != vm_uuid: |
---|
90 | session.xenapi.VDI.destroy(vdi_ref) |
---|
91 | FAIL("VBD_get_VM returned wrong result") |
---|
92 | |
---|
93 | res = session.xenapi.VBD.get_VDI(vbd_ref) |
---|
94 | if res != vdi_ref: |
---|
95 | session.xenapi.VDI.destroy(vdi_ref) |
---|
96 | FAIL("VBD_get_VDI returned wrong result") |
---|
97 | |
---|
98 | res = session.xenapi.VBD.get_device(vbd_ref) |
---|
99 | print "VBD device: %s" % res |
---|
100 | if res != vbd_rec['device']+":disk": |
---|
101 | session.xenapi.VDI.destroy(vdi_ref) |
---|
102 | FAIL("VBD_get_device returned wrong result") |
---|
103 | |
---|
104 | res = session.xenapi.VM.get_VBDs(vm_uuid) |
---|
105 | if vbd_ref not in res: |
---|
106 | session.xenapi.VDI.destroy(vdi_ref) |
---|
107 | FAIL("VM_get_VBDS does not show created VBD") |
---|
108 | |
---|
109 | |
---|
110 | rc = domain.start() |
---|
111 | |
---|
112 | console = domain.getConsole() |
---|
113 | |
---|
114 | try: |
---|
115 | run = console.runCmd("cat /proc/interrupts") |
---|
116 | except ConsoleError, e: |
---|
117 | saveLog(console.getHistory()) |
---|
118 | session.xenapi.VDI.destroy(vdi_ref) |
---|
119 | FAIL("Could not access proc-filesystem") |
---|
120 | |
---|
121 | |
---|
122 | domain.stop() |
---|
123 | domain.destroy() |
---|
124 | |
---|
125 | session.xenapi.VDI.destroy(vdi_ref) |
---|
126 | |
---|
127 | res = session.xenapi.SR.get_VDIs(sr_uuid[0]) |
---|
128 | if vdi_ref in res: |
---|
129 | FAIL("SR_get_VDI still shows deleted VDI") |
---|