forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomputersystem_test.go
395 lines (341 loc) · 11 KB
/
computersystem_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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"strings"
"testing"
"github.com/stmcginnis/gofish/common"
)
var computerSystemBody = `{
"@odata.context": "/redfish/v1/$metadata#ComputerSystem.ComputerSystem",
"@odata.id": "/redfish/v1/Systems/System-1",
"@odata.type": "#ComputerSystem.v1_3_0.ComputerSystem",
"Id": "System-1",
"Name": "My Computer System",
"SystemType": "Physical",
"AssetTag": "free form asset tag",
"Manufacturer": "Manufacturer Name",
"Model": "Model Name",
"SKU": "",
"SerialNumber": "2M220100SL",
"PartNumber": "",
"Description": "Description of server",
"UUID": "00000000-0000-0000-0000-000000000000",
"HostName": "web-srv344",
"Status": {
"State": "Enabled",
"Health": "OK",
"HealthRollup": "OK"
},
"IndicatorLED": "Off",
"PowerState": "On",
"Boot": {
"AutomaticRetryAttempts": 3,
"AutomaticRetryConfig": "Disabled",
"[email protected]": [
"Disabled",
"RetryAttempts"
],
"BootSourceOverrideEnabled": "Once",
"BootSourceOverrideMode": "UEFI",
"BootSourceOverrideTarget": "Pxe",
"[email protected]": [
"None",
"Pxe",
"Floppy",
"Cd",
"Usb",
"Hdd",
"BiosSetup",
"Utilities",
"Diags",
"UefiTarget",
"SDCard",
"UefiHttp"
],
"BootOptions": {
"@odata.id": "/redfish/v1/Systems/1/BootOptions"
},
"BootNext": "",
"BootOrder": [
"Boot0003",
"Boot0011",
"Boot0014",
"Boot0007",
"Boot0008",
"Boot0009",
"Boot000A",
"Boot000B",
"Boot000C",
"Boot000D",
"Boot000E",
"Boot000F",
"Boot0002"
],
"UefiTargetBootSourceOverride": "uefi device path",
"HttpBootUri": "http://localhost/boot.efi"
},
"BiosVersion": "P79 v1.00 (09/20/2013)",
"ProcessorSummary": {
"Status": {
"Health": "OK",
"State": "Enabled"
},
"Count": 2,
"Model": "Multi-Core Intel(R) Xeon(R) processor 7500 Series"
},
"MemorySummary": {
"Status": {
"Health": "OK",
"State": "Enabled"
},
"TotalSystemMemoryGiB": 65536,
"TotalSystemPersistentMemoryGiB": 262144
},
"TrustedModules": [
{
"Status": {
"State": "Enabled",
"Health": "OK"
},
"ModuleType": "TPM2_0",
"FirmwareVersion": "3.1",
"FirmwareVersion2": "1",
"InterfaceTypeSelection": "None"
}
],
"Processors": {
"@odata.id": "/redfish/v1/Systems/System-1/Processors"
},
"Memory": {
"@odata.id": "/redfish/v1/Systems/System-1/Memory"
},
"EthernetInterfaces": {
"@odata.id": "/redfish/v1/Systems/System-1/EthernetInterfaces"
},
"SimpleStorage": {
"@odata.id": "/redfish/v1/Systems/System-1/SimpleStorage"
},
"Storage": {
"@odata.id": "/redfish/v1/Systems/1/Storage"
},
"LogServices": {
"@odata.id": "/redfish/v1/Systems/1/LogServices"
},
"SecureBoot": {
"@odata.id": "/redfish/v1/Systems/1/SecureBoot"
},
"Bios": {
"@odata.id": "/redfish/v1/Systems/1/Bios"
},
"USBControllers": {
"@odata.id": "/redfish/v1/Systems/System_0/USBControllers"
},
"Links": {
"Chassis": [
{
"@odata.id": "/redfish/v1/Chassis/Chassis-1"
}
],
"ManagedBy": [
{
"@odata.id": "/redfish/v1/Managers/BMC-1"
}
],
"Oem": {}
},
"Actions": {
"#ComputerSystem.Reset": {
"target": "/redfish/v1/Systems/System-1/Actions/ComputerSystem.Reset",
"@Redfish.ActionInfo": "/redfish/v1/Systems/System-1/ResetActionInfo",
"[email protected]": [
"On",
"ForceOff",
"ForceRestart",
"Nmi",
"ForceOn",
"PushPowerButton"
]
},
"#ComputerSystem.SetDefaultBootOrder": {
"target": "/redfish/v1/Systems/System-1/Actions/ComputerSystem.SetDefaultBootOrder"
}
}
}`
// TestComputerSystem tests the parsing of ComputerSystem objects.
func TestComputerSystem(t *testing.T) { //nolint
var result ComputerSystem
err := json.NewDecoder(strings.NewReader(computerSystemBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "System-1" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Name != "My Computer System" {
t.Errorf("Received invalid name: %s", result.Name)
}
if result.SystemType != PhysicalSystemType {
t.Errorf("Incorrect system type: %s", result.SystemType)
}
if result.AssetTag != "free form asset tag" {
t.Errorf("Received incorrect asset tag: %s", result.AssetTag)
}
if result.Status.Health != common.OKHealth {
t.Errorf("Received invalid health status: %s", result.Status.Health)
}
if result.Status.HealthRollup != common.OKHealth {
t.Errorf("Received invalid health rollup status: %s", result.Status.HealthRollup)
}
if result.IndicatorLED != common.OffIndicatorLED {
t.Errorf("Received invalid indicator status: %s", result.IndicatorLED)
}
if result.PowerState != OnPowerState {
t.Errorf("Received invalid power status: %s", result.PowerState)
}
if result.Boot.AutomaticRetryAttempts != 3 {
t.Errorf("Received invalid boot automatic retry attempts: %d", result.Boot.AutomaticRetryAttempts)
}
if result.Boot.AutomaticRetryConfig != "Disabled" {
t.Errorf("Received invalid boot automatic retry config: %s", result.Boot.AutomaticRetryConfig)
}
if result.Boot.BootSourceOverrideEnabled != "Once" {
t.Errorf("Received invalid boot source override: %s", result.Boot.BootSourceOverrideEnabled)
}
if result.Boot.BootSourceOverrideMode != "UEFI" {
t.Errorf("Received invalid boot source override mode: %s", result.Boot.BootSourceOverrideMode)
}
if result.Boot.BootSourceOverrideTarget != "Pxe" {
t.Errorf("Received invalid boot source target: %s", result.Boot.BootSourceOverrideTarget)
}
if result.Boot.UefiTargetBootSourceOverride != "uefi device path" {
t.Errorf("Received invalid uefi target boot source: %s", result.Boot.UefiTargetBootSourceOverride)
}
if result.Boot.HTTPBootURI != "http://localhost/boot.efi" {
t.Errorf("Received invalid http boot uri: %s", result.Boot.HTTPBootURI)
}
if result.ProcessorSummary.Status.State != common.EnabledState {
t.Errorf("Received invalid processor summary state: %s", result.ProcessorSummary.Status.State)
}
if result.ProcessorSummary.Count != 2 {
t.Errorf("Received invalid processor count: %d", result.ProcessorSummary.Count)
}
if result.MemorySummary.Status.State != common.EnabledState {
t.Errorf("Received invalid memory summary state: %s", result.MemorySummary.Status.State)
}
if result.MemorySummary.TotalSystemMemoryGiB != 65536 {
t.Errorf("Received invalid total system memory: %f", result.MemorySummary.TotalSystemMemoryGiB)
}
if result.MemorySummary.TotalSystemPersistentMemoryGiB != 262144 {
t.Errorf("Received invalid total system persistent memory: %f",
result.MemorySummary.TotalSystemPersistentMemoryGiB)
}
if len(result.TrustedModules) != 1 {
t.Errorf("Received invalid number of trusted modules: %d", len(result.TrustedModules))
}
if result.TrustedModules[0].Status.Health != common.OKHealth {
t.Errorf("Received invalid trusted module health: %s",
result.TrustedModules[0].Status.Health)
}
if result.TrustedModules[0].InterfaceTypeSelection != NoneInterfaceTypeSelection {
t.Errorf("Received invalid trusted module interface type selection: %s",
result.TrustedModules[0].InterfaceTypeSelection)
}
if result.processors != "/redfish/v1/Systems/System-1/Processors" {
t.Errorf("Received invalid processors reference: %s", result.processors)
}
if result.memory != "/redfish/v1/Systems/System-1/Memory" {
t.Errorf("Received invalid memory reference: %s", result.memory)
}
if result.ethernetInterfaces != "/redfish/v1/Systems/System-1/EthernetInterfaces" {
t.Errorf("Received invalid ethernet interface reference: %s", result.ethernetInterfaces)
}
if result.simpleStorage != "/redfish/v1/Systems/System-1/SimpleStorage" {
t.Errorf("Received invalid simple storage reference: %s", result.simpleStorage)
}
if len(result.chassis) != 1 {
t.Errorf("Received invalid number of chassis: %d", len(result.chassis))
}
if result.chassis[0] != TestChassisPath {
t.Errorf("Received invalid chassis reference: %s", result.chassis[0])
}
if result.resetTarget != "/redfish/v1/Systems/System-1/Actions/ComputerSystem.Reset" {
t.Errorf("Invalid reset action target: %s", result.resetTarget)
}
if len(result.SupportedResetTypes) != 6 {
t.Errorf("Invalid allowable reset actions, expected 6, got %d",
len(result.SupportedResetTypes))
}
if len(result.managedBy) != 1 {
t.Errorf("Received invalid number of ManagedBy: %d", len(result.managedBy))
}
if result.managedBy[0] != "/redfish/v1/Managers/BMC-1" {
t.Errorf("Received invalid Managers reference: %s", result.managedBy[0])
}
}
// TestComputerSystemUpdate tests the Update call.
func TestComputerSystemUpdate(t *testing.T) {
var result ComputerSystem
err := json.NewDecoder(strings.NewReader(computerSystemBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
testClient := &common.TestClient{}
result.SetClient(testClient)
result.AssetTag = TestAssetTag
result.HostName = "TestHostName"
result.IndicatorLED = common.BlinkingIndicatorLED
err = result.Update()
if err != nil {
t.Errorf("Error making Update call: %s", err)
}
calls := testClient.CapturedCalls()
if !strings.Contains(calls[0].Payload, "AssetTag:TestAssetTag") {
t.Errorf("Unexpected AssetTag update payload: %s", calls[0].Payload)
}
if !strings.Contains(calls[0].Payload, "HostName:TestHostName") {
t.Errorf("Unexpected HostName update payload: %s", calls[0].Payload)
}
if !strings.Contains(calls[0].Payload, "IndicatorLED:Blinking") {
t.Errorf("Unexpected IndicatorLED update payload: %s", calls[0].Payload)
}
}
var bootOptionBody = `{
"@odata.context": "/redfish/v1/$metadata#BootOption.BootOption",
"@odata.etag": "W/\"A3A6BF43\"",
"@odata.id": "/redfish/v1/Systems/1/BootOptions/1/",
"@odata.type": "#BootOption.v1_0_1.BootOption",
"Id": "1",
"Alias": "None",
"BootOptionReference": "Boot0015",
"DisplayName": "URL File : http://assets.example.com/ipxe.efi (IPv4)",
"Name": "Boot Option",
"UefiDevicePath": "IPv4(0.0.0.0)/Uri(http://assets.example.com/ipxe.efi)"
}`
func TestBootOption(t *testing.T) {
var result BootOption
err := json.NewDecoder(strings.NewReader(bootOptionBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}
if result.ID != "1" {
t.Errorf("Received invalid ID: %s", result.ID)
}
if result.Name != "Boot Option" {
t.Errorf("Received invalid name: %s", result.Name)
}
if result.Alias != "None" {
t.Errorf("Received invalid alias: %s", result.Alias)
}
if result.BootOptionReference != "Boot0015" {
t.Errorf("Received invalid bootoptionreference: %s", result.BootOptionReference)
}
if result.DisplayName != "URL File : http://assets.example.com/ipxe.efi (IPv4)" {
t.Errorf("Received invalid displayname: %s", result.DisplayName)
}
if result.UefiDevicePath != "IPv4(0.0.0.0)/Uri(http://assets.example.com/ipxe.efi)" {
t.Errorf("Received invalid uefidevicepath: %s", result.UefiDevicePath)
}
}