blob: 79d7121b8eaef066a2385cac983fc5d8509d9554 [file] [log] [blame]
Simon Murraya9d5de42016-11-03 15:06:44 +00001package testing
2
3import (
4 "fmt"
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +02005 "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/compute/v2/hypervisors"
6 "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper"
7 "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper/client"
Simon Murraya9d5de42016-11-03 15:06:44 +00008 "net/http"
9 "testing"
10)
11
12// The first hypervisor represents what the specification says (~Newton)
13// The second is exactly the same, but what you can get off a real system (~Kilo)
14const HypervisorListBody = `
15{
16 "hypervisors": [
17 {
18 "cpu_info": {
19 "arch": "x86_64",
20 "model": "Nehalem",
21 "vendor": "Intel",
22 "features": [
23 "pge",
24 "clflush"
25 ],
26 "topology": {
27 "cores": 1,
28 "threads": 1,
29 "sockets": 4
30 }
31 },
32 "current_workload": 0,
33 "status": "enabled",
34 "state": "up",
35 "disk_available_least": 0,
36 "host_ip": "1.1.1.1",
37 "free_disk_gb": 1028,
38 "free_ram_mb": 7680,
39 "hypervisor_hostname": "fake-mini",
40 "hypervisor_type": "fake",
41 "hypervisor_version": 2002000,
42 "id": 1,
43 "local_gb": 1028,
44 "local_gb_used": 0,
45 "memory_mb": 8192,
46 "memory_mb_used": 512,
47 "running_vms": 0,
48 "service": {
49 "host": "e6a37ee802d74863ab8b91ade8f12a67",
50 "id": 2,
51 "disabled_reason": null
52 },
53 "vcpus": 1,
54 "vcpus_used": 0
55 },
56 {
57 "cpu_info": "{\"arch\": \"x86_64\", \"model\": \"Nehalem\", \"vendor\": \"Intel\", \"features\": [\"pge\", \"clflush\"], \"topology\": {\"cores\": 1, \"threads\": 1, \"sockets\": 4}}",
58 "current_workload": 0,
59 "status": "enabled",
60 "state": "up",
61 "disk_available_least": 0,
62 "host_ip": "1.1.1.1",
63 "free_disk_gb": 1028,
64 "free_ram_mb": 7680,
65 "hypervisor_hostname": "fake-mini",
66 "hypervisor_type": "fake",
67 "hypervisor_version": 2.002e+06,
68 "id": 1,
69 "local_gb": 1028,
70 "local_gb_used": 0,
71 "memory_mb": 8192,
72 "memory_mb_used": 512,
73 "running_vms": 0,
74 "service": {
75 "host": "e6a37ee802d74863ab8b91ade8f12a67",
76 "id": 2,
77 "disabled_reason": null
78 },
79 "vcpus": 1,
80 "vcpus_used": 0
81 }
82 ]
83}`
84
85var (
86 HypervisorFake = hypervisors.Hypervisor{
87 CPUInfo: hypervisors.CPUInfo{
88 Arch: "x86_64",
89 Model: "Nehalem",
90 Vendor: "Intel",
91 Features: []string{
92 "pge",
93 "clflush",
94 },
95 Topology: hypervisors.Topology{
96 Cores: 1,
97 Threads: 1,
98 Sockets: 4,
99 },
100 },
101 CurrentWorkload: 0,
102 Status: "enabled",
103 State: "up",
104 DiskAvailableLeast: 0,
105 HostIP: "1.1.1.1",
106 FreeDiskGB: 1028,
107 FreeRamMB: 7680,
108 HypervisorHostname: "fake-mini",
109 HypervisorType: "fake",
110 HypervisorVersion: 2002000,
111 ID: 1,
112 LocalGB: 1028,
113 LocalGBUsed: 0,
114 MemoryMB: 8192,
115 MemoryMBUsed: 512,
116 RunningVMs: 0,
117 Service: hypervisors.Service{
118 Host: "e6a37ee802d74863ab8b91ade8f12a67",
119 ID: 2,
120 DisabledReason: "",
121 },
122 VCPUs: 1,
123 VCPUsUsed: 0,
124 }
125)
126
127func HandleHypervisorListSuccessfully(t *testing.T) {
128 testhelper.Mux.HandleFunc("/os-hypervisors/detail", func(w http.ResponseWriter, r *http.Request) {
129 testhelper.TestMethod(t, r, "GET")
130 testhelper.TestHeader(t, r, "X-Auth-Token", client.TokenID)
131
132 w.Header().Add("Content-Type", "application/json")
133 fmt.Fprintf(w, HypervisorListBody)
134 })
135}