github.com/vmware/govmomi@v0.43.0/govc/test/vm_dataset.bats (about) 1 #!/usr/bin/env bats 2 3 load test_helper 4 5 # Data set support requires the virtual machine be at virtual hardware version vmx-20 or later 6 new_unsupported_hardware_vm() { 7 id=$(new_id) 8 govc vm.create -version=vmx-19 $id 9 echo $id 10 } 11 12 new_supported_hardware_vm() { 13 id=$(new_id) 14 govc vm.create -version=vmx-20 $id 15 echo $id 16 } 17 18 @test "vm.dataset.ls" { 19 vcsim_env 20 21 old_vm=$(new_unsupported_hardware_vm) 22 vm=$(new_supported_hardware_vm) 23 24 run govc vm.dataset.ls -vm $vm 25 assert_success "" 26 27 # non-existing VM 28 run govc vm.dataset.ls -vm enoent 29 assert_failure "govc: vm 'enoent' not found" 30 31 # VM hardware too old 32 run govc vm.dataset.ls -vm $old_vm 33 assert_failure "govc: 400 Bad Request: {\"error_type\":\"UNSUPPORTED\", \"messages\":[]}" 34 } 35 36 @test "vm.dataset.create" { 37 vcsim_env 38 39 old_vm=$(new_unsupported_hardware_vm) 40 vm=$(new_supported_hardware_vm) 41 42 # create 43 id=$(new_id) 44 run govc vm.dataset.create -vm $vm $id 45 assert_success "$id" 46 47 # list the created data set 48 run govc vm.dataset.ls -vm $vm 49 assert_success "$id" 50 51 # create second data set 52 id2=$(new_id) 53 run govc vm.dataset.create -vm $vm $id2 54 assert_success "$id2" 55 56 # list the two data sets 57 run govc vm.dataset.ls -vm $vm 58 assert_success 59 assert_line "$id" 60 assert_line "$id2" 61 62 # create with duplicate name 63 run govc vm.dataset.create -vm $vm $id 64 assert_failure "govc: 400 Bad Request: {\"error_type\":\"ALREADY_EXISTS\", \"messages\":[]}" 65 66 # create on non-existing VM 67 run govc vm.dataset.create -vm enoent $(new_id) 68 assert_failure "govc: vm 'enoent' not found" 69 70 # create on unsupported VM 71 run govc vm.dataset.create -vm $old_vm $(new_id) 72 assert_failure "govc: 400 Bad Request: {\"error_type\":\"UNSUPPORTED\", \"messages\":[]}" 73 74 # create on suspended VM 75 govc vm.power -suspend $vm 76 run govc vm.dataset.create -vm $vm $(new_id) 77 assert_failure "govc: 400 Bad Request: {\"error_type\":\"NOT_ALLOWED_IN_CURRENT_STATE\", \"messages\":[]}" 78 } 79 80 @test "vm.dataset.info" { 81 vcsim_env 82 83 vm=$(new_supported_hardware_vm) 84 85 # create 86 id=$(new_id) 87 run govc vm.dataset.create -vm $vm -d "Some description." -guest-access READ_ONLY -omit-from-snapshot=false $id 88 assert_success "$id" 89 90 # get 91 run govc vm.dataset.info -vm $vm $id 92 assert_success 93 assert_line "Name: $id" 94 assert_line "Description: Some description." 95 assert_line "Host: READ_WRITE" 96 assert_line "Guest: READ_ONLY" 97 assert_line "Used: 0" 98 assert_line "OmitFromSnapshotAndClone: false" 99 100 # create an entry 101 run govc vm.dataset.entry.set -vm $vm -dataset $id key1 val1 102 assert_success 103 104 # get to verify the 'Used' field includes the footprint of the entry 105 run govc vm.dataset.info -vm $vm $id 106 assert_success 107 assert_line "Name: $id" 108 assert_line "Description: Some description." 109 assert_line "Host: READ_WRITE" 110 assert_line "Guest: READ_ONLY" 111 assert_line "Used: 8" 112 assert_line "OmitFromSnapshotAndClone: false" 113 114 # non-existing VM 115 run govc vm.dataset.info -vm enoent $id 116 assert_failure "govc: vm 'enoent' not found" 117 118 # non-existing data set 119 run govc vm.dataset.info -vm $vm enoent 120 assert_failure 121 assert_matches "404 Not Found" 122 } 123 124 @test "vm.dataset.update" { 125 vcsim_env 126 127 vm=$(new_supported_hardware_vm) 128 129 # create 130 id=$(new_id) 131 run govc vm.dataset.create -vm $vm -d "Initial description." $id 132 assert_success "$id" 133 134 # update description 135 run govc vm.dataset.update -vm $vm -d "Updated description." $id 136 assert_success "" 137 138 # get the updated 139 run govc vm.dataset.info -vm $vm $id 140 assert_success 141 assert_line "Name: $id" 142 assert_line "Description: Updated description." 143 144 # update on non-existing VM 145 run govc vm.dataset.update -vm enoent -d "Even newer description." $id 146 assert_failure "govc: vm 'enoent' not found" 147 148 # update non-existing data set 149 run govc vm.dataset.update -vm $vm -d "Even newer description." enoent 150 assert_failure 151 assert_matches "404 Not Found" 152 153 # update on suspended VM 154 govc vm.power -suspend $vm 155 run govc vm.dataset.update -vm $vm -d "Even newer description." $id 156 assert_failure "govc: 400 Bad Request: {\"error_type\":\"NOT_ALLOWED_IN_CURRENT_STATE\", \"messages\":[]}" 157 } 158 159 @test "vm.dataset.rm" { 160 vcsim_env 161 162 vm=$(new_supported_hardware_vm) 163 164 # create 165 id=$(new_id) 166 run govc vm.dataset.create -vm $vm -d "Initial description." $id 167 assert_success "$id" 168 169 # delete on non-existing VM 170 run govc vm.dataset.rm -vm enoent $id 171 assert_failure "govc: vm 'enoent' not found" 172 173 # delete non-existing data set 174 run govc vm.dataset.rm -vm $vm enoent 175 assert_failure 176 assert_matches "404 Not Found" 177 178 # delete on suspended VM 179 govc vm.power -suspend $vm 180 run govc vm.dataset.rm -vm $vm $id 181 assert_failure "govc: 400 Bad Request: {\"error_type\":\"NOT_ALLOWED_IN_CURRENT_STATE\", \"messages\":[]}" 182 govc vm.power -on $vm 183 184 # delete 185 run govc vm.dataset.rm -vm $vm $id 186 assert_success "" 187 188 # list to verify 189 run govc vm.dataset.ls -vm $vm 190 assert_success "" 191 192 # create a data set with an entry 193 id=$(new_id) 194 run govc vm.dataset.create -vm $vm -d "Initial description." $id 195 assert_success "$id" 196 run govc vm.dataset.entry.set -vm $vm -dataset $id key1 val1 197 assert_success 198 199 # try to delete the non-empty data set 200 run govc vm.dataset.rm -vm $vm $id 201 assert_failure "govc: 400 Bad Request: {\"error_type\":\"RESOURCE_IN_USE\", \"messages\":[]}" 202 203 # delete the non-empty data set with force 204 run govc vm.dataset.rm -vm $vm -force=true $id 205 assert_success "" 206 } 207 208 @test "vm.dataset.vmclone" { 209 vcsim_env 210 211 vm=$(new_supported_hardware_vm) 212 213 # create data set which is included in clones/snapshots 214 id=$(new_id) 215 run govc vm.dataset.create -vm $vm -d "First data set." -omit-from-snapshot=false $id 216 assert_success "$id" 217 218 # create data set which is excluded from clones/snapshots 219 id2=$(new_id) 220 run govc vm.dataset.create -vm $vm -d "Second data set." -omit-from-snapshot=true $id2 221 assert_success "$id2" 222 223 # clone the VM 224 cloned_vm=$(new_id) 225 run govc vm.clone -vm $vm $cloned_vm 226 assert_success 227 228 # update the description of the data set on the original VM 229 run govc vm.dataset.update -vm $vm -d "Updated description." $id 230 assert_success "" 231 232 # create another data set which is included in clones/snapshots on the original VM 233 id3=$(new_id) 234 run govc vm.dataset.create -vm $vm -d "Third data set." -omit-from-snapshot=false $id3 235 assert_success "$id3" 236 237 # list the data sets on the cloned VM 238 run govc vm.dataset.ls -vm $cloned_vm 239 assert_success "$id" 240 241 # verify the data set on the cloned VM was not affected by the update 242 run govc vm.dataset.info -vm $cloned_vm $id 243 assert_success 244 assert_line "Name: $id" 245 assert_line "Description: First data set." 246 } 247 248 @test "vm.dataset.vmsnapshot" { 249 vcsim_env 250 251 vm=$(new_supported_hardware_vm) 252 253 # create data set which is included in clones/snapshots 254 id=$(new_id) 255 run govc vm.dataset.create -vm $vm -d "First data set." -omit-from-snapshot=false $id 256 assert_success "$id" 257 258 # create data set which is excluded from clones/snapshots 259 id2=$(new_id) 260 run govc vm.dataset.create -vm $vm -d "Second data set." -omit-from-snapshot=true $id2 261 assert_success "$id2" 262 263 # create a snapshot 264 snapshot=$(new_id) 265 run govc snapshot.create -vm $vm $snapshot 266 assert_success 267 268 # update the description of the data set on the original VM 269 run govc vm.dataset.update -vm $vm -d "Updated description." $id 270 assert_success "" 271 272 # create another data set which is included in clones/snapshots 273 id3=$(new_id) 274 run govc vm.dataset.create -vm $vm -d "Third data set." -omit-from-snapshot=false $id3 275 assert_success "$id3" 276 277 # revert the VM to the snapshot 278 run govc snapshot.revert -vm $vm $snapshot 279 assert_success 280 281 # list the data sets on the VM 282 run govc vm.dataset.ls -vm $vm 283 assert_success "$id" 284 285 # verify the data set does not contain the update 286 run govc vm.dataset.info -vm $vm $id 287 assert_success 288 assert_line "Name: $id" 289 assert_line "Description: First data set." 290 } 291 292 @test "vm.dataset.entry.ls" { 293 vcsim_env 294 295 # setup VM and data set 296 vm=$(new_supported_hardware_vm) 297 ds=$(new_id) 298 run govc vm.dataset.create -vm $vm $ds 299 assert_success "$ds" 300 301 run govc vm.dataset.entry.ls -vm $vm -dataset $ds 302 assert_success "" 303 304 # non-existing VM 305 run govc vm.dataset.entry.ls -vm enoent -dataset $ds 306 assert_failure "govc: vm 'enoent' not found" 307 308 # non-existing data set 309 run govc vm.dataset.entry.ls -vm $vm -dataset enoent 310 assert_failure 311 assert_matches "404 Not Found" 312 313 # host does not have read access to the data set 314 run govc vm.dataset.update -vm $vm -host-access NONE $ds 315 assert_success "" 316 run govc vm.dataset.entry.ls -vm $vm -dataset $ds 317 assert_failure "govc: 400 Bad Request: {\"error_type\":\"UNAUTHORIZED\", \"messages\":[]}" 318 } 319 320 @test "vm.dataset.entry.get" { 321 vcsim_env 322 323 # setup VM and data set 324 vm=$(new_supported_hardware_vm) 325 ds=$(new_id) 326 run govc vm.dataset.create -vm $vm $ds 327 assert_success "$ds" 328 329 # non-existing VM 330 run govc vm.dataset.entry.get -vm enoent -dataset $ds somekey 331 assert_failure "govc: vm 'enoent' not found" 332 333 # non-existing data set 334 run govc vm.dataset.entry.get -vm $vm -dataset enoent somekey 335 assert_failure 336 assert_matches "404 Not Found" 337 338 # non-existing entry 339 run govc vm.dataset.entry.get -vm $vm -dataset $ds enoent 340 assert_failure 341 assert_matches "404 Not Found" 342 } 343 344 @test "vm.dataset.entry.set" { 345 vcsim_env 346 347 # setup VM and data set 348 vm=$(new_supported_hardware_vm) 349 ds=$(new_id) 350 run govc vm.dataset.create -vm $vm $ds 351 assert_success "$ds" 352 353 # create new entry 354 run govc vm.dataset.entry.set -vm $vm -dataset $ds key1 val1 355 assert_success 356 357 # list the created entry 358 run govc vm.dataset.entry.ls -vm $vm -dataset $ds 359 assert_success "key1" 360 361 # get the value of the created entry 362 run govc vm.dataset.entry.get -vm $vm -dataset $ds key1 363 assert_success "val1" 364 365 # update the value of the entry 366 run govc vm.dataset.entry.set -vm $vm -dataset $ds key1 val1b 367 assert_success 368 369 # get the updated value 370 run govc vm.dataset.entry.get -vm $vm -dataset $ds key1 371 assert_success "val1b" 372 373 # non-existing VM 374 run govc vm.dataset.entry.set -vm enoent -dataset $ds key2 val2 375 assert_failure "govc: vm 'enoent' not found" 376 377 # non-existing data set 378 run govc vm.dataset.entry.set -vm $vm -dataset enoent key2 val2 379 assert_failure 380 assert_matches "404 Not Found" 381 382 # suspended VM 383 govc vm.power -suspend $vm 384 run govc vm.dataset.entry.set -vm $vm -dataset $ds key2 val2 385 assert_failure "govc: 400 Bad Request: {\"error_type\":\"NOT_ALLOWED_IN_CURRENT_STATE\", \"messages\":[]}" 386 govc vm.power -on $vm 387 } 388 389 @test "vm.dataset.entry.rm" { 390 vcsim_env 391 392 # setup VM, data set and entry 393 vm=$(new_supported_hardware_vm) 394 ds=$(new_id) 395 run govc vm.dataset.create -vm $vm $ds 396 assert_success "$ds" 397 run govc vm.dataset.entry.set -vm $vm -dataset $ds key1 val1 398 assert_success 399 400 # delete on non-existing VM 401 run govc vm.dataset.entry.rm -vm enoent -dataset $ds key1 402 assert_failure "govc: vm 'enoent' not found" 403 404 # delete on non-existing data set 405 run govc vm.dataset.entry.rm -vm $vm -dataset enoent key1 406 assert_failure 407 assert_matches "404 Not Found" 408 409 # delete on suspended VM 410 govc vm.power -suspend $vm 411 run govc vm.dataset.entry.rm -vm $vm -dataset $ds key1 412 assert_failure "govc: 400 Bad Request: {\"error_type\":\"NOT_ALLOWED_IN_CURRENT_STATE\", \"messages\":[]}" 413 govc vm.power -on $vm 414 415 # delete 416 run govc vm.dataset.entry.rm -vm $vm -dataset $ds key1 417 assert_success 418 419 # list to verify 420 run govc vm.dataset.entry.ls -vm $vm -dataset $ds 421 assert_success "" 422 } 423 424 @test "vm.dataset.entry.access" { 425 vcsim_env 426 427 # setup VM, data set and entry 428 vm=$(new_supported_hardware_vm) 429 ds=$(new_id) 430 run govc vm.dataset.create -vm $vm $ds 431 assert_success "$ds" 432 run govc vm.dataset.entry.set -vm $vm -dataset $ds key1 val1 433 assert_success 434 435 # change the host access to NONE (govc calls the VC API, so the guest access does not matter here) 436 # the default access mode is READ_WRITE and has already been covered by previous tests 437 run govc vm.dataset.update -vm $vm -host-access NONE $ds 438 assert_success 439 440 # list 441 run govc vm.dataset.entry.ls -vm $vm -dataset $ds 442 assert_failure "govc: 400 Bad Request: {\"error_type\":\"UNAUTHORIZED\", \"messages\":[]}" 443 444 # get 445 run govc vm.dataset.entry.get -vm $vm -dataset $ds key1 446 assert_failure "govc: 400 Bad Request: {\"error_type\":\"UNAUTHORIZED\", \"messages\":[]}" 447 448 # set 449 run govc vm.dataset.entry.set -vm $vm -dataset $ds key1 val1b 450 assert_failure "govc: 400 Bad Request: {\"error_type\":\"UNAUTHORIZED\", \"messages\":[]}" 451 452 # delete 453 run govc vm.dataset.entry.rm -vm $vm -dataset $ds key1 454 assert_failure "govc: 400 Bad Request: {\"error_type\":\"UNAUTHORIZED\", \"messages\":[]}" 455 456 # change the host access to READ_ONLY 457 run govc vm.dataset.update -vm $vm -host-access READ_ONLY $ds 458 assert_success 459 460 # list 461 run govc vm.dataset.entry.ls -vm $vm -dataset $ds 462 assert_success "key1" 463 464 # get 465 run govc vm.dataset.entry.get -vm $vm -dataset $ds key1 466 assert_success "val1" 467 468 # set 469 run govc vm.dataset.entry.set -vm $vm -dataset $ds key1 val1b 470 assert_failure "govc: 400 Bad Request: {\"error_type\":\"UNAUTHORIZED\", \"messages\":[]}" 471 472 # delete 473 run govc vm.dataset.entry.rm -vm $vm -dataset $ds key1 474 assert_failure "govc: 400 Bad Request: {\"error_type\":\"UNAUTHORIZED\", \"messages\":[]}" 475 }