diff --git a/pkg/common/constants.go b/pkg/common/constants.go index a1851652c622fb77509d28cbe5db6f43c070bbbe..64dcf10e09ab96f1445d032fd2249c7dedbf0ec3 100644 --- a/pkg/common/constants.go +++ b/pkg/common/constants.go @@ -161,6 +161,8 @@ const ( // GeneralMapSize general map size GeneralMapSize = 8 + // MapSizeTwo map size two + MapSizeTwo = 2 // GeneralSubscribeTime general subscribe try time GeneralSubscribeTime = 3 // Hex hexadecimal diff --git a/pkg/device/ascendcommon.go b/pkg/device/ascendcommon.go index c95bcaa4b0fe2565fead69def2f066f37ac80972..1e7d0a32078fbb484522deef2841c4474f6b1910 100644 --- a/pkg/device/ascendcommon.go +++ b/pkg/device/ascendcommon.go @@ -421,7 +421,7 @@ func (tool *AscendTools) groupDevsByStatus(subClassDevices []*common.NpuDevice, sets.String{}, sets.String{}, sets.String{}, sets.String{} deviceFaults := make([]common.DeviceFault, 0, common.GeneralMapSize) for _, device := range subClassDevices { - tool.updateDeviceFaults(device, deviceFaults) + deviceFaults = append(deviceFaults, tool.getDeviceFaults(device)...) if device.NetworkHealth == v1beta1.Unhealthy { totalNetworkUHDevices.Insert(device.DeviceName) } @@ -441,6 +441,7 @@ func (tool *AscendTools) groupDevsByStatus(subClassDevices []*common.NpuDevice, hwlog.RunLog.Debugf("total unhealthy devices %#v", totalUHDevices) hwlog.RunLog.Debugf("total network unhealthy devices %#v", totalNetworkUHDevices) hwlog.RunLog.Debugf("total recovering devices %#v", totalRCDevices) + hwlog.RunLog.Debugf("device fault list is %#v", deviceFaults) return common.DevStatusSet{ HealthDevices: healthDevice, UnHealthyDevice: totalUHDevices, @@ -450,8 +451,9 @@ func (tool *AscendTools) groupDevsByStatus(subClassDevices []*common.NpuDevice, } } -// updateDeviceFaults update device fault list -func (tool *AscendTools) updateDeviceFaults(device *common.NpuDevice, deviceFaults []common.DeviceFault) { +// getDeviceFaults get device fault list +func (tool *AscendTools) getDeviceFaults(device *common.NpuDevice) []common.DeviceFault { + deviceFaults := make([]common.DeviceFault, 0, common.MapSizeTwo) if len(device.NetworkFaultCodes) != 0 || device.NetworkHealth == v1beta1.Unhealthy { newCode := tool.removeDuplicateErr(append(device.NetworkFaultCodes, common.GetTimeoutFaultCodes(common.NetworkFaultMode)...)) @@ -472,6 +474,7 @@ func (tool *AscendTools) updateDeviceFaults(device *common.NpuDevice, deviceFaul FaultCode: strings.ToUpper(common.Int64Tool.ToHexString(newCode)), }) } + return deviceFaults } func (tool *AscendTools) removeDuplicateErr(faultCodes []int64) []int64 {