Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mellanox] Improve FW upgrade logging #13465

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions platform/mellanox/mlnx-fw-upgrade.j2
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ declare -rA FW_FILE_MAP=( \
)

IMAGE_UPGRADE="${NO_PARAM}"
SYSLOG_LOGGER="${NO_PARAM}"
VERBOSE_LEVEL="${VERBOSE_MIN}"

function PrintHelp() {
Expand All @@ -48,7 +49,8 @@ function PrintHelp() {
echo
echo "OPTIONS:"
echo " -u, --upgrade Upgrade ASIC firmware using next boot image (useful after SONiC-To-SONiC update)"
echo " -v, --verbose Verbose mode"
echo " -s, --syslog Use syslog logger (enabled when -u|--upgrade)"
echo " -v, --verbose Verbose mode (enabled when -u|--upgrade)"
echo " -h, --help Print help"
echo
echo "Examples:"
Expand All @@ -63,10 +65,14 @@ function ParseArguments() {
case "$1" in
-u|--upgrade)
IMAGE_UPGRADE="${YES_PARAM}"
SYSLOG_LOGGER="${YES_PARAM}"
;;
-v|--verbose)
VERBOSE_LEVEL="${VERBOSE_MAX}"
;;
-s|--syslog)
SYSLOG_LOGGER="${YES_PARAM}"
;;
-h|--help)
PrintHelp
exit "${EXIT_SUCCESS}"
Expand All @@ -79,25 +85,42 @@ function ParseArguments() {
function LogError() {
if [[ "${VERBOSE_LEVEL}" -ge "${VERBOSE_ERROR}" ]]; then
echo "ERROR: $*"
logger -p "ERROR" -t "${SCRIPT_NAME}" "$*"
fi

if [[ "${SYSLOG_LOGGER}" = "${YES_PARAM}" ]]; then
logger -p "ERROR" -t "${SCRIPT_NAME}" "$*"
fi
}

function LogWarning() {
if [[ "${VERBOSE_LEVEL}" -ge "${VERBOSE_WARNING}" ]]; then
echo "WARNING: $*"
fi

if [[ "${SYSLOG_LOGGER}" = "${YES_PARAM}" ]]; then
logger -p "WARNING" -t "${SCRIPT_NAME}" "$*"
fi
}

function LogNotice() {
if [[ "${VERBOSE_LEVEL}" -ge "${VERBOSE_NOTICE}" ]]; then
echo "NOTICE: $*"
fi

if [[ "${SYSLOG_LOGGER}" = "${YES_PARAM}" ]]; then
logger -p "NOTICE" -t "${SCRIPT_NAME}" "$*"
fi
}

function LogInfo() {
if [[ "${VERBOSE_LEVEL}" -ge "${VERBOSE_INFO}" ]]; then
echo "INFO: $*"
fi

if [[ "${SYSLOG_LOGGER}" = "${YES_PARAM}" ]]; then
logger -p "INFO" -t "${SCRIPT_NAME}" "$*"
fi
}

function ExitFailure() {
Expand Down Expand Up @@ -186,6 +209,23 @@ function RunCmd() {
fi
}

function RunFwUpdateCmd() {
local ERROR_CODE="${EXIT_SUCCESS}"
local COMMAND="${BURN_CMD} $@"

if [[ "${VERBOSE_LEVEL}" -eq "${VERBOSE_MAX}" ]]; then
output=$(eval "${COMMAND}")
else
output=$(eval "${COMMAND}") >/dev/null 2>&1
fi

ERROR_CODE="$?"
if [[ "${ERROR_CODE}" != "${EXIT_SUCCESS}" ]]; then
failure_msg="${output#*Fail : }"
ExitFailure "FW Update command: ${COMMAND} failed with error: ${failure_msg}"
fi
}

function UpgradeFW() {
local -r _FS_MOUNTPOINT="$1"

Expand Down Expand Up @@ -229,9 +269,9 @@ function UpgradeFW() {
local -r _MST_DEVICE="$(GetMstDevice)"
if [[ "${_MST_DEVICE}" = "${UNKN_MST}" ]]; then
LogWarning "could not find fastest mst device, using default device"
RunCmd "${BURN_CMD} -i ${_FW_FILE}"
RunFwUpdateCmd "-i ${_FW_FILE}"
else
RunCmd "${BURN_CMD} -d ${_MST_DEVICE} -i ${_FW_FILE}"
RunFwUpdateCmd "-d ${_MST_DEVICE} -i ${_FW_FILE}"
fi
fi
}
Expand Down