github.com/vmware/govmomi@v0.37.1/govc/test/disk.bats (about) 1 #!/usr/bin/env bats 2 3 load test_helper 4 5 @test "disk.ls" { 6 vcsim_env 7 8 run govc disk.ls 9 assert_success 10 11 run govc disk.ls enoent 12 assert_failure 13 } 14 15 @test "disk.create" { 16 vcsim_env 17 18 name=$(new_id) 19 20 run govc disk.create -size 10M "$name" 21 assert_success 22 id="${lines[1]}" 23 24 run govc disk.ls "$id" 25 assert_success 26 27 govc disk.ls -json "$id" | jq . 28 29 run govc disk.rm "$id" 30 assert_success 31 32 run govc disk.rm "$id" 33 assert_failure 34 } 35 36 @test "disk.create -datastore-cluster" { 37 vcsim_env -pod 1 -ds 3 -cluster 2 38 39 pod=/DC0/datastore/DC0_POD0 40 id=$(new_id) 41 42 run govc disk.create -datastore-cluster $pod "$id" 43 assert_failure 44 45 run govc find $pod -type s 46 assert_success 47 [ ${#lines[@]} -eq 0 ] 48 49 run govc object.mv /DC0/datastore/LocalDS_{1,2} $pod 50 assert_success 51 52 run govc find $pod -type s 53 assert_success 54 [ ${#lines[@]} -eq 2 ] 55 56 run govc disk.create -datastore-cluster $pod -size 10M "$id" 57 assert_success 58 59 id=$(new_id) 60 pool=$GOVC_RESOURCE_POOL 61 unset GOVC_RESOURCE_POOL 62 run govc disk.create -datastore-cluster $pod -size 10M "$id" 63 assert_failure # -pool is required 64 65 run govc disk.create -datastore-cluster $pod -size 10M -pool "$pool" "$id" 66 assert_success 67 } 68 69 @test "disk.register" { 70 vcsim_env 71 72 id=$(new_id) 73 vmdk="$id/$id.vmdk" 74 75 run govc datastore.mkdir "$id" 76 assert_success 77 78 # create with VirtualDiskManager 79 run govc datastore.disk.create -size 10M "$vmdk" 80 assert_success 81 82 run govc disk.register "$id" "$id" 83 assert_failure # expect fail for directory 84 85 run govc disk.register "" "$id" 86 assert_failure # expect fail for empty path 87 88 run govc disk.register "$vmdk" "$id" 89 assert_success 90 id="$output" 91 92 run govc disk.ls "$id" 93 assert_success 94 95 run govc disk.register "$vmdk" "$id" 96 assert_failure 97 98 run govc disk.rm "$id" 99 assert_success 100 101 run govc disk.rm "$id" 102 assert_failure 103 } 104 105 @test "disk.snapshot" { 106 vcsim_env 107 108 name=$(new_id) 109 110 run govc disk.create -size 10M "$name" 111 assert_success 112 id="${lines[1]}" 113 114 run govc disk.snapshot.ls "$id" 115 assert_success 116 117 run govc disk.snapshot.create "$id" 118 assert_success 119 sid="${lines[1]}" 120 121 govc disk.snapshot.ls "$id" | grep "$sid" 122 123 govc disk.snapshot.ls -json "$id" | jq . 124 125 run govc disk.snapshot.rm "$id" "$sid" 126 assert_success 127 128 run govc disk.snapshot.rm "$id" "$sid" 129 assert_failure 130 131 run govc disk.rm "$id" 132 assert_success 133 } 134 135 @test "disk.tags" { 136 vcsim_env 137 138 run govc tags.category.create region 139 assert_success 140 141 run govc tags.create -c region US-WEST 142 assert_success 143 144 name=$(new_id) 145 146 run govc disk.create -size 10M "$name" 147 assert_success 148 id="${lines[1]}" 149 150 run govc disk.ls "$id" 151 assert_success 152 153 run govc disk.ls -c region -t US-WEST 154 assert_success "" 155 156 govc disk.ls -T | grep -v US-WEST 157 158 run govc disk.tags.attach -c region US-WEST "$id" 159 assert_success 160 161 run govc disk.ls -c region -t US-WEST 162 assert_success 163 assert_matches "$id" 164 165 run govc disk.ls -T 166 assert_success 167 assert_matches US-WEST 168 169 run govc disk.tags.detach -c region enoent "$id" 170 assert_failure 171 172 run govc disk.tags.detach -c region US-WEST "$id" 173 assert_success 174 175 govc disk.ls -T | grep -v US-WEST 176 } 177 178 @test "disk.reconcile" { 179 vcsim_env 180 181 name=$(new_id) 182 183 run govc disk.create -size 10M "$name" 184 assert_success 185 id="${lines[1]}" 186 187 run govc disk.create -size 10M "$(new_id)" 188 assert_success 189 190 run govc disk.ls 191 assert_success 192 193 path=$(govc disk.ls -json "$id" | jq -r .objects[].config.backing.filePath) 194 run govc datastore.rm "$path" 195 assert_success 196 197 run govc disk.ls 198 assert_failure # file backing was removed without using disk.rm, results in NotFound fault 199 200 run govc disk.ls -R 201 assert_success 202 }