Skip to content

Commit 87c3594

Browse files
cjcon90facebook-github-bot
authored andcommitted
Fix missing MTD error handling - add specific error
Summary: Currently, upgrades that fail because of a blank /proc/mtd are being classed as `UNSAFE_TO_REBOOT` errors. This is because to classify as a `BAD_FLASH_CHIP` error, Flashy is grepping for the particular string *'Cannot access MTD device'* whereas the error on the BMC is returning: ``` root@rsw006-oob:~# cat /proc/mtd dev: size erasesize name root@rsw006-oob:~# fw_printenv bootargs Cannot open /dev/mtd1: No such file or directory ``` Let's fix this by skipping the string grepping logic completely, as we already know that we cannot see MTD at this stage Also added as separate error class, as missing MTD is a specific issue that we see quite frequently and good to classify it separately Test Plan: Unit tests ``` $ ./tools/flashy/scripts/run_unit_tests.sh ... ... ... 142/142 unit tests passed ``` --- Will handle exceptions in oobgrader and test in following diff Reviewed By: doranand Differential Revision: D60115096 fbshipit-source-id: 77e0cb6aa18fdb71e4c711d3951c7282aab23b6a
1 parent c4871cf commit 87c3594

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

tools/flashy/checks_and_remediations/common/04_ensure_flash_available.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,13 @@ func ensureFlashAvailable(stepParams step.StepParams) step.StepExitError {
7575
}
7676

7777
// Check for mtdparts aleady being set.
78-
cmd = []string{"fw_printenv", "bootargs"}
78+
cmd = []string{"ls", "/dev/mtd*"}
7979
_, err, stdout, stderr = utils.RunCommand(cmd, 30*time.Second)
8080
if err != nil {
81-
if strings.Contains(stderr, "Cannot access MTD device") {
82-
errMsg := errors.Errorf(
83-
"U-Boot environment is inaccessible: broken flash chip?" +
84-
" Error code: %v, stderr: %v", err, stderr)
85-
return step.ExitBadFlashChip{Err: errMsg}
86-
}
87-
log.Printf("fw_printenv doesn't work: %v, stderr: %v", err, stderr)
88-
return nil
81+
errMsg := errors.Errorf(
82+
"Broken flash chip? U-Boot environment is inaccessible." +
83+
" Error code: %v, stderr: %v", err, stderr)
84+
return step.ExitMissingMtd{Err: errMsg}
8985
}
9086

9187
// Override mtdparts on next boot.

tools/flashy/checks_and_remediations/common/04_ensure_flash_available_test.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,15 @@ func TestEnsureFlashAvailable(t *testing.T) {
103103
want: step.ExitMustReboot{Err: errors.Errorf("Forcing reboot for new bootargs to take effect")},
104104
},
105105
{
106-
name: "fw_printenv broken because reasons",
107-
vbootUtilExists: false,
108-
lfOpenBMC: false,
109-
failGrep: false,
110-
failPrint: true,
111-
failSet: false,
112-
printOutput: "",
113-
grepOutput: "",
114-
want: nil,
115-
},
116-
{
117-
name: "fw_printenv broken because missing flash",
106+
name: "missing flash",
118107
vbootUtilExists: false,
119108
lfOpenBMC: false,
120109
failGrep: false,
121110
failPrint: true,
122111
failSet: false,
123112
printOutput: "Cannot access MTD device /dev/mtd1: No such file or directory",
124113
grepOutput: "",
125-
want: step.ExitBadFlashChip{Err: errors.Errorf("U-Boot environment is inaccessible: broken flash chip? Error code: err1, stderr: Cannot access MTD device /dev/mtd1: No such file or directory")},
114+
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")},
126115
},
127116
{
128117
name: "fw_setenv broken",
@@ -149,7 +138,7 @@ func TestEnsureFlashAvailable(t *testing.T) {
149138
} else {
150139
return 0, nil, tc.grepOutput, ""
151140
}
152-
} else if (cmdArr[0] == "fw_printenv") {
141+
} else if (cmdArr[0] == "ls") {
153142
if (tc.failPrint) {
154143
return 1, errors.Errorf("err1"), "", tc.printOutput
155144
} else {

tools/flashy/lib/step/error.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const (
3636
FLASHY_ERROR_SAFE_TO_REBOOT = 42
3737
FLASHY_ERROR_UNSAFE_TO_REBOOT = 52
3838
FLASHY_ERROR_BROKEN_SYSTEM = 53
39+
FLASHY_ERROR_MISSING_MTD = 54
3940
)
4041

4142
type StepExitError interface {
@@ -56,6 +57,10 @@ type ExitBadFlashChip struct {
5657
Err error
5758
}
5859

60+
type ExitMissingMtd struct {
61+
Err error
62+
}
63+
5964
type ExitMustReboot struct {
6065
Err error
6166
}
@@ -100,6 +105,18 @@ func (e ExitBadFlashChip) GetType() string {
100105
return "ExitBadFlashChip"
101106
}
102107

108+
func (e ExitMissingMtd) GetError() string {
109+
return e.Err.Error()
110+
}
111+
112+
func (e ExitMissingMtd) GetExitCode() int {
113+
return FLASHY_ERROR_MISSING_MTD
114+
}
115+
116+
func (e ExitMissingMtd) GetType() string {
117+
return "ExitMissingMtd"
118+
}
119+
103120
func (e ExitMustReboot) GetError() string {
104121
return e.Err.Error()
105122
}
@@ -157,6 +174,7 @@ func HandleStepError(err StepExitError) {
157174
case ExitUnsafeToReboot,
158175
ExitUnknownError,
159176
ExitBadFlashChip,
177+
ExitMissingMtd,
160178
ExitMustReboot:
161179

162180
encodeExitError(err)

0 commit comments

Comments
 (0)