From 10c9a8b8fe59a511375d84bc70a0d6c88af2cf14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Olguy=20Can=C3=A9us?= Date: Fri, 9 Oct 2020 12:54:57 -0700 Subject: [PATCH] seutil time out fix 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 --- .../openbmc-utils/files/sup_eeprom.sh | 21 +++++++++++ .../openbmc-utils/openbmc-utils_%.bbappend | 6 ++- .../rest-api/files/rest_seutil.py | 37 +++++++++---------- 3 files changed, 44 insertions(+), 20 deletions(-) create mode 100644 meta-facebook/meta-yamp/recipes-utils/openbmc-utils/files/sup_eeprom.sh diff --git a/meta-facebook/meta-yamp/recipes-utils/openbmc-utils/files/sup_eeprom.sh b/meta-facebook/meta-yamp/recipes-utils/openbmc-utils/files/sup_eeprom.sh new file mode 100644 index 000000000000..f99b2870bf3e --- /dev/null +++ b/meta-facebook/meta-yamp/recipes-utils/openbmc-utils/files/sup_eeprom.sh @@ -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 diff --git a/meta-facebook/meta-yamp/recipes-utils/openbmc-utils/openbmc-utils_%.bbappend b/meta-facebook/meta-yamp/recipes-utils/openbmc-utils/openbmc-utils_%.bbappend index 65fe30c4b8b5..1481bbb0197b 100644 --- a/meta-facebook/meta-yamp/recipes-utils/openbmc-utils/openbmc-utils_%.bbappend +++ b/meta-facebook/meta-yamp/recipes-utils/openbmc-utils/openbmc-utils_%.bbappend @@ -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 += " \ @@ -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 . diff --git a/meta-facebook/meta-yamp/recipes-utils/rest-api/files/rest_seutil.py b/meta-facebook/meta-yamp/recipes-utils/rest-api/files/rest_seutil.py index cfa99ffbda4b..f10ba52ebe88 100644 --- a/meta-facebook/meta-yamp/recipes-utils/rest-api/files/rest_seutil.py +++ b/meta-facebook/meta-yamp/recipes-utils/rest-api/files/rest_seutil.py @@ -18,10 +18,11 @@ # 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 @@ -29,21 +30,19 @@ 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