github.com/gophercloud/gophercloud@v1.11.0/openstack/compute/v2/extensions/hypervisors/testing/fixtures_test.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/hypervisors" 9 "github.com/gophercloud/gophercloud/testhelper" 10 "github.com/gophercloud/gophercloud/testhelper/client" 11 ) 12 13 // HypervisorListBodyPre253 represents a raw hypervisor list from the Compute 14 // API with microversion older than 2.53. 15 // The first hypervisor represents what the specification says (~Newton) 16 // The second is exactly the same, but what you can get off a real system (~Kilo) 17 const HypervisorListBodyPre253 = ` 18 { 19 "hypervisors": [ 20 { 21 "cpu_info": { 22 "arch": "x86_64", 23 "model": "Nehalem", 24 "vendor": "Intel", 25 "features": [ 26 "pge", 27 "clflush" 28 ], 29 "topology": { 30 "cores": 1, 31 "threads": 1, 32 "sockets": 4 33 } 34 }, 35 "current_workload": 0, 36 "status": "enabled", 37 "state": "up", 38 "disk_available_least": 0, 39 "host_ip": "1.1.1.1", 40 "free_disk_gb": 1028, 41 "free_ram_mb": 7680, 42 "hypervisor_hostname": "fake-mini", 43 "hypervisor_type": "fake", 44 "hypervisor_version": 2002000, 45 "id": 1, 46 "local_gb": 1028, 47 "local_gb_used": 0, 48 "memory_mb": 8192, 49 "memory_mb_used": 512, 50 "running_vms": 0, 51 "service": { 52 "host": "e6a37ee802d74863ab8b91ade8f12a67", 53 "id": 2, 54 "disabled_reason": null 55 }, 56 "vcpus": 1, 57 "vcpus_used": 0 58 }, 59 { 60 "cpu_info": "{\"arch\": \"x86_64\", \"model\": \"Nehalem\", \"vendor\": \"Intel\", \"features\": [\"pge\", \"clflush\"], \"topology\": {\"cores\": 1, \"threads\": 1, \"sockets\": 4}}", 61 "current_workload": 0, 62 "status": "enabled", 63 "state": "up", 64 "disk_available_least": 0, 65 "host_ip": "1.1.1.1", 66 "free_disk_gb": 1028, 67 "free_ram_mb": 7680, 68 "hypervisor_hostname": "fake-mini", 69 "hypervisor_type": "fake", 70 "hypervisor_version": 2.002e+06, 71 "id": 1, 72 "local_gb": 1028, 73 "local_gb_used": 0, 74 "memory_mb": 8192, 75 "memory_mb_used": 512, 76 "running_vms": 0, 77 "service": { 78 "host": "e6a37ee802d74863ab8b91ade8f12a67", 79 "id": 2, 80 "disabled_reason": null 81 }, 82 "vcpus": 1, 83 "vcpus_used": 0 84 } 85 ] 86 }` 87 88 // HypervisorListBody represents a raw hypervisor list result with Pike+ release. 89 const HypervisorListBody = ` 90 { 91 "hypervisors": [ 92 { 93 "cpu_info": { 94 "arch": "x86_64", 95 "model": "Nehalem", 96 "vendor": "Intel", 97 "features": [ 98 "pge", 99 "clflush" 100 ], 101 "topology": { 102 "cores": 1, 103 "threads": 1, 104 "sockets": 4 105 } 106 }, 107 "current_workload": 0, 108 "status": "enabled", 109 "state": "up", 110 "disk_available_least": 0, 111 "host_ip": "1.1.1.1", 112 "free_disk_gb": 1028, 113 "free_ram_mb": 7680, 114 "hypervisor_hostname": "fake-mini", 115 "hypervisor_type": "fake", 116 "hypervisor_version": 2002000, 117 "id": "c48f6247-abe4-4a24-824e-ea39e108874f", 118 "local_gb": 1028, 119 "local_gb_used": 0, 120 "memory_mb": 8192, 121 "memory_mb_used": 512, 122 "running_vms": 0, 123 "service": { 124 "host": "e6a37ee802d74863ab8b91ade8f12a67", 125 "id": "9c2566e7-7a54-4777-a1ae-c2662f0c407c", 126 "disabled_reason": null 127 }, 128 "vcpus": 1, 129 "vcpus_used": 0 130 }, 131 { 132 "cpu_info": "{\"arch\": \"x86_64\", \"model\": \"Nehalem\", \"vendor\": \"Intel\", \"features\": [\"pge\", \"clflush\"], \"topology\": {\"cores\": 1, \"threads\": 1, \"sockets\": 4}}", 133 "current_workload": 0, 134 "status": "enabled", 135 "state": "up", 136 "disk_available_least": 0, 137 "host_ip": "1.1.1.1", 138 "free_disk_gb": 1028, 139 "free_ram_mb": 7680, 140 "hypervisor_hostname": "fake-mini", 141 "hypervisor_type": "fake", 142 "hypervisor_version": 2.002e+06, 143 "id": "c48f6247-abe4-4a24-824e-ea39e108874f", 144 "local_gb": 1028, 145 "local_gb_used": 0, 146 "memory_mb": 8192, 147 "memory_mb_used": 512, 148 "running_vms": 0, 149 "service": { 150 "host": "e6a37ee802d74863ab8b91ade8f12a67", 151 "id": "9c2566e7-7a54-4777-a1ae-c2662f0c407c", 152 "disabled_reason": null 153 }, 154 "vcpus": 1, 155 "vcpus_used": 0 156 } 157 ] 158 }` 159 160 // HypervisorListWithParametersBody represents a raw hypervisor list result with Pike+ release. 161 const HypervisorListWithParametersBody = ` 162 { 163 "hypervisors": [ 164 { 165 "cpu_info": { 166 "arch": "x86_64", 167 "model": "Nehalem", 168 "vendor": "Intel", 169 "features": [ 170 "pge", 171 "clflush" 172 ], 173 "topology": { 174 "cores": 1, 175 "threads": 1, 176 "sockets": 4 177 } 178 }, 179 "current_workload": 0, 180 "status": "enabled", 181 "state": "up", 182 "disk_available_least": 0, 183 "host_ip": "1.1.1.1", 184 "free_disk_gb": 1028, 185 "free_ram_mb": 7680, 186 "hypervisor_hostname": "fake-mini", 187 "hypervisor_type": "fake", 188 "hypervisor_version": 2002000, 189 "id": "c48f6247-abe4-4a24-824e-ea39e108874f", 190 "local_gb": 1028, 191 "local_gb_used": 0, 192 "memory_mb": 8192, 193 "memory_mb_used": 512, 194 "running_vms": 0, 195 "service": { 196 "host": "e6a37ee802d74863ab8b91ade8f12a67", 197 "id": "9c2566e7-7a54-4777-a1ae-c2662f0c407c", 198 "disabled_reason": null 199 }, 200 "servers": [ 201 { 202 "name": "instance-00000001", 203 "uuid": "c42acc8d-eab3-4e4d-9d90-01b0791328f4" 204 }, 205 { 206 "name": "instance-00000002", 207 "uuid": "8aaf2941-b774-41fc-921b-20c4757cc359" 208 } 209 ], 210 "vcpus": 1, 211 "vcpus_used": 0 212 }, 213 { 214 "cpu_info": "{\"arch\": \"x86_64\", \"model\": \"Nehalem\", \"vendor\": \"Intel\", \"features\": [\"pge\", \"clflush\"], \"topology\": {\"cores\": 1, \"threads\": 1, \"sockets\": 4}}", 215 "current_workload": 0, 216 "status": "enabled", 217 "state": "up", 218 "disk_available_least": 0, 219 "host_ip": "1.1.1.1", 220 "free_disk_gb": 1028, 221 "free_ram_mb": 7680, 222 "hypervisor_hostname": "fake-mini", 223 "hypervisor_type": "fake", 224 "hypervisor_version": 2.002e+06, 225 "id": "c48f6247-abe4-4a24-824e-ea39e108874f", 226 "local_gb": 1028, 227 "local_gb_used": 0, 228 "memory_mb": 8192, 229 "memory_mb_used": 512, 230 "running_vms": 0, 231 "servers": [ 232 { 233 "name": "instance-00000001", 234 "uuid": "c42acc8d-eab3-4e4d-9d90-01b0791328f4" 235 }, 236 { 237 "name": "instance-00000002", 238 "uuid": "8aaf2941-b774-41fc-921b-20c4757cc359" 239 } 240 ], 241 "service": { 242 "host": "e6a37ee802d74863ab8b91ade8f12a67", 243 "id": "9c2566e7-7a54-4777-a1ae-c2662f0c407c", 244 "disabled_reason": null 245 }, 246 "vcpus": 1, 247 "vcpus_used": 0 248 } 249 ] 250 }` 251 252 const HypervisorsStatisticsBody = ` 253 { 254 "hypervisor_statistics": { 255 "count": 1, 256 "current_workload": 0, 257 "disk_available_least": 0, 258 "free_disk_gb": 1028, 259 "free_ram_mb": 7680, 260 "local_gb": 1028, 261 "local_gb_used": 0, 262 "memory_mb": 8192, 263 "memory_mb_used": 512, 264 "running_vms": 0, 265 "vcpus": 2, 266 "vcpus_used": 0 267 } 268 } 269 ` 270 271 // HypervisorGetBody represents a raw hypervisor GET result with Pike+ release. 272 const HypervisorGetBody = ` 273 { 274 "hypervisor":{ 275 "cpu_info":{ 276 "arch":"x86_64", 277 "model":"Nehalem", 278 "vendor":"Intel", 279 "features":[ 280 "pge", 281 "clflush" 282 ], 283 "topology":{ 284 "cores":1, 285 "threads":1, 286 "sockets":4 287 } 288 }, 289 "current_workload":0, 290 "status":"enabled", 291 "state":"up", 292 "disk_available_least":0, 293 "host_ip":"1.1.1.1", 294 "free_disk_gb":1028, 295 "free_ram_mb":7680, 296 "hypervisor_hostname":"fake-mini", 297 "hypervisor_type":"fake", 298 "hypervisor_version":2002000, 299 "id":"c48f6247-abe4-4a24-824e-ea39e108874f", 300 "local_gb":1028, 301 "local_gb_used":0, 302 "memory_mb":8192, 303 "memory_mb_used":512, 304 "running_vms":0, 305 "service":{ 306 "host":"e6a37ee802d74863ab8b91ade8f12a67", 307 "id":"9c2566e7-7a54-4777-a1ae-c2662f0c407c", 308 "disabled_reason":null 309 }, 310 "vcpus":1, 311 "vcpus_used":0 312 } 313 } 314 ` 315 316 // HypervisorGetEmptyCPUInfoBody represents a raw hypervisor GET result with 317 // no cpu_info 318 const HypervisorGetEmptyCPUInfoBody = ` 319 { 320 "hypervisor":{ 321 "cpu_info": "", 322 "current_workload":0, 323 "status":"enabled", 324 "state":"up", 325 "disk_available_least":0, 326 "host_ip":"1.1.1.1", 327 "free_disk_gb":1028, 328 "free_ram_mb":7680, 329 "hypervisor_hostname":"fake-mini", 330 "hypervisor_type":"fake", 331 "hypervisor_version":2002000, 332 "id":"c48f6247-abe4-4a24-824e-ea39e108874f", 333 "local_gb":1028, 334 "local_gb_used":0, 335 "memory_mb":8192, 336 "memory_mb_used":512, 337 "running_vms":0, 338 "service":{ 339 "host":"e6a37ee802d74863ab8b91ade8f12a67", 340 "id":"9c2566e7-7a54-4777-a1ae-c2662f0c407c", 341 "disabled_reason":null 342 }, 343 "vcpus":1, 344 "vcpus_used":0 345 } 346 } 347 ` 348 349 // HypervisorUptimeBody represents a raw hypervisor uptime request result with 350 // Pike+ release. 351 const HypervisorUptimeBody = ` 352 { 353 "hypervisor": { 354 "hypervisor_hostname": "fake-mini", 355 "id": "c48f6247-abe4-4a24-824e-ea39e108874f", 356 "state": "up", 357 "status": "enabled", 358 "uptime": " 08:32:11 up 93 days, 18:25, 12 users, load average: 0.20, 0.12, 0.14" 359 } 360 } 361 ` 362 363 var ( 364 HypervisorFakePre253 = hypervisors.Hypervisor{ 365 CPUInfo: hypervisors.CPUInfo{ 366 Arch: "x86_64", 367 Model: "Nehalem", 368 Vendor: "Intel", 369 Features: []string{ 370 "pge", 371 "clflush", 372 }, 373 Topology: hypervisors.Topology{ 374 Cores: 1, 375 Threads: 1, 376 Sockets: 4, 377 }, 378 }, 379 CurrentWorkload: 0, 380 Status: "enabled", 381 State: "up", 382 DiskAvailableLeast: 0, 383 HostIP: "1.1.1.1", 384 FreeDiskGB: 1028, 385 FreeRamMB: 7680, 386 HypervisorHostname: "fake-mini", 387 HypervisorType: "fake", 388 HypervisorVersion: 2002000, 389 ID: "1", 390 LocalGB: 1028, 391 LocalGBUsed: 0, 392 MemoryMB: 8192, 393 MemoryMBUsed: 512, 394 RunningVMs: 0, 395 Service: hypervisors.Service{ 396 Host: "e6a37ee802d74863ab8b91ade8f12a67", 397 ID: "2", 398 DisabledReason: "", 399 }, 400 VCPUs: 1, 401 VCPUsUsed: 0, 402 } 403 404 HypervisorFake = hypervisors.Hypervisor{ 405 CPUInfo: hypervisors.CPUInfo{ 406 Arch: "x86_64", 407 Model: "Nehalem", 408 Vendor: "Intel", 409 Features: []string{ 410 "pge", 411 "clflush", 412 }, 413 Topology: hypervisors.Topology{ 414 Cores: 1, 415 Threads: 1, 416 Sockets: 4, 417 }, 418 }, 419 CurrentWorkload: 0, 420 Status: "enabled", 421 State: "up", 422 DiskAvailableLeast: 0, 423 HostIP: "1.1.1.1", 424 FreeDiskGB: 1028, 425 FreeRamMB: 7680, 426 HypervisorHostname: "fake-mini", 427 HypervisorType: "fake", 428 HypervisorVersion: 2002000, 429 ID: "c48f6247-abe4-4a24-824e-ea39e108874f", 430 LocalGB: 1028, 431 LocalGBUsed: 0, 432 MemoryMB: 8192, 433 MemoryMBUsed: 512, 434 RunningVMs: 0, 435 Service: hypervisors.Service{ 436 Host: "e6a37ee802d74863ab8b91ade8f12a67", 437 ID: "9c2566e7-7a54-4777-a1ae-c2662f0c407c", 438 DisabledReason: "", 439 }, 440 VCPUs: 1, 441 VCPUsUsed: 0, 442 } 443 444 HypervisorFakeWithParameters = hypervisors.Hypervisor{ 445 CPUInfo: hypervisors.CPUInfo{ 446 Arch: "x86_64", 447 Model: "Nehalem", 448 Vendor: "Intel", 449 Features: []string{ 450 "pge", 451 "clflush", 452 }, 453 Topology: hypervisors.Topology{ 454 Cores: 1, 455 Threads: 1, 456 Sockets: 4, 457 }, 458 }, 459 CurrentWorkload: 0, 460 Status: "enabled", 461 State: "up", 462 DiskAvailableLeast: 0, 463 HostIP: "1.1.1.1", 464 FreeDiskGB: 1028, 465 FreeRamMB: 7680, 466 HypervisorHostname: "fake-mini", 467 HypervisorType: "fake", 468 HypervisorVersion: 2002000, 469 ID: "c48f6247-abe4-4a24-824e-ea39e108874f", 470 LocalGB: 1028, 471 LocalGBUsed: 0, 472 MemoryMB: 8192, 473 MemoryMBUsed: 512, 474 RunningVMs: 0, 475 Service: hypervisors.Service{ 476 Host: "e6a37ee802d74863ab8b91ade8f12a67", 477 ID: "9c2566e7-7a54-4777-a1ae-c2662f0c407c", 478 DisabledReason: "", 479 }, 480 Servers: &[]hypervisors.Server{ 481 { 482 Name: "instance-00000001", 483 UUID: "c42acc8d-eab3-4e4d-9d90-01b0791328f4", 484 }, 485 { 486 Name: "instance-00000002", 487 UUID: "8aaf2941-b774-41fc-921b-20c4757cc359", 488 }, 489 }, 490 VCPUs: 1, 491 VCPUsUsed: 0, 492 } 493 494 HypervisorEmptyCPUInfo = hypervisors.Hypervisor{ 495 CurrentWorkload: 0, 496 Status: "enabled", 497 State: "up", 498 DiskAvailableLeast: 0, 499 HostIP: "1.1.1.1", 500 FreeDiskGB: 1028, 501 FreeRamMB: 7680, 502 HypervisorHostname: "fake-mini", 503 HypervisorType: "fake", 504 HypervisorVersion: 2002000, 505 ID: "c48f6247-abe4-4a24-824e-ea39e108874f", 506 LocalGB: 1028, 507 LocalGBUsed: 0, 508 MemoryMB: 8192, 509 MemoryMBUsed: 512, 510 RunningVMs: 0, 511 Service: hypervisors.Service{ 512 Host: "e6a37ee802d74863ab8b91ade8f12a67", 513 ID: "9c2566e7-7a54-4777-a1ae-c2662f0c407c", 514 DisabledReason: "", 515 }, 516 VCPUs: 1, 517 VCPUsUsed: 0, 518 } 519 520 HypervisorsStatisticsExpected = hypervisors.Statistics{ 521 Count: 1, 522 CurrentWorkload: 0, 523 DiskAvailableLeast: 0, 524 FreeDiskGB: 1028, 525 FreeRamMB: 7680, 526 LocalGB: 1028, 527 LocalGBUsed: 0, 528 MemoryMB: 8192, 529 MemoryMBUsed: 512, 530 RunningVMs: 0, 531 VCPUs: 2, 532 VCPUsUsed: 0, 533 } 534 535 HypervisorUptimeExpected = hypervisors.Uptime{ 536 HypervisorHostname: "fake-mini", 537 ID: "c48f6247-abe4-4a24-824e-ea39e108874f", 538 State: "up", 539 Status: "enabled", 540 Uptime: " 08:32:11 up 93 days, 18:25, 12 users, load average: 0.20, 0.12, 0.14", 541 } 542 ) 543 544 func HandleHypervisorsStatisticsSuccessfully(t *testing.T) { 545 testhelper.Mux.HandleFunc("/os-hypervisors/statistics", func(w http.ResponseWriter, r *http.Request) { 546 testhelper.TestMethod(t, r, "GET") 547 testhelper.TestHeader(t, r, "X-Auth-Token", client.TokenID) 548 549 w.Header().Add("Content-Type", "application/json") 550 fmt.Fprintf(w, HypervisorsStatisticsBody) 551 }) 552 } 553 554 func HandleHypervisorListPre253Successfully(t *testing.T) { 555 testhelper.Mux.HandleFunc("/os-hypervisors/detail", func(w http.ResponseWriter, r *http.Request) { 556 testhelper.TestMethod(t, r, "GET") 557 testhelper.TestHeader(t, r, "X-Auth-Token", client.TokenID) 558 559 w.Header().Add("Content-Type", "application/json") 560 fmt.Fprintf(w, HypervisorListBodyPre253) 561 }) 562 } 563 564 func HandleHypervisorListSuccessfully(t *testing.T) { 565 testhelper.Mux.HandleFunc("/os-hypervisors/detail", func(w http.ResponseWriter, r *http.Request) { 566 testhelper.TestMethod(t, r, "GET") 567 testhelper.TestHeader(t, r, "X-Auth-Token", client.TokenID) 568 569 w.Header().Add("Content-Type", "application/json") 570 fmt.Fprintf(w, HypervisorListBody) 571 }) 572 } 573 574 func HandleHypervisorListWithParametersSuccessfully(t *testing.T) { 575 testhelper.Mux.HandleFunc("/os-hypervisors/detail", func(w http.ResponseWriter, r *http.Request) { 576 testhelper.TestMethod(t, r, "GET") 577 testhelper.TestHeader(t, r, "X-Auth-Token", client.TokenID) 578 testhelper.TestFormValues(t, r, map[string]string{ 579 "with_servers": "true", 580 }) 581 582 w.Header().Add("Content-Type", "application/json") 583 fmt.Fprintf(w, HypervisorListWithParametersBody) 584 }) 585 } 586 587 func HandleHypervisorGetSuccessfully(t *testing.T) { 588 testhelper.Mux.HandleFunc("/os-hypervisors/"+HypervisorFake.ID, func(w http.ResponseWriter, r *http.Request) { 589 testhelper.TestMethod(t, r, "GET") 590 testhelper.TestHeader(t, r, "X-Auth-Token", client.TokenID) 591 592 w.Header().Add("Content-Type", "application/json") 593 fmt.Fprintf(w, HypervisorGetBody) 594 }) 595 } 596 597 func HandleHypervisorGetEmptyCPUInfoSuccessfully(t *testing.T) { 598 testhelper.Mux.HandleFunc("/os-hypervisors/"+HypervisorFake.ID, func(w http.ResponseWriter, r *http.Request) { 599 testhelper.TestMethod(t, r, "GET") 600 testhelper.TestHeader(t, r, "X-Auth-Token", client.TokenID) 601 602 w.Header().Add("Content-Type", "application/json") 603 fmt.Fprintf(w, HypervisorGetEmptyCPUInfoBody) 604 }) 605 } 606 607 func HandleHypervisorUptimeSuccessfully(t *testing.T) { 608 testhelper.Mux.HandleFunc("/os-hypervisors/"+HypervisorFake.ID+"/uptime", func(w http.ResponseWriter, r *http.Request) { 609 testhelper.TestMethod(t, r, "GET") 610 testhelper.TestHeader(t, r, "X-Auth-Token", client.TokenID) 611 612 w.Header().Add("Content-Type", "application/json") 613 fmt.Fprintf(w, HypervisorUptimeBody) 614 }) 615 }