forked from vmware/govmomi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datastore_file_manager_test.sh
executable file
·102 lines (73 loc) · 2.62 KB
/
datastore_file_manager_test.sh
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
#!/bin/bash -e
# This test is not run via bats
# See also: datastore.bats@test "datastore.disk"
export GOVC_TEST_URL=$GOVC_URL
. "$(dirname "$0")"/test_helper.bash
echo -n "checking datastore type..."
type=$(govc object.collect -s "datastore/$GOVC_DATASTORE" summary.type)
echo "$type"
if [ "$type" = "vsan" ] ; then
echo -n "checking for orphan objects..."
objs=($(govc datastore.vsan.dom.ls -o))
echo "${#objs[@]}"
if [ "${#objs[@]}" -ne "0" ] ; then
govc datastore.vsan.dom.rm "${objs[@]}"
fi
fi
dir=govc-test-dfm
echo "uploading plain file..."
cal | govc datastore.upload - $dir/cal.txt
echo "removing plain file..."
govc datastore.rm $dir/cal.txt
scratch=$dir/govc-test-scratch/govc-test-scratch.vmdk
govc datastore.mkdir -p "$(dirname $scratch)"
echo "creating disk $scratch..."
govc datastore.disk.create -size 1M $scratch
id=$(new_id)
echo "creating $id VM with disk linked to $scratch..."
govc vm.create -on=false -link -disk $scratch "$id"
info=$(govc device.info -vm "$id" disk-*)
echo "$info"
disk="$(grep Name: <<<"$info" | awk '{print $2}')"
vmdk="$id/$id.vmdk"
echo "removing $disk device but keeping the .vmdk backing file..."
govc device.remove -vm "$id" -keep "$disk"
echo -n "checking delta disk ddb.deletable..."
govc datastore.download "$vmdk" - | grep -q -v ddb.deletable
echo "yes"
echo -n "checking scratch disk ddb.deletable..."
govc datastore.download "$scratch" - | grep ddb.deletable | grep -q false
echo "no"
echo "removing $vmdk"
govc datastore.rm "$vmdk"
echo -n "checking that rm $scratch fails..."
govc datastore.rm "$scratch" 2>/dev/null || echo "yes"
echo -n "checking that rm -f $scratch deletes..."
govc datastore.rm -f "$scratch" && echo "yes"
echo "removing disk Directory via FileManager..."
govc datastore.mkdir -p "$(dirname $scratch)"
govc datastore.disk.create -size 1M $scratch
govc datastore.rm "$(dirname $scratch)"
echo -n "checking for remaining files..."
govc datastore.ls -p -R $dir
teardown
status=0
if [ "$type" = "vsan" ] ; then
echo -n "checking for leaked objects..."
objs=($(govc datastore.vsan.dom.ls -l -o | awk '{print $3}'))
echo "${#objs[@]}"
if [ "${#objs[@]}" -ne "0" ] ; then
printf "%s\n" "${objs[@]}"
status=1
else
# this is expected to leak on vSAN currently
echo -n "checking if FileManager.Delete still leaks..."
govc datastore.mkdir -p "$(dirname $scratch)"
govc datastore.disk.create -size 1M $scratch
# '-t=false' forces use of FileManager instead of VirtualDiskManager
govc datastore.rm -t=false $scratch
govc datastore.rm $dir
govc datastore.vsan.dom.ls -o | xargs -r govc datastore.vsan.dom.rm -v
fi
fi
exit $status