forked from vmware/govmomi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
device.bats
executable file
·342 lines (233 loc) · 6.91 KB
/
device.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#!/usr/bin/env bats
load test_helper
@test "device.ls" {
vcsim_env
vm=$(new_empty_vm)
result=$(govc device.ls -vm $vm ethernet-* | wc -l)
[ $result -eq 1 ]
}
@test "device.info" {
vcsim_env -esx
vm=$(new_empty_vm)
run govc device.info -vm $vm ide-200
assert_success
run govc device.info -vm $vm ide-20000
assert_failure
run govc device.info -vm $vm -net enoent
assert_failure
run govc device.info -vm $vm -net "VM Network" ide-200
assert_failure
result=$(govc device.info -vm $vm -net "VM Network" | grep "MAC Address" | wc -l)
[ $result -eq 1 ]
run govc device.info -vm $vm -json
assert_matches ethernet-
assert_matches '"name":' # injected field
assert_matches '"type":' # injected field
}
@test "device.boot" {
vcsim_env
vm="DC0_H0_VM0"
run govc device.remove -vm $vm cdrom-*
assert_success
result=$(govc device.ls -vm $vm -boot | wc -l)
[ $result -eq 0 ]
run govc device.boot -vm $vm -order floppy,cdrom,ethernet,disk
assert_success
result=$(govc device.ls -vm $vm -boot | wc -l)
[ $result -eq 2 ]
run govc device.cdrom.add -vm $vm
assert_success
run govc device.floppy.add -vm $vm
assert_success
run govc device.boot -vm $vm -order floppy,cdrom,ethernet,disk
assert_success
result=$(govc device.ls -vm $vm -boot | wc -l)
[ $result -eq 4 ]
run govc device.boot -vm $vm -order -
assert_success
result=$(govc device.ls -vm $vm -boot | wc -l)
[ $result -eq 0 ]
run govc device.boot -vm $vm -secure
assert_failure
run govc device.boot -vm $vm -secure -firmware efi
assert_success
run govc device.boot -vm $vm -order -
assert_success
firmware=$(govc object.collect -s vm/$vm config.firmware)
assert_equal efi "$firmware"
}
@test "device.cdrom" {
vcsim_env
vm=$(new_empty_vm)
result=$(govc device.ls -vm $vm | grep cdrom- | wc -l)
[ $result -eq 0 ]
run govc device.cdrom.add -vm $vm
assert_success
id=$output
result=$(govc device.ls -vm $vm | grep $id | wc -l)
[ $result -eq 1 ]
run govc device.info -vm $vm $id
assert_success
run govc device.cdrom.insert -vm $vm -device $id x.iso
assert_success
run govc device.info -vm $vm $id
assert_line "Summary: ISO [${GOVC_DATASTORE}] x.iso"
run govc device.disconnect -vm $vm $id
assert_success
run govc device.connect -vm $vm $id
assert_success
run govc device.remove -vm $vm $id
assert_success
run govc device.disconnect -vm $vm $id
assert_failure "govc: device '$id' not found"
run govc device.cdrom.insert -vm $vm -device $id x.iso
assert_failure "govc: device '$id' not found"
run govc device.remove -vm $vm $id
assert_failure "govc: device '$id' not found"
}
@test "device.floppy" {
vcsim_env
vm=$(new_empty_vm)
result=$(govc device.ls -vm $vm | grep floppy- | wc -l)
[ $result -eq 0 ]
run govc device.floppy.add -vm $vm
assert_success
id=$output
result=$(govc device.ls -vm $vm | grep $id | wc -l)
[ $result -eq 1 ]
run govc device.info -vm $vm $id
assert_success
run govc device.floppy.insert -vm $vm -device $id x.img
assert_success
run govc device.info -vm $vm $id
assert_line "Summary: Image [${GOVC_DATASTORE}] x.img"
run govc device.disconnect -vm $vm $id
assert_success
run govc device.connect -vm $vm $id
assert_success
run govc device.remove -vm $vm $id
assert_success
run govc device.disconnect -vm $vm $id
assert_failure "govc: device '$id' not found"
run govc device.floppy.insert -vm $vm -device $id x.img
assert_failure "govc: device '$id' not found"
run govc device.remove -vm $vm $id
assert_failure "govc: device '$id' not found"
}
@test "device.serial" {
vcsim_env
vm=$(new_empty_vm)
result=$(govc device.ls -vm $vm | grep serial- | wc -l)
[ $result -eq 0 ]
run govc device.serial.add -vm $vm
assert_success
id=$output
result=$(govc device.ls -vm $vm | grep $id | wc -l)
[ $result -eq 1 ]
run govc device.info -vm $vm $id
assert_success
run govc device.serial.connect -vm $vm -
assert_success
run govc device.info -vm $vm $id
assert_line "Summary: File [$GOVC_DATASTORE] $vm/${id}.log"
uri=telnet://:33233
run govc device.serial.connect -vm $vm -device $id $uri
assert_success
run govc device.info -vm $vm $id
assert_line "Summary: Remote $uri"
run govc device.serial.disconnect -vm $vm -device $id
assert_success
run govc device.info -vm $vm $id
assert_line "Summary: Remote localhost:0"
run govc device.disconnect -vm $vm $id
assert_success
run govc device.connect -vm $vm $id
assert_success
run govc device.remove -vm $vm $id
assert_success
run govc device.disconnect -vm $vm $id
assert_failure "govc: device '$id' not found"
run govc device.serial.connect -vm $vm -device $id $uri
assert_failure "govc: device '$id' not found"
run govc device.remove -vm $vm $id
assert_failure "govc: device '$id' not found"
}
@test "device.scsi" {
vcsim_env
vm=$(new_empty_vm)
result=$(govc device.ls -vm $vm | grep lsilogic- | wc -l)
[ $result -eq 1 ]
run govc device.scsi.add -vm $vm
assert_success
id=$output
result=$(govc device.ls -vm $vm | grep $id | wc -l)
[ $result -eq 1 ]
result=$(govc device.ls -vm $vm | grep lsilogic- | wc -l)
[ $result -eq 2 ]
run govc device.scsi.add -vm $vm -type pvscsi
assert_success
id=$output
result=$(govc device.ls -vm $vm | grep $id | wc -l)
[ $result -eq 1 ]
}
@test "device.usb" {
vcsim_env
vm=$(new_empty_vm)
result=$(govc device.ls -vm $vm | grep usb | wc -l)
[ $result -eq 0 ]
run govc device.usb.add -type enoent -vm $vm
assert_failure
run govc device.usb.add -vm $vm
assert_success
id=$output
result=$(govc device.ls -vm $vm | grep $id | wc -l)
[ $result -eq 1 ]
run govc device.usb.add -type xhci -vm $vm
assert_success
id=$output
result=$(govc device.ls -vm $vm | grep $id | wc -l)
[ $result -eq 1 ]
}
@test "device.clock" {
vcsim_env
vm=$(new_empty_vm)
result=$(govc device.ls -vm "$vm" | grep clock | wc -l)
[ "$result" -eq 0 ]
run govc device.clock.add -vm "$vm"
assert_success
id=$output
result=$(govc device.ls -vm "$vm" | grep "$id" | wc -l)
[ "$result" -eq 1 ]
}
@test "device.scsi slots" {
vcsim_env
vm=$(new_empty_vm)
for i in $(seq 1 15) ; do
name="disk-${i}"
run govc vm.disk.create -vm "$vm" -name "$name" -size 1K
assert_success
result=$(govc device.ls -vm "$vm" | grep disk- | wc -l)
[ "$result" -eq "$i" ]
done
}
@test "device.match" {
vcsim_env
vm=DC0_H0_VM0
run govc device.ls -vm $vm enoent-*
assert_failure
run govc device.info -vm $vm enoent-*
assert_failure
run govc device.info -vm $vm disk-*
assert_success
run govc vm.disk.create -vm $vm -name $vm/disk2.vmdk -size 10M
assert_success
run govc device.ls -vm $vm disk-*
assert_success
[ ${#lines[@]} -eq 2 ]
run govc device.remove -vm $vm enoent-*
assert_failure
run govc device.remove -vm $vm disk-*
assert_success
run govc device.ls -vm $vm disk-*
assert_failure
}