-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: - the format of /etc/issue is slightly unusual - refuse to upgrade anything older than v2023.07.1 (bricks the BMC) Test Plan: ``` 0 ~/local/openbmc/tools/flashy $ ./build.sh && ./build_dev.sh && go test ./... ok github.com/facebook/openbmc/tools/flashy 3.117s ok github.com/facebook/openbmc/tools/flashy/checks_and_remediations/bletchley (cached) ok github.com/facebook/openbmc/tools/flashy/checks_and_remediations/common (cached) ok github.com/facebook/openbmc/tools/flashy/checks_and_remediations/galaxy100 (cached) ok github.com/facebook/openbmc/tools/flashy/checks_and_remediations/wedge100 (cached) ok github.com/facebook/openbmc/tools/flashy/checks_and_remediations/yamp (cached) ? github.com/facebook/openbmc/tools/flashy/flash_procedure [no test files] ok github.com/facebook/openbmc/tools/flashy/install 0.005s ok github.com/facebook/openbmc/tools/flashy/lib/fileutils (cached) ok github.com/facebook/openbmc/tools/flashy/lib/flash (cached) ok github.com/facebook/openbmc/tools/flashy/lib/flash/flashcp (cached) ok github.com/facebook/openbmc/tools/flashy/lib/flash/flashutils (cached) ok github.com/facebook/openbmc/tools/flashy/lib/flash/flashutils/devices (cached) ? github.com/facebook/openbmc/tools/flashy/lib/logger [no test files] ok github.com/facebook/openbmc/tools/flashy/lib/step (cached) ok github.com/facebook/openbmc/tools/flashy/lib/utils (cached) ok github.com/facebook/openbmc/tools/flashy/lib/validate (cached) ok github.com/facebook/openbmc/tools/flashy/lib/validate/image (cached) ok github.com/facebook/openbmc/tools/flashy/lib/validate/partition (cached) ? github.com/facebook/openbmc/tools/flashy/tests [no test files] ? github.com/facebook/openbmc/tools/flashy/utilities [no test files] 0 ~/local/openbmc/tools/flashy $ echo $? 0 ``` Reviewed By: williamspatrick Differential Revision: D45050113 fbshipit-source-id: 5625c2da100ea562c4ce70925dd3a7c9c8cf3aae
- Loading branch information
1 parent
8d3b722
commit 45fe1cf
Showing
5 changed files
with
174 additions
and
9 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
tools/flashy/checks_and_remediations/bletchley/00_check_version.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
package remediations_bletchley | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/facebook/openbmc/tools/flashy/lib/step" | ||
"github.com/facebook/openbmc/tools/flashy/lib/utils" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func init() { | ||
step.RegisterStep(checkVersion) | ||
} | ||
|
||
func checkVersion(stepParams step.StepParams) step.StepExitError { | ||
version, err := utils.GetOpenBMCVersionFromIssueFile() | ||
if err != nil { | ||
errMsg := errors.Errorf("Unable to fetch version info: %v", err) | ||
return step.ExitUnsafeToReboot{Err: errMsg} | ||
} | ||
|
||
const re = `bletchley-v(?P<year>[0-9]+).(?P<month>[0-9]+)` | ||
versionMap, err := utils.GetRegexSubexpMap(re, version) | ||
if err != nil { | ||
errMsg := errors.Errorf("Unable to parse version info: %v", err) | ||
return step.ExitUnsafeToReboot{Err: errMsg} | ||
} | ||
|
||
year, err := strconv.Atoi(versionMap["year"]) | ||
if err != nil { | ||
errMsg := errors.Errorf("Unable to parse version info: %v", err) | ||
return step.ExitUnsafeToReboot{Err: errMsg} | ||
} | ||
|
||
month, err := strconv.Atoi(versionMap["month"]) | ||
if err != nil { | ||
errMsg := errors.Errorf("Unable to parse version info: %v", err) | ||
return step.ExitUnsafeToReboot{Err: errMsg} | ||
} | ||
|
||
if year < 2023 || (year == 2023 && month < 07) { | ||
errMsg := errors.Errorf("Cannot upgrade this version: %v", version) | ||
return step.ExitUnsafeToReboot{Err: errMsg} | ||
} | ||
|
||
return nil | ||
} |
83 changes: 83 additions & 0 deletions
83
tools/flashy/checks_and_remediations/bletchley/00_check_version_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
package remediations_bletchley | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/facebook/openbmc/tools/flashy/lib/step" | ||
"github.com/facebook/openbmc/tools/flashy/lib/utils" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func TestCheckVersion(t *testing.T) { | ||
// mock and defer restore RunCommand | ||
getOpenBMCVersionFromIssueFileOrig := utils.GetOpenBMCVersionFromIssueFile | ||
defer func() { | ||
utils.GetOpenBMCVersionFromIssueFile = getOpenBMCVersionFromIssueFileOrig | ||
}() | ||
cases := []struct { | ||
name string | ||
version string | ||
err error | ||
want step.StepExitError | ||
}{ | ||
{ | ||
name: "failed", | ||
version: "bletchley-v2023.02.1", | ||
err: nil, | ||
want: step.ExitUnsafeToReboot{ | ||
errors.Errorf("Cannot upgrade this version: bletchley-v2023.02.1"), | ||
}, | ||
}, | ||
{ | ||
name: "succeeded", | ||
version: "bletchley-v2023.07.1", | ||
err: nil, | ||
want: nil, | ||
}, | ||
{ | ||
name: "garbage", | ||
version: "garbage", | ||
err: nil, | ||
want: step.ExitUnsafeToReboot{ | ||
errors.Errorf("Unable to parse version info: No match for regex 'bletchley-v(?P<year>[0-9]+).(?P<month>[0-9]+)' for input 'garbage'"), | ||
}, | ||
}, | ||
{ | ||
name: "error", | ||
version: "", | ||
err: errors.Errorf("fail"), | ||
want: step.ExitUnsafeToReboot{ | ||
errors.Errorf("Unable to fetch version info: fail"), | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
utils.GetOpenBMCVersionFromIssueFile = func() (string, error) { | ||
return tc.version, tc.err | ||
} | ||
got := checkVersion(step.StepParams{}) | ||
step.CompareTestExitErrors(tc.want, got, t) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters