From 88e5a42e8d2cd5205b16b35770136778f9d35e4b Mon Sep 17 00:00:00 2001 From: Marco Kawajiri Date: Fri, 18 Oct 2024 09:31:02 -0700 Subject: [PATCH] Run kill_mfg_tool_processes in all LF OpenBMC platforms Summary: Move `kill_mfg_tool_processes` step to `checks_and_remediations/common` as the issue can potentially affect all LF OpenBMC platforms (cc: williamspatrick) Test Plan: Unit tests, build+push flashy to a device with stuck mfg-tool processes: ``` ~/openbmc/tools/flashy$ scripts/run_flashy_remote.sh --device mtd:bmc --imagepath flash-yosemite4 --host sled325442309-oob.31.atn1.facebook.com --dry-run ``` Run new flashy step, ensure it successfully kills mfg-tool processes: ``` root@sled325442309-oob:~# /run/flashy/flashy -install && /run/flashy/checks_and_remediations/common/31_kill_mfg_tool_processes -imagepath /run/upgrade/image -device mtd:bmc 2024/10/18 08:27:29 Installing flashy... 2024/10/18 08:27:29 Finished installing flashy 2024/10/18 08:27:29 Starting: checks_and_remediations/common/31_kill_mfg_tool_processes 2024/10/18 08:27:29 Found 6 mfg-tool running processes 2024/10/18 08:27:29 Killing mfg-tool process with pid=10918 2024/10/18 08:27:29 Killing mfg-tool process with pid=11847 2024/10/18 08:27:29 Killing mfg-tool process with pid=12687 2024/10/18 08:27:29 Killing mfg-tool process with pid=12846 2024/10/18 08:27:29 Killing mfg-tool process with pid=13280 2024/10/18 08:27:29 Killing mfg-tool process with pid=15439 2024/10/18 08:27:29 Finished: checks_and_remediations/common/31_kill_mfg_tool_processes ``` Reviewed By: williamspatrick Differential Revision: D64603338 fbshipit-source-id: 8e52359e73e9e007e2dee7a32a27a856e5273151 --- .../31_kill_mfg_tool_processes.go} | 8 +++- .../31_kill_mfg_tool_processes_test.go} | 43 ++++++++++++++----- tools/flashy/install/install.go | 1 - 3 files changed, 40 insertions(+), 12 deletions(-) rename tools/flashy/checks_and_remediations/{yosemite4/00_kill_mfg_tool_processes.go => common/31_kill_mfg_tool_processes.go} (92%) rename tools/flashy/checks_and_remediations/{yosemite4/00_kill_mfg_tool_processes_test.go => common/31_kill_mfg_tool_processes_test.go} (76%) diff --git a/tools/flashy/checks_and_remediations/yosemite4/00_kill_mfg_tool_processes.go b/tools/flashy/checks_and_remediations/common/31_kill_mfg_tool_processes.go similarity index 92% rename from tools/flashy/checks_and_remediations/yosemite4/00_kill_mfg_tool_processes.go rename to tools/flashy/checks_and_remediations/common/31_kill_mfg_tool_processes.go index 514958b82693..e33c51107c72 100644 --- a/tools/flashy/checks_and_remediations/yosemite4/00_kill_mfg_tool_processes.go +++ b/tools/flashy/checks_and_remediations/common/31_kill_mfg_tool_processes.go @@ -17,7 +17,7 @@ * Boston, MA 02110-1301 USA */ -package remediations_yosemite4 +package common import ( "github.com/facebook/openbmc/tools/flashy/lib/step" @@ -33,6 +33,12 @@ func init() { } func killMfgToolProcesses(stepParams step.StepParams) step.StepExitError { + // Only run this on LF OpenBMC + if !utils.IsLFOpenBMC() { + log.Printf("This step only applies to LF OpenBMC, skipping") + return nil + } + // Find all running mfg-tool processes mfgToolRegex := regexp.MustCompile(`(^|/)mfg-tool(\x00|$)`) mfgToolProcs, err := utils.ListProcessesMatchingRegex(mfgToolRegex) diff --git a/tools/flashy/checks_and_remediations/yosemite4/00_kill_mfg_tool_processes_test.go b/tools/flashy/checks_and_remediations/common/31_kill_mfg_tool_processes_test.go similarity index 76% rename from tools/flashy/checks_and_remediations/yosemite4/00_kill_mfg_tool_processes_test.go rename to tools/flashy/checks_and_remediations/common/31_kill_mfg_tool_processes_test.go index 140353e2961d..c9c57a4a50c9 100644 --- a/tools/flashy/checks_and_remediations/yosemite4/00_kill_mfg_tool_processes_test.go +++ b/tools/flashy/checks_and_remediations/common/31_kill_mfg_tool_processes_test.go @@ -17,20 +17,20 @@ * Boston, MA 02110-1301 USA */ - package remediations_yosemite4 +package common - import ( +import ( + "bytes" "github.com/facebook/openbmc/tools/flashy/lib/step" "github.com/facebook/openbmc/tools/flashy/lib/utils" "log" - "testing" - "bytes" "os" "regexp" "strings" - ) + "testing" +) - func TestKillMfgToolProcesses(t *testing.T) { +func TestKillMfgToolProcesses(t *testing.T) { // save log output into buf for testing var logBuffer bytes.Buffer log.SetOutput(&logBuffer) @@ -38,15 +38,18 @@ // mock cleanup realListProcessesMatchingRegex := utils.ListProcessesMatchingRegex realKill := kill + realIsLFOpenBMC := utils.IsLFOpenBMC defer func() { log.SetOutput(os.Stderr) kill = realKill utils.ListProcessesMatchingRegex = realListProcessesMatchingRegex + utils.IsLFOpenBMC = realIsLFOpenBMC }() t.Run("Must not kill mfg-tool if there's a single process", func(t *testing.T) { logBuffer.Reset() + utils.IsLFOpenBMC = func() bool { return true } // Simulate a single mfg-tool process utils.ListProcessesMatchingRegex = func(regex *regexp.Regexp) ([]*os.Process, error) { @@ -55,9 +58,9 @@ // Mock kill killCalled := false - kill = func (proc *os.Process) error { + kill = func(proc *os.Process) error { killCalled = true - return nil; + return nil } res := killMfgToolProcesses(step.StepParams{}) @@ -77,6 +80,7 @@ t.Run("Must kill all mfg-tool if there are multiple mfg-tool processes", func(t *testing.T) { logBuffer.Reset() + utils.IsLFOpenBMC = func() bool { return true } // Simulate multiple mfg-tool processes utils.ListProcessesMatchingRegex = func(regex *regexp.Regexp) ([]*os.Process, error) { @@ -85,9 +89,9 @@ // Mock kill killCalled := false - kill = func (proc *os.Process) error { + kill = func(proc *os.Process) error { killCalled = true - return nil; + return nil } res := killMfgToolProcesses(step.StepParams{}) @@ -110,5 +114,24 @@ } }) + t.Run("Only run on LF OpenBMC platforms", func(t *testing.T) { + logBuffer.Reset() + utils.IsLFOpenBMC = func() bool { return false } + + utils.ListProcessesMatchingRegex = func(regex *regexp.Regexp) ([]*os.Process, error) { + t.Errorf("Expected ListProcessesMatchingRegex() to not be called") + return nil, nil + } + + res := killMfgToolProcesses(step.StepParams{}) + + if res != nil { + t.Errorf("Expected killMfgToolProcesses() to return nil, got %v", res) + } + + if !strings.Contains(logBuffer.String(), "This step only applies to LF OpenBMC, skipping") { + t.Errorf("Expected skipped step log message, got %v", logBuffer.String()) + } + }) } diff --git a/tools/flashy/install/install.go b/tools/flashy/install/install.go index 6767f635ddda..fa9a2eff0cea 100644 --- a/tools/flashy/install/install.go +++ b/tools/flashy/install/install.go @@ -35,7 +35,6 @@ import ( _ "github.com/facebook/openbmc/tools/flashy/checks_and_remediations/wedge100" _ "github.com/facebook/openbmc/tools/flashy/checks_and_remediations/yamp" _ "github.com/facebook/openbmc/tools/flashy/checks_and_remediations/grandteton" - _ "github.com/facebook/openbmc/tools/flashy/checks_and_remediations/yosemite4" _ "github.com/facebook/openbmc/tools/flashy/flash_procedure" _ "github.com/facebook/openbmc/tools/flashy/utilities" )