已开启
新增支持 长城crps 电源适配 #1506
iss_renping创建于 11 天前
新增支持 长城crps 电源适配 #1506
已开启
iss_renping创建于 11 天前
3 个文件变更+29-9
@@ -1,5 +1,8 @@
1# Changelog1# Changelog
2All notable changes to this project will be documented in this file.2All notable changes to this project will be documented in this file.
3+## [1.110.129] 2026-08-26
4+新增支持 长城crps 电源适配
5+ 
3## [1.110.128] 2026-08-266## [1.110.128] 2026-08-26
4能效裁剪webrest接口7能效裁剪webrest接口
5 8 
@@ -169,15 +169,15 @@ local function get_component_info(input)
169 for k = 1, #input[3] do169 for k = 1, #input[3] do
170 table.insert(slots, string.byte(input[3], k))170 table.insert(slots, string.byte(input[3], k))
171 end171 end
172- 172+
openUBMC-robot

⚠️ 警告:空行被改成了「含一个空格的行」,引入了行尾空格

本次 diff 把 get_component_info / get_psu_cnt_and_slot 中的多处空行从完全空行改成带单个空格的行(-+ )。当前新版本文件中约 172、175、180、190、193 行均存在行尾空格。

影响

  • 仓库 pre-commit 已配置 trailing-whitespace 钩子(见 CONTRIBUTING.md),此类行尾空格会在提交/检查时被标记或自动修复,与本仓库代码规范不符。

修复建议: 将该批 + 行恢复为真正的空行(去掉末尾空格),避免引入行尾空白。

likedislike
173 return count, slots173 return count, slots
174end174end
175- 175+
176local function get_psu_cnt_and_slot(input)176local function get_psu_cnt_and_slot(input)
177 local psu_cnt = 0177 local psu_cnt = 0
178 local psu_slots = {}178 local psu_slots = {}
179 local psu_board_slots = {}179 local psu_board_slots = {}
180- 180+
181 for i = 1, #input do181 for i = 1, #input do
182 for j = 1, #input[i] do182 for j = 1, #input[i] do
183 if input[i][j][1] == 'Psu' then183 if input[i][j][1] == 'Psu' then
@@ -187,10 +187,10 @@ local function get_psu_cnt_and_slot(input)
187 end187 end
188 end188 end
189 end189 end
190- 190+
191 return psu_cnt, psu_slots, psu_board_slots191 return psu_cnt, psu_slots, psu_board_slots
192end192end
193- 193+
194function m.get_supply_list(input)194function m.get_supply_list(input)
195 local supply_list = cjson.json_object_new_array()195 local supply_list = cjson.json_object_new_array()
196 local supply_paths =196 local supply_paths =
@@ -209,8 +209,25 @@ function m.get_supply_list(input)
209 209 
210 local psu_cnt, psu_slots, psu_board_slots = get_psu_cnt_and_slot(input)210 local psu_cnt, psu_slots, psu_board_slots = get_psu_cnt_and_slot(input)
211 211 
212- for i = 1, psu_cnt do212+ -- 合并 psu_slots psu_board_slots,去重排序,用实际槽位号遍历
213- local powerName = string.format('PSU%d', i)213+ local slot_set = {}
214+ local all_slots = {}
215+ for _, slot in ipairs(psu_slots) do
216+ if not slot_set[slot] then
217+ slot_set[slot] = true
218+ all_slots[#all_slots + 1] = slot
219+ end
220+ end
221+ for _, slot in ipairs(psu_board_slots) do
222+ if not slot_set[slot] then
223+ slot_set[slot] = true
224+ all_slots[#all_slots + 1] = slot
225+ end
226+ end
227+ table.sort(all_slots)
228+ 
229+ for _, slot in ipairs(all_slots) do
openUBMC-robot

⚠️ 警告:psu_cnt 已变为未使用变量,且槽位列表全部为空时会把已发现的真实 PSU 一并丢弃

改为按 all_slots(合并去重后的实际槽位)遍历后,第 210 行 get_psu_cnt_and_slot(input) 返回的 psu_cnt 在调用方已不再使用(luacheck 也会报 unused local),get_psu_cnt_and_slot 内部仍统计该值,属于遗留死变量。

更需要注意的行为回退:若 psu_slotspsu_board_slots 均为空(例如 get_component_infoinput[3] 槽位字节串为空)而 psu_cnt > 0,则 all_slots 为空、本循环不会执行,psu_map / psu_metrics_map 中已发现的真实 PSU(如 psu_map['PSU1'])将不再输出到 supply_list;而旧代码以 1..psu_cnt 为界遍历,这些真实 PSU 仍会被渲染。这会导致 PSU 信息在槽位枚举数据缺失时静默丢失。

修复建议: 在 all_slots 为空且 psu_cnt > 0 时回退按 1..psu_cnt 兜底遍历(仍复用上面的按槽位命名逻辑),或删除不再使用的 psu_cnt 并以真实槽位遍历为主、增加空列表兜底,确保槽位数据缺失时已有真实 PSU 不被丢弃。

likedislike
230+ local powerName = string.format('PSU%d', slot)
214 if psu_map[powerName] and psu_metrics_map[powerName] then231 if psu_map[powerName] and psu_metrics_map[powerName] then
215 local supply = cjson.json_object_new_object()232 local supply = cjson.json_object_new_object()
216 local is_abnormal = psu_status_map[powerName] ~= nil and psu_status_map[powerName].CommunicationStatus == 1233 local is_abnormal = psu_status_map[powerName] ~= nil and psu_status_map[powerName].CommunicationStatus == 1
@@ -232,7 +249,7 @@ function m.get_supply_list(input)
232 supply.Presence = psu_map[powerName].Presence249 supply.Presence = psu_map[powerName].Presence
233 supply.Position = psu_map[powerName].Position250 supply.Position = psu_map[powerName].Position
234 supply_list[#supply_list + 1] = supply251 supply_list[#supply_list + 1] = supply
235- elseif is_include(psu_slots, i) or is_include(psu_board_slots, i) then252+ else
236 supply_list[#supply_list + 1] = get_defult_psu(powerName)253 supply_list[#supply_list + 1] = get_defult_psu(powerName)
237 end254 end
238 end255 end
@@ -1,7 +1,7 @@
1{1{
2 "name": "rackmount",2 "name": "rackmount",
3 "type": "configuration",3 "type": "configuration",
4- "version": "1.110.128",4+ "version": "1.110.129",
5 "author": "Huawei",5 "author": "Huawei",
6 "license": "Mulan PSL v2",6 "license": "Mulan PSL v2",
7 "options": {7 "options": {