@@ -15,13 +15,6 @@ import (
1515
1616var _ BMC = (* RedfishLocalBMC )(nil )
1717
18- var defaultMockedBMCSetting = map [string ]map [string ]any {
19- "abc" : {"type" : redfish .StringAttributeType , "reboot" : false , "value" : "bar" },
20- "fooreboot" : {"type" : redfish .IntegerAttributeType , "reboot" : true , "value" : 123 },
21- }
22-
23- var PendingMockedBMCSetting = map [string ]map [string ]any {}
24-
2518// RedfishLocalBMC is an implementation of the BMC interface for Redfish.
2619type RedfishLocalBMC struct {
2720 * RedfishBMC
@@ -211,20 +204,18 @@ func (r *RedfishLocalBMC) ResetManager(ctx context.Context, UUID string, resetTy
211204
212205 // mock the bmc update here with timed delay
213206 go func () {
214- if len (PendingMockedBMCSetting ) > 0 {
215- time .Sleep (1 * time .Second )
216- for key , data := range PendingMockedBMCSetting {
217- if _ , ok := defaultMockedBMCSetting [key ]; ok {
218- defaultMockedBMCSetting [key ] = data
207+ if len (UnitTestMockUps . PendingBMCSetting ) > 0 {
208+ time .Sleep (150 * time .Millisecond )
209+ for key , data := range UnitTestMockUps . PendingBMCSetting {
210+ if _ , ok := UnitTestMockUps . BMCSettingAttr [key ]; ok {
211+ UnitTestMockUps . BMCSettingAttr [key ] = data
219212 }
220213 }
221- PendingMockedBMCSetting = map [string ]map [string ]any {}
222- r .StoredBMCSettingData = defaultMockedBMCSetting
214+ UnitTestMockUps .ResetPendingBMCSetting ()
223215 }
224216 }()
225217
226218 return nil
227-
228219}
229220
230221// mock SetBiosAttributesOnReset sets given bios attributes for unit testing.
@@ -237,39 +228,25 @@ func (r *RedfishLocalBMC) SetBMCAttributesImediately(
237228 for name , value := range attributes {
238229 attrs [name ] = value
239230 }
240- if len (defaultMockedBMCSetting ) == 0 {
241- defaultMockedBMCSetting = map [string ]map [string ]any {}
242- }
243231
244232 for key , attrData := range attributes {
245- if AttributesData , ok := defaultMockedBMCSetting [key ]; ok {
233+ if AttributesData , ok := UnitTestMockUps . BMCSettingAttr [key ]; ok {
246234 if reboot , ok := AttributesData ["reboot" ]; ok && ! reboot .(bool ) {
247235 // if reboot not needed, set the attribute immediately.
248236 AttributesData ["value" ] = attrData
249237 } else {
250238 // if reboot needed, set the attribute at next power on.
251- PendingMockedBMCSetting [key ] = map [string ]any {
239+ UnitTestMockUps . PendingBMCSetting [key ] = map [string ]any {
252240 "type" : AttributesData ["type" ],
253241 "reboot" : AttributesData ["reboot" ],
254242 "value" : attrData ,
255243 }
256244 }
257245 }
258246 }
259- r .StoredBMCSettingData = defaultMockedBMCSetting
260-
261247 return nil
262248}
263249
264- func (r * RedfishLocalBMC ) getMockedBMCSettingData () map [string ]map [string ]any {
265-
266- if len (r .StoredBMCSettingData ) > 0 {
267- return r .StoredBMCSettingData
268- }
269- return defaultMockedBMCSetting
270-
271- }
272-
273250func (r * RedfishLocalBMC ) GetBMCAttributeValues (
274251 ctx context.Context ,
275252 UUID string ,
@@ -278,21 +255,17 @@ func (r *RedfishLocalBMC) GetBMCAttributeValues(
278255 result redfish.SettingsAttributes ,
279256 err error ,
280257) {
281-
282258 if len (attributes ) == 0 {
283259 return
284260 }
285-
286- mockedAttributes := r .getMockedBMCSettingData ()
287-
288261 filteredAttr , err := r .getFilteredBMCRegistryAttributes (false , false )
289262 if err != nil {
290263 return
291264 }
292265 result = make (redfish.SettingsAttributes , len (attributes ))
293266 for _ , name := range attributes {
294267 if _ , ok := filteredAttr [name ]; ok {
295- if AttributesData , ok := mockedAttributes [name ]; ok {
268+ if AttributesData , ok := UnitTestMockUps . BMCSettingAttr [name ]; ok {
296269 result [name ] = AttributesData ["value" ]
297270 }
298271 }
@@ -307,13 +280,13 @@ func (r *RedfishLocalBMC) GetBMCPendingAttributeValues(
307280 redfish.SettingsAttributes ,
308281 error ,
309282) {
310- if len (PendingMockedBMCSetting ) == 0 {
283+ if len (UnitTestMockUps . PendingBMCSetting ) == 0 {
311284 return redfish.SettingsAttributes {}, nil
312285 }
313286
314- result := make (redfish.SettingsAttributes , len (PendingMockedBMCSetting ))
287+ result := make (redfish.SettingsAttributes , len (UnitTestMockUps . PendingBMCSetting ))
315288
316- for key , data := range PendingMockedBMCSetting {
289+ for key , data := range UnitTestMockUps . PendingBMCSetting {
317290 result [key ] = data ["value" ]
318291 }
319292
@@ -327,12 +300,11 @@ func (r *RedfishLocalBMC) getFilteredBMCRegistryAttributes(
327300 filtered map [string ]redfish.Attribute ,
328301 err error ,
329302) {
330- mockedAttributes := r .getMockedBMCSettingData ()
331303 filtered = make (map [string ]redfish.Attribute )
332- if len (mockedAttributes ) == 0 {
304+ if len (UnitTestMockUps . BMCSettingAttr ) == 0 {
333305 return filtered , fmt .Errorf ("no bmc setting attributes found" )
334306 }
335- for name , AttributesData := range mockedAttributes {
307+ for name , AttributesData := range UnitTestMockUps . BMCSettingAttr {
336308 data := redfish.Attribute {}
337309 data .AttributeName = name
338310 data .Immutable = immutable
0 commit comments