forked from vmware/govmomi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.bats
executable file
·195 lines (136 loc) · 4.92 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
#!/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
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 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)
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)
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)
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"
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"
}