Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAOS-10028 control: Move core types into daos package #14174

Merged
merged 23 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d73d0dd
DAOS-10028 control: Move core types into daos package
mjmac Apr 12, 2024
33f1d61
Address review feedback
mjmac Apr 17, 2024
44e9b9c
Merge branch 'master' into mjmac/DAOS-10028-pool
mjmac Apr 18, 2024
8ef0b8d
Converge on svc_ldr for JSON field name
mjmac Apr 18, 2024
f8637bb
Merge branch 'master' into mjmac/DAOS-10028-pool
mjmac Apr 20, 2024
7774a48
fix a few more broken tests
mjmac Apr 20, 2024
ff065b7
Update expected output in list_verbose.py tests
mjmac Apr 23, 2024
837cc09
Merge branch 'master' into mjmac/DAOS-10028-pool
mjmac Apr 23, 2024
d734c1e
Merge branch 'master' into mjmac/DAOS-10028-pool
mjmac Apr 23, 2024
adb2099
Fix wonky clang-format changes
mjmac Apr 24, 2024
0088935
Fix dict key (why not just use the JSON keys??)
mjmac Apr 24, 2024
5069a56
Merge branch 'master' into mjmac/DAOS-10028-pool
mjmac Apr 29, 2024
e20fd59
Merge branch 'master' into mjmac/DAOS-10028-pool
mjmac Apr 29, 2024
9fbf277
Adjust expected output in list_verbose.py
mjmac Apr 29, 2024
a0b54f0
Merge branch 'master' into mjmac/DAOS-10028-pool
mjmac Apr 30, 2024
19c8644
Merge branch 'master' into mjmac/DAOS-10028-pool
mjmac May 2, 2024
f6d3e7b
Update control/dmg_pool_query_test.py
mjmac May 2, 2024
0b63c75
Merge branch 'master' into mjmac/DAOS-10028-pool
mjmac May 4, 2024
140c2b2
Fix pool query test
mjmac May 4, 2024
b950a2c
Rargh. Fix a Go unit test
mjmac May 6, 2024
18388a5
Merge branch 'master' into mjmac/DAOS-10028-pool
mjmac May 6, 2024
fcd9fad
forgot to update the tier_name field
mjmac May 6, 2024
03c76ec
Merge branch 'master' into mjmac/DAOS-10028-pool
mjmac May 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/control/cmd/daos/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/daos-stack/daos/src/control/common/proto/convert"
mgmtpb "github.com/daos-stack/daos/src/control/common/proto/mgmt"
"github.com/daos-stack/daos/src/control/lib/control"
"github.com/daos-stack/daos/src/control/lib/daos"
"github.com/daos-stack/daos/src/control/lib/ranklist"
"github.com/daos-stack/daos/src/control/lib/ui"
)
Expand Down Expand Up @@ -370,7 +371,7 @@ func convertPoolTargetInfo(ptinfo *C.daos_target_info_t) (*control.PoolQueryTarg
pqti := new(control.PoolQueryTargetInfo)
pqti.Type = control.PoolQueryTargetType(ptinfo.ta_type)
pqti.State = control.PoolQueryTargetState(ptinfo.ta_state)
pqti.Space = []*control.StorageTargetUsage{
pqti.Space = []*daos.StorageTargetUsage{
{
Total: uint64(ptinfo.ta_space.s_total[C.DAOS_MEDIA_SCM]),
Free: uint64(ptinfo.ta_space.s_free[C.DAOS_MEDIA_SCM]),
Expand Down
76 changes: 76 additions & 0 deletions src/control/cmd/daos/pretty/pool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// (C) Copyright 2020-2023 Intel Corporation.
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//

package pretty

import (
"fmt"
"io"

"github.com/dustin/go-humanize"
"github.com/pkg/errors"

"github.com/daos-stack/daos/src/control/lib/daos"
"github.com/daos-stack/daos/src/control/lib/txtfmt"
)

const msgNoPools = "No pools in system"

func getTierNameText(tierIdx int) string {
switch tierIdx {
case int(daos.StorageMediaTypeScm):
return fmt.Sprintf("- Storage tier %d (SCM):", tierIdx)
case int(daos.StorageMediaTypeNvme):
return fmt.Sprintf("- Storage tier %d (NVMe):", tierIdx)
default:
return fmt.Sprintf("- Storage tier %d (unknown):", tierIdx)
}
}

// PrintPoolInfo generates a human-readable representation of the supplied
// PoolQueryResp struct and writes it to the supplied io.Writer.
func PrintPoolInfo(pi *daos.PoolInfo, out io.Writer) error {
if pi == nil {
return errors.Errorf("nil %T", pi)
}
w := txtfmt.NewErrWriter(out)

// Maintain output compatibility with the `daos pool query` output.
fmt.Fprintf(w, "Pool %s, ntarget=%d, disabled=%d, leader=%d, version=%d, state=%s\n",
pi.UUID, pi.TotalTargets, pi.DisabledTargets, pi.Leader, pi.Version, pi.State)

if pi.PoolLayoutVer != pi.UpgradeLayoutVer {
fmt.Fprintf(w, "Pool layout out of date (%d < %d) -- see `dmg pool upgrade` for details.\n",
pi.PoolLayoutVer, pi.UpgradeLayoutVer)
}
fmt.Fprintln(w, "Pool space info:")
if pi.EnabledRanks != nil {
fmt.Fprintf(w, "- Enabled ranks: %s\n", pi.EnabledRanks)
}
if pi.DisabledRanks != nil {
fmt.Fprintf(w, "- Disabled ranks: %s\n", pi.DisabledRanks)
}
fmt.Fprintf(w, "- Target(VOS) count:%d\n", pi.ActiveTargets)
if pi.TierStats != nil {
for tierIdx, tierStats := range pi.TierStats {
fmt.Fprintln(w, getTierNameText(tierIdx))
fmt.Fprintf(w, " Total size: %s\n", humanize.Bytes(tierStats.Total))
fmt.Fprintf(w, " Free: %s, min:%s, max:%s, mean:%s\n",
humanize.Bytes(tierStats.Free), humanize.Bytes(tierStats.Min),
humanize.Bytes(tierStats.Max), humanize.Bytes(tierStats.Mean))
}
}
if pi.Rebuild != nil {
if pi.Rebuild.Status == 0 {
fmt.Fprintf(w, "Rebuild %s, %d objs, %d recs\n",
pi.Rebuild.State, pi.Rebuild.Objects, pi.Rebuild.Records)
} else {
fmt.Fprintf(w, "Rebuild failed, status=%d\n", pi.Rebuild.Status)
}
}

return w.Err
}
261 changes: 261 additions & 0 deletions src/control/cmd/daos/pretty/pool_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
//
// (C) Copyright 2020-2024 Intel Corporation.
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//

package pretty

import (
"fmt"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/uuid"

"github.com/daos-stack/daos/src/control/common/test"
"github.com/daos-stack/daos/src/control/lib/daos"
"github.com/daos-stack/daos/src/control/lib/ranklist"
)

func TestPretty_PrintPoolInfo(t *testing.T) {
poolUUID := test.MockPoolUUID()
backtickStr := "`" + "dmg pool upgrade" + "`"
for name, tc := range map[string]struct {
pi *daos.PoolInfo
expPrintStr string
}{
"empty response": {
pi: &daos.PoolInfo{},
expPrintStr: fmt.Sprintf(`
Pool %s, ntarget=0, disabled=0, leader=0, version=0, state=Creating
Pool space info:
- Target(VOS) count:0
`, uuid.Nil.String()),
},
"normal response": {
pi: &daos.PoolInfo{
State: daos.PoolServiceStateDegraded,
UUID: poolUUID,
TotalTargets: 2,
DisabledTargets: 1,
ActiveTargets: 1,
Leader: 42,
Version: 100,
PoolLayoutVer: 1,
UpgradeLayoutVer: 2,
Rebuild: &daos.PoolRebuildStatus{
State: daos.PoolRebuildStateBusy,
Objects: 42,
Records: 21,
},
TierStats: []*daos.StorageUsageStats{
{
Total: 2,
Free: 1,
},
{
Total: 2,
Free: 1,
},
},
},
expPrintStr: fmt.Sprintf(`
Pool %s, ntarget=2, disabled=1, leader=42, version=100, state=Degraded
Pool layout out of date (1 < 2) -- see `+backtickStr+` for details.
Pool space info:
- Target(VOS) count:1
- Storage tier 0 (SCM):
Total size: 2 B
Free: 1 B, min:0 B, max:0 B, mean:0 B
- Storage tier 1 (NVMe):
Total size: 2 B
Free: 1 B, min:0 B, max:0 B, mean:0 B
Rebuild busy, 42 objs, 21 recs
`, poolUUID.String()),
},
"normal response; enabled ranks": {
pi: &daos.PoolInfo{
State: daos.PoolServiceStateDegraded,
UUID: poolUUID,
TotalTargets: 2,
DisabledTargets: 1,
ActiveTargets: 1,
Leader: 42,
Version: 100,
PoolLayoutVer: 1,
UpgradeLayoutVer: 2,
EnabledRanks: ranklist.MustCreateRankSet("[0,1,2]"),
Rebuild: &daos.PoolRebuildStatus{
State: daos.PoolRebuildStateBusy,
Objects: 42,
Records: 21,
},
TierStats: []*daos.StorageUsageStats{
{
Total: 2,
Free: 1,
},
{
Total: 2,
Free: 1,
},
},
},
expPrintStr: fmt.Sprintf(`
Pool %s, ntarget=2, disabled=1, leader=42, version=100, state=Degraded
Pool layout out of date (1 < 2) -- see `+backtickStr+` for details.
Pool space info:
- Enabled ranks: 0-2
- Target(VOS) count:1
- Storage tier 0 (SCM):
Total size: 2 B
Free: 1 B, min:0 B, max:0 B, mean:0 B
- Storage tier 1 (NVMe):
Total size: 2 B
Free: 1 B, min:0 B, max:0 B, mean:0 B
Rebuild busy, 42 objs, 21 recs
`, poolUUID.String()),
},
"normal response; disabled ranks": {
pi: &daos.PoolInfo{
State: daos.PoolServiceStateDegraded,
UUID: poolUUID,
TotalTargets: 2,
DisabledTargets: 1,
ActiveTargets: 1,
Leader: 42,
Version: 100,
PoolLayoutVer: 1,
UpgradeLayoutVer: 2,
DisabledRanks: ranklist.MustCreateRankSet("[0,1,3]"),
Rebuild: &daos.PoolRebuildStatus{
State: daos.PoolRebuildStateBusy,
Objects: 42,
Records: 21,
},
TierStats: []*daos.StorageUsageStats{
{
Total: 2,
Free: 1,
},
{
Total: 2,
Free: 1,
},
},
},
expPrintStr: fmt.Sprintf(`
Pool %s, ntarget=2, disabled=1, leader=42, version=100, state=Degraded
Pool layout out of date (1 < 2) -- see `+backtickStr+` for details.
Pool space info:
- Disabled ranks: 0-1,3
- Target(VOS) count:1
- Storage tier 0 (SCM):
Total size: 2 B
Free: 1 B, min:0 B, max:0 B, mean:0 B
- Storage tier 1 (NVMe):
Total size: 2 B
Free: 1 B, min:0 B, max:0 B, mean:0 B
Rebuild busy, 42 objs, 21 recs
`, poolUUID.String()),
},
"unknown/invalid rebuild state response": {
pi: &daos.PoolInfo{
State: daos.PoolServiceStateDegraded,
UUID: poolUUID,
TotalTargets: 2,
DisabledTargets: 1,
ActiveTargets: 1,
Leader: 42,
Version: 100,
PoolLayoutVer: 1,
UpgradeLayoutVer: 2,
DisabledRanks: ranklist.MustCreateRankSet("[0,1,3]"),
Rebuild: &daos.PoolRebuildStatus{
State: 42,
Objects: 42,
Records: 21,
},
TierStats: []*daos.StorageUsageStats{
{
Total: 2,
Free: 1,
},
{
Total: 2,
Free: 1,
},
},
},
expPrintStr: fmt.Sprintf(`
Pool %s, ntarget=2, disabled=1, leader=42, version=100, state=Degraded
Pool layout out of date (1 < 2) -- see `+backtickStr+` for details.
Pool space info:
- Disabled ranks: 0-1,3
- Target(VOS) count:1
- Storage tier 0 (SCM):
Total size: 2 B
Free: 1 B, min:0 B, max:0 B, mean:0 B
- Storage tier 1 (NVMe):
Total size: 2 B
Free: 1 B, min:0 B, max:0 B, mean:0 B
Rebuild unknown, 42 objs, 21 recs
`, poolUUID.String()),
},
"rebuild failed": {
pi: &daos.PoolInfo{
State: daos.PoolServiceStateDegraded,
UUID: poolUUID,
TotalTargets: 2,
DisabledTargets: 1,
ActiveTargets: 1,
Leader: 42,
Version: 100,
PoolLayoutVer: 1,
UpgradeLayoutVer: 2,
Rebuild: &daos.PoolRebuildStatus{
Status: 2,
State: daos.PoolRebuildStateBusy,
Objects: 42,
Records: 21,
},
TierStats: []*daos.StorageUsageStats{
{
Total: 2,
Free: 1,
},
{
Total: 2,
Free: 1,
},
},
},
expPrintStr: fmt.Sprintf(`
Pool %s, ntarget=2, disabled=1, leader=42, version=100, state=Degraded
Pool layout out of date (1 < 2) -- see `+backtickStr+` for details.
Pool space info:
- Target(VOS) count:1
- Storage tier 0 (SCM):
Total size: 2 B
Free: 1 B, min:0 B, max:0 B, mean:0 B
- Storage tier 1 (NVMe):
Total size: 2 B
Free: 1 B, min:0 B, max:0 B, mean:0 B
Rebuild failed, status=2
`, poolUUID.String()),
},
} {
t.Run(name, func(t *testing.T) {
var bld strings.Builder
if err := PrintPoolInfo(tc.pi, &bld); err != nil {
t.Fatal(err)
}

if diff := cmp.Diff(strings.TrimLeft(tc.expPrintStr, "\n"), bld.String()); diff != "" {
t.Fatalf("unexpected format string (-want, +got):\n%s\n", diff)
}
})
}
}
Loading
Loading