Skip to content

Commit

Permalink
Run kill_mfg_tool_processes in all LF OpenBMC platforms
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kawmarco authored and facebook-github-bot committed Oct 18, 2024
1 parent ce71547 commit 88e5a42
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Boston, MA 02110-1301 USA
*/

package remediations_yosemite4
package common

import (
"github.com/facebook/openbmc/tools/flashy/lib/step"
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,39 @@
* 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)

// 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) {
Expand All @@ -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{})
Expand All @@ -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) {
Expand All @@ -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{})
Expand All @@ -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())
}
})

}
1 change: 0 additions & 1 deletion tools/flashy/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

0 comments on commit 88e5a42

Please sign in to comment.