Skip to content

Commit ef78c7d

Browse files
ssinpremmeta-codesync[bot]
authored andcommitted
common: restapi : fix bug at endpoint /api/fw_versions
Summary: # Description - import and use Tuple insteads tuple in rest_fw_versions.py - get `bash` real path insteads fixing in source code # Motivation Fix bug the restapi failed on start ``` root@bmc-oob:~# rest.py Traceback (most recent call last): File "/usr/local/bin/rest.py", line 38, in <module> from setup_plat_routes import setup_plat_routes File "/usr/local/fbpackages/rest-api/setup_plat_routes.py", line 23, in <module> from board_setup_routes import setup_board_routes File "/usr/local/fbpackages/rest-api/board_setup_routes.py", line 22, in <module> from board_endpoint import boardApp_Handler File "/usr/local/fbpackages/rest-api/board_endpoint.py", line 26, in <module> import rest_fw_versions File "/usr/local/fbpackages/rest-api/rest_fw_versions.py", line 50, in <module> def _run_command(cmd: str) -> tuple[str, str]: TypeError: 'type' object is not subscriptable ``` fix bug `/usr/local/bash` path not found ``` root@bmc-oob:~# curl http://localhost:8080/api/fw_versions | python -m json.tool { "Information": { "firmware_versions": { "bic": "", "bios": "", "fcm": "", "fpga": "", "pwr": "", "scm": "", "smb": "" }, "firmware_string": "bic:,bios:,fcm:,fpga:,pwr:,scm:,smb:", "firmware_hash": "369bbdb4c097", "errors": { "bic": "Command exception: /usr/bin/fw-util scm --version |grep Bri|grep -v Boot| cut -d ' ' -f 3 - FileNotFoundError(2, 'No such file or directory')", "bios": "Command exception: /usr/bin/fw-util scm --version |grep BIOS| cut -d ' ' -f 3 - FileNotFoundError(2, 'No such file or directory')", "fcm": "Command exception: /usr/local/bin/cpld_ver.sh |grep FCM|cut -d ' ' -f 2 - FileNotFoundError(2, 'No such file or directory')", "fpga": "Command exception: /usr/local/bin/fpga_ver.sh |grep FPGA|head -1|cut -d ' ' -f 2 - FileNotFoundError(2, 'No such file or directory')", "pwr": "Command exception: /usr/local/bin/cpld_ver.sh |grep PWR|cut -d ' ' -f 2 - FileNotFoundError(2, 'No such file or directory')", "scm": "Command exception: /usr/local/bin/cpld_ver.sh |grep SCM|cut -d ' ' -f 2 - FileNotFoundError(2, 'No such file or directory')", "smb": "Command exception: /usr/local/bin/cpld_ver.sh |grep SYSCPLD|cut -d ' ' -f 2 - FileNotFoundError(2, 'No such file or directory')" } }, "Actions": [], "Resources": [] } ``` X-link: https://github.com/facebookexternal/openbmc.celestica/pull/1903 Test Plan: Test on wedge400 ``` root@bmc-oob:~# curl http://localhost:8080/api/sys {"Information": {"Description": "Wedge System"}, "Actions": [], "Resources": ["bmc", "board_revision", "fc_present", "feutil", "firmware_info", "fscd_sensor_data", "gb_freq", "gpios", "mb", "modbus", "modbus_registers", "ntp", "optics_thermal", "presence", "psu_update", "sensors", "server", "seutil", "switch_reset", "vddcore"]} ``` ``` root@bmc-oob:~# curl http://localhost:8080/api/fw_versions | python -m json.tool { "Information": { "firmware_versions": { "bic": "1.15", "bios": "XG1_3A12", "fcm": "4.2", "fpga": "0.56", "pwr": "2.4", "scm": "4.0", "smb": "2.5" }, "firmware_string": "bic:1.15,bios:XG1_3A12,fcm:4.2,fpga:0.56,pwr:2.4,scm:4.0,smb:2.5", "firmware_hash": "a45435f67303", "errors": {} }, "Actions": [], "Resources": [] } root@bmc-oob:~# ``` Reviewed By: binhuang00 Differential Revision: D90559411 Pulled By: ezeob002 fbshipit-source-id: faa33f2216446e5ed2708d65e23f78e62fc0df58
1 parent 5ba1f45 commit ef78c7d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

common/recipes-rest/rest-api/files/rest_fw_versions.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
import hashlib
2222
import json
2323
import re
24+
import shutil
2425
import subprocess
25-
from typing import Dict
26+
from typing import Dict, Tuple
2627

2728
from aiohttp.web_exceptions import HTTPNotFound
2829
from rest_utils import DEFAULT_TIMEOUT_SEC
2930

31+
_BASH_PATH = shutil.which("bash")
3032
_REGEX_VERSION_PATTERN = r"^[v]?([0-9]*)\.([0-9]*)$"
3133
_MANIFEST_FILE = "/etc/ufw_manifest.json"
3234

@@ -47,13 +49,15 @@ def _normalize_version(version: str) -> str:
4749
return version
4850

4951

50-
def _run_command(cmd: str) -> tuple[str, str]:
52+
def _run_command(cmd: str) -> Tuple[str, str]:
5153
"""
5254
Run a shell command and return (stdout, error_message).
5355
"""
5456
try:
57+
if not _BASH_PATH:
58+
return "", "bash executable not found"
5559
proc = subprocess.Popen(
56-
["/usr/bin/bash", "-o", "pipefail", "-c", cmd],
60+
[_BASH_PATH, "-o", "pipefail", "-c", cmd],
5761
stdout=subprocess.PIPE,
5862
stderr=subprocess.PIPE,
5963
)
@@ -87,7 +91,7 @@ def _check_condition(condition: str, entity: str) -> bool:
8791
return proc.returncode == 0
8892

8993

90-
def _get_firmware_versions() -> tuple[Dict[str, str], Dict[str, str]]:
94+
def _get_firmware_versions() -> Tuple[Dict[str, str], Dict[str, str]]:
9195
"""
9296
Get all firmware versions and return as tuple of dicts.
9397
fw_key: version, fw_key: error (if applicable)

0 commit comments

Comments
 (0)