Skip to content

Commit

Permalink
Merge branch 'master' into feature/cat_recovery
Browse files Browse the repository at this point in the history
Features: recovery
  • Loading branch information
mjmac committed Mar 20, 2023
2 parents a6e53bb + b8dd05e commit a3b5964
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 19 deletions.
4 changes: 1 addition & 3 deletions ci/bandit.config
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
# B306 : mktemp_q
# B307 : eval
# B308 : mark_safe
# B309 : httpsconnection
# B310 : urllib_urlopen
# B311 : random
# B312 : telnetlib
Expand All @@ -45,7 +44,6 @@
# B321 : ftplib
# B323 : unverified_context
# B324 : hashlib_new_insecure_functions
# B325 : tempnam
# B401 : import_telnetlib
# B402 : import_ftplib
# B403 : import_pickle
Expand Down Expand Up @@ -85,7 +83,7 @@
# IPAS Required Checkers. Do not disable these
# Additional checkers may be added if desired
tests:
[ 'B301', 'B302', 'B303', 'B304', 'B305', 'B306', 'B308', 'B309', 'B310', 'B311', 'B312', 'B313', 'B314', 'B315', 'B316', 'B317', 'B318', 'B319', 'B320', 'B321', 'B323', 'B324', 'B325', 'B401', 'B402', 'B403', 'B404', 'B405', 'B406', 'B407', 'B408', 'B409', 'B410', 'B411', 'B412', 'B413']
[ 'B301', 'B302', 'B303', 'B304', 'B305', 'B306', 'B308', 'B310', 'B311', 'B312', 'B313', 'B314', 'B315', 'B316', 'B317', 'B318', 'B319', 'B320', 'B321', 'B323', 'B324', 'B401', 'B402', 'B403', 'B404', 'B405', 'B406', 'B407', 'B408', 'B409', 'B410', 'B411', 'B412', 'B413']

# (optional) list skipped test IDs here, eg '[B101, B406]':
# The following checkers are not required but be added to tests list if desired
Expand Down
14 changes: 9 additions & 5 deletions src/control/cmd/dmg/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ type PoolCmd struct {
Upgrade PoolUpgradeCmd `command:"upgrade" description:"Upgrade pool to latest format"`
}

var (
// Default to 6% SCM:94% NVMe
defaultTierRatios = []float64{0.06, 0.94}
)

type tierRatioFlag struct {
ratios []float64
}
Expand All @@ -59,14 +64,13 @@ func (trf tierRatioFlag) Ratios() []float64 {
return trf.ratios
}

// Default to 6% SCM:94% NVMe
return []float64{0.06, 0.94}
return defaultTierRatios
}

func (trf tierRatioFlag) String() string {
var ratioStrs []string
for _, ratio := range trf.Ratios() {
ratioStrs = append(ratioStrs, fmt.Sprintf("%.2f", ratio))
ratioStrs = append(ratioStrs, pretty.PrintTierRatio(ratio))
}
return strings.Join(ratioStrs, ",")
}
Expand All @@ -85,7 +89,7 @@ func (trf *tierRatioFlag) UnmarshalFlag(fv string) error {
}

