github.com/vmware/govmomi@v0.37.1/govc/test/namespace.bats (about) 1 #!/usr/bin/env bats 2 3 load test_helper 4 5 @test "namespace.cluster.ls" { 6 vcsim_env 7 8 run govc namespace.cluster.ls 9 assert_success "" 10 11 run govc namespace.cluster.ls -json 12 assert_success "[]" 13 14 run govc cluster.create WCP-cluster 15 assert_success 16 17 run govc namespace.cluster.ls 18 assert_success /DC0/host/WCP-cluster 19 20 run govc namespace.cluster.ls -l 21 assert_success 22 assert_matches RUNNING 23 assert_matches READY 24 25 id=$(govc namespace.cluster.ls -json | jq -r .[].cluster) 26 27 run govc object.collect -s "ClusterComputeResource:$id" name 28 assert_success WCP-cluster 29 } 30 31 @test "namespace.cluster.enable" { 32 vcsim_env 33 34 # need to set up some dependencies 35 govc cluster.create WCP-Cluster 36 assert_success 37 38 govc dvs.create "DVPG-Management Network" 39 assert_success 40 41 govc namespace.cluster.enable \ 42 --service-cidr 10.96.0.0/23 \ 43 --pod-cidrs 10.244.0.0/20 \ 44 --cluster "WCP-Cluster" \ 45 --control-plane-dns 8.8.8.8 \ 46 --worker-dns 8.8.8.8 \ 47 --control-plane-dns-search-domains example.com \ 48 --control-plane-dns-names wcp.example.com \ 49 --control-plane-ntp-servers pool.ntp.org \ 50 --network-provider "NSXT_CONTAINER_PLUGIN" \ 51 --workload-network.egress-cidrs 10.0.0.128/26 \ 52 --workload-network.ingress-cidrs "10.0.0.64/26" \ 53 --workload-network.switch VDS \ 54 --workload-network.edge-cluster Edge-Cluster-1 \ 55 --size TINY \ 56 --mgmt-network.mode STATICRANGE \ 57 --mgmt-network.network "DVPG-Management Network" \ 58 --mgmt-network.gateway 10.0.0.1 \ 59 --mgmt-network.starting-address 10.0.0.45 \ 60 --mgmt-network.subnet-mask 255.255.255.0 \ 61 --ephemeral-storage-policy "vSAN Default Storage Policy" \ 62 --control-plane-storage-policy "vSAN Default Storage Policy" \ 63 --image-storage-policy "vSAN Default Storage Policy" 64 assert_success 65 } 66 67 @test "namespace.cluster.disable" { 68 vcsim_env 69 70 govc cluster.create WCP-Cluster 71 assert_success 72 73 govc namespace.cluster.disable --cluster WCP-Cluster 74 assert_success 75 } 76 77 @test "namespace.logs" { 78 vcsim_env 79 80 id=$(govc find -i -maxdepth 0 host/DC0_C0 | awk -F: '{print $2}') 81 82 run govc namespace.logs.download -cluster DC0_C0 83 assert_success 84 85 rm "wcp-support-bundle-$id-"*.tar 86 87 govc namespace.logs.download -cluster DC0_C0 - | tar -xvOf- 88 } 89 90 @test "namespace.service.ls" { 91 vcsim_env 92 93 run govc namespace.service.ls 94 assert_success 95 assert_matches service1 96 assert_matches service2 97 98 run govc namespace.service.ls -l 99 assert_success 100 assert_matches ACTIVATED 101 assert_matches mock-service-1 102 } 103 104 @test "namespace.service.info" { 105 vcsim_env 106 107 run govc namespace.service.info service1 108 assert_success 109 assert_matches mock-service-1 110 assert_matches ACTIVATED 111 assert_matches "Description of service1" 112 113 run govc namespace.service.info -json service2 114 assert_matches DE-ACTIVATED 115 } 116 117 @test "namespace.create" { 118 vcsim_env 119 120 run govc namespace.create -supervisor=domain-c1 test-namespace-1 121 assert_success 122 123 ns=$(govc namespace.info -json test-namespace-1 | jq) 124 assert_equal "domain-c1" $(echo $ns | jq -r '."cluster"') 125 assert_equal "0" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"' | jq length) 126 127 run govc namespace.create -supervisor=domain-c1 -library=lib1 -library=lib2 test-namespace-2 128 assert_success 129 130 ns=$(govc namespace.info -json test-namespace-2 | jq) 131 assert_equal "2" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"' | jq length) 132 } 133 134 @test "namespace.update" { 135 vcsim_env 136 137 govc namespace.create -supervisor=domain-c1 test-namespace-1 138 139 run govc namespace.update -library=lib1 -library=lib2 -vm-class=class1 test-namespace-1 140 assert_success 141 142 ns=$(govc namespace.info -json test-namespace-1 | jq) 143 assert_equal "2" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"' | jq length) 144 assert_matches "lib[0-9]+" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"[0]') 145 assert_matches "lib[0-9]+" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"[1]') 146 assert_equal "1" $(echo $ns | jq -r '."vm_service_spec"."vm_classes"' | jq length) 147 assert_equal "class1" $(echo $ns | jq -r '."vm_service_spec"."vm_classes"[0]') 148 149 run govc namespace.update -library=lib3 test-namespace-1 150 assert_success 151 152 ns=$(govc namespace.info -json test-namespace-1 | jq) 153 assert_equal "1" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"' | jq length) 154 assert_equal "lib3" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"[0]') 155 assert_equal "0" $(echo $ns | jq -r '."vm_service_spec"."vm_classes"' | jq length) 156 157 run govc namespace.update -vm-class=class3 test-namespace-1 158 assert_success 159 160 ns=$(govc namespace.info -json test-namespace-1 | jq) 161 assert_equal "0" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"' | jq length) 162 assert_equal "1" $(echo $ns | jq -r '."vm_service_spec"."vm_classes"' | jq length) 163 assert_equal "class3" $(echo $ns | jq -r '."vm_service_spec"."vm_classes"[0]') 164 165 run govc namespace.update -library=lib4 -vm-class=class4 test-namespace-1 166 assert_success 167 168 ns=$(govc namespace.info -json test-namespace-1 | jq) 169 assert_equal "1" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"' | jq length) 170 assert_equal "lib4" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"[0]') 171 assert_equal "1" $(echo $ns | jq -r '."vm_service_spec"."vm_classes"' | jq length) 172 assert_equal "class4" $(echo $ns | jq -r '."vm_service_spec"."vm_classes"[0]') 173 174 run govc namespace.update -library=lib1 -library=lib2 -vm-class=class1 non-existing-namespace 175 assert_failure 176 assert_matches "404 Not Found" 177 } 178 179 @test "namespace.info" { 180 vcsim_env 181 182 govc namespace.create -supervisor=domain-c1 test-namespace-1 183 184 ns=$(govc namespace.info -json test-namespace-1 | jq) 185 assert_equal "domain-c1" $(echo $ns | jq -r '."cluster"') 186 187 run govc namespace.info test-namespace-1 188 assert_success 189 190 run govc namespace.info non-existing-namespace 191 assert_failure 192 assert_matches "404 Not Found" 193 } 194 195 @test "namespace.ls" { 196 vcsim_env 197 198 run govc namespace.ls 199 assert_success "" 200 201 ls=$(govc namespace.ls -json) 202 assert_equal "0" $(echo $ls | jq length) 203 204 govc namespace.create -supervisor=domain-c1 test-namespace-1 205 ls=$(govc namespace.ls -json) 206 assert_equal "1" $(echo $ls | jq length) 207 assert_equal "test-namespace-1" $(echo $ls | jq -r '.[0]."namespace"') 208 209 run govc namespace.ls 210 assert_success test-namespace-1 211 212 govc namespace.create -supervisor=domain-c1 test-namespace-2 213 ls=$(govc namespace.ls -json) 214 assert_equal "2" $(echo $ls | jq length) 215 assert_equal "domain-c1" $(echo $ls | jq -r '.[0]."cluster"') 216 assert_matches "test-namespace-[0-9]+" $(echo $ls | jq -r '.[0]."namespace"') 217 assert_equal "domain-c1" $(echo $ls | jq -r '.[1]."cluster"') 218 assert_matches "test-namespace-[0-9]+" $(echo $ls | jq -r '.[1]."namespace"') 219 } 220 221 @test "namespace.rm" { 222 vcsim_env 223 224 run govc namespace.rm non-existing-namespace 225 assert_failure 226 assert_matches "404 Not Found" 227 228 govc namespace.create -supervisor=domain-c1 test-namespace-1 229 230 run govc namespace.rm test-namespace-1 231 assert_success 232 } 233 234 @test "namespace.vmclass.create" { 235 vcsim_env 236 237 run govc namespace.vmclass.create -cpus=16 -memory=16000 test-class-1 238 assert_success 239 240 c=$(govc namespace.vmclass.info -json test-class-1 | jq) 241 assert_equal "16" $(echo $c | jq -r '."cpu_count"') 242 assert_equal "16000" $(echo $c | jq -r '."memory_mb"') 243 } 244 245 @test "namespace.vmclass.update" { 246 vcsim_env 247 248 govc namespace.vmclass.create -cpus=16 -memory=16000 test-class-1 249 250 govc namespace.vmclass.update -cpus=24 -memory=24000 test-class-1 251 c=$(govc namespace.vmclass.info -json test-class-1 | jq) 252 assert_equal "24" $(echo $c | jq -r '."cpu_count"') 253 assert_equal "24000" $(echo $c | jq -r '."memory_mb"') 254 } 255 256 @test "namespace.vmclass.info" { 257 vcsim_env 258 259 run govc namespace.vmclass.info 260 assert_failure 261 262 run govc namespace.vmclass.create -cpus=16 -memory=16000 test-class-1 263 assert_success 264 265 run govc namespace.vmclass.info test-class-1 266 assert_success 267 268 c=$(govc namespace.vmclass.info -json test-class-1 | jq) 269 assert_equal "16" $(echo $c | jq -r '."cpu_count"') 270 assert_equal "16000" $(echo $c | jq -r '."memory_mb"') 271 272 run govc namespace.vmclass.info non-existing-class 273 assert_failure 274 assert_matches "404 Not Found" 275 } 276 277 @test "namespace.vmclass.ls" { 278 vcsim_env 279 280 run govc namespace.vmclass.ls 281 assert_success "" 282 283 ls=$(govc namespace.vmclass.ls -json) 284 assert_equal "0" $(echo $ls | jq length) 285 286 govc namespace.vmclass.create -cpus=16 -memory=16000 test-class-1 287 ls=$(govc namespace.vmclass.ls -json) 288 assert_equal "1" $(echo $ls | jq length) 289 290 govc namespace.vmclass.create -cpus=16 -memory=16000 test-class-2 291 ls=$(govc namespace.vmclass.ls -json) 292 assert_equal "2" $(echo $ls | jq length) 293 } 294 295 @test "namespace.vmclass.rm" { 296 vcsim_env 297 298 run govc namespace.vmclass.rm non-existing-class 299 assert_failure 300 assert_matches "404 Not Found" 301 302 govc namespace.vmclass.create -cpus=16 -memory=16000 test-class-1 303 304 run govc namespace.vmclass.rm test-class-1 305 assert_success 306 }