-
Notifications
You must be signed in to change notification settings - Fork 911
/
disk.bats
executable file
·217 lines (149 loc) · 3.9 KB
/
disk.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
#!/usr/bin/env bats
load test_helper
@test "disk.ls" {
vcsim_env
run govc disk.ls
assert_success
run govc disk.ls enoent
assert_failure
}
@test "disk.create" {
vcsim_env
name=$(new_id)
run govc disk.create -size 10M "$name"
assert_success
id="${lines[1]}"
run govc disk.ls "$id"
assert_success
govc disk.ls -json "$id" | jq .
vm=DC0_H0_VM0
run govc disk.attach -vm $vm "$id"
assert_success
run govc disk.detach -vm $vm "$id"
assert_success
run govc disk.rm "$id"
assert_success
run govc disk.rm "$id"
assert_failure
name=$(new_id)
run govc disk.create -profile enoent "$name"
assert_failure # profile does not exist
run govc disk.create -profile "vSAN Default Storage Policy" "$name"
assert_success
}
@test "disk.create -datastore-cluster" {
vcsim_env -pod 1 -ds 3 -cluster 2
pod=/DC0/datastore/DC0_POD0
id=$(new_id)
run govc disk.create -datastore-cluster $pod "$id"
assert_failure
run govc find $pod -type s
assert_success
[ ${#lines[@]} -eq 0 ]
run govc object.mv /DC0/datastore/LocalDS_{1,2} $pod
assert_success
run govc find $pod -type s
assert_success
[ ${#lines[@]} -eq 2 ]
run govc disk.create -datastore-cluster $pod -size 10M "$id"
assert_success
id=$(new_id)
pool=$GOVC_RESOURCE_POOL
unset GOVC_RESOURCE_POOL
run govc disk.create -datastore-cluster $pod -size 10M "$id"
assert_failure # -pool is required
run govc disk.create -datastore-cluster $pod -size 10M -pool "$pool" "$id"
assert_success
}
@test "disk.register" {
vcsim_env
id=$(new_id)
vmdk="$id/$id.vmdk"
run govc datastore.mkdir "$id"
assert_success
# create with VirtualDiskManager
run govc datastore.disk.create -size 10M "$vmdk"
assert_success
run govc disk.register "$id" "$id"
assert_failure # expect fail for directory
run govc disk.register "" "$id"
assert_failure # expect fail for empty path
run govc disk.register "$vmdk" "$id"
assert_success
id="$output"
run govc disk.ls "$id"
assert_success
run govc disk.register "$vmdk" "$id"
assert_failure
run govc disk.rm "$id"
assert_success
run govc disk.rm "$id"
assert_failure
}
@test "disk.snapshot" {
vcsim_env
name=$(new_id)
run govc disk.create -size 10M "$name"
assert_success
id="${lines[1]}"
run govc disk.snapshot.ls "$id"
assert_success
run govc disk.snapshot.create "$id"
assert_success
sid="${lines[1]}"
govc disk.snapshot.ls "$id" | grep "$sid"
govc disk.snapshot.ls -json "$id" | jq .
run govc disk.snapshot.rm "$id" "$sid"
assert_success
run govc disk.snapshot.rm "$id" "$sid"
assert_failure
run govc disk.rm "$id"
assert_success
}
@test "disk.tags" {
vcsim_env
run govc tags.category.create region
assert_success
run govc tags.create -c region US-WEST
assert_success
name=$(new_id)
run govc disk.create -size 10M "$name"
assert_success
id="${lines[1]}"
run govc disk.ls "$id"
assert_success
run govc disk.ls -c region -t US-WEST
assert_success ""
govc disk.ls -T | grep -v US-WEST
run govc disk.tags.attach -c region US-WEST "$id"
assert_success
run govc disk.ls -c region -t US-WEST
assert_success
assert_matches "$id"
run govc disk.ls -T
assert_success
assert_matches US-WEST
run govc disk.tags.detach -c region enoent "$id"
assert_failure
run govc disk.tags.detach -c region US-WEST "$id"
assert_success
govc disk.ls -T | grep -v US-WEST
}
@test "disk.reconcile" {
vcsim_env
name=$(new_id)
run govc disk.create -size 10M "$name"
assert_success
id="${lines[1]}"
run govc disk.create -size 10M "$(new_id)"
assert_success
run govc disk.ls
assert_success
path=$(govc disk.ls -json "$id" | jq -r .objects[].config.backing.filePath)
run govc datastore.rm "$path"
assert_success
run govc disk.ls
assert_failure # file backing was removed without using disk.rm, results in NotFound fault
run govc disk.ls -R
assert_success
}