github.com/vmware/govmomi@v0.43.0/govc/test/pool.bats (about) 1 #!/usr/bin/env bats 2 3 load test_helper 4 5 @test "pool.create" { 6 vcsim_env -esx 7 8 path="*/Resources/$(new_id)/$(new_id)" 9 run govc pool.create $path 10 assert_failure 11 assert_line "govc: cannot create resource pool '$(basename ${path})': parent not found" 12 13 id=$(new_id) 14 path="*/Resources/$id" 15 run govc pool.create -cpu.shares low -mem.reservation 500 $path 16 assert_success 17 18 run govc pool.info $path 19 assert_success 20 21 assert_line "Name: $id" 22 assert_line "CPU Shares: low" 23 assert_line "Mem Reservation: 500MB (expandable=true)" 24 25 run govc pool.destroy $path 26 assert_success 27 } 28 29 @test "pool.create multiple" { 30 vcsim_env -esx 31 32 id=$(new_id) 33 path="*/Resources/$id" 34 govc pool.create $path 35 36 # Finder.List($path) 37 run govc pool.info "$path" 38 assert_success 39 40 # Finder.Find($name) 41 run govc pool.info "$id" 42 assert_success 43 44 # Create multiple parent pools with multiple arguments (without globbing) 45 run govc pool.create $path/a $path/b 46 assert_success 47 result=$(govc ls "host/$path/*" | wc -l) 48 [ $result -eq 2 ] 49 50 # Create multiple child pools with one argument (with globbing) 51 run govc pool.create $path/*/{a,b} 52 assert_success 53 result=$(govc ls "host/$path/*/*" | wc -l) 54 [ $result -eq 4 ] 55 56 # Clean up 57 run govc pool.destroy $path/*/* $path/* $path 58 assert_success 59 } 60 61 @test "pool.change" { 62 vcsim_env -esx 63 64 id=$(new_id) 65 root=$(govc find /ha-datacenter/host -type p -name Resources) 66 path="$root/$id" 67 68 run govc pool.create -cpu.reservation 100 $path 69 assert_success 70 71 run govc object.collect -s $path config.cpuAllocation.reservation 72 assert_success "100" 73 74 run govc pool.change -cpu.reservation 0 -mem.shares high $path 75 assert_success 76 run govc pool.info $path 77 assert_success 78 assert_line "Mem Shares: high" 79 assert_line "CPU Shares: normal" 80 run govc object.collect -s $path config.cpuAllocation.reservation 81 assert_success "0" 82 83 nid=$(new_id) 84 run govc pool.change -name $nid $path 85 assert_success 86 path="*/Resources/$nid" 87 88 run govc pool.info $path 89 assert_success 90 assert_line "Name: $nid" 91 92 run govc pool.destroy $path 93 assert_success 94 } 95 96 @test "pool.change multiple" { 97 vcsim_env 98 99 id=$(new_id) 100 path="*/Resources/$id" 101 govc pool.create $path 102 103 # Create some nested pools so that we can test changing multiple in one call 104 govc pool.create $path/{a,b} $path/{a,b}/test 105 106 # Test precondition 107 run govc pool.info $path/a/test 108 assert_success 109 assert_line "Name: test" 110 run govc pool.info $path/b/test 111 assert_success 112 assert_line "Name: test" 113 114 # Change name of both test pools 115 run govc pool.change -name hello $path/*/test 116 assert_success 117 118 # Test postcondition 119 run govc pool.info $path/a/hello 120 assert_success 121 assert_line "Name: hello" 122 run govc pool.info $path/b/hello 123 assert_success 124 assert_line "Name: hello" 125 126 # Clean up 127 govc pool.destroy $path/a/hello 128 govc pool.destroy $path/a 129 govc pool.destroy $path/b/hello 130 govc pool.destroy $path/b 131 govc pool.destroy $path 132 } 133 134 @test "pool.destroy" { 135 vcsim_env 136 137 id=$(new_id) 138 139 # parent pool 140 path="*/Resources/$id" 141 run govc pool.create $path 142 assert_success 143 144 result=$(govc ls "host/$path/*" | wc -l) 145 [ $result -eq 0 ] 146 147 # child pools 148 id1=$(new_id) 149 run govc pool.create $path/$id1 150 assert_success 151 152 id2=$(new_id) 153 run govc pool.create $path/$id2 154 assert_success 155 156 # 2 child pools 157 result=$(govc ls "host/$path/*" | wc -l) 158 [ $result -eq 4 ] 159 160 # 1 parent pool 161 result=$(govc ls "host/$path" | wc -l) 162 [ $result -eq 2 ] 163 164 run govc pool.destroy $path 165 assert_success 166 167 # no more parent pool 168 result=$(govc ls "host/$path" | wc -l) 169 [ $result -eq 0 ] 170 171 # the child pools are not present anymore 172 # the only place they could pop into is the parent pool 173 174 # first child pool 175 result=$(govc ls "host/*/Resources/$id1" | wc -l) 176 [ $result -eq 2 ] 177 178 # second child pool 179 result=$(govc ls "host/*/Resources/$id2" | wc -l) 180 [ $result -eq 2 ] 181 } 182 183 @test "pool.destroy children" { 184 vcsim_env 185 186 id=$(new_id) 187 188 # parent pool 189 path="*/Resources/$id" 190 run govc pool.create $path 191 assert_success 192 193 result=$(govc ls "host/$path/*" | wc -l) 194 [ $result -eq 0 ] 195 196 # child pools 197 run govc pool.create $path/$(new_id) 198 assert_success 199 200 run govc pool.create $path/$(new_id) 201 assert_success 202 203 # 2 child pools 204 result=$(govc ls "host/$path/*" | wc -l) 205 [ $result -eq 4 ] 206 207 # 1 parent pool 208 result=$(govc ls "host/*/Resources/govc-test-*" | wc -l) 209 [ $result -eq 2 ] 210 211 # delete children 212 run govc pool.destroy -children $path 213 assert_success 214 215 # no more child pools 216 result=$(govc ls "host/$path/*" | wc -l) 217 [ $result -eq 0 ] 218 219 # cleanup 220 run govc pool.destroy $path 221 assert_success 222 223 # cleanup check 224 result=$(govc ls "host/$path" | wc -l) 225 [ $result -eq 0 ] 226 } 227 228 @test "pool.destroy multiple" { 229 vcsim_env -esx 230 231 id=$(new_id) 232 path="*/Resources/$id" 233 govc pool.create $path 234 235 # Create some nested pools so that we can test destroying multiple in one call 236 govc pool.create $path/{a,b} 237 238 # Test precondition 239 result=$(govc ls "host/$path/*" | wc -l) 240 [ $result -eq 2 ] 241 242 # Destroy both pools 243 run govc pool.destroy $path/{a,b} 244 assert_success 245 246 # Test postcondition 247 result=$(govc ls "host/$path/*" | wc -l) 248 [ $result -eq 0 ] 249 250 # Clean up 251 govc pool.destroy $path 252 } 253 254 @test "vm.create -pool" { 255 vcsim_env -esx 256 257 # test with full inventory path to pools 258 parent_path=$(govc ls 'host/*/Resources') 259 parent_name=$(basename $parent_path) 260 [ "$parent_name" = "Resources" ] 261 262 child_name=$(new_id) 263 child_path="$parent_path/$child_name" 264 265 grand_child_name=$(new_id) 266 grand_child_path="$child_path/$grand_child_name" 267 268 run govc pool.create $parent_path/$child_name{,/$grand_child_name} 269 assert_success 270 271 for path in $parent_path $child_path $grand_child_path 272 do 273 run govc vm.create -pool $path $(new_id) 274 assert_success 275 done 276 277 run govc pool.change -mem.limit 100 $child_path 278 assert_success 279 280 run govc pool.change -mem.limit 120 -mem.expandable $child_path 281 assert_success 282 283 # test with glob inventory path to pools 284 parent_path="*/$parent_name" 285 child_path="$parent_path/$child_name" 286 grand_child_path="$child_path/$grand_child_name" 287 288 for path in $grand_child_path $child_path 289 do 290 run govc pool.destroy $path 291 assert_success 292 done 293 } 294 295 @test "vm.create -pool host" { 296 vcsim_env -esx 297 298 id=$(new_id) 299 300 path=$(govc ls host) 301 302 run govc vm.create -on=false -pool enoent $id 303 assert_failure "govc: resource pool 'enoent' not found" 304 305 run govc vm.create -on=false -pool $path $id 306 assert_success 307 } 308 309 @test "vm.create -pool cluster" { 310 vcsim_env 311 312 id=$(new_id) 313 314 path=$(dirname $GOVC_HOST) 315 316 unset GOVC_HOST 317 unset GOVC_RESOURCE_POOL 318 319 run govc vm.create -on=false -pool enoent $id 320 assert_failure "govc: resource pool 'enoent' not found" 321 322 run govc vm.create -on=false -pool $path $id 323 assert_success 324 }