github.com/vmware/govmomi@v0.37.2/govc/test/device.bats (about)

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