From f5510f3d1be8d5035f319a4bbb212e67cf7291e8 Mon Sep 17 00:00:00 2001 From: Ciaran Concannon Date: Thu, 25 Jul 2024 07:23:16 -0700 Subject: [PATCH] Restore fw_printenv command Summary: D60115096 introduced a potential bug whereby `fw_printenv` check is expecintg stdout from the previous command, which is now replaced by an `ls` command Restore the previous command and clearly differentiate between the two errors Test Plan: Unit tests ``` $ ./tools/flashy/scripts/run_unit_tests.sh ... ... ... 142/142 unit tests passed ``` Reviewed By: kawmarco Differential Revision: D60234128 fbshipit-source-id: 50ebd779d47082ca8487bbf53bb68d5db292c883 --- .../common/04_ensure_flash_available.go | 10 ++++- .../common/04_ensure_flash_available_test.go | 37 ++++++++++++++++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/tools/flashy/checks_and_remediations/common/04_ensure_flash_available.go b/tools/flashy/checks_and_remediations/common/04_ensure_flash_available.go index b6c2a7046bf1..a687e36a578f 100644 --- a/tools/flashy/checks_and_remediations/common/04_ensure_flash_available.go +++ b/tools/flashy/checks_and_remediations/common/04_ensure_flash_available.go @@ -79,12 +79,20 @@ func ensureFlashAvailable(stepParams step.StepParams) step.StepExitError { _, err, stdout, stderr = utils.RunCommand(cmd, 30*time.Second) if err != nil { errMsg := errors.Errorf( - "Broken flash chip? U-Boot environment is inaccessible." + + "Broken flash chip? Cannot see MTD chips on device." + " Error code: %v, stderr: %v", err, stderr) return step.ExitMissingMtd{Err: errMsg} } // Override mtdparts on next boot. + cmd = []string{"fw_printenv", "bootargs"} + _, err, stdout, stderr = utils.RunCommand(cmd, 30*time.Second) + if err != nil { + errMsg := errors.Errorf( + "Broken flash chip? U-Boot environment is inaccessible." + + " Error code: %v, stderr: %v", err, stderr) + return step.ExitBadFlashChip{Err: errMsg} + } bootargs := strings.Replace(strings.TrimSpace(stdout), "bootargs=", "", 1) log.Printf("Current bootargs: [%v]", bootargs) if !strings.Contains(stdout, bootargsAppend) { diff --git a/tools/flashy/checks_and_remediations/common/04_ensure_flash_available_test.go b/tools/flashy/checks_and_remediations/common/04_ensure_flash_available_test.go index 58afb2d18187..89d97effe183 100644 --- a/tools/flashy/checks_and_remediations/common/04_ensure_flash_available_test.go +++ b/tools/flashy/checks_and_remediations/common/04_ensure_flash_available_test.go @@ -50,10 +50,12 @@ func TestEnsureFlashAvailable(t *testing.T) { cases := []struct { name string vbootUtilExists bool - lfOpenBMC bool + lfOpenBMC bool failGrep bool + failLs bool failPrint bool failSet bool + lsOutput string printOutput string grepOutput string want step.StepExitError @@ -63,8 +65,10 @@ func TestEnsureFlashAvailable(t *testing.T) { vbootUtilExists: true, lfOpenBMC: false, failGrep: false, + failLs: false, failPrint: false, failSet: false, + lsOutput: "/dev/mtd1", printOutput: "derp", grepOutput: "foo", want: nil, @@ -74,8 +78,10 @@ func TestEnsureFlashAvailable(t *testing.T) { vbootUtilExists: false, lfOpenBMC: true, failGrep: false, + failLs: false, failPrint: false, failSet: false, + lsOutput: "/dev/mtd1", printOutput: "derp", grepOutput: "foo", want: nil, @@ -85,8 +91,10 @@ func TestEnsureFlashAvailable(t *testing.T) { vbootUtilExists: false, lfOpenBMC: false, failGrep: false, + failLs: false, failPrint: false, failSet: false, + lsOutput: "/dev/mtd1", printOutput: "bootargs=console=ttyS2,9600n8 root=/dev/ram rw", grepOutput: "mtd4: 02000000 00010000 \"flash0\"", want: nil, @@ -96,8 +104,10 @@ func TestEnsureFlashAvailable(t *testing.T) { vbootUtilExists: false, lfOpenBMC: false, failGrep: true, + failLs: false, failPrint: false, failSet: false, + lsOutput: "/dev/mtd1", printOutput: "bootargs=console=ttyS2,9600n8 root=/dev/ram rw", grepOutput: "", want: step.ExitMustReboot{Err: errors.Errorf("Forcing reboot for new bootargs to take effect")}, @@ -107,19 +117,36 @@ func TestEnsureFlashAvailable(t *testing.T) { vbootUtilExists: false, lfOpenBMC: false, failGrep: false, + failLs: true, + failPrint: false, + failSet: false, + lsOutput: "Cannot access MTD device /dev/mtd1: No such file or directory", + printOutput: "", + grepOutput: "", + want: step.ExitMissingMtd{Err: errors.Errorf("Broken flash chip? Cannot see MTD chips on device. Error code: err1, stderr: Cannot access MTD device /dev/mtd1: No such file or directory")}, + }, + { + name: "fw_printenv broken", + vbootUtilExists: false, + lfOpenBMC: false, + failGrep: false, + failLs: false, failPrint: true, failSet: false, + lsOutput: "/dev/mtd1", printOutput: "Cannot access MTD device /dev/mtd1: No such file or directory", grepOutput: "", - want: step.ExitMissingMtd{Err: errors.Errorf("Broken flash chip? U-Boot environment is inaccessible. Error code: err1, stderr: Cannot access MTD device /dev/mtd1: No such file or directory")}, + want: step.ExitBadFlashChip{Err: errors.Errorf("Broken flash chip? U-Boot environment is inaccessible. Error code: err1, stderr: Cannot access MTD device /dev/mtd1: No such file or directory")}, }, { name: "fw_setenv broken", vbootUtilExists: false, lfOpenBMC: false, failGrep: false, + failLs: false, failPrint: false, failSet: true, + lsOutput: "/dev/mtd1", printOutput: "bootargs=console=ttyS2,9600n8 root=/dev/ram rw", grepOutput: "", want: nil, @@ -139,6 +166,12 @@ func TestEnsureFlashAvailable(t *testing.T) { return 0, nil, tc.grepOutput, "" } } else if (cmdArr[0] == "ls") { + if (tc.failLs) { + return 1, errors.Errorf("err1"), "", tc.lsOutput + } else { + return 0, nil, "", tc.lsOutput + } + } else if (cmdArr[0] == "fw_printenv") { if (tc.failPrint) { return 1, errors.Errorf("err1"), "", tc.printOutput } else {