-
Notifications
You must be signed in to change notification settings - Fork 913
/
host.bats
executable file
·301 lines (220 loc) · 6.35 KB
/
host.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
#!/usr/bin/env bats
load test_helper
@test "host info esx" {
vcsim_env
run govc host.info
assert_success
grep -q Manufacturer: <<<"$output"
run govc host.info -host enoent
assert_failure "govc: host 'enoent' not found"
for opt in dns ip ipath uuid
do
run govc host.info "-host.$opt" enoent
assert_failure "govc: no such host"
done
# avoid hardcoding the esxbox hostname
local name=$(govc ls -t HostSystem '/*/host/*' | head -1)
run govc host.info -host "$name"
assert_success
grep -q Manufacturer: <<<"$output"
run govc host.info -host ${name##*/}
assert_success
grep -q Manufacturer: <<<"$output"
run govc host.info -host.ipath "$name"
assert_success
run govc host.info -host.dns localhost
assert_success
uuid=$(govc host.info -json | jq -r .hostSystems[].hardware.systemInfo.uuid)
run govc host.info -host.uuid "$uuid"
assert_success
run govc host.info "*"
assert_success
}
@test "host info vc" {
vcsim_env
run govc host.info
assert_success
grep -q Manufacturer: <<<"$output"
run govc host.info -host enoent
assert_failure "govc: host 'enoent' not found"
for opt in ipath uuid # dns ip # TODO: SearchIndex:SearchIndex does not implement: FindByDnsName
do
run govc host.info "-host.$opt" enoent
assert_failure "govc: no such host"
done
local name=$GOVC_HOST
unset GOVC_HOST
run govc host.info
assert_failure "govc: default host resolves to multiple instances, please specify"
run govc host.info -host "$name"
assert_success
grep -q Manufacturer: <<<"$output"
run govc host.info -host.ipath "$name"
assert_success
run govc host.info -host.dns $(basename "$name")
assert_failure # TODO: SearchIndex:SearchIndex does not implement: FindByDnsName
uuid=$(govc host.info -host "$name" -json | jq -r .hostSystems[].summary.hardware.uuid)
run govc host.info -host.uuid "$uuid"
assert_success
# summary.host should have a reference to the generated moid, not the template esx.HostSystem.Self (ha-host)
govc object.collect -s -type h / summary.host | grep -v ha-host
}
@test "host maintenance vc" {
vcsim_env
run govc host.info
assert_success
grep -q -v Maintenance <<<"$output"
run govc host.maintenance.enter "$GOVC_HOST"
assert_success
run govc host.info
assert_success
grep -q Maintenance <<<"$output"
run govc host.maintenance.exit "$GOVC_HOST"
assert_success
run govc host.info
assert_success
grep -q -v Maintenance <<<"$output"
}
@test "host.vnic.info" {
vcsim_env
run govc host.vnic.info
assert_success
govc host.vnic.info -json | jq .
}
@test "host.vnic.hint" {
vcsim_env
run govc host.vnic.hint -xml -host DC0_C0_H0
assert_success
run govc host.disconnect DC0_C0_H0
assert_success
run govc host.vnic.hint -xml -host DC0_C0_H0
assert_failure
assert_matches HostNotConnected "$output"
}
@test "host.vswitch.info" {
vcsim_env -esx
run govc host.vswitch.info
assert_success
run govc host.vswitch.info -json
assert_success
}
@test "host.portgroup.info" {
vcsim_env -esx
run govc host.portgroup.info
assert_success
run govc host.portgroup.info -json
assert_success
}
@test "host.storage.info" {
vcsim_env
run govc host.storage.info
assert_success
run govc host.storage.info -rescan -refresh -rescan-vmfs
assert_success
run govc host.storage.info -t hba
assert_success
names=$(govc host.storage.info -json | jq -r .storageDeviceInfo.scsiLun[].alternateName[].data)
# given data is hex encoded []byte and:
# [0] == encoding
# [1] == type
# [2] == ?
# [3] == length
# validate name is at least 2 char x 4
for name in $names; do
[ "${#name}" -ge 8 ]
done
}
@test "host.options" {
vcsim_env -esx
govc host.option.ls
run govc host.option.ls Config.HostAgent.log.level
assert_success
run govc host.option.ls Config.HostAgent.log.
assert_success
run govc host.option.ls -json Config.HostAgent.log.
assert_success
run govc host.option.ls Config.HostAgent.plugins.solo.ENOENT
assert_failure
}
@test "host.service" {
esx_env
run govc host.service.ls
assert_success
run govc host.service.ls -json
assert_success
run govc host.service status TSM-SSH
assert_success
}
@test "host.cert.info" {
vcsim_env -esx
run govc host.cert.info
assert_success
run govc host.cert.info -json
assert_success
expires=$(govc host.cert.info -json | jq -r .notAfter)
about_expires=$(govc about.cert -json | jq -r .notAfter)
assert_equal "$expires" "$about_expires"
run govc host.cert.info -show
assert_success
run openssl x509 -text <<<"$output"
assert_success
}
@test "host.cert.csr" {
vcsim_env -esx
# Requested Extensions:
# X509v3 Subject Alternative Name:
# IP Address:...
result=$(govc host.cert.csr -ip | openssl req -text -noout)
assert_matches "IP Address:" "$result"
! assert_matches "DNS:" "$result"
# Requested Extensions:
# X509v3 Subject Alternative Name:
# DNS:...
result=$(govc host.cert.csr | openssl req -text -noout)
! assert_matches "IP Address:" "$result"
assert_matches "DNS:" "$result"
}
@test "host.cert.import" {
vcsim_env -esx
expires=$(govc host.cert.info -json | jq -r .notAfter)
govc host.cert.csr -ip | ./host_cert_sign.sh | govc host.cert.import
expires2=$(govc host.cert.info -json | jq -r .notAfter)
# cert expiration should have changed
[ "$expires" != "$expires2" ]
# verify hostd is using the new cert too
expires=$(govc host.cert.info -json | jq -r .notAfter)
assert_equal "$expires" "$expires2"
}
@test "host.date.info" {
esx_env
run govc host.date.info
assert_success
run govc host.date.info -json
assert_success
}
@test "host.disconnect and host.reconnect" {
vcsim_env
run govc host.info
assert_success
status=$(govc host.info| grep -i "State"| awk '{print $2}')
assert_equal 'connected' $status
run govc host.disconnect "$GOVC_HOST"
assert_success
run govc host.info
assert_success
status=$(govc host.info| grep -i "State"| awk '{print $2}')
assert_equal 'disconnected' $status
run govc host.reconnect "$GOVC_HOST"
assert_success
run govc host.info
assert_success
status=$(govc host.info| grep -i "State"| awk '{print $2}')
assert_equal 'connected' $status
}
@test "host.tpm" {
vcsim_env
run govc host.tpm.info
assert_success
run govc host.tpm.report
assert_success
}