github.com/vmware/govmomi@v0.43.0/govc/test/host.bats (about)

     1  #!/usr/bin/env bats
     2  load test_helper
     3  
     4  @test "host info esx" {
     5    vcsim_env
     6  
     7    run govc host.info
     8    assert_success
     9    grep -q Manufacturer: <<<"$output"
    10  
    11    run govc host.info -host enoent
    12    assert_failure "govc: host 'enoent' not found"
    13  
    14    for opt in dns ip ipath uuid
    15    do
    16      run govc host.info "-host.$opt" enoent
    17      assert_failure "govc: no such host"
    18    done
    19  
    20    # avoid hardcoding the esxbox hostname
    21    local name=$(govc ls -t HostSystem '/*/host/*' | head -1)
    22  
    23    run govc host.info -host "$name"
    24    assert_success
    25    grep -q Manufacturer: <<<"$output"
    26  
    27    run govc host.info -host ${name##*/}
    28    assert_success
    29    grep -q Manufacturer: <<<"$output"
    30  
    31    run govc host.info -host.ipath "$name"
    32    assert_success
    33  
    34    run govc host.info -host.dns localhost
    35    assert_success
    36  
    37    uuid=$(govc host.info -json | jq -r .hostSystems[].hardware.systemInfo.uuid)
    38  
    39    run govc host.info -host.uuid "$uuid"
    40    assert_success
    41  
    42    run govc host.info "*"
    43    assert_success
    44  }
    45  
    46  @test "host info vc" {
    47    vcsim_env
    48  
    49    run govc host.info
    50    assert_success
    51    grep -q Manufacturer: <<<"$output"
    52  
    53    run govc host.info -host enoent
    54    assert_failure "govc: host 'enoent' not found"
    55  
    56    for opt in ipath uuid # dns ip # TODO: SearchIndex:SearchIndex does not implement: FindByDnsName
    57    do
    58      run govc host.info "-host.$opt" enoent
    59      assert_failure "govc: no such host"
    60    done
    61  
    62    local name=$GOVC_HOST
    63  
    64    unset GOVC_HOST
    65    run govc host.info
    66    assert_failure "govc: default host resolves to multiple instances, please specify"
    67  
    68    run govc host.info -host "$name"
    69    assert_success
    70    grep -q Manufacturer: <<<"$output"
    71  
    72    run govc host.info -host.ipath "$name"
    73    assert_success
    74  
    75    run govc host.info -host.dns $(basename "$name")
    76    assert_failure # TODO: SearchIndex:SearchIndex does not implement: FindByDnsName
    77  
    78    uuid=$(govc host.info -host "$name" -json | jq -r .hostSystems[].summary.hardware.uuid)
    79    run govc host.info -host.uuid "$uuid"
    80    assert_success
    81  
    82    # summary.host should have a reference to the generated moid, not the template esx.HostSystem.Self (ha-host)
    83    govc object.collect -s -type h / summary.host | grep -v ha-host
    84  }
    85  
    86  @test "host maintenance vc" {
    87    vcsim_env
    88  
    89    run govc host.info
    90    assert_success
    91    grep -q -v Maintenance <<<"$output"
    92  
    93    run govc host.maintenance.enter "$GOVC_HOST"
    94    assert_success
    95  
    96    run govc host.info
    97    assert_success
    98    grep -q Maintenance <<<"$output"
    99  
   100    run govc host.maintenance.exit "$GOVC_HOST"
   101    assert_success
   102  
   103    run govc host.info
   104    assert_success
   105    grep -q -v Maintenance <<<"$output"
   106  }
   107  
   108  @test "host.vnic.info" {
   109    vcsim_env
   110  
   111    run govc host.vnic.info
   112    assert_success
   113  
   114    govc host.vnic.info -json | jq .
   115  }
   116  
   117  @test "host.vnic.hint" {
   118    vcsim_env
   119  
   120    run govc host.vnic.hint -xml -host DC0_C0_H0
   121    assert_success
   122  
   123    run govc host.disconnect DC0_C0_H0
   124    assert_success
   125  
   126    run govc host.vnic.hint -xml -host DC0_C0_H0
   127    assert_failure
   128    assert_matches HostNotConnected "$output"
   129  }
   130  
   131  @test "host.vswitch.info" {
   132    vcsim_env -esx
   133  
   134    run govc host.vswitch.info
   135    assert_success
   136  
   137    run govc host.vswitch.info -json
   138    assert_success
   139  }
   140  
   141  @test "host.portgroup.info" {
   142    vcsim_env -esx
   143  
   144    run govc host.portgroup.info
   145    assert_success
   146  
   147    run govc host.portgroup.info -json
   148    assert_success
   149  }
   150  
   151  @test "host.storage.info" {
   152      vcsim_env
   153  
   154      run govc host.storage.info
   155      assert_success
   156  
   157      run govc host.storage.info -rescan -refresh -rescan-vmfs
   158      assert_success
   159  
   160      run govc host.storage.info -t hba
   161      assert_success
   162  
   163      names=$(govc host.storage.info -json | jq -r .storageDeviceInfo.scsiLun[].alternateName[].data)
   164      # given data is hex encoded []byte and:
   165      #   [0] == encoding
   166      #   [1] == type
   167      #   [2] == ?
   168      #   [3] == length
   169      # validate name is at least 2 char x 4
   170      for name in $names; do
   171        [ "${#name}" -ge 8 ]
   172      done
   173  }
   174  
   175  @test "host.options" {
   176    vcsim_env -esx
   177    govc host.option.ls
   178    run govc host.option.ls Config.HostAgent.log.level
   179    assert_success
   180  
   181    run govc host.option.ls Config.HostAgent.log.
   182    assert_success
   183  
   184    run govc host.option.ls -json Config.HostAgent.log.
   185    assert_success
   186  
   187    run govc host.option.ls Config.HostAgent.plugins.solo.ENOENT
   188    assert_failure
   189  }
   190  
   191  @test "host.service" {
   192    esx_env
   193  
   194    run govc host.service.ls
   195    assert_success
   196  
   197    run govc host.service.ls -json
   198    assert_success
   199  
   200    run govc host.service status TSM-SSH
   201    assert_success
   202  }
   203  
   204  @test "host.cert.info" {
   205    vcsim_env -esx
   206  
   207    run govc host.cert.info
   208    assert_success
   209  
   210    run govc host.cert.info -json
   211    assert_success
   212  
   213    expires=$(govc host.cert.info -json | jq -r .notAfter)
   214    about_expires=$(govc about.cert -json | jq -r .notAfter)
   215    assert_equal "$expires" "$about_expires"
   216  
   217    run govc host.cert.info -show
   218    assert_success
   219  
   220    run openssl x509 -text <<<"$output"
   221    assert_success
   222  }
   223  
   224  @test "host.cert.csr" {
   225    vcsim_env -esx
   226  
   227    #   Requested Extensions:
   228    #       X509v3 Subject Alternative Name:
   229    #       IP Address:...
   230    result=$(govc host.cert.csr -ip | openssl req -text -noout)
   231    assert_matches "IP Address:" "$result"
   232    ! assert_matches "DNS:" "$result"
   233  
   234    #   Requested Extensions:
   235    #       X509v3 Subject Alternative Name:
   236    #       DNS:...
   237    result=$(govc host.cert.csr | openssl req -text -noout)
   238    ! assert_matches "IP Address:" "$result"
   239    assert_matches "DNS:" "$result"
   240  }
   241  
   242  @test "host.cert.import" {
   243    vcsim_env -esx
   244  
   245    expires=$(govc host.cert.info -json | jq -r .notAfter)
   246  
   247    govc host.cert.csr -ip | ./host_cert_sign.sh | govc host.cert.import
   248    expires2=$(govc host.cert.info -json | jq -r .notAfter)
   249  
   250    # cert expiration should have changed
   251    [ "$expires" != "$expires2" ]
   252  
   253    # verify hostd is using the new cert too
   254    expires=$(govc host.cert.info -json | jq -r .notAfter)
   255    assert_equal "$expires" "$expires2"
   256  }
   257  
   258  @test "host.date.info" {
   259    esx_env
   260  
   261    run govc host.date.info
   262    assert_success
   263  
   264    run govc host.date.info -json
   265    assert_success
   266  }
   267  
   268  @test "host.disconnect and host.reconnect" {
   269    vcsim_env
   270  
   271    run govc host.info
   272    assert_success
   273    status=$(govc host.info| grep -i "State"| awk '{print $2}')
   274    assert_equal 'connected' $status
   275  
   276    run govc host.disconnect "$GOVC_HOST"
   277    assert_success
   278  
   279    run govc host.info
   280    assert_success
   281    status=$(govc host.info| grep -i "State"| awk '{print $2}')
   282    assert_equal 'disconnected' $status
   283  
   284    run govc host.reconnect "$GOVC_HOST"
   285    assert_success
   286  
   287    run govc host.info
   288    assert_success
   289    status=$(govc host.info| grep -i "State"| awk '{print $2}')
   290    assert_equal 'connected' $status
   291  }
   292  
   293  @test "host.tpm" {
   294    vcsim_env
   295  
   296    run govc host.tpm.info
   297    assert_success
   298  
   299    run govc host.tpm.report
   300    assert_success
   301  }