-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodes_test.go
276 lines (254 loc) · 8.72 KB
/
nodes_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
package proxmox
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
func TestGetNodes(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api2/json/nodes", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, err := fmt.Fprint(w, fixture("nodes/get_nodes.json"))
if err != nil {
return
}
})
want := GetNodesResponse{
Data: []GetNodesData{
{CPU: 0.0522061746389294, Disk: 5513633792, ID: "node/srv3", Level: "", MaxCPU: 8, MaxDisk: 100861726720, MaxMem: 16367738880, Mem: 14766223360, Node: "srv3", SSLFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00", Status: "online", Type: "node", Uptime: 418333},
{CPU: 0.0220677146311971, Disk: 5727686656, ID: "node/srv1", Level: "", MaxCPU: 16, MaxDisk: 100861726720, MaxMem: 134850498560, Mem: 45189853184, Node: "srv1", SSLFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00", Status: "online", Type: "node", Uptime: 418326},
{CPU: 0.0673548074849297, Disk: 5488590848, ID: "node/srv2", Level: "", MaxCPU: 8, MaxDisk: 100861726720, MaxMem: 16367742976, Mem: 13080690688, Node: "srv2", SSLFingerprint: "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00", Status: "online", Type: "node", Uptime: 418322},
},
}
r, resp, err := client.Nodes.GetNodes()
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, want, *r)
}
func TestGetNode(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api2/json/nodes/srv1/status", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, err := fmt.Fprint(w, fixture("nodes/get_node_status.json"))
if err != nil {
return
}
})
want := GetNodeStatusResponse{
Data: GetNodeStatusData{
BootInfo: BootInfo{Mode: "efi", SecureBoot: 0},
CPU: 0.0282238002623366,
CPUInfo: CPUInfo{Cores: 50, CPUs: 200, Flags: "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx avx512f avx512dq rdseed adx smap avx512ifma clflushopt intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid fsrm md_clear flush_l1d arch_capabilities", HVM: "1", MHz: "4886.225", Model: "99th Gen Intel(R) Core(TM) i19-9000 @ 6.50GHz", Sockets: 1, UserHz: 100},
CurrentKernel: CurrentKernel{Machine: "x86_64", Release: "6.5.11-8-pve", SysName: "Linux", Version: "#1 SMP PREEMPT_DYNAMIC PMX 6.5.11-8 (2024-01-30T12:27Z)"},
Idle: 0,
KSM: KSM{Shared: 0},
Kversion: "Linux 6.5.11-8-pve #1 SMP PREEMPT_DYNAMIC PMX 6.5.11-8 (2024-01-30T12:27Z)",
LoadAvg: []string{"0.53", "0.46", "0.43"},
Memory: Memory{Free: 89574653952, Total: 134850498560, Used: 45275844608},
PveVersion: "pve-manager/0.0.0/0000000000000000",
RootFs: RootFS{Avail: 89962983424, Free: 95133720576, Total: 100861726720, Used: 5728006144},
Swap: Swap{Free: 8589930496, Total: 8589930496, Used: 0},
Uptime: 419090,
Wait: 0.00150768163794533,
},
}
r, resp, err := client.Nodes.GetNodeStatus("srv1")
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, want, *r)
}
func TestGetNodeLxc(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api2/json/nodes/srv1/lxc", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, err := fmt.Fprint(w, fixture("nodes/get_node_lxc.json"))
if err != nil {
return
}
})
want := GetNodeLxcResponse{
Data: []GetNodeLxcData{
{
CPU: 0,
CPUs: 1,
Disk: 0,
DiskRead: 0,
DiskWrite: 0,
MaxDisk: 8589934592,
MaxMem: 536870912,
MaxSwap: 536870912,
Mem: 0,
Name: "CT103",
NetIn: 0,
NetOut: 0,
Status: "stopped",
Type: "lxc",
Uptime: 0,
VMID: IntOrString("103"),
},
{
CPU: 0,
CPUs: 1,
Disk: 0,
DiskRead: 0,
DiskWrite: 0,
MaxDisk: 8589934592,
MaxMem: 536870912,
MaxSwap: 536870912,
Mem: 0,
Name: "CT104",
NetIn: 0,
NetOut: 0,
Status: "stopped",
Type: "lxc",
Uptime: 0,
VMID: IntOrString("104"),
},
},
}
r, resp, err := client.Nodes.GetNodeLxc("srv1")
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, want, *r)
}
func TestGetNodeQemu(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api2/json/nodes/srv1/qemu", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, err := fmt.Fprint(w, fixture("nodes/get_node_qemu.json"))
if err != nil {
return
}
})
want := GetNodeQemuResponse{
Data: []GetNodeQemuData{
{
CPU: 0.0156071608339279,
CPUs: 5,
Disk: 0,
DiskRead: 0,
DiskWrite: 0,
MaxDisk: 274877906944,
MaxMem: 8589934592,
Mem: 3072665958,
PID: 1551,
Name: "test",
NetIn: 294680188,
NetOut: 200064110,
Status: "running",
Uptime: 28661,
VMID: IntOrString("104"),
},
},
}
r, resp, err := client.Nodes.GetNodeQemu("srv1")
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, want, *r)
}
func TestGetNodeDisksList(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api2/json/nodes/srv1/disks/list", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, err := fmt.Fprint(w, fixture("nodes/get_node_disks_list.json"))
if err != nil {
return
}
})
want := GetNodeDisksListResponse{
Data: []GetNodeDisksListData{
{
DevPath: "/dev/nvme0n1",
WWN: "testwwn",
Serial: "testser",
ByIDLink: "/dev/disk/by-id/nvme-drive",
Size: 512110190592,
Used: "BIOS boot",
RPM: IntOrString("0"),
Wearout: IntOrString("99"),
GPT: 1,
Health: "PASSED",
Model: "Test Model",
Vendor: "unknown",
Type: "nvme",
},
{
Serial: "testser",
ByIDLink: "/dev/disk/by-id/ata-TOSHIBA_THNS",
Bluestore: 1,
DevPath: "/dev/sda",
OSDEncrypted: 0,
Type: "ssd",
Health: "PASSED",
RPM: IntOrString("0"),
Wearout: IntOrString("N/A"),
GPT: 0,
Vendor: "unknown",
Size: 1920383410176,
Model: "Test Model",
WWN: "testwwn",
Used: "LVM",
},
{
DevPath: "/dev/sda",
WWN: "testwwn",
Serial: "testser",
ByIDLink: "/dev/disk/by-id/ata-ST2000",
Size: 2000398934016,
Used: "LVM",
RPM: IntOrString("5400"),
Wearout: IntOrString("N/A"),
GPT: 0,
Health: "PASSED",
Model: "Test Model",
Vendor: "unknown",
Type: "hdd",
},
{
DevPath: "/dev/sdc",
WWN: "testwwn",
Serial: "testser",
ByIDLink: "/dev/disk/by-id/ata-WDC_DRIVE2",
Size: 5000947302400,
Used: "ext4",
RPM: IntOrString("4800"),
Wearout: IntOrString("N/A"),
GPT: 0,
Health: "PASSED",
Model: "Test Model",
Vendor: "unknown",
Type: "hdd",
},
{
DevPath: "/dev/sde",
WWN: "testwwn",
Serial: "testser",
ByIDLink: "/dev/disk/by-id/ata-WDC_DRIVE1",
Size: 5000947302400,
Used: "ZFS",
RPM: IntOrString("4800"),
Wearout: IntOrString("N/A"),
GPT: 0,
Health: "PASSED",
Model: "Test Model",
Vendor: "unknown",
Type: "hdd",
},
},
}
r, resp, err := client.Nodes.GetNodeDisksList("srv1")
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, want, *r)
}