diff --git a/src/control/lib/control/pool.go b/src/control/lib/control/pool.go index b92c47819a6..4f29cb696e9 100644 --- a/src/control/lib/control/pool.go +++ b/src/control/lib/control/pool.go @@ -136,10 +136,17 @@ func (pcr *PoolCreateReq) MarshalJSON() ([]byte, error) { type toJSON PoolCreateReq return json.Marshal(struct { + UUID string `json:"uuid,omitempty"` Properties []*mgmtpb.PoolProperty `json:"properties"` ACL []string `json:"acl"` *toJSON }{ + UUID: func() string { + if pcr.UUID == uuid.Nil { + return "" + } + return pcr.UUID.String() + }(), Properties: props, ACL: acl, toJSON: (*toJSON)(pcr), @@ -199,6 +206,7 @@ type ( // PoolCreateReq contains the parameters for a pool create request. PoolCreateReq struct { poolRequest + UUID uuid.UUID `json:"uuid,omitempty"` // Optional UUID; auto-generate if not supplied User string `json:"user"` UserGroup string `json:"user_group"` ACL *AccessControlList `json:"-"` @@ -299,7 +307,9 @@ func poolCreateGenPBReq(ctx context.Context, rpcClient UnaryInvoker, in *PoolCre return } - out.Uuid = uuid.New().String() + if out.Uuid == "" { + out.Uuid = uuid.New().String() + } return } diff --git a/src/control/lib/control/pool_test.go b/src/control/lib/control/pool_test.go index da21bc08c21..444608dfd6c 100644 --- a/src/control/lib/control/pool_test.go +++ b/src/control/lib/control/pool_test.go @@ -516,11 +516,13 @@ func TestControl_PoolCreate(t *testing.T) { humanize.GiByte * 10, }, } + customPoolUUID := test.MockPoolUUID() for name, tc := range map[string]struct { mic *MockInvokerConfig req *PoolCreateReq expResp *PoolCreateResp + cmpUUID bool expErr error }{ "local failure": { @@ -687,6 +689,36 @@ func TestControl_PoolCreate(t *testing.T) { TgtRanks: []uint32{0, 1, 2}, }, }, + "custom UUID": { + req: &PoolCreateReq{ + UUID: customPoolUUID, + TierRatio: mockTierRatios, + TotalBytes: humanize.GiByte * 20, + Properties: []*daos.PoolProperty{ + { + Name: "label", + Number: daos.PoolPropertyLabel, + Value: strVal("foo"), + }, + }, + }, + mic: &MockInvokerConfig{ + UnaryResponse: MockMSResponse("host1", nil, + &mgmtpb.PoolCreateResp{ + SvcLdr: 1, + SvcReps: []uint32{0, 1, 2}, + TgtRanks: []uint32{0, 1, 2}, + }, + ), + }, + expResp: &PoolCreateResp{ + UUID: customPoolUUID.String(), + Leader: 1, + SvcReps: []uint32{0, 1, 2}, + TgtRanks: []uint32{0, 1, 2}, + }, + cmpUUID: true, + }, } { t.Run(name, func(t *testing.T) { log, buf := logging.NewTestLogger(t.Name()) @@ -706,8 +738,11 @@ func TestControl_PoolCreate(t *testing.T) { return } - cmpOpt := cmpopts.IgnoreFields(PoolCreateResp{}, "UUID") - if diff := cmp.Diff(tc.expResp, gotResp, cmpOpt); diff != "" { + var cmpOpts cmp.Options + if !tc.cmpUUID { + cmpOpts = append(cmpOpts, cmpopts.IgnoreFields(PoolCreateResp{}, "UUID")) + } + if diff := cmp.Diff(tc.expResp, gotResp, cmpOpts...); diff != "" { t.Fatalf("Unexpected response (-want, +got):\n%s\n", diff) } })