-
Notifications
You must be signed in to change notification settings - Fork 911
/
import.bats
executable file
·261 lines (180 loc) · 7.01 KB
/
import.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
#!/usr/bin/env bats
load test_helper
@test "import.ova" {
vcsim_env -app 1
run govc import.ova "$GOVC_IMAGES/$TTYLINUX_NAME.ova"
assert_success
run govc device.ls -vm "$TTYLINUX_NAME"
assert_success
assert_matches "disk-"
run govc vm.destroy "$TTYLINUX_NAME"
assert_success
# link ovf/ova to datastore so we can test with an http source
dir=$(govc datastore.info -json | jq -r .datastores[].info.url)
ln -s "$GOVC_IMAGES/$TTYLINUX_NAME."* "$dir"
run govc import.spec "https://$(govc env GOVC_URL)/folder/$TTYLINUX_NAME.ovf"
assert_success
run govc import.spec "https://$(govc env GOVC_URL)/folder/$TTYLINUX_NAME.ova"
assert_success
proto=$(jq -r .IPProtocol <<<"$output")
assert_equal IPv4 "$proto"
run govc import.ova -verbose "https://$(govc env GOVC_URL)/folder/$TTYLINUX_NAME.ova"
assert_success
run govc device.ls -vm "$TTYLINUX_NAME"
assert_success
assert_matches "disk-"
run govc vm.destroy "$TTYLINUX_NAME"
assert_success
run govc import.ova -verbose -pool /DC0/host/DC0_C0/Resources/DC0_C0_APP0 "$GOVC_IMAGES/$TTYLINUX_NAME.ova"
assert_success
}
@test "import.ova with checksum validation" {
vcsim_env -app 1
run govc import.ova -name=bad-checksum-vm -m "$GOVC_IMAGES/$TTYLINUX_NAME-bad-checksum.ova"
assert_failure # vmdk checksum mismatch
run govc import.ova -name=good-checksum-vm -m "$GOVC_IMAGES/$TTYLINUX_NAME.ova"
assert_success
}
@test "import.ova with iso" {
vcsim_env
run govc import.ova "$GOVC_IMAGES/${TTYLINUX_NAME}-live.ova"
assert_success
run govc device.ls -vm "${TTYLINUX_NAME}-live"
assert_success
assert_matches "disk-"
assert_matches "cdrom-.* ${TTYLINUX_NAME}-live/_deviceImage0.iso"
run govc vm.destroy "${TTYLINUX_NAME}-live"
assert_success
}
@test "import.ovf" {
vcsim_env
run govc import.ovf $GOVC_IMAGES/${TTYLINUX_NAME}.ovf
assert_success
run govc vm.destroy ${TTYLINUX_NAME}
assert_success
# test w/ relative dir
pushd $BATS_TEST_DIRNAME >/dev/null
run govc import.ovf ./images/${TTYLINUX_NAME}.ovf
assert_success
popd >/dev/null
run govc vm.destroy ${TTYLINUX_NAME}
assert_success
# ensure vcsim doesn't panic without capacityAllocationUnits
dir=$($mktemp --tmpdir -d govc-test-XXXXX 2>/dev/null || $mktemp -d -t govc-test-XXXXX)
sed -e s/capacityAllocationUnits/invalid/ "$GOVC_IMAGES/$TTYLINUX_NAME.ovf" > "$dir/$TTYLINUX_NAME.ovf"
touch "$dir/$TTYLINUX_NAME-disk1.vmdk" # .vmdk contents don't matter to vcsim
run govc import.ovf "$dir/$TTYLINUX_NAME.ovf"
assert_success
rm -rf "$dir"
}
@test "import.ovf -host.ipath" {
vcsim_env
run govc import.ovf -host.ipath="$(govc find / -type h | head -1)" "$GOVC_IMAGES/${TTYLINUX_NAME}.ovf"
assert_success
run govc vm.destroy "$TTYLINUX_NAME"
assert_success
}
@test "import.ovf with name in options" {
vcsim_env
name=$(new_id)
file=$($mktemp --tmpdir govc-test-XXXXX 2>/dev/null || $mktemp -t govc-test-XXXXX)
echo "{ \"Name\": \"${name}\"}" > ${file}
run govc import.ovf -options="${file}" $GOVC_IMAGES/${TTYLINUX_NAME}.ovf
assert_success
run govc vm.destroy "${name}"
assert_success
rm -f ${file}
}
@test "import.ovf with import.spec result" {
vcsim_env
file=$($mktemp --tmpdir govc-test-XXXXX 2>/dev/null || $mktemp -t govc-test-XXXXX)
name=$(new_id)
govc import.spec $GOVC_IMAGES/${TTYLINUX_NAME}.ovf > ${file}
run govc import.ovf -name="${name}" -options="${file}" $GOVC_IMAGES/${TTYLINUX_NAME}.ovf
assert_success
run govc vm.destroy "${name}"
assert_success
}
@test "import.ovf with name as argument" {
vcsim_env
name=$(new_id)
run govc import.ova -name="${name}" $GOVC_IMAGES/${TTYLINUX_NAME}.ova
assert_success
run govc vm.destroy "${name}"
assert_success
}
@test "import.vmdk" {
esx_env
name=$(new_id)
run govc import.vmdk "$GOVC_TEST_VMDK_SRC" "$name"
assert_success
run govc import.vmdk "$GOVC_TEST_VMDK_SRC" "$name"
assert_failure # exists
run govc import.vmdk -force "$GOVC_TEST_VMDK_SRC" "$name"
assert_success # exists, but -force was used
}
@test "import duplicate dvpg names" {
vcsim_env
run govc dvs.create DVS1 # DVS0 already exists
assert_success
run govc dvs.portgroup.add -dvs DVS0 -type ephemeral NSX-dvpg
assert_success
run govc dvs.portgroup.add -dvs DVS1 -type ephemeral NSX-dvpg
assert_success
ovf="$GOVC_IMAGES/$TTYLINUX_NAME.ovf"
spec=$(govc import.spec "$GOVC_IMAGES/$TTYLINUX_NAME.ovf")
run govc import.ovf -name ttylinux -options - "$ovf" <<<"$spec"
assert_success # no network specified
options=$(jq ".NetworkMapping[].Network = \"enoent\"" <<<"$spec")
run govc import.ovf -options - "$ovf" <<<"$options"
assert_failure # network not found
options=$(jq ".NetworkMapping[].Network = \"NSX-dvpg\"" <<<"$spec")
run govc import.ovf -options - "$ovf" <<<"$options"
assert_failure # 2 networks have the same name
options=$(jq ".NetworkMapping[].Network = \"DVS0/NSX-dvpg\"" <<<"$spec")
run govc import.ovf -name ttylinux2 -options - "$ovf" <<<"$options"
assert_success # switch_name/portgroup_name is unique
grep -v "invalid NetworkMapping.Name" <<<"$output"
options=$(jq ".NetworkMapping[].Network = \"/DC0/host/DC0_C0/DC0_DVPG0\"" <<<"$spec")
run govc import.ovf -name ttylinux3 -options - "$ovf" <<<"$options"
assert_success # cluster path is unique
switch=$(govc find -i network -name DVS0)
id=$(govc find -i network -config.distributedVirtualSwitch "$switch" -name NSX-dvpg)
options=$(jq ".NetworkMapping[].Network = \"$id\"" <<<"$spec")
options=$(jq ".NetworkMapping[].Name = \"enoent\"" <<<"$options")
run govc import.ovf -options - "$ovf" <<<"$options"
assert_success # using raw MO id
grep "invalid NetworkMapping.Name" <<<"$output"
}
@test "import invalid disk provisioning" {
vcsim_env
ovf="$GOVC_IMAGES/$TTYLINUX_NAME.ovf"
spec=$(govc import.spec "$GOVC_IMAGES/$TTYLINUX_NAME.ovf")
options=$(jq ".DiskProvisioning = \"enoent\"" <<<"$spec")
run govc import.ovf -options - "$ovf" <<<"$options"
assert_failure "govc: Disk provisioning type not supported: enoent"
options=$(jq ".DiskProvisioning = \"monolithicSparse\"" <<<"$spec")
run govc import.ovf -options - "$ovf" <<<"$options"
assert_failure
assert_matches DeviceUnsupportedForVmPlatform
}
@test "import properties" {
vcsim_env
ovf=../../ovf/fixtures/properties.ovf
govc import.spec $ovf | grep -q -v nfs_mount
options=$(govc import.spec -hidden $ovf)
grep -q -v vm.name <<<"$options"
grep -q nfs_mount <<<"$options"
run govc import.ovf -name "$(new_id)" -options - "$ovf" <<<"$options"
assert_success # hidden options but no value changes
run govc import.ovf -options - "$ovf" <<<"${options//transfer/other}"
assert_failure # userConfigurable=false
id=$(new_id)
run govc import.ovf -name "$id" -hidden -options - "$ovf" <<<"${options//transfer/other}"
assert_success # userConfigurable=true
config=$(govc object.collect -o -json "vm/$id" | jq .config.vAppConfig)
name=$(jq -r .product[0].name <<<"$config")
version=$(jq -r .product[0].version <<<"$config")
assert_equal ttylinux "$name"
assert_equal 16.1 "$version"
}