Skip to content

Commit

Permalink
seutil time out fix
Browse files Browse the repository at this point in the history
Summary:
Endpoint seutil which call weutil sup sometimes time out due to
the fact that it takes quite some time for flashrom to read the content
of the flash. Therefore, we are caching this content and changing the
rest-api logic to read from it which would solve that issue

Test Plan: See this paste P144881106

Reviewed By: mikechoifb

fbshipit-source-id: de1f6b40b4
  • Loading branch information
joancaneus authored and facebook-github-bot committed Oct 9, 2020
1 parent 58376b8 commit 10c9a8b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
#
# 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
#

weutil SUP > /tmp/sup_weutil.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ SRC_URI += "file://bios_util.sh \
file://scdinfo \
file://psu_show_tech.py \
file://show_tech.py \
file://sup_eeprom.sh \
"

OPENBMC_UTILS_FILES += " \
Expand Down Expand Up @@ -85,13 +86,16 @@ do_install_board() {
# derivied from the correct MAC address.
install -m 755 eth0_mac_fixup.sh ${D}${sysconfdir}/init.d/eth0_mac_fixup.sh
update-rc.d -r ${D} eth0_mac_fixup.sh start 2 2 3 4 5 .

install -m 755 setup_board.sh ${D}${sysconfdir}/init.d/setup_board.sh
update-rc.d -r ${D} setup_board.sh start 80 S .

install -m 755 power-on.sh ${D}${sysconfdir}/init.d/power-on.sh
update-rc.d -r ${D} power-on.sh start 85 S .

install -m 755 sup_eeprom.sh ${D}${sysconfdir}/init.d/sup_eeprom.sh
update-rc.d -r ${D} sup_eeprom.sh start 90 2 3 4 5 .

install -m 0755 ${WORKDIR}/rc.local ${D}${sysconfdir}/init.d/rc.local
update-rc.d -r ${D} rc.local start 99 2 3 4 5 .

Expand Down
37 changes: 18 additions & 19 deletions meta-facebook/meta-yamp/recipes-utils/rest-api/files/rest_seutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,31 @@
# Boston, MA 02110-1301 USA
#

import subprocess
import os
from typing import Dict

from rest_utils import DEFAULT_TIMEOUT_SEC

PATH = "/tmp/sup_weutil.txt"


# Handler for seutil resource endpoint
def get_seutil() -> Dict:
return {"Information": get_seutil_data(), "Actions": [], "Resources": []}


def _parse_seutil_data(data) -> Dict:
result = {}
# need to remove the first info line from seutil
adata = data.split("\n", 1)
for sdata in adata[1].split("\n"):
tdata = sdata.split(":", 1)
if len(tdata) < 2:
continue
result[tdata[0].strip()] = tdata[1].strip()
return result


def get_seutil_data() -> Dict:
cmd = ["/usr/local/bin/seutil"]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
data, _ = proc.communicate(timeout=DEFAULT_TIMEOUT_SEC)
data = data.decode(errors="ignore")
return _parse_seutil_data(data)
result = {}
if not os.path.exists(PATH):
raise Exception("Path for sup_weutil doesn't exist")
with open(PATH, "r") as fp:
# start reading after lines 8
lines = fp.readlines()[8:]
if lines:
for line in lines:
tdata = line.split(":", 1)
if len(tdata) < 2:
continue
result[tdata[0].strip()] = tdata[1].strip()
else:
raise Exception("sup_weutil file is empty")
return result

0 comments on commit 10c9a8b

Please sign in to comment.