@@ -107,7 +107,7 @@ func (r *Store) AssetByID(ctx context.Context, id string, fetchBmcCredentials bo
107
107
if err != nil {
108
108
span .SetStatus (codes .Error , "Get() server failed" )
109
109
110
- return nil , errors .Wrap (ErrServerServiceQuery , "error querying server attributes: " + err .Error ())
110
+ return nil , errors .Wrap (model . ErrInventoryQuery , "error querying server attributes: " + err .Error ())
111
111
}
112
112
113
113
var credential * serverserviceapi.ServerCredential
@@ -120,7 +120,7 @@ func (r *Store) AssetByID(ctx context.Context, id string, fetchBmcCredentials bo
120
120
if err != nil {
121
121
span .SetStatus (codes .Error , "GetCredential() failed" )
122
122
123
- return nil , errors .Wrap (ErrServerServiceQuery , "error querying BMC credentials: " + err .Error ())
123
+ return nil , errors .Wrap (model . ErrInventoryQuery , "error querying BMC credentials: " + err .Error ())
124
124
}
125
125
}
126
126
@@ -157,7 +157,7 @@ func (r *Store) AssetsByOffsetLimit(ctx context.Context, offset, limit int) (ass
157
157
if err != nil {
158
158
span .SetStatus (codes .Error , "List() servers failed" )
159
159
160
- return nil , 0 , errors .Wrap (ErrServerServiceQuery , err .Error ())
160
+ return nil , 0 , errors .Wrap (model . ErrInventoryQuery , err .Error ())
161
161
}
162
162
163
163
assets = make ([]* model.Asset , 0 , len (servers ))
@@ -168,7 +168,7 @@ func (r *Store) AssetsByOffsetLimit(ctx context.Context, offset, limit int) (ass
168
168
if err != nil {
169
169
span .SetStatus (codes .Error , "GetCredential() failed" )
170
170
171
- return nil , 0 , errors .Wrap (ErrServerServiceQuery , err .Error ())
171
+ return nil , 0 , errors .Wrap (model . ErrInventoryQuery , err .Error ())
172
172
}
173
173
174
174
asset , err := toAsset (server , credential , true )
@@ -213,7 +213,7 @@ func (r *Store) AssetUpdate(ctx context.Context, asset *model.Asset) error {
213
213
// count error
214
214
metrics .ServerServiceQueryErrorCount .With (stageLabel ).Inc ()
215
215
216
- return errors .Wrap (ErrServerServiceQuery , err .Error ())
216
+ return errors .Wrap (model . ErrInventoryQuery , err .Error ())
217
217
}
218
218
219
219
if server == nil {
@@ -223,28 +223,58 @@ func (r *Store) AssetUpdate(ctx context.Context, asset *model.Asset) error {
223
223
"hr" : hr ,
224
224
}).Warn ("server service server query returned nil object" )
225
225
226
- return errors .Wrap (ErrServerServiceQuery , "got nil Server object" )
226
+ return errors .Wrap (model . ErrInventoryQuery , "got nil Server object" )
227
227
}
228
228
229
229
// publish server inventory
230
- if errPublish := r .publish (ctx , asset , server ); errPublish != nil {
230
+ if errPublishInv := r .publishInventory (ctx , asset , server ); errPublishInv != nil {
231
231
r .logger .WithFields (
232
232
logrus.Fields {
233
233
"id" : id ,
234
234
"hr" : hr ,
235
- "err" : errPublish .Error (),
236
- }).Warn ("inventory asset insert/update error" )
235
+ "err" : errPublishInv .Error (),
236
+ }).Warn ("asset inventory insert/update error" )
237
237
238
238
metricInventorized .With (prometheus.Labels {"status" : "failed" }).Add (1 )
239
+
240
+ return errors .Wrap (model .ErrInventoryQuery , errPublishInv .Error ())
239
241
}
240
242
241
243
// count devices with no errors
242
244
metricInventorized .With (prometheus.Labels {"status" : "success" }).Add (1 )
243
245
246
+ if errPublishBiosCfg := r .publishBiosConfig (ctx , asset , server ); errPublishBiosCfg != nil {
247
+ r .logger .WithFields (
248
+ logrus.Fields {
249
+ "id" : server .UUID .String (),
250
+ "err" : errPublishBiosCfg ,
251
+ }).Warn ("asset bios configuration insert/update error" )
252
+
253
+ metricBiosCfgCollected .With (prometheus.Labels {"status" : "failed" }).Add (1 )
254
+
255
+ return errors .Wrap (model .ErrInventoryQuery , errPublishBiosCfg .Error ())
256
+ }
257
+
258
+ metricBiosCfgCollected .With (prometheus.Labels {"status" : "success" }).Add (1 )
259
+
244
260
return nil
245
261
}
246
262
247
- func (r * Store ) publish (ctx context.Context , asset * model.Asset , server * serverserviceapi.Server ) error {
263
+ func (r * Store ) publishBiosConfig (ctx context.Context , asset * model.Asset , server * serverserviceapi.Server ) error {
264
+ // Don't publish bios config if there's no bios config data made avai
265
+ if len (asset .BiosConfig ) == 0 {
266
+ errNoBiosConfig := errors .New ("no BIOS configuration collected" )
267
+ return errNoBiosConfig
268
+ }
269
+
270
+ if asset .HasError (outofband .GetBiosConfigError ) {
271
+ return errors .New (string (outofband .GetBiosConfigError ))
272
+ }
273
+
274
+ return r .createUpdateServerBIOSConfiguration (ctx , server .UUID , asset .BiosConfig )
275
+ }
276
+
277
+ func (r * Store ) publishInventory (ctx context.Context , asset * model.Asset , server * serverserviceapi.Server ) error {
248
278
// create/update server bmc error attributes - for out of band data collection
249
279
if r .appKind == model .AppKindOutOfBand && len (asset .Errors ) > 0 {
250
280
if err := r .createUpdateServerBMCErrorAttributes (
@@ -253,59 +283,32 @@ func (r *Store) publish(ctx context.Context, asset *model.Asset, server *servers
253
283
attributeByNamespace (serverBMCErrorsAttributeNS , server .Attributes ),
254
284
asset ,
255
285
); err != nil {
256
- return errors .Wrap (ErrServerServiceQuery , "BMC error attribute create/update error: " + err .Error ())
286
+ return errors .Wrap (model . ErrInventoryQuery , "BMC error attribute create/update error: " + err .Error ())
257
287
}
258
288
259
289
// both inventory and BIOS configuration collection failed on a login failure
260
290
if asset .HasError (outofband .LoginError ) {
261
291
return errors .New (string (outofband .LoginError ))
262
292
}
263
- }
264
293
265
- // publish server inventory
266
- if ! asset .HasError (outofband .InventoryError ) {
267
- if errPublishInventory := r .publishInventory (ctx , server , asset ); errPublishInventory != nil {
268
- return errPublishInventory
294
+ if asset .HasError (outofband .InventoryError ) {
295
+ return errors .New (string (outofband .InventoryError ))
269
296
}
270
297
}
271
298
272
- // Don't publish bios config if there's no bios config data
273
- if len (asset .BiosConfig ) == 0 {
274
- errNoBiosConfig := errors .New ("no BIOS configuration collected" )
275
- return errNoBiosConfig
276
- }
277
-
278
- if asset .HasError (outofband .GetBiosConfigError ) {
279
- return errors .New (string (outofband .GetBiosConfigError ))
280
- }
281
-
282
- // publish bios configuration
283
- err := r .createUpdateServerBIOSConfiguration (ctx , server .UUID , asset .BiosConfig )
284
- if err != nil {
285
- r .logger .WithFields (
286
- logrus.Fields {
287
- "id" : server .UUID .String (),
288
- "err" : err ,
289
- }).Warn ("error in server bios configuration versioned attribute update" )
290
- }
291
-
292
- return nil
293
- }
294
-
295
- func (r * Store ) publishInventory (ctx context.Context , server * serverserviceapi.Server , asset * model.Asset ) error {
296
299
// create/update server serial, vendor, model attributes
297
300
if err := r .createUpdateServerAttributes (ctx , server , asset ); err != nil {
298
- return errors .Wrap (ErrServerServiceQuery , "Server Vendor attribute create/update error: " + err .Error ())
301
+ return errors .Wrap (model . ErrInventoryQuery , "Server Vendor attribute create/update error: " + err .Error ())
299
302
}
300
303
301
304
// create update server metadata attributes
302
305
if err := r .createUpdateServerMetadataAttributes (ctx , server .UUID , asset ); err != nil {
303
- return errors .Wrap (ErrServerServiceQuery , "Server Metadata attribute create/update error: " + err .Error ())
306
+ return errors .Wrap (model . ErrInventoryQuery , "Server Metadata attribute create/update error: " + err .Error ())
304
307
}
305
308
306
309
// create update server component
307
310
if err := r .createUpdateServerComponents (ctx , server .UUID , asset ); err != nil {
308
- return errors .Wrap (ErrServerServiceQuery , "Server Component create/update error: " + err .Error ())
311
+ return errors .Wrap (model . ErrInventoryQuery , "Server Component create/update error: " + err .Error ())
309
312
}
310
313
311
314
return nil
@@ -345,7 +348,7 @@ func (r *Store) createUpdateServerComponents(ctx context.Context, serverID uuid.
345
348
// set span status
346
349
span .SetStatus (codes .Error , "GetComponents() failed" )
347
350
348
- return errors .Wrap (ErrServerServiceQuery , err .Error ())
351
+ return errors .Wrap (model . ErrInventoryQuery , err .Error ())
349
352
}
350
353
351
354
// For debugging and to capture test fixtures data.
@@ -372,7 +375,7 @@ func (r *Store) createUpdateServerComponents(ctx context.Context, serverID uuid.
372
375
// identify changes to be applied
373
376
add , update , remove , err := serverServiceChangeList (ctx , currentInventoryPtrSlice , newInventory )
374
377
if err != nil {
375
- return errors .Wrap (ErrServerServiceQuery , err .Error ())
378
+ return errors .Wrap (model . ErrInventoryQuery , err .Error ())
376
379
}
377
380
378
381
if len (add ) == 0 && len (update ) == 0 && len (remove ) == 0 {
@@ -409,7 +412,7 @@ func (r *Store) createUpdateServerComponents(ctx context.Context, serverID uuid.
409
412
// set span status
410
413
span .SetStatus (codes .Error , "CreateComponents() failed" )
411
414
412
- return errors .Wrap (ErrServerServiceQuery , "CreateComponents: " + err .Error ())
415
+ return errors .Wrap (model . ErrInventoryQuery , "CreateComponents: " + err .Error ())
413
416
}
414
417
}
415
418
@@ -433,7 +436,7 @@ func (r *Store) createUpdateServerComponents(ctx context.Context, serverID uuid.
433
436
// set span status
434
437
span .SetStatus (codes .Error , "UpdateComponents() failed" )
435
438
436
- return errors .Wrap (ErrServerServiceQuery , "UpdateComponents: " + err .Error ())
439
+ return errors .Wrap (model . ErrInventoryQuery , "UpdateComponents: " + err .Error ())
437
440
}
438
441
}
439
442
0 commit comments