for _, trStr := range strings.Split(fv, ",") {
tr, err := strconv.ParseFloat(strings.TrimSpace(trStr), 64)
tr, err := strconv.ParseFloat(strings.TrimSpace(strings.Trim(trStr, "%")), 64)
if err != nil {
return errors.Wrapf(err, "invalid tier ratio %s", trStr)
}
Expand All @@ -101,7 +105,7 @@ func (trf *tierRatioFlag) UnmarshalFlag(fv string) error {

var totalRatios float64
for _, ratio := range trf.ratios {
if ratio > 1 {
if ratio < 0 || ratio > 1 {
return errors.New("Storage tier ratio must be a value between 0-100")
}
totalRatios += ratio
Expand Down
109 changes: 102 additions & 7 deletions src/control/cmd/dmg/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,116 @@ import (

"github.com/dustin/go-humanize"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pkg/errors"

"github.com/daos-stack/daos/src/control/cmd/dmg/pretty"
mgmtpb "github.com/daos-stack/daos/src/control/common/proto/mgmt"
"github.com/daos-stack/daos/src/control/common/test"
. "github.com/daos-stack/daos/src/control/common/test"
"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/logging"
"github.com/daos-stack/daos/src/control/system"
)

var (
defaultPoolUUID = MockUUID()
)
func Test_Dmg_PoolTierRatioFlag(t *testing.T) {
for name, tc := range map[string]struct {
input string
expRatios []float64
expString string
expErr error
}{
"empty": {
expErr: errors.New("no tier ratio specified"),
},
"less than 100%": {
input: "10,80",
expErr: errors.New("must add up to"),
},
"total more than 100%": {
input: "30,90",
expErr: errors.New("must add up to"),
},
"non-numeric": {
input: "0.3,foo",
expErr: errors.New("invalid"),
},
"negative adds up to 100": {
input: "-30,130",
expErr: errors.New("0-100"),
},
"0,0": {
input: "0,0",
expErr: errors.New("must add up to"),
},
"%,%": {
input: "%,%",
expErr: errors.New("invalid"),
},
"defaults": {
input: "defaults",
expRatios: defaultTierRatios,
expString: func() string {
rStrs := make([]string, len(defaultTierRatios))
for i, ratio := range defaultTierRatios {
rStrs[i] = pretty.PrintTierRatio(ratio)
}
return strings.Join(rStrs, ",")
}(),
},
"0": {
input: "0",
expRatios: []float64{0, 1},
expString: "0.00%,100.00%",
},
"100": {
input: "100",
expRatios: []float64{1},
expString: "100.00%",
},
"single tier padded": {
input: "45.3",
expRatios: []float64{0.453, 0.547},
expString: "45.30%,54.70%",
},
"valid two tiers": {
input: "0.3,99.7",
expRatios: []float64{0.003, 0.997},
expString: "0.30%,99.70%",
},
"valid three tiers": {
input: "0.3,69.7,30.0",
expRatios: []float64{0.003, 0.697, 0.3},
expString: "0.30%,69.70%,30.00%",
},
"valid with %": {
input: "7 %,93%",
expRatios: []float64{0.07, 0.93},
expString: "7.00%,93.00%",
},
} {
t.Run(name, func(t *testing.T) {
var trf tierRatioFlag
if tc.input != "defaults" {
err := trf.UnmarshalFlag(tc.input)
test.CmpErr(t, tc.expErr, err)
if err != nil {
return
}
}
cmpOpts := []cmp.Option{
cmpopts.EquateApprox(0.01, 0),
}
if diff := cmp.Diff(tc.expRatios, trf.Ratios(), cmpOpts...); diff != "" {
t.Fatalf("unexpected tier ratio (-want, +got):\n%s\n", diff)
}
if diff := cmp.Diff(tc.expString, trf.String()); diff != "" {
t.Fatalf("unexpected string (-want, +got):\n%s\n", diff)
}
})
}
}

func createACLFile(t *testing.T, dir string, acl *control.AccessControlList) string {
t.Helper()
Expand All @@ -53,7 +148,7 @@ func TestPoolCommands(t *testing.T) {
t.Fatal(err)
}

tmpDir, tmpCleanup := CreateTestDir(t)
tmpDir, tmpCleanup := test.CreateTestDir(t)
defer tmpCleanup()

// Some tests need a valid ACL file
Expand Down Expand Up @@ -916,9 +1011,9 @@ func TestPoolCommands(t *testing.T) {

func TestPoolGetACLToFile_Success(t *testing.T) {
log, buf := logging.NewTestLogger(t.Name())
defer ShowBufferOnFailure(t, buf)
defer test.ShowBufferOnFailure(t, buf)

tmpDir, tmpCleanup := CreateTestDir(t)
tmpDir, tmpCleanup := test.CreateTestDir(t)
defer tmpCleanup()

aclFile := filepath.Join(tmpDir, "out.txt")
Expand Down
14 changes: 10 additions & 4 deletions src/control/cmd/dmg/pretty/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ func PrintPoolQueryTargetResponse(pqtr *control.PoolQueryTargetResp, out io.Writ
return w.Err
}

// PrintTierRatio generates a human-readable representation of the supplied
// tier ratio.
func PrintTierRatio(ratio float64) string {
return fmt.Sprintf("%.2f%%", ratio*100)
}

// PrintPoolCreateResponse generates a human-readable representation of the pool create
// response and prints it to the supplied io.Writer.
func PrintPoolCreateResponse(pcr *control.PoolCreateResp, out io.Writer, opts ...PrintConfigOption) error {
Expand All @@ -113,10 +119,10 @@ func PrintPoolCreateResponse(pcr *control.PoolCreateResp, out io.Writer, opts ..
totalSize += tierBytes
}

tierRatio := make([]float64, len(pcr.TierBytes))
tierRatios := make([]float64, len(pcr.TierBytes))
if totalSize != 0 {
for tierIdx, tierBytes := range pcr.TierBytes {
tierRatio[tierIdx] = float64(tierBytes) / float64(totalSize)
tierRatios[tierIdx] = float64(tierBytes) / float64(totalSize)
}
}

Expand All @@ -134,13 +140,13 @@ func PrintPoolCreateResponse(pcr *control.PoolCreateResp, out io.Writer, opts ..

title := "Pool created with "
tierName := "SCM"
for tierIdx, tierRatio := range tierRatio {
for tierIdx, tierRatio := range tierRatios {
if tierIdx > 0 {
title += ","
tierName = "NVMe"
}

title += fmt.Sprintf("%0.2f%%", tierRatio*100)
title += PrintTierRatio(tierRatio)
fmtName := fmt.Sprintf("Storage tier %d (%s)", tierIdx, tierName)
fmtArgs = append(fmtArgs, txtfmt.TableRow{fmtName: fmt.Sprintf("%s (%s / rank)", humanize.Bytes(pcr.TierBytes[tierIdx]*numRanks), humanize.Bytes(pcr.TierBytes[tierIdx]))})
}
Expand Down

0 comments on commit a3b5964

Please sign in to comment.