Skip to content

Commit

Permalink
consolidate reintegrate methods into drain and coalesce invalid rank …
Browse files Browse the repository at this point in the history
…failures

Features: control
Required-githooks: true

Signed-off-by: Tom Nabarro <thomas.nabarro@hpe.com>
  • Loading branch information
tanabarr committed Dec 27, 2024
1 parent e8c7622 commit 7fb508b
Show file tree
Hide file tree
Showing 16 changed files with 652 additions and 1,169 deletions.
2 changes: 0 additions & 2 deletions src/control/cmd/dmg/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ func (bci *bridgeConnInvoker) InvokeUnaryRPC(ctx context.Context, uReq control.U
resp = control.MockMSResponse("", nil, &mgmtpb.SystemExcludeResp{})
case *control.SystemDrainReq:
resp = control.MockMSResponse("", nil, &mgmtpb.SystemDrainResp{})
case *control.SystemReintReq:
resp = control.MockMSResponse("", nil, &mgmtpb.SystemReintResp{})
case *control.SystemQueryReq:
if req.FailOnUnavailable {
resp = control.MockMSResponse("", system.ErrRaftUnavail, nil)
Expand Down
29 changes: 8 additions & 21 deletions src/control/cmd/dmg/pretty/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,14 @@ func PrintSystemCleanupResponse(out io.Writer, resp *control.SystemCleanupResp,
fmt.Fprintln(out, "System Cleanup Success")
}

func printSysOsaResults(out io.Writer, results []*control.SystemOsaResult) {
// PrintPoolRankResults generates a table showing results of operations on pool ranks. Each row will
// indicate a result for a group of ranks on a pool.
func PrintPoolRankResults(out io.Writer, results []*control.PoolRankResult) {
if len(results) == 0 {
fmt.Fprintln(out, "No pool ranks processed")
return
}

titles := []string{"Pool", "Ranks", "Result", "Reason"}
formatter := txtfmt.NewTableFormatter(titles...)

Expand All @@ -245,23 +252,3 @@ func printSysOsaResults(out io.Writer, results []*control.SystemOsaResult) {

fmt.Fprintln(out, formatter.Format(table))
}

// PrintSystemDrainResponse generates a human-readable representation of the response's
// SystemOsaResults and writes it to the supplied io.Writer.
func PrintSystemDrainResponse(out io.Writer, resp *control.SystemDrainResp) {
if len(resp.Results) == 0 {
fmt.Fprintln(out, "No pool ranks drained")
return
}
printSysOsaResults(out, resp.Results)
}

// PrintSystemReintResponse generates a human-readable representation of the response's
// SystemOsaResults and writes it to the supplied io.Writer.
func PrintSystemReintResponse(out io.Writer, resp *control.SystemReintResp) {
if len(resp.Results) == 0 {
fmt.Fprintln(out, "No pool ranks reintegrated")
return
}
printSysOsaResults(out, resp.Results)
}
10 changes: 5 additions & 5 deletions src/control/cmd/dmg/pretty/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,11 @@ Unknown 3 hosts: foo[7-9]

func TestPretty_printSysOsaResp(t *testing.T) {
for name, tc := range map[string]struct {
results []*control.SystemOsaResult
results []*control.PoolRankResult
expOut string
}{
"normal response": {
results: []*control.SystemOsaResult{
results: []*control.PoolRankResult{
{PoolID: test.MockUUID(1), Ranks: "0-3"},
{PoolID: test.MockUUID(2), Ranks: "1-4"},
},
Expand All @@ -631,7 +631,7 @@ Pool Ranks Result Reason
`,
},
"normal response; use labels": {
results: []*control.SystemOsaResult{
results: []*control.PoolRankResult{
{PoolID: "label1", Ranks: "0-3"},
{PoolID: "label2", Ranks: "1-4"},
},
Expand All @@ -644,7 +644,7 @@ label2 1-4 OK -
`,
},
"response with failures": {
results: []*control.SystemOsaResult{
results: []*control.PoolRankResult{
{PoolID: test.MockUUID(1), Ranks: "1-2"},
{PoolID: test.MockUUID(2), Ranks: "0"},
{
Expand All @@ -664,7 +664,7 @@ Pool Ranks Result Reason
} {
t.Run(name, func(t *testing.T) {
var out strings.Builder
printSysOsaResults(&out, tc.results)
PrintPoolRankResults(&out, tc.results)

if diff := cmp.Diff(strings.TrimLeft(tc.expOut, "\n"), out.String()); diff != "" {
t.Fatalf("unexpected stdout (-want, +got):\n%s\n", diff)
Expand Down
50 changes: 15 additions & 35 deletions src/control/cmd/dmg/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,13 @@ type systemDrainCmd struct {
baseRankListCmd
}

func (cmd *systemDrainCmd) Execute(_ []string) (errOut error) {
func (cmd *systemDrainCmd) execute(reint bool) (errOut error) {
defer func() {
errOut = errors.Wrap(errOut, "system drain failed")
op := "drain"
if reint {
op = "reintegrate"
}
errOut = errors.Wrapf(errOut, "system %s failed", op)
}()

if err := cmd.validateHostsRanks(); err != nil {
Expand All @@ -325,6 +329,7 @@ func (cmd *systemDrainCmd) Execute(_ []string) (errOut error) {
req.SetSystem(cmd.config.SystemName)
req.Hosts.Replace(&cmd.Hosts.HostSet)
req.Ranks.Replace(&cmd.Ranks.RankSet)
req.Reint = reint

resp, err := control.SystemDrain(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if err != nil {
Expand All @@ -336,47 +341,22 @@ func (cmd *systemDrainCmd) Execute(_ []string) (errOut error) {
}

var out strings.Builder
pretty.PrintSystemDrainResponse(&out, resp)
pretty.PrintPoolRankResults(&out, resp.Results)
cmd.Info(out.String())

return resp.Errors()
}

type systemReintCmd struct {
baseRankListCmd
func (cmd *systemDrainCmd) Execute(_ []string) error {
return cmd.execute(false)
}

func (cmd *systemReintCmd) Execute(_ []string) (errOut error) {
defer func() {
errOut = errors.Wrap(errOut, "system drain failed")
}()

if err := cmd.validateHostsRanks(); err != nil {
return err
}
if cmd.Ranks.Count() == 0 && cmd.Hosts.Count() == 0 {
return errNoRanks
}

req := new(control.SystemReintReq)
req.SetSystem(cmd.config.SystemName)
req.Hosts.Replace(&cmd.Hosts.HostSet)
req.Ranks.Replace(&cmd.Ranks.RankSet)

resp, err := control.SystemReint(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if err != nil {
return err // control api returned an error, disregard response
}

if cmd.JSONOutputEnabled() {
return cmd.OutputJSON(resp, resp.Errors())
}

var out strings.Builder
pretty.PrintSystemReintResponse(&out, resp)
cmd.Info(out.String())
type systemReintCmd struct {
systemDrainCmd
}

return resp.Errors()
func (cmd *systemReintCmd) Execute(_ []string) error {
return cmd.execute(true)
}

type systemCleanupCmd struct {
Expand Down
4 changes: 2 additions & 2 deletions src/control/cmd/dmg/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func TestDmg_SystemCommands(t *testing.T) {
"system reintegrate --rank-hosts foo-[0,1,4]",
strings.Join([]string{
printRequest(t, withSystem(
withHosts(&control.SystemReintReq{}, "foo-[0-1,4]"),
withHosts(&control.SystemDrainReq{Reint: true}, "foo-[0-1,4]"),
"daos_server")),
}, " "),
nil,
Expand All @@ -299,7 +299,7 @@ func TestDmg_SystemCommands(t *testing.T) {
"system reintegrate --ranks 0,1,4",
strings.Join([]string{
printRequest(t, withSystem(
withRanks(&control.SystemReintReq{}, 0, 1, 4),
withRanks(&control.SystemDrainReq{Reint: true}, 0, 1, 4),
"daos_server")),
}, " "),
nil,
Expand Down
Loading

0 comments on commit 7fb508b

Please sign in to comment.