Skip to content

Commit

Permalink
ELBERT: REST: Add firmware_info endpoint (#81)
Browse files Browse the repository at this point in the history
Summary:
ELBERT: REST: Add firmware_info endpoint

Testing:
root@bmc-oob:~# curl -s http://localhost:8080/api/sys/firmware_info/all
{"SCM": "1.11", "FAN": "1.1", "SMB": "1.15", "SMB_CPLD": "4.1", "PIM 2":
"NOT", "PIM 3": "4.2", "PIM 4": "4.2", "PIM 5": "NOT", "PIM 6": "NOT",
"PIM 7": "NOT", "PIM 8": "NOT", "PIM 9": "NOT"}

Pull Request resolved: facebookexternal/openbmc.arista#81

Reviewed By: mikechoifb

fbshipit-source-id: 7b3603cbd2
  • Loading branch information
joancaneus authored and facebook-github-bot committed Sep 24, 2020
1 parent 3c152e0 commit e2943f3
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import re

# import rest_fw_ver
import rest_fw_ver
import rest_fruid_scm
import rest_peutil
import rest_pim_present
Expand Down Expand Up @@ -70,3 +70,7 @@ async def rest_pim_present_hdl(self, request):
# Handler for sys/smb_info resource endpoint (version)
async def rest_smbinfo_hdl(self, request):
return web.json_response(rest_smbinfo.get_smbinfo())

async def rest_firmware_info_all_hdl(self, request):
fws = await rest_fw_ver.get_all_fw_ver()
return web.json_response(fws, dumps=dumps_bytestr)
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ def setup_board_routes(app: Application, write_enabled: bool):
app.router.add_get(board_routes[12], bhandler.rest_pimstatus_hdl)
app.router.add_get(board_routes[13], bhandler.rest_pim_present_hdl)
app.router.add_get(board_routes[14], bhandler.rest_smbinfo_hdl)
app.router.add_get(board_routes[15], bhandler.rest_firmware_info_all_hdl)
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
"/api/sys/pimstatus",
"/api/sys/pim_present",
"/api/sys/smbinfo",
"/api/sys/firmware_info/all",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env python3
#
# Copyright 2020-present Facebook. All Rights Reserved.
#
# This program file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program in a file named COPYING; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#

import re
import subprocess
from asyncio.subprocess import PIPE, create_subprocess_exec
from typing import Dict

from rest_utils import DEFAULT_TIMEOUT_SEC


def _parse_all_fpga_ver(data) -> Dict:
"""Example output:
------SCM-FPGA------
SCM_FPGA: 1.11
------FAN-FPGA------
FAN_FPGA: 1.1
------SMB-FPGA------
SMB_FPGA: 1.15
------SMB-CPLD------
SMB_CPLD: 4.1
------PIM-FPGA------
PIM 2: 4.2
PIM 3: 4.2
PIM 4: 4.2
PIM 5: 4.2
PIM 6: 4.2
PIM 7: 4.2
PIM 8: 4.2
PIM 9: 4.2
Will return a dict of the form:
{"PIM 2": "4.2",
"PIM 3": "4.2",
"PIM 4": "4.2",
...
"SCM": "1.11",
"SMB": "14.4"}
"""
rs = {}
pim = 0
pim_rx = re.compile("^PIM ([2-9])\s*:\s*(\S+)")
fpga_rx = re.compile("([a-zA-Z]+)[_ ]FPGA\s*:\s*(\S+)")
cpld_rx = re.compile("([a-zA-Z]+_CPLD)\s*:\s*(\S+)")
for l in data.splitlines():
m = pim_rx.match(l)
if m:
pim = m.group(1)
rs["PIM " + pim] = m.group(2)
continue
m = fpga_rx.match(l)
if m:
rs[m.group(1)] = m.group(2)
continue
m = cpld_rx.match(l)
if m:
rs[m.group(1)] = m.group(2)

return rs


async def get_all_fw_ver() -> Dict:
cmd = "/usr/local/bin/fpga_ver.sh"
proc = await create_subprocess_exec(cmd, stdout=PIPE)
data, _ = await proc.communicate()
await proc.wait()
return _parse_all_fpga_ver(data.decode(errors="ignore"))
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ SRC_URI += " \
file://rest_pimserial.py \
file://rest_pimstatus.py \
file://rest_smbinfo.py \
file://rest_fw_ver.py \
"

binfiles1 += " \
Expand All @@ -38,4 +39,5 @@ binfiles1 += " \
rest_pimserial.py \
rest_pimstatus.py \
rest_smbinfo.py \
rest_fw_ver.py \
"

0 comments on commit e2943f3

Please sign in to comment.