Skip to content

Commit b51a31c

Browse files
authored
DAOS-14750 control: fix cont get-prop values (#17040)
Fix the output values of daos get-prop command of the properties rd_fac, rd_lvl and layout_type Signed-off-by: Cedric Koch-Hofer <[email protected]>
1 parent d8194a4 commit b51a31c

File tree

2 files changed

+90
-35
lines changed

2 files changed

+90
-35
lines changed

src/control/lib/daos/container_property.go

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//
22
// (C) Copyright 2021-2023 Intel Corporation.
3+
// (C) Copyright 2025 Hewlett Packard Enterprise Development LP
34
// (C) Copyright 2025 Google LLC
45
//
56
// SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -368,7 +369,7 @@ var propHdlrs = propHdlrMap{
368369
},
369370
C.DAOS_PROP_ENTRY_REDUN_FAC: {
370371
C.DAOS_PROP_CO_REDUN_FAC,
371-
"Redundancy Factor",
372+
"Redundancy Factor (0-4)",
372373
nil,
373374
valHdlrMap{
374375
"0": genSetValHdlr(C.DAOS_PROP_CO_REDUN_RF0),
@@ -381,15 +382,15 @@ var propHdlrs = propHdlrMap{
381382
func(p *ContainerProperty) string {
382383
switch p.GetValue() {
383384
case C.DAOS_PROP_CO_REDUN_RF0:
384-
return "rd_fac0"
385+
return "0"
385386
case C.DAOS_PROP_CO_REDUN_RF1:
386-
return "rd_fac1"
387+
return "1"
387388
case C.DAOS_PROP_CO_REDUN_RF2:
388-
return "rd_fac2"
389+
return "2"
389390
case C.DAOS_PROP_CO_REDUN_RF3:
390-
return "rd_fac3"
391+
return "3"
391392
case C.DAOS_PROP_CO_REDUN_RF4:
392-
return "rd_fac4"
393+
return "4"
393394
default:
394395
return propInvalidValue(p)
395396
}
@@ -500,7 +501,7 @@ var propHdlrs = propHdlrMap{
500501
},
501502
C.DAOS_PROP_ENTRY_REDUN_LVL: {
502503
C.DAOS_PROP_CO_REDUN_LVL,
503-
"Redundancy Level",
504+
"Redundancy Level (rank=1, node=2)",
504505
nil,
505506
valHdlrMap{
506507
"1": genSetValHdlr(C.DAOS_PROP_CO_REDUN_RANK),
@@ -510,14 +511,13 @@ var propHdlrs = propHdlrMap{
510511
},
511512
[]string{"rf_lvl"},
512513
func(p *ContainerProperty) string {
513-
lvl := p.GetValue()
514-
switch lvl {
514+
switch p.GetValue() {
515515
case C.DAOS_PROP_CO_REDUN_RANK:
516-
return fmt.Sprintf("rank (%d)", lvl)
516+
return "rank"
517517
case C.DAOS_PROP_CO_REDUN_NODE:
518-
return fmt.Sprintf("node (%d)", lvl)
518+
return "node"
519519
default:
520-
return fmt.Sprintf("(%d)", lvl)
520+
return propInvalidValue(p)
521521
}
522522
},
523523
false,
@@ -549,7 +549,16 @@ var propHdlrs = propHdlrMap{
549549
// ----------------------------------------
550550
C.DAOS_PROP_ENTRY_LAYOUT_TYPE: {
551551
C.DAOS_PROP_CO_LAYOUT_TYPE,
552-
"Layout Type",
552+
func() string {
553+
acc := []string{}
554+
for i := 0; i < C.DAOS_PROP_CO_LAYOUT_MAX; i++ {
555+
var loStr [10]C.char
556+
557+
C.daos_unparse_ctype(C.ushort(i), &loStr[0])
558+
acc = append(acc, C.GoString(&loStr[0]))
559+
}
560+
return "Layout Type (" + strings.Join(acc, ", ") + ")"
561+
}(),
553562
nil,
554563
nil,
555564
nil,
@@ -558,7 +567,7 @@ var propHdlrs = propHdlrMap{
558567
loInt := C.ushort(p.GetValue())
559568

560569
C.daos_unparse_ctype(loInt, &loStr[0])
561-
return fmt.Sprintf("%s (%d)", C.GoString(&loStr[0]), loInt)
570+
return fmt.Sprintf("%s", C.GoString(&loStr[0]))
562571
},
563572
true,
564573
},

src/control/lib/daos/container_property_test.go

Lines changed: 67 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//
22
// (C) Copyright 2021-2022 Intel Corporation.
3+
// (C) Copyright 2025 Hewlett Packard Enterprise Development LP
34
// (C) Copyright 2025 Google LLC
45
//
56
// SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -201,13 +202,13 @@ func TestDaos_ContainerProperty_RedunLevel(t *testing.T) {
201202
var expStr string
202203
switch inputKey {
203204
case "1":
204-
expStr = "rank (1)"
205+
expStr = "rank"
205206
case "2":
206-
expStr = "node (2)"
207+
expStr = "node"
207208
case "rank":
208-
expStr = "rank (1)"
209+
expStr = "rank"
209210
case "node":
210-
expStr = "node (2)"
211+
expStr = "node"
211212
default:
212213
t.Fatalf("untested key %q", inputKey)
213214
}
@@ -218,7 +219,7 @@ func TestDaos_ContainerProperty_RedunLevel(t *testing.T) {
218219
t.Run("unexpected level", func(t *testing.T) {
219220
testProp := newTestContainerProperty(ContainerPropRedunLevel)
220221
testProp.SetValue(42)
221-
test.AssertEqual(t, "(42)", testProp.StringValue(), "unexpected string value")
222+
test.AssertEqual(t, fmt.Sprintf("property %q: invalid value 0x2a", testProp.Name), testProp.StringValue(), "unexpected string value")
222223
})
223224
}
224225

@@ -233,15 +234,15 @@ func TestDaos_ContainerProperty_RedunFactor(t *testing.T) {
233234
var expStr string
234235
switch inputKey {
235236
case "0":
236-
expStr = "rd_fac0"
237+
expStr = "0"
237238
case "1":
238-
expStr = "rd_fac1"
239+
expStr = "1"
239240
case "2":
240-
expStr = "rd_fac2"
241+
expStr = "2"
241242
case "3":
242-
expStr = "rd_fac3"
243+
expStr = "3"
243244
case "4":
244-
expStr = "rd_fac4"
245+
expStr = "4"
245246
default:
246247
t.Fatalf("untested key %q", inputKey)
247248
}
@@ -323,19 +324,64 @@ func testReadOnlyContainerProperty(t *testing.T, propType ContainerPropType) {
323324
test.CmpErr(t, errors.Errorf("property %q is read-only", testProp.Name), testProp.Set("whoops"))
324325
}
325326

326-
func TestDaos_ContainerProperty_Layout(t *testing.T) {
327+
func TestDaos_ContainerProperty_LayoutValues(t *testing.T) {
327328
testReadOnlyContainerProperty(t, ContainerPropLayoutType)
328329

329-
t.Run("valid layout", func(t *testing.T) {
330-
testProp := newTestContainerProperty(ContainerPropLayoutType)
331-
testProp.SetValue(uint64(ContainerLayoutPOSIX))
332-
test.AssertEqual(t, testProp.StringValue(), fmt.Sprintf("%s (%d)", ContainerLayoutPOSIX, ContainerLayoutPOSIX), "unexpected string value")
333-
})
334-
t.Run("unknown layout", func(t *testing.T) {
335-
testProp := newTestContainerProperty(ContainerPropLayoutType)
336-
testProp.SetValue(uint64(ContainerLayoutUnknown))
337-
test.AssertEqual(t, testProp.StringValue(), "unknown (0)", "unexpected string value")
338-
})
330+
for name, tc := range map[string]struct {
331+
propVal uint64
332+
expStr string
333+
}{
334+
"Valid unknown layout": {
335+
propVal: uint64(ContainerLayoutUnknown),
336+
expStr: "unknown",
337+
},
338+
"Valid POSIX layout": {
339+
propVal: uint64(ContainerLayoutPOSIX),
340+
expStr: "POSIX",
341+
},
342+
"Valid HDF5 layout": {
343+
propVal: uint64(ContainerLayoutHDF5),
344+
expStr: "HDF5",
345+
},
346+
"Valid PYTHON layout": {
347+
propVal: uint64(ContainerLayoutPython),
348+
expStr: "PYTHON",
349+
},
350+
"Valid SPARK layout": {
351+
propVal: uint64(ContainerLayoutSpark),
352+
expStr: "SPARK",
353+
},
354+
"Valid DATABASE layout": {
355+
propVal: uint64(ContainerLayoutDatabase),
356+
expStr: "DATABASE",
357+
},
358+
"Valid ROOT layout": {
359+
propVal: uint64(ContainerLayoutRoot),
360+
expStr: "ROOT",
361+
},
362+
"Valid SEISMIC layout": {
363+
propVal: uint64(ContainerLayoutSeismic),
364+
expStr: "SEISMIC",
365+
},
366+
"Valid METEO layout": {
367+
propVal: uint64(ContainerLayoutMeteo),
368+
expStr: "METEO",
369+
},
370+
} {
371+
t.Run(name, func(t *testing.T) {
372+
testProp := newTestContainerProperty(ContainerPropLayoutType)
373+
testProp.SetValue(tc.propVal)
374+
375+
test.AssertEqual(t, tc.expStr, testProp.StringValue(), "unexpected string value")
376+
})
377+
}
378+
}
379+
380+
func TestDaos_ContainerProperty_LayoutDescription(t *testing.T) {
381+
testReadOnlyContainerProperty(t, ContainerPropLayoutType)
382+
383+
testProp := newTestContainerProperty(ContainerPropLayoutType)
384+
test.AssertEqual(t, testProp.Description, "Layout Type (unknown, POSIX, HDF5, PYTHON, SPARK, DATABASE, ROOT, SEISMIC, METEO)", "unexpected description")
339385
}
340386

341387
func TestDaos_ContainerProperty_ACL(t *testing.T) {

0 commit comments

Comments
 (0)