forked from vmware/govmomi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
host.bats
executable file
·248 lines (181 loc) · 5.44 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
#!/usr/bin/env bats
load test_helper
@test "host info esx" {
esx_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 '/*/host/*' | grep -v Resources)
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 "$(basename $(dirname $name))"
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" {
esx_env
run govc host.vnic.info
assert_success
govc host.vnic.info -json | jq .
}
@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
}
@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" {
esx_env
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"
}
@test "host.cert.csr" {
esx_env
# 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" {
esx_env
issuer=$(govc host.cert.info -json | jq -r .Issuer)
expires=$(govc host.cert.info -json | jq -r .NotAfter)
# only mess with the cert if its already been signed by our test CA
if [[ "$issuer" != CN=govc-ca,* ]] ; then
skip "host cert not signed by govc-ca"
fi
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 about.cert -json | jq -r .NotAfter)
assert_equal "$expires" "$expires2"
# our cert is not trusted against the system CA list
status=$(govc about.cert | grep Status:)
assert_matches ERROR "$status"
# with our CA trusted, the cert should be too
status=$(govc about.cert -tls-ca-certs ./govc_ca.pem | grep Status:)
assert_matches good "$status"
}
@test "host.date.info" {
esx_env
run govc host.date.info
assert_success
run govc host.date.info -json
assert_success
}