-
Notifications
You must be signed in to change notification settings - Fork 911
/
vm_dataset.bats
475 lines (371 loc) · 13.1 KB
/
vm_dataset.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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
#!/usr/bin/env bats
load test_helper
# Data set support requires the virtual machine be at virtual hardware version vmx-20 or later
new_unsupported_hardware_vm() {
id=$(new_id)
govc vm.create -version=vmx-19 $id
echo $id
}
new_supported_hardware_vm() {
id=$(new_id)
govc vm.create -version=vmx-20 $id
echo $id
}
@test "vm.dataset.ls" {
vcsim_env
old_vm=$(new_unsupported_hardware_vm)
vm=$(new_supported_hardware_vm)
run govc vm.dataset.ls -vm $vm
assert_success ""
# non-existing VM
run govc vm.dataset.ls -vm enoent
assert_failure "govc: vm 'enoent' not found"
# VM hardware too old
run govc vm.dataset.ls -vm $old_vm
assert_failure "govc: 400 Bad Request: {\"error_type\":\"UNSUPPORTED\", \"messages\":[]}"
}
@test "vm.dataset.create" {
vcsim_env
old_vm=$(new_unsupported_hardware_vm)
vm=$(new_supported_hardware_vm)
# create
id=$(new_id)
run govc vm.dataset.create -vm $vm $id
assert_success "$id"
# list the created data set
run govc vm.dataset.ls -vm $vm
assert_success "$id"
# create second data set
id2=$(new_id)
run govc vm.dataset.create -vm $vm $id2
assert_success "$id2"
# list the two data sets
run govc vm.dataset.ls -vm $vm
assert_success
assert_line "$id"
assert_line "$id2"
# create with duplicate name
run govc vm.dataset.create -vm $vm $id
assert_failure "govc: 400 Bad Request: {\"error_type\":\"ALREADY_EXISTS\", \"messages\":[]}"
# create on non-existing VM
run govc vm.dataset.create -vm enoent $(new_id)
assert_failure "govc: vm 'enoent' not found"
# create on unsupported VM
run govc vm.dataset.create -vm $old_vm $(new_id)
assert_failure "govc: 400 Bad Request: {\"error_type\":\"UNSUPPORTED\", \"messages\":[]}"
# create on suspended VM
govc vm.power -suspend $vm
run govc vm.dataset.create -vm $vm $(new_id)
assert_failure "govc: 400 Bad Request: {\"error_type\":\"NOT_ALLOWED_IN_CURRENT_STATE\", \"messages\":[]}"
}
@test "vm.dataset.info" {
vcsim_env
vm=$(new_supported_hardware_vm)
# create
id=$(new_id)
run govc vm.dataset.create -vm $vm -d "Some description." -guest-access READ_ONLY -omit-from-snapshot=false $id
assert_success "$id"
# get
run govc vm.dataset.info -vm $vm $id
assert_success
assert_line "Name: $id"
assert_line "Description: Some description."
assert_line "Host: READ_WRITE"
assert_line "Guest: READ_ONLY"
assert_line "Used: 0"
assert_line "OmitFromSnapshotAndClone: false"
# create an entry
run govc vm.dataset.entry.set -vm $vm -dataset $id key1 val1
assert_success
# get to verify the 'Used' field includes the footprint of the entry
run govc vm.dataset.info -vm $vm $id
assert_success
assert_line "Name: $id"
assert_line "Description: Some description."
assert_line "Host: READ_WRITE"
assert_line "Guest: READ_ONLY"
assert_line "Used: 8"
assert_line "OmitFromSnapshotAndClone: false"
# non-existing VM
run govc vm.dataset.info -vm enoent $id
assert_failure "govc: vm 'enoent' not found"
# non-existing data set
run govc vm.dataset.info -vm $vm enoent
assert_failure
assert_matches "404 Not Found"
}
@test "vm.dataset.update" {
vcsim_env
vm=$(new_supported_hardware_vm)
# create
id=$(new_id)
run govc vm.dataset.create -vm $vm -d "Initial description." $id
assert_success "$id"
# update description
run govc vm.dataset.update -vm $vm -d "Updated description." $id
assert_success ""
# get the updated
run govc vm.dataset.info -vm $vm $id
assert_success
assert_line "Name: $id"
assert_line "Description: Updated description."
# update on non-existing VM
run govc vm.dataset.update -vm enoent -d "Even newer description." $id
assert_failure "govc: vm 'enoent' not found"
# update non-existing data set
run govc vm.dataset.update -vm $vm -d "Even newer description." enoent
assert_failure
assert_matches "404 Not Found"
# update on suspended VM
govc vm.power -suspend $vm
run govc vm.dataset.update -vm $vm -d "Even newer description." $id
assert_failure "govc: 400 Bad Request: {\"error_type\":\"NOT_ALLOWED_IN_CURRENT_STATE\", \"messages\":[]}"
}
@test "vm.dataset.rm" {
vcsim_env
vm=$(new_supported_hardware_vm)
# create
id=$(new_id)
run govc vm.dataset.create -vm $vm -d "Initial description." $id
assert_success "$id"
# delete on non-existing VM
run govc vm.dataset.rm -vm enoent $id
assert_failure "govc: vm 'enoent' not found"
# delete non-existing data set
run govc vm.dataset.rm -vm $vm enoent
assert_failure
assert_matches "404 Not Found"
# delete on suspended VM
govc vm.power -suspend $vm
run govc vm.dataset.rm -vm $vm $id
assert_failure "govc: 400 Bad Request: {\"error_type\":\"NOT_ALLOWED_IN_CURRENT_STATE\", \"messages\":[]}"
govc vm.power -on $vm
# delete
run govc vm.dataset.rm -vm $vm $id
assert_success ""
# list to verify
run govc vm.dataset.ls -vm $vm
assert_success ""
# create a data set with an entry
id=$(new_id)
run govc vm.dataset.create -vm $vm -d "Initial description." $id
assert_success "$id"
run govc vm.dataset.entry.set -vm $vm -dataset $id key1 val1
assert_success
# try to delete the non-empty data set
run govc vm.dataset.rm -vm $vm $id
assert_failure "govc: 400 Bad Request: {\"error_type\":\"RESOURCE_IN_USE\", \"messages\":[]}"
# delete the non-empty data set with force
run govc vm.dataset.rm -vm $vm -force=true $id
assert_success ""
}
@test "vm.dataset.vmclone" {
vcsim_env
vm=$(new_supported_hardware_vm)
# create data set which is included in clones/snapshots
id=$(new_id)
run govc vm.dataset.create -vm $vm -d "First data set." -omit-from-snapshot=false $id
assert_success "$id"
# create data set which is excluded from clones/snapshots
id2=$(new_id)
run govc vm.dataset.create -vm $vm -d "Second data set." -omit-from-snapshot=true $id2
assert_success "$id2"
# clone the VM
cloned_vm=$(new_id)
run govc vm.clone -vm $vm $cloned_vm
assert_success
# update the description of the data set on the original VM
run govc vm.dataset.update -vm $vm -d "Updated description." $id
assert_success ""
# create another data set which is included in clones/snapshots on the original VM
id3=$(new_id)
run govc vm.dataset.create -vm $vm -d "Third data set." -omit-from-snapshot=false $id3
assert_success "$id3"
# list the data sets on the cloned VM
run govc vm.dataset.ls -vm $cloned_vm
assert_success "$id"
# verify the data set on the cloned VM was not affected by the update
run govc vm.dataset.info -vm $cloned_vm $id
assert_success
assert_line "Name: $id"
assert_line "Description: First data set."
}
@test "vm.dataset.vmsnapshot" {
vcsim_env
vm=$(new_supported_hardware_vm)
# create data set which is included in clones/snapshots
id=$(new_id)
run govc vm.dataset.create -vm $vm -d "First data set." -omit-from-snapshot=false $id
assert_success "$id"
# create data set which is excluded from clones/snapshots
id2=$(new_id)
run govc vm.dataset.create -vm $vm -d "Second data set." -omit-from-snapshot=true $id2
assert_success "$id2"
# create a snapshot
snapshot=$(new_id)
run govc snapshot.create -vm $vm $snapshot
assert_success
# update the description of the data set on the original VM
run govc vm.dataset.update -vm $vm -d "Updated description." $id
assert_success ""
# create another data set which is included in clones/snapshots
id3=$(new_id)
run govc vm.dataset.create -vm $vm -d "Third data set." -omit-from-snapshot=false $id3
assert_success "$id3"
# revert the VM to the snapshot
run govc snapshot.revert -vm $vm $snapshot
assert_success
# list the data sets on the VM
run govc vm.dataset.ls -vm $vm
assert_success "$id"
# verify the data set does not contain the update
run govc vm.dataset.info -vm $vm $id
assert_success
assert_line "Name: $id"
assert_line "Description: First data set."
}
@test "vm.dataset.entry.ls" {
vcsim_env
# setup VM and data set
vm=$(new_supported_hardware_vm)
ds=$(new_id)
run govc vm.dataset.create -vm $vm $ds
assert_success "$ds"
run govc vm.dataset.entry.ls -vm $vm -dataset $ds
assert_success ""
# non-existing VM
run govc vm.dataset.entry.ls -vm enoent -dataset $ds
assert_failure "govc: vm 'enoent' not found"
# non-existing data set
run govc vm.dataset.entry.ls -vm $vm -dataset enoent
assert_failure
assert_matches "404 Not Found"
# host does not have read access to the data set
run govc vm.dataset.update -vm $vm -host-access NONE $ds
assert_success ""
run govc vm.dataset.entry.ls -vm $vm -dataset $ds
assert_failure "govc: 400 Bad Request: {\"error_type\":\"UNAUTHORIZED\", \"messages\":[]}"
}
@test "vm.dataset.entry.get" {
vcsim_env
# setup VM and data set
vm=$(new_supported_hardware_vm)
ds=$(new_id)
run govc vm.dataset.create -vm $vm $ds
assert_success "$ds"
# non-existing VM
run govc vm.dataset.entry.get -vm enoent -dataset $ds somekey
assert_failure "govc: vm 'enoent' not found"
# non-existing data set
run govc vm.dataset.entry.get -vm $vm -dataset enoent somekey
assert_failure
assert_matches "404 Not Found"
# non-existing entry
run govc vm.dataset.entry.get -vm $vm -dataset $ds enoent
assert_failure
assert_matches "404 Not Found"
}
@test "vm.dataset.entry.set" {
vcsim_env
# setup VM and data set
vm=$(new_supported_hardware_vm)
ds=$(new_id)
run govc vm.dataset.create -vm $vm $ds
assert_success "$ds"
# create new entry
run govc vm.dataset.entry.set -vm $vm -dataset $ds key1 val1
assert_success
# list the created entry
run govc vm.dataset.entry.ls -vm $vm -dataset $ds
assert_success "key1"
# get the value of the created entry
run govc vm.dataset.entry.get -vm $vm -dataset $ds key1
assert_success "val1"
# update the value of the entry
run govc vm.dataset.entry.set -vm $vm -dataset $ds key1 val1b
assert_success
# get the updated value
run govc vm.dataset.entry.get -vm $vm -dataset $ds key1
assert_success "val1b"
# non-existing VM
run govc vm.dataset.entry.set -vm enoent -dataset $ds key2 val2
assert_failure "govc: vm 'enoent' not found"
# non-existing data set
run govc vm.dataset.entry.set -vm $vm -dataset enoent key2 val2
assert_failure
assert_matches "404 Not Found"
# suspended VM
govc vm.power -suspend $vm
run govc vm.dataset.entry.set -vm $vm -dataset $ds key2 val2
assert_failure "govc: 400 Bad Request: {\"error_type\":\"NOT_ALLOWED_IN_CURRENT_STATE\", \"messages\":[]}"
govc vm.power -on $vm
}
@test "vm.dataset.entry.rm" {
vcsim_env
# setup VM, data set and entry
vm=$(new_supported_hardware_vm)
ds=$(new_id)
run govc vm.dataset.create -vm $vm $ds
assert_success "$ds"
run govc vm.dataset.entry.set -vm $vm -dataset $ds key1 val1
assert_success
# delete on non-existing VM
run govc vm.dataset.entry.rm -vm enoent -dataset $ds key1
assert_failure "govc: vm 'enoent' not found"
# delete on non-existing data set
run govc vm.dataset.entry.rm -vm $vm -dataset enoent key1
assert_failure
assert_matches "404 Not Found"
# delete on suspended VM
govc vm.power -suspend $vm
run govc vm.dataset.entry.rm -vm $vm -dataset $ds key1
assert_failure "govc: 400 Bad Request: {\"error_type\":\"NOT_ALLOWED_IN_CURRENT_STATE\", \"messages\":[]}"
govc vm.power -on $vm
# delete
run govc vm.dataset.entry.rm -vm $vm -dataset $ds key1
assert_success
# list to verify
run govc vm.dataset.entry.ls -vm $vm -dataset $ds
assert_success ""
}
@test "vm.dataset.entry.access" {
vcsim_env
# setup VM, data set and entry
vm=$(new_supported_hardware_vm)
ds=$(new_id)
run govc vm.dataset.create -vm $vm $ds
assert_success "$ds"
run govc vm.dataset.entry.set -vm $vm -dataset $ds key1 val1
assert_success
# change the host access to NONE (govc calls the VC API, so the guest access does not matter here)
# the default access mode is READ_WRITE and has already been covered by previous tests
run govc vm.dataset.update -vm $vm -host-access NONE $ds
assert_success
# list
run govc vm.dataset.entry.ls -vm $vm -dataset $ds
assert_failure "govc: 400 Bad Request: {\"error_type\":\"UNAUTHORIZED\", \"messages\":[]}"
# get
run govc vm.dataset.entry.get -vm $vm -dataset $ds key1
assert_failure "govc: 400 Bad Request: {\"error_type\":\"UNAUTHORIZED\", \"messages\":[]}"
# set
run govc vm.dataset.entry.set -vm $vm -dataset $ds key1 val1b
assert_failure "govc: 400 Bad Request: {\"error_type\":\"UNAUTHORIZED\", \"messages\":[]}"
# delete
run govc vm.dataset.entry.rm -vm $vm -dataset $ds key1
assert_failure "govc: 400 Bad Request: {\"error_type\":\"UNAUTHORIZED\", \"messages\":[]}"
# change the host access to READ_ONLY
run govc vm.dataset.update -vm $vm -host-access READ_ONLY $ds
assert_success
# list
run govc vm.dataset.entry.ls -vm $vm -dataset $ds
assert_success "key1"
# get
run govc vm.dataset.entry.get -vm $vm -dataset $ds key1
assert_success "val1"
# set
run govc vm.dataset.entry.set -vm $vm -dataset $ds key1 val1b
assert_failure "govc: 400 Bad Request: {\"error_type\":\"UNAUTHORIZED\", \"messages\":[]}"
# delete
run govc vm.dataset.entry.rm -vm $vm -dataset $ds key1
assert_failure "govc: 400 Bad Request: {\"error_type\":\"UNAUTHORIZED\", \"messages\":[]}"
}