github.com/vmware/govmomi@v0.37.1/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 esx_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 164 @test "host.options" { 165 vcsim_env -esx 166 govc host.option.ls 167 run govc host.option.ls Config.HostAgent.log.level 168 assert_success 169 170 run govc host.option.ls Config.HostAgent.log. 171 assert_success 172 173 run govc host.option.ls -json Config.HostAgent.log. 174 assert_success 175 176 run govc host.option.ls Config.HostAgent.plugins.solo.ENOENT 177 assert_failure 178 } 179 180 @test "host.service" { 181 esx_env 182 183 run govc host.service.ls 184 assert_success 185 186 run govc host.service.ls -json 187 assert_success 188 189 run govc host.service status TSM-SSH 190 assert_success 191 } 192 193 @test "host.cert.info" { 194 esx_env 195 196 run govc host.cert.info 197 assert_success 198 199 run govc host.cert.info -json 200 assert_success 201 202 expires=$(govc host.cert.info -json | jq -r .notAfter) 203 about_expires=$(govc about.cert -json | jq -r .notAfter) 204 assert_equal "$expires" "$about_expires" 205 } 206 207 @test "host.cert.csr" { 208 esx_env 209 210 # Requested Extensions: 211 # X509v3 Subject Alternative Name: 212 # IP Address:... 213 result=$(govc host.cert.csr -ip | openssl req -text -noout) 214 assert_matches "IP Address:" "$result" 215 ! assert_matches "DNS:" "$result" 216 217 # Requested Extensions: 218 # X509v3 Subject Alternative Name: 219 # DNS:... 220 result=$(govc host.cert.csr | openssl req -text -noout) 221 ! assert_matches "IP Address:" "$result" 222 assert_matches "DNS:" "$result" 223 } 224 225 @test "host.cert.import" { 226 esx_env 227 228 issuer=$(govc host.cert.info -json | jq -r .issuer) 229 expires=$(govc host.cert.info -json | jq -r .notAfter) 230 231 # only mess with the cert if its already been signed by our test CA 232 if [[ "$issuer" != CN=govc-ca,* ]] ; then 233 skip "host cert not signed by govc-ca" 234 fi 235 236 govc host.cert.csr -ip | ./host_cert_sign.sh | govc host.cert.import 237 expires2=$(govc host.cert.info -json | jq -r .notAfter) 238 239 # cert expiration should have changed 240 [ "$expires" != "$expires2" ] 241 242 # verify hostd is using the new cert too 243 expires=$(govc about.cert -json | jq -r .notAfter) 244 assert_equal "$expires" "$expires2" 245 246 # our cert is not trusted against the system CA list 247 status=$(govc about.cert | grep Status:) 248 assert_matches ERROR "$status" 249 250 # with our CA trusted, the cert should be too 251 status=$(govc about.cert -tls-ca-certs ./govc_ca.pem | grep Status:) 252 assert_matches good "$status" 253 } 254 255 @test "host.date.info" { 256 esx_env 257 258 run govc host.date.info 259 assert_success 260 261 run govc host.date.info -json 262 assert_success 263 } 264 265 @test "host.disconnect and host.reconnect" { 266 vcsim_env 267 268 run govc host.info 269 assert_success 270 status=$(govc host.info| grep -i "State"| awk '{print $2}') 271 assert_equal 'connected' $status 272 273 run govc host.disconnect "$GOVC_HOST" 274 assert_success 275 276 run govc host.info 277 assert_success 278 status=$(govc host.info| grep -i "State"| awk '{print $2}') 279 assert_equal 'disconnected' $status 280 281 run govc host.reconnect "$GOVC_HOST" 282 assert_success 283 284 run govc host.info 285 assert_success 286 status=$(govc host.info| grep -i "State"| awk '{print $2}') 287 assert_equal 'connected' $status 288 }