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 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
|
#!/usr/bin/env bats
load test_helper
upload_file() {
name=$(new_id)
echo "Hello world" | govc datastore.upload - "$name"
assert_success
echo "$name"
}
@test "datastore.ls" {
vcsim_env -esx
name=$(upload_file)
# Single argument
run govc datastore.ls "${name}"
assert_success
[ ${#lines[@]} -eq 1 ]
# Multiple arguments
run govc datastore.ls "${name}" "${name}"
assert_success
[ ${#lines[@]} -eq 2 ]
# Pattern argument
run govc datastore.ls "./govc-test-*"
assert_success
[ ${#lines[@]} -ge 1 ]
# Long listing
run govc datastore.ls -l "./govc-test-*"
assert_success
assert_equal "12B" $(awk '{ print $1 }' <<<${output})
}
@test "datastore.ls-R" {
esx_env
dir=$(new_id)
run govc datastore.mkdir "$dir"
assert_success
for name in one two three ; do
echo "$name world" | govc datastore.upload - "$dir/file-$name"
run govc datastore.mkdir -p "$dir/dir-$name/subdir-$name"
run govc datastore.mkdir -p "$dir/dir-$name/.hidden"
assert_success
echo "$name world" | govc datastore.upload - "$dir/dir-$name/.hidden/other-$name"
echo "$name world" | govc datastore.upload - "$dir/dir-$name/other-$name"
echo "$name world" | govc datastore.upload - "$dir/dir-$name/subdir-$name/last-$name"
done
# without -R
json=$(govc datastore.ls -json -l -p "$dir")
result=$(jq -r .[].File[].Path <<<"$json" | wc -l)
[ "$result" -eq 6 ]
result=$(jq -r .[].FolderPath <<<"$json" | wc -l)
[ "$result" -eq 1 ]
# with -R
json=$(govc datastore.ls -json -l -p -R "$dir")
result=$(jq -r .[].File[].Path <<<"$json" | wc -l)
[ "$result" -eq 15 ]
result=$(jq -r .[].FolderPath <<<"$json" | wc -l)
[ "$result" -eq 7 ]
# with -R -a
json=$(govc datastore.ls -json -l -p -R -a "$dir")
result=$(jq -r .[].File[].Path <<<"$json" | wc -l)
[ "$result" -eq 21 ]
result=$(jq -r .[].FolderPath <<<"$json" | wc -l)
[ "$result" -eq 10 ]
}
@test "datastore.rm" {
vcsim_env -esx
name=$(upload_file)
# Not found is a failure
run govc datastore.rm "${name}.notfound"
assert_failure
# Not found is NOT a failure with the force flag
run govc datastore.rm -f "${name}.notfound"
assert_success
assert_empty "${output}"
# Verify the file is present
run govc datastore.ls "${name}"
assert_success
# Delete the file
run govc datastore.rm "${name}"
assert_success
assert_empty "${output}"
# Verify the file is gone
run govc datastore.ls "${name}"
assert_failure
}
@test "datastore.info" {
vcsim_env
run govc datastore.info enoent
assert_failure
run govc datastore.info
assert_success
[ ${#lines[@]} -gt 1 ]
run govc datastore.info -H
assert_failure
cluster=$(dirname "$GOVC_RESOURCE_POOL")
hosts=($(govc object.collect -s -d $'\n' "$cluster" host))
run govc datastore.info -H "${hosts[@]}"
assert_success
run govc cluster.add -cluster "$cluster" -hostname test.example.com -username user -password pass
assert_success
run govc datastore.create -type local -name tmpds -path "$BATS_TMPDIR" test.example.com
assert_success
hosts=($(govc object.collect -s -d $'\n' "$cluster" host))
run govc datastore.info -H "${hosts[@]}"
assert_failure # host test.example.com hast no shared datastores
}
@test "datastore.mkdir" {
vcsim_env -esx
name=$(new_id)
# Not supported datastore type is a failure
run govc datastore.mkdir -namespace "notfound"
assert_failure
assert_matches "govc: ServerFaultCode: .*" "${output}"
run govc datastore.mkdir "${name}"
assert_success
assert_empty "${output}"
# Verify the dir is present
run govc datastore.ls "${name}"
assert_success
# Delete the dir on an unsupported datastore type is a failure
run govc datastore.rm -namespace "${name}"
assert_failure
assert_matches "govc: ServerFaultCode: .*" "${output}"
# Delete the dir
run govc datastore.rm "${name}"
assert_success
assert_empty "${output}"
# Verify the dir is gone
run govc datastore.ls "${name}"
assert_failure
}
@test "datastore.download" {
vcsim_env -esx
name=$(upload_file)
run govc datastore.download "$name" -
assert_success
assert_output "Hello world"
run govc datastore.download "$name" "$BATS_TMPDIR/$name"
assert_success
run cat "$BATS_TMPDIR/$name"
assert_output "Hello world"
rm "$BATS_TMPDIR/$name"
}
@test "datastore.upload" {
esx_env
name=$(new_id)
echo -n "Hello world" | govc datastore.upload - "$name"
run govc datastore.download "$name" -
assert_success
assert_output "Hello world"
}
@test "datastore.tail" {
esx_env
run govc datastore.tail "enoent/enoent.log"
assert_failure
id=$(new_id)
govc vm.create "$id"
govc vm.power -off "$id"
# test with .log (> bufSize) and .vmx (< bufSize)
for file in "$id/vmware.log" "$id/$id.vmx" ; do
log=$(govc datastore.download "$file" -)
for n in 0 1 5 10 123 456 7890 ; do
expect=$(tail -n $n <<<"$log")
run govc datastore.tail -n $n "$file"
assert_output "$expect"
expect=$(tail -c $n <<<"$log")
run govc datastore.tail -c $n "$file"
assert_output "$expect"
done
done
}
@test "datastore.disk" {
esx_env
id=$(new_id)
vmdk="$id/$id.vmdk"
run govc datastore.mkdir "$id"
assert_success
run govc datastore.disk.create "$vmdk"
assert_success
run govc datastore.disk.info "$vmdk"
assert_success
run govc datastore.disk.info -uuid "$vmdk"
assert_success
run govc datastore.rm "$vmdk"
assert_success
run govc datastore.mkdir -p "$id"
assert_success
run govc datastore.disk.create "$vmdk"
assert_success
id=$(new_id)
run govc vm.create -on=false -link -disk "$vmdk" "$id"
assert_success
run govc datastore.disk.info -d "$vmdk"
assert_success
run govc datastore.disk.info -p=false "$vmdk"
assert_success
run govc datastore.disk.info -c "$vmdk"
assert_success
run govc datastore.disk.info -json "$vmdk"
assert_success
# should fail due to: ddb.deletable=false
run govc datastore.rm "$vmdk"
assert_failure
run govc datastore.rm -f "$vmdk"
assert_success
# one more time, but rm the directory w/o -f
run govc datastore.mkdir -p "$id"
assert_success
run govc datastore.disk.create "$vmdk"
assert_success
id=$(new_id)
run govc vm.create -on=false -link -disk "$vmdk" "$id"
assert_success
run govc datastore.rm "$(dirname "$vmdk")"
assert_success
}
@test "datastore.cp" {
vcsim_env -dc 2 -ds 2
id=$(new_id)
vmdk="$id/$id.vmdk"
# GOVC_DATACENTER and GOVC_DATACENTER are set during these tests
run govc datastore.mkdir "$id"
assert_success
run govc datastore.disk.create "$vmdk"
assert_success
clone="$id/$id-2.vmdk"
run govc datastore.cp "$vmdk" "$clone"
assert_success
# Specifying -dc and -ds flags in the tests below
unset GOVC_DATASTORE GOVC_DATACENTER
run govc datastore.ls -dc DC0 -ds LocalDS_0 "$clone"
assert_success # created this file above
run govc datastore.ls -dc DC0 -ds LocalDS_1 "$clone"
assert_failure # should not exist in DS_1
run govc datastore.ls -dc DC1 -ds LocalDS_1 "$clone"
assert_failure # should not exist in DC1 DS_1
run govc datastore.mkdir -dc DC1 -ds LocalDS_1 "$id"
assert_success
for op in cp mv ; do
run govc datastore.ls -dc DC1 -ds LocalDS_0 "$clone"
assert_failure # should not exist in DC1 DS_0
# From DC0 DS_0 to DC1 DS_1
run govc datastore.$op -dc DC0 -ds LocalDS_0 -dc-target DC1 -ds-target LocalDS_1 "$clone" "$clone"
assert_success
run govc datastore.ls -dc DC1 -ds LocalDS_1 "$clone"
assert_success # now the file exists
run govc datastore.rm -dc DC1 -ds LocalDS_1 "$clone"
assert_success
done
}
@test "datastore.disk.info" {
esx_env
import_ttylinux_vmdk
run govc datastore.disk.info
assert_failure
run govc datastore.disk.info enoent
assert_failure
run govc datastore.disk.info "$GOVC_TEST_VMDK"
assert_success
run govc datastore.disk.info -d "$GOVC_TEST_VMDK"
assert_success
run govc datastore.disk.info -c "$GOVC_TEST_VMDK"
assert_success
}
@test "datastore.disk.inflate" {
esx_env
id=$(new_id)
vmdk="$id/$id.vmdk"
run govc datastore.mkdir "$id"
assert_success
run govc datastore.disk.create -size 10MB "$vmdk"
assert_success
type=$(govc datastore.disk.info -json "$vmdk" | jq -r .[].DiskType)
[ "$type" = "thin" ]
run govc datastore.disk.inflate "$vmdk"
assert_success
type=$(govc datastore.disk.info -json "$vmdk" | jq -r .[].DiskType)
[ "$type" = "eagerZeroedThick" ]
run govc datastore.disk.shrink "$vmdk"
assert_success
run govc datastore.disk.shrink -copy "$vmdk"
assert_success
run govc datastore.disk.shrink -copy=false "$vmdk"
assert_success
}
@test "datastore.cluster" {
vcsim_env
pod=/DC0/datastore/DC0_POD0
run govc folder.create -pod $pod
assert_success
run govc datastore.cluster.info
assert_success
run govc folder.create -pod $pod
assert_failure # duplicate name
run govc datastore.cluster.change -drs-enabled -drs-mode manual $pod
assert_success
run govc datastore.cluster.info -json
assert_success
}
|