From 0428d705c24615ca76e5a964fd7f1ffbe5a9e07b Mon Sep 17 00:00:00 2001 From: alice-px Date: Mon, 22 Jan 2024 13:55:08 -0800 Subject: [PATCH 1/3] PWX-35559: add correlation tracing to nsm filter Stats (#2402) --- api/client/volume/client.go | 15 +- api/client/volume/client_volume_test.go | 3 +- api/server/docker.go | 24 +- api/server/middleware_auth.go | 8 +- api/server/sdk/node.go | 2 +- api/server/sdk/node_test.go | 3 +- api/server/sdk/server_interceptors_test.go | 2 +- api/server/sdk/volume_ops.go | 13 +- api/server/sdk/volume_ops_test.go | 54 +- api/server/volume.go | 534 +++++++++--------- api/server/volume_test.go | 220 ++++---- cli/volumes.go | 5 +- csi/controller_test.go | 56 +- csi/csi.go | 2 +- csi/node_test.go | 10 +- pkg/sanity/backup_restore.go | 2 +- pkg/sanity/osd_test_util.go | 5 +- pkg/sanity/snapshot.go | 6 +- pkg/sanity/volume.go | 10 +- pkg/util/volume.go | 9 +- pkg/util/volume_test.go | 33 +- volume/drivers/buse/buse.go | 4 +- .../common/default_store_enumerator.go | 3 +- .../common/default_store_enumerator_test.go | 5 +- volume/drivers/fake/fake.go | 27 +- volume/drivers/fake/fake_test.go | 10 +- volume/drivers/mock/driver.mock.go | 24 +- volume/drivers/nfs/nfs.go | 9 +- volume/drivers/test/driver.go | 17 +- volume/volume.go | 7 +- volume/volume_not_supported.go | 10 +- 31 files changed, 579 insertions(+), 553 deletions(-) diff --git a/api/client/volume/client.go b/api/client/volume/client.go index 3d849928d..696f20a8b 100644 --- a/api/client/volume/client.go +++ b/api/client/volume/client.go @@ -169,13 +169,13 @@ func (v *volumeClient) Status() [][2]string { // Inspect specified volumes. // Errors ErrEnoEnt may be returned. -func (v *volumeClient) Inspect(ids []string) ([]*api.Volume, error) { - if len(ids) == 0 { +func (v *volumeClient) Inspect(ctx context.Context, volumeIDs []string) ([]*api.Volume, error) { + if len(volumeIDs) == 0 { return nil, nil } var volumes []*api.Volume request := v.c.Get().Resource(volumePath) - for _, id := range ids { + for _, id := range volumeIDs { request.QueryOption(api.OptVolumeID, id) } if err := request.Do().Unmarshal(&volumes); err != nil { @@ -246,10 +246,7 @@ func (v *volumeClient) Restore(volumeID string, snapID string) error { // Stats for specified volume. // Errors ErrEnoEnt may be returned -func (v *volumeClient) Stats( - volumeID string, - cumulative bool, -) (*api.Stats, error) { +func (v *volumeClient) Stats(ctx context.Context, volumeID string, cumulative bool) (*api.Stats, error) { stats := &api.Stats{} req := v.c.Get().Resource(volumePath + "/stats").Instance(volumeID) req.QueryOption(api.OptCumulative, strconv.FormatBool(cumulative)) @@ -306,9 +303,7 @@ func (v *volumeClient) CapacityUsage( return requests, nil } -func (v *volumeClient) VolumeUsageByNode( - nodeID string, -) (*api.VolumeUsageByNode, error) { +func (v *volumeClient) VolumeUsageByNode(ctx context.Context, nodeID string) (*api.VolumeUsageByNode, error) { return nil, volume.ErrNotSupported diff --git a/api/client/volume/client_volume_test.go b/api/client/volume/client_volume_test.go index a2c16456d..96ceea212 100644 --- a/api/client/volume/client_volume_test.go +++ b/api/client/volume/client_volume_test.go @@ -1,6 +1,7 @@ package volume import ( + "context" "crypto/tls" "encoding/json" "net/http" @@ -25,7 +26,7 @@ func TestClientTLS(t *testing.T) { clnt.SetTLS(&tls.Config{InsecureSkipVerify: true}) - _, err = VolumeDriver(clnt).Inspect([]string{"12345"}) + _, err = VolumeDriver(clnt).Inspect(context.TODO(), []string{"12345"}) require.NoError(t, err) } diff --git a/api/server/docker.go b/api/server/docker.go index 5597d7e3c..f5f0493be 100644 --- a/api/server/docker.go +++ b/api/server/docker.go @@ -141,12 +141,12 @@ func (d *driver) errorResponse(method string, w http.ResponseWriter, err error) } } -func (d *driver) volFromName(name string) (*api.Volume, error) { +func (d *driver) volFromName(ctx context.Context, name string) (*api.Volume, error) { v, err := volumedrivers.Get(d.name) if err != nil { - return nil, fmt.Errorf("Cannot locate volume driver for %s: %s", d.name, err.Error()) + return nil, fmt.Errorf("cannot locate volume driver for %s: %s", d.name, err.Error()) } - return util.VolumeFromName(v, name) + return util.VolumeFromName(ctx, v, name) } func (d *driver) volFromNameOrIDSdk(ctx context.Context, volumes api.OpenStorageVolumeClient, name string) (*api.Volume, error) { @@ -254,10 +254,10 @@ func (d *driver) attachTokenMount(ctx context.Context, request *mountRequest) (c // parseTokenInput reads token input from the given name and opts. // The following is the order of precedence for token in types: -// 1. token= in name -// 2. token in opts -// 3. token_secret= in name -// 4. token_secret in opts +// 1. token= in name +// 2. token in opts +// 3. token_secret= in name +// 4. token_secret in opts func (d *driver) parseTokenInput(name string, opts map[string]string) (string, error) { // get token from name tokenFromName, tokenInName := d.GetTokenFromString(name) @@ -484,7 +484,7 @@ func (d *driver) scaleUp( return nil, err } id := resp.GetVolumeId() - if outVol, err = d.volFromName(id); err != nil { + if outVol, err = d.volFromName(ctx, id); err != nil { return nil, err } _, err = mountClient.Attach(ctx, &api.SdkVolumeAttachRequest{ @@ -571,7 +571,7 @@ func (d *driver) attachScale( return d.scaleUp(ctx, conn, method, vd, inSpec, inVol, allVols, attachOptions) } id := resp.GetVolumeId() - outVol, err := d.volFromName(id) + outVol, err := d.volFromName(ctx, id) if err != nil { return nil, err } @@ -791,7 +791,7 @@ func (d *driver) path(w http.ResponseWriter, r *http.Request) { } _, _, _, _, name := d.SpecFromString(request.Name) - vol, err := d.volFromName(name) + vol, err := d.volFromName(r.Context(), name) if err != nil { e := d.volNotFound(method, request.Name, err, w) d.errorResponse(method, w, e) @@ -824,7 +824,7 @@ func (d *driver) get(w http.ResponseWriter, r *http.Request) { } else { returnName = name } - vol, err := d.volFromName(name) + vol, err := d.volFromName(correlation.TODO(), name) if err != nil { e := d.volNotFound(method, request.Name, err, w) d.errorResponse(method, w, e) @@ -859,7 +859,7 @@ func (d *driver) unmount(w http.ResponseWriter, r *http.Request) { _, _, _, _, name := d.SpecFromString(request.Name) nameWithID := name + request.ID - vol, err := d.volFromName(name) + vol, err := d.volFromName(ctx, name) if err != nil { e := d.volNotFound(method, name, err, w) d.errorResponse(method, w, e) diff --git a/api/server/middleware_auth.go b/api/server/middleware_auth.go index ad7d3b5e7..0d7ac8b05 100644 --- a/api/server/middleware_auth.go +++ b/api/server/middleware_auth.go @@ -243,7 +243,7 @@ func (a *authMiddleware) setWithAuth(w http.ResponseWriter, r *http.Request, nex if err != nil { processErrorForVolSetResponse(req.Action, err, &resp) } else { - v, err := d.Inspect([]string{volumeID}) + v, err := d.Inspect(correlation.TODO(), []string{volumeID}) if err != nil { processErrorForVolSetResponse(req.Action, err, &resp) } else if v == nil || len(v) != 1 { @@ -279,7 +279,7 @@ func (a *authMiddleware) deleteWithAuth(w http.ResponseWriter, r *http.Request, return } - vols, err := d.Inspect([]string{volumeID}) + vols, err := d.Inspect(correlation.TODO(), []string{volumeID}) if err != nil || len(vols) == 0 || vols[0] == nil { json.NewEncoder(w).Encode(volumeResponse) return @@ -338,7 +338,7 @@ func (a *authMiddleware) inspectWithAuth(w http.ResponseWriter, r *http.Request, return } - dk, err := d.Inspect([]string{volumeID}) + dk, err := d.Inspect(correlation.TODO(), []string{volumeID}) if err != nil { a.log(volumeID, fn).WithError(err).Error("Failed to inspect volume") http.Error(w, err.Error(), http.StatusNotFound) @@ -368,7 +368,7 @@ func (a *authMiddleware) enumerateWithAuth(w http.ResponseWriter, r *http.Reques } volumeID := volIDs[0] - vols, err := d.Inspect([]string{volumeID}) + vols, err := d.Inspect(correlation.TODO(), []string{volumeID}) if err != nil || len(vols) == 0 || vols[0] == nil { a.log(volumeID, fn).WithError(err).Error("Failed to get volume object") json.NewEncoder(w).Encode(emptyVols) diff --git a/api/server/sdk/node.go b/api/server/sdk/node.go index 2e91c81ea..c9c72eb4c 100644 --- a/api/server/sdk/node.go +++ b/api/server/sdk/node.go @@ -191,7 +191,7 @@ func (s *NodeServer) VolumeUsageByNode( if s.server.driver(ctx) == nil { return nil, status.Error(codes.Unavailable, "Resource has not been initialized") } - resp, err := s.server.driver(ctx).VolumeUsageByNode(req.GetNodeId()) + resp, err := s.server.driver(ctx).VolumeUsageByNode(ctx, req.GetNodeId()) if err != nil { return nil, status.Errorf(codes.Internal, " Failed to get VolumeUsageByNode :%v", err.Error()) } diff --git a/api/server/sdk/node_test.go b/api/server/sdk/node_test.go index d1da68ae0..69ad5fc6c 100644 --- a/api/server/sdk/node_test.go +++ b/api/server/sdk/node_test.go @@ -23,6 +23,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/golang/mock/gomock" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -460,7 +461,7 @@ func TestSdkVolumeUsageByNode(t *testing.T) { s.MockCluster().EXPECT().Enumerate().Return(cluster, nil).Times(1) s.MockCluster().EXPECT().Inspect(nodeid).Return(node, nil).Times(2) - s.MockDriver().EXPECT().VolumeUsageByNode(nodeid).Return(&volumeUsageInfo, nil).Times(1) + s.MockDriver().EXPECT().VolumeUsageByNode(gomock.Any(), nodeid).Return(&volumeUsageInfo, nil).Times(1) // Setup client c := api.NewOpenStorageNodeClient(s.Conn()) diff --git a/api/server/sdk/server_interceptors_test.go b/api/server/sdk/server_interceptors_test.go index 91c79c1e2..5f6121fb2 100644 --- a/api/server/sdk/server_interceptors_test.go +++ b/api/server/sdk/server_interceptors_test.go @@ -115,7 +115,7 @@ func TestAuthorizationServerInterceptorCreateVolume(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). AnyTimes(), s.MockDriver(). diff --git a/api/server/sdk/volume_ops.go b/api/server/sdk/volume_ops.go index a1a1cdf93..c84f030a6 100644 --- a/api/server/sdk/volume_ops.go +++ b/api/server/sdk/volume_ops.go @@ -27,6 +27,7 @@ import ( "github.com/libopenstorage/openstorage/api" "github.com/libopenstorage/openstorage/pkg/auth" + "github.com/libopenstorage/openstorage/pkg/correlation" policy "github.com/libopenstorage/openstorage/pkg/storagepolicy" "github.com/libopenstorage/openstorage/pkg/util" "github.com/libopenstorage/openstorage/volume" @@ -53,7 +54,7 @@ func (s *VolumeServer) waitForVolumeReady(ctx context.Context, id string) (*api. func() (bool, error) { var err error // Get the latest status from the volume - v, err = util.VolumeFromName(s.driver(ctx), id) + v, err = util.VolumeFromName(correlation.TODO(), s.driver(ctx), id) if err != nil { return false, status.Errorf(codes.Internal, err.Error()) } @@ -88,7 +89,7 @@ func (s *VolumeServer) waitForVolumeRemoved(ctx context.Context, id string) erro 250*time.Millisecond, // period func() (bool, error) { // Get the latest status from the volume - if _, err := util.VolumeFromName(s.driver(ctx), id); err != nil { + if _, err := util.VolumeFromName(correlation.TODO(), s.driver(ctx), id); err != nil { // Removed return false, nil } @@ -108,7 +109,7 @@ func (s *VolumeServer) create( // Check if the volume has already been created or is in process of creation volName := locator.GetName() - v, err := util.VolumeFromName(s.driver(ctx), volName) + v, err := util.VolumeFromName(ctx, s.driver(ctx), volName) // If the volume is still there but it is being delete, then wait until it is removed if err == nil && v.GetState() == api.VolumeState_VOLUME_STATE_DELETED { if err = s.waitForVolumeRemoved(ctx, volName); err != nil { @@ -155,7 +156,7 @@ func (s *VolumeServer) create( var id string if len(source.GetParent()) != 0 { // Get parent volume information - parent, err := util.VolumeFromName(s.driver(ctx), source.Parent) + parent, err := util.VolumeFromName(correlation.TODO(), s.driver(ctx), source.Parent) if err != nil { return "", status.Errorf( codes.NotFound, @@ -501,7 +502,7 @@ func (s *VolumeServer) Inspect( } v = vols[0] } else { - vols, err := s.driver(ctx).Inspect([]string{req.GetVolumeId()}) + vols, err := s.driver(ctx).Inspect(correlation.TODO(), []string{req.GetVolumeId()}) if err == kvdb.ErrNotFound || (err == nil && len(vols) == 0) { return nil, status.Errorf( codes.NotFound, @@ -754,7 +755,7 @@ func (s *VolumeServer) Stats( return nil, err } - stats, err := s.driver(ctx).Stats(req.GetVolumeId(), !req.GetNotCumulative()) + stats, err := s.driver(ctx).Stats(ctx, req.GetVolumeId(), !req.GetNotCumulative()) if err != nil { return nil, status.Errorf( codes.Internal, diff --git a/api/server/sdk/volume_ops_test.go b/api/server/sdk/volume_ops_test.go index 574297109..efd9c4c84 100644 --- a/api/server/sdk/volume_ops_test.go +++ b/api/server/sdk/volume_ops_test.go @@ -76,22 +76,22 @@ func TestSdkVolumeCreateCheckIdempotencyWaitForRemoved(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return([]*api.Volume{vol}, nil), s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return([]*api.Volume{vol}, nil), s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return([]*api.Volume{vol}, nil), s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("MOCK ERROR")), s.MockDriver(). @@ -150,8 +150,8 @@ func TestSdkVolumeCreateCheckIdempotencyWaitForReady(t *testing.T) { // 1 for waiting but getting that the volume is up s.MockDriver(). EXPECT(). - Inspect([]string{name}). - Do(func([]string) { + Inspect(gomock.Any(), []string{name}). + Do(func(context.Context, []string) { count++ if count == 4 { vol.Status = api.VolumeStatus_VOLUME_STATUS_UP @@ -187,7 +187,7 @@ func TestSdkVolumeCreateCheckIdempotency(t *testing.T) { id := "myid" s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return([]*api.Volume{ { Id: id, @@ -231,7 +231,7 @@ func TestSdkVolumeCreate(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -295,7 +295,7 @@ func TestSdkVolumeClone(t *testing.T) { s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -307,7 +307,7 @@ func TestSdkVolumeClone(t *testing.T) { s.MockDriver(). EXPECT(). - Inspect([]string{parentid}). + Inspect(gomock.Any(), []string{parentid}). Return([]*api.Volume{parentVol}, nil). Times(1), @@ -456,7 +456,7 @@ func TestSdkVolumeInspect(t *testing.T) { req.Options = &api.VolumeInspectOptions{Deep: true} s.MockDriver(). EXPECT(). - Inspect([]string{id}). + Inspect(gomock.Any(), []string{id}). Return([]*api.Volume{ { Id: id, @@ -505,7 +505,7 @@ func TestSdkVolumeInspectKeyNotFound(t *testing.T) { // Returns key not found s.MockDriver(). EXPECT(). - Inspect([]string{id}). + Inspect(gomock.Any(), []string{id}). Return([]*api.Volume{}, kvdb.ErrNotFound). Times(1) @@ -522,7 +522,7 @@ func TestSdkVolumeInspectKeyNotFound(t *testing.T) { // Key not found, err is nil but empty list returned s.MockDriver(). EXPECT(). - Inspect([]string{id}). + Inspect(gomock.Any(), []string{id}). Return([]*api.Volume{}, nil). Times(1) @@ -539,7 +539,7 @@ func TestSdkVolumeInspectKeyNotFound(t *testing.T) { expectedErr := fmt.Errorf("WEIRD ERROR") s.MockDriver(). EXPECT(). - Inspect([]string{id}). + Inspect(gomock.Any(), []string{id}). Return([]*api.Volume{}, expectedErr). Times(1) @@ -720,7 +720,7 @@ func TestSdkVolumeStats(t *testing.T) { Times(1) s.MockDriver(). EXPECT(). - Stats(id, cumulative). + Stats(gomock.Any(), id, cumulative). Return(&api.Stats{ Reads: 12345, }, nil). @@ -1069,7 +1069,7 @@ func TestSdkCloneOwnership(t *testing.T) { mv. EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1081,7 +1081,7 @@ func TestSdkCloneOwnership(t *testing.T) { mv. EXPECT(). - Inspect([]string{parentid}). + Inspect(gomock.Any(), []string{parentid}). Return([]*api.Volume{parentVol}, nil). Times(1), @@ -1116,7 +1116,7 @@ func TestSdkCloneOwnership(t *testing.T) { mv. EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1128,7 +1128,7 @@ func TestSdkCloneOwnership(t *testing.T) { mv. EXPECT(). - Inspect([]string{parentid}). + Inspect(gomock.Any(), []string{parentid}). Return([]*api.Volume{parentVol}, nil). Times(1), @@ -1187,7 +1187,7 @@ func TestSdkCloneOwnership(t *testing.T) { mv. EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1199,7 +1199,7 @@ func TestSdkCloneOwnership(t *testing.T) { mv. EXPECT(). - Inspect([]string{parentid}). + Inspect(gomock.Any(), []string{parentid}). Return([]*api.Volume{parentVol}, nil). Times(1), @@ -1243,7 +1243,7 @@ func TestSdkCloneOwnership(t *testing.T) { mv. EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1255,7 +1255,7 @@ func TestSdkCloneOwnership(t *testing.T) { mv. EXPECT(). - Inspect([]string{parentid}). + Inspect(gomock.Any(), []string{parentid}). Return([]*api.Volume{parentVol}, nil). Times(1), @@ -1386,7 +1386,7 @@ func TestSdkVolumeCreateEnforced(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1562,7 +1562,7 @@ func TestSdkVolumeCreateDefaultPolicyOwnership(t *testing.T) { id := "myid" gomock.InOrder( mv.EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1615,7 +1615,7 @@ func TestSdkVolumeCreateDefaultPolicyOwnership(t *testing.T) { // Create response gomock.InOrder( mv.EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1763,7 +1763,7 @@ func TestSdkVolumeUpdatePolicyOwnership(t *testing.T) { id := "myid" gomock.InOrder( mv.EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), diff --git a/api/server/volume.go b/api/server/volume.go index c08fdce62..8c452a92a 100644 --- a/api/server/volume.go +++ b/api/server/volume.go @@ -129,7 +129,7 @@ func (vd *volAPI) annotateContext(r *http.Request) (context.Context, context.Can return ctx, cancel, nil } func (vd *volAPI) getVolDriver(r *http.Request) (volume.VolumeDriver, error) { - // Check if the driver has registered by it's user agent name + // Check if the driver has registered by its user agent name userAgent := r.Header.Get("User-Agent") if len(userAgent) > 0 { clientName := strings.Split(userAgent, "/") @@ -288,26 +288,28 @@ func processErrorForVolSetResponse(action *api.VolumeStateAction, err error, res // produces: // - application/json // parameters: -// - name: id -// in: path -// description: id to get volume with -// required: true -// type: integer -// - name: spec -// in: body -// description: spec to set volume with -// required: true -// schema: -// "$ref": "#/definitions/VolumeSetRequest" -// responses: -// '200': -// description: volume set response -// schema: -// "$ref": "#/definitions/VolumeSetResponse" -// default: -// description: unexpected error +// - name: id +// in: path +// description: id to get volume with +// required: true +// type: integer +// - name: spec +// in: body +// description: spec to set volume with +// required: true // schema: -// "$ref": "#/definitions/VolumeSetResponse" +// "$ref": "#/definitions/VolumeSetRequest" +// +// responses: +// +// '200': +// description: volume set response +// schema: +// "$ref": "#/definitions/VolumeSetResponse" +// default: +// description: unexpected error +// schema: +// "$ref": "#/definitions/VolumeSetResponse" func (vd *volAPI) volumeSet(w http.ResponseWriter, r *http.Request) { var ( volumeID string @@ -692,16 +694,18 @@ func getVolumeUpdateSpec(spec *api.VolumeSpec, vol *api.Volume, isSchedulerReque // produces: // - application/json // parameters: -// - name: id -// in: path -// description: id to get volume with -// required: true -// type: integer +// - name: id +// in: path +// description: id to get volume with +// required: true +// type: integer +// // responses: -// '200': -// description: volume get response -// schema: -// "$ref": "#/definitions/Volume" +// +// '200': +// description: volume get response +// schema: +// "$ref": "#/definitions/Volume" func (vd *volAPI) inspect(w http.ResponseWriter, r *http.Request) { var err error var volumeID string @@ -771,20 +775,22 @@ func (vd *volAPI) inspect(w http.ResponseWriter, r *http.Request) { // produces: // - application/json // parameters: -// - name: id -// in: path -// description: id to get volume with -// required: true -// type: integer +// - name: id +// in: path +// description: id to get volume with +// required: true +// type: integer +// // responses: -// '200': -// description: volume set response -// schema: -// "$ref": "#/definitions/VolumeResponse" -// default: -// description: unexpected error -// schema: -// "$ref": "#/definitions/VolumeResponse" +// +// '200': +// description: volume set response +// schema: +// "$ref": "#/definitions/VolumeResponse" +// default: +// description: unexpected error +// schema: +// "$ref": "#/definitions/VolumeResponse" func (vd *volAPI) delete(w http.ResponseWriter, r *http.Request) { var volumeID string var err error @@ -824,7 +830,7 @@ func (vd *volAPI) delete(w http.ResponseWriter, r *http.Request) { // swagger:operation GET /osd-volumes volume enumerateVolumes // -// Enumerate all volumes +// # Enumerate all volumes // // --- // consumes: @@ -832,38 +838,40 @@ func (vd *volAPI) delete(w http.ResponseWriter, r *http.Request) { // produces: // - application/json // parameters: -// - name: Name -// in: query -// description: User specified volume name (Case Sensitive) -// required: false -// type: string -// - name: Label -// in: formData -// description: | -// Comma separated name value pairs -// example: {"label1","label2"} -// required: false -// type: string -// - name: ConfigLabel -// in: formData -// description: | -// Comma separated name value pairs -// example: {"label1","label2"} -// required: false -// type: string -// - name: VolumeID -// in: query -// description: Volume UUID -// required: false -// type: string -// format: uuid +// - name: Name +// in: query +// description: User specified volume name (Case Sensitive) +// required: false +// type: string +// - name: Label +// in: formData +// description: | +// Comma separated name value pairs +// example: {"label1","label2"} +// required: false +// type: string +// - name: ConfigLabel +// in: formData +// description: | +// Comma separated name value pairs +// example: {"label1","label2"} +// required: false +// type: string +// - name: VolumeID +// in: query +// description: Volume UUID +// required: false +// type: string +// format: uuid +// // responses: -// '200': -// description: an array of volumes -// schema: -// type: array -// items: -// $ref: '#/definitions/Volume' +// +// '200': +// description: an array of volumes +// schema: +// type: array +// items: +// $ref: '#/definitions/Volume' func (vd *volAPI) enumerate(w http.ResponseWriter, r *http.Request) { var locator api.VolumeLocator var configLabels map[string]string @@ -959,32 +967,34 @@ func (vd *volAPI) enumerate(w http.ResponseWriter, r *http.Request) { // swagger:operation POST /osd-snapshots snapshot createSnap // -// Take a snapshot of volume in SnapCreateRequest +// # Take a snapshot of volume in SnapCreateRequest // // --- // produces: // - application/json // parameters: -// - name: id -// in: query -// description: id to get volume with -// required: true -// type: integer -// - name: spec -// in: body -// description: spec to create snap with -// required: true -// schema: -// "$ref": "#/definitions/SnapCreateRequest" -// responses: -// '200': -// description: an array of volumes -// schema: -// "$ref": '#/definitions/SnapCreateResponse' -// default: -// description: unexpected error +// - name: id +// in: query +// description: id to get volume with +// required: true +// type: integer +// - name: spec +// in: body +// description: spec to create snap with +// required: true // schema: -// "$ref": "#/definitions/SnapCreateResponse" +// "$ref": "#/definitions/SnapCreateRequest" +// +// responses: +// +// '200': +// description: an array of volumes +// schema: +// "$ref": '#/definitions/SnapCreateResponse' +// default: +// description: unexpected error +// schema: +// "$ref": "#/definitions/SnapCreateResponse" func (vd *volAPI) snap(w http.ResponseWriter, r *http.Request) { var snapReq api.SnapCreateRequest var snapRes api.SnapCreateResponse @@ -1044,20 +1054,22 @@ func (vd *volAPI) snap(w http.ResponseWriter, r *http.Request) { // produces: // - application/json // parameters: -// - name: id -// in: path -// description: id of snapshot to restore -// required: true -// type: integer +// - name: id +// in: path +// description: id of snapshot to restore +// required: true +// type: integer +// // responses: -// '200': -// description: Restored volume -// schema: -// "$ref": '#/definitions/VolumeResponse' -// default: -// description: unexpected error -// schema: -// "$ref": "#/definitions/VolumeResponse" +// +// '200': +// description: Restored volume +// schema: +// "$ref": '#/definitions/VolumeResponse' +// default: +// description: unexpected error +// schema: +// "$ref": "#/definitions/VolumeResponse" func (vd *volAPI) restore(w http.ResponseWriter, r *http.Request) { var volumeID, snapID string var err error @@ -1113,38 +1125,40 @@ func (vd *volAPI) restore(w http.ResponseWriter, r *http.Request) { // produces: // - application/json // parameters: -// - name: name -// in: query -// description: Volume name that maps to this snap -// required: false -// type: string -// - name: VolumeLabels -// in: formData -// description: | -// Comma separated volume labels -// example: {"label1","label2"} -// required: false -// type: string -// - name: SnapLabels -// in: formData -// description: | -// Comma separated snap labels -// example: {"label1","label2"} -// required: false -// type: string -// - name: uuid -// in: query -// description: Snap UUID -// required: false -// type: string -// format: uuid +// - name: name +// in: query +// description: Volume name that maps to this snap +// required: false +// type: string +// - name: VolumeLabels +// in: formData +// description: | +// Comma separated volume labels +// example: {"label1","label2"} +// required: false +// type: string +// - name: SnapLabels +// in: formData +// description: | +// Comma separated snap labels +// example: {"label1","label2"} +// required: false +// type: string +// - name: uuid +// in: query +// description: Snap UUID +// required: false +// type: string +// format: uuid +// // responses: -// '200': -// description: an array of snapshots -// schema: -// type: array -// items: -// $ref: '#/definitions/Volume' +// +// '200': +// description: an array of snapshots +// schema: +// type: array +// items: +// $ref: '#/definitions/Volume' func (vd *volAPI) snapEnumerate(w http.ResponseWriter, r *http.Request) { var err error var labels map[string]string @@ -1220,22 +1234,24 @@ func (vd *volAPI) snapEnumerate(w http.ResponseWriter, r *http.Request) { // produces: // - application/json // parameters: -// - name: id -// in: path -// description: id to get volume with -// required: true -// type: integer +// - name: id +// in: path +// description: id to get volume with +// required: true +// type: integer +// // responses: -// '200': -// description: volume set response -// schema: -// "$ref": "#/definitions/Stats" +// +// '200': +// description: volume set response +// schema: +// "$ref": "#/definitions/Stats" func (vd *volAPI) stats(w http.ResponseWriter, r *http.Request) { var volumeID string var err error if volumeID, err = vd.parseID(r); err != nil { - e := fmt.Errorf("Failed to parse volumeID: %s", err.Error()) + e := fmt.Errorf("failed to parse volumeID: %s", err.Error()) http.Error(w, e.Error(), http.StatusBadRequest) return } @@ -1243,10 +1259,9 @@ func (vd *volAPI) stats(w http.ResponseWriter, r *http.Request) { params := r.URL.Query() // By default always report /proc/diskstats style stats. cumulative := true - if opt, ok := params[string(api.OptCumulative)]; ok { + if opt, ok := params[api.OptCumulative]; ok { if boolValue, err := strconv.ParseBool(strings.Join(opt[:], "")); !ok { - e := fmt.Errorf("Failed to parse %s option: %s", - api.OptCumulative, err.Error()) + e := fmt.Errorf("failed to parse %s option: %s", api.OptCumulative, err.Error()) http.Error(w, e.Error(), http.StatusBadRequest) return } else { @@ -1260,7 +1275,7 @@ func (vd *volAPI) stats(w http.ResponseWriter, r *http.Request) { return } - stats, err := d.Stats(volumeID, cumulative) + stats, err := d.Stats(context.TODO(), volumeID, cumulative) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return @@ -1328,16 +1343,18 @@ func (vd *volAPI) stats(w http.ResponseWriter, r *http.Request) { // produces: // - application/json // parameters: -// - name: id -// in: path -// description: id to get volume with -// required: true -// type: integer +// - name: id +// in: path +// description: id to get volume with +// required: true +// type: integer +// // responses: -// '200': -// description: volume set response -// type: integer -// format: int64 +// +// '200': +// description: volume set response +// type: integer +// format: int64 func (vd *volAPI) usedsize(w http.ResponseWriter, r *http.Request) { var volumeID string var err error @@ -1410,16 +1427,18 @@ func (vd *volAPI) usedsize(w http.ResponseWriter, r *http.Request) { // produces: // - application/json // parameters: -// - name: id -// in: path -// description: id to get volume with -// required: true -// type: integer +// - name: id +// in: path +// description: id to get volume with +// required: true +// type: integer +// // responses: -// '200': -// description: volume set response -// schema: -// "$ref": "#/definitions/ActiveRequests" +// +// '200': +// description: volume set response +// schema: +// "$ref": "#/definitions/ActiveRequests" func (vd *volAPI) requests(w http.ResponseWriter, r *http.Request) { var err error @@ -1500,7 +1519,6 @@ func (vd *volAPI) volumeBytesUsedByNode(w http.ResponseWriter, r *http.Request) json.NewEncoder(w).Encode(&result) } - // swagger:operation GET /osd-volumes/quiesce/{id} volume quiesceVolume // // Quiesce volume with specified id. @@ -1509,20 +1527,22 @@ func (vd *volAPI) volumeBytesUsedByNode(w http.ResponseWriter, r *http.Request) // produces: // - application/json // parameters: -// - name: id -// in: path -// description: id to get volume with -// required: true -// type: integer +// - name: id +// in: path +// description: id to get volume with +// required: true +// type: integer +// // responses: -// '200': -// description: volume set response -// schema: -// "$ref": "#/definitions/VolumeResponse" -// default: -// description: unexpected error -// schema: -// "$ref": "#/definitions/VolumeResponse" +// +// '200': +// description: volume set response +// schema: +// "$ref": "#/definitions/VolumeResponse" +// default: +// description: unexpected error +// schema: +// "$ref": "#/definitions/VolumeResponse" func (vd *volAPI) quiesce(w http.ResponseWriter, r *http.Request) { var volumeID string var err error @@ -1574,20 +1594,22 @@ func (vd *volAPI) quiesce(w http.ResponseWriter, r *http.Request) { // produces: // - application/json // parameters: -// - name: id -// in: path -// description: id to get volume with -// required: true -// type: integer +// - name: id +// in: path +// description: id to get volume with +// required: true +// type: integer +// // responses: -// '200': -// description: volume set response -// schema: -// "$ref": "#/definitions/VolumeResponse" -// default: -// description: unexpected error -// schema: -// "$ref": "#/definitions/VolumeResponse" +// +// '200': +// description: volume set response +// schema: +// "$ref": "#/definitions/VolumeResponse" +// default: +// description: unexpected error +// schema: +// "$ref": "#/definitions/VolumeResponse" func (vd *volAPI) unquiesce(w http.ResponseWriter, r *http.Request) { var volumeID string var err error @@ -1614,27 +1636,29 @@ func (vd *volAPI) unquiesce(w http.ResponseWriter, r *http.Request) { // swagger:operation POST /osd-snapshots/groupsnap volumegroup snapVolumeGroup // -// Take a snapshot of volumegroup +// # Take a snapshot of volumegroup // // --- // produces: // - application/json // parameters: -// - name: groupspec -// in: body -// description: GroupSnap create request -// required: true -// schema: -// "$ref": "#/definitions/GroupSnapCreateRequest" -// responses: -// '200': -// description: group snap create response +// - name: groupspec +// in: body +// description: GroupSnap create request +// required: true // schema: -// "$ref": "#/definitions/GroupSnapCreateResponse" -// default: -// description: unexpected error -// schema: -// "$ref": "#/definitions/GroupSnapCreateResponse" +// "$ref": "#/definitions/GroupSnapCreateRequest" +// +// responses: +// +// '200': +// description: group snap create response +// schema: +// "$ref": "#/definitions/GroupSnapCreateResponse" +// default: +// description: unexpected error +// schema: +// "$ref": "#/definitions/GroupSnapCreateResponse" func (vd *volAPI) snapGroup(w http.ResponseWriter, r *http.Request) { var snapReq api.GroupSnapCreateRequest var snapRes *api.GroupSnapCreateResponse @@ -1666,12 +1690,13 @@ func (vd *volAPI) snapGroup(w http.ResponseWriter, r *http.Request) { // produces: // - application/json // responses: -// '200': -// description: Supported versions -// schema: -// type: array -// items: -// type: string +// +// '200': +// description: Supported versions +// schema: +// type: array +// items: +// type: string func (vd *volAPI) versions(w http.ResponseWriter, r *http.Request) { versions := []string{ volume.APIVersion, @@ -1689,26 +1714,28 @@ func (vd *volAPI) versions(w http.ResponseWriter, r *http.Request) { // produces: // - application/json // parameters: -// - name: id -// in: path -// description: id to get volume with -// required: true -// type: integer -// - name: subfolder -// in: query -// description: Optional path inside mount to catalog. -// required: false -// type: string -// - name: depth -// in: query -// description: Folder depth we wish to return, default is all. -// required: false -// type: string +// - name: id +// in: path +// description: id to get volume with +// required: true +// type: integer +// - name: subfolder +// in: query +// description: Optional path inside mount to catalog. +// required: false +// type: string +// - name: depth +// in: query +// description: Folder depth we wish to return, default is all. +// required: false +// type: string +// // responses: -// '200': -// description: volume catalog response -// schema: -// $ref: '#/definitions/CatalogResponse' +// +// '200': +// description: volume catalog response +// schema: +// $ref: '#/definitions/CatalogResponse' func (vd *volAPI) catalog(w http.ResponseWriter, r *http.Request) { var err error var volumeID string @@ -1751,29 +1778,30 @@ func (vd *volAPI) catalog(w http.ResponseWriter, r *http.Request) { // swagger:operation POST /osd-volumes/volservice/{id} volume VolumeService // -// Does Volume Service operation in the background on a given volume +// # Does Volume Service operation in the background on a given volume // // --- // produces: // - application/json // parameters: -// - name: id -// in: path -// description: id to get volume with -// required: true -// type: integer -// - name: VolumeServiceRequest -// in: body -// description: Contains the volume service command and parameters for the command -// required: true -// schema: -// "$ref": "#/definitions/VolumeServiceRequest" -// responses: -// '200': -// description: volume service response +// - name: id +// in: path +// description: id to get volume with +// required: true +// type: integer +// - name: VolumeServiceRequest +// in: body +// description: Contains the volume service command and parameters for the command +// required: true // schema: -// $ref: '#/definitions/VolumeServiceResponse' +// "$ref": "#/definitions/VolumeServiceRequest" +// +// responses: // +// '200': +// description: volume service response +// schema: +// $ref: '#/definitions/VolumeServiceResponse' func (vd *volAPI) VolService(w http.ResponseWriter, r *http.Request) { var ( volumeID string diff --git a/api/server/volume_test.go b/api/server/volume_test.go index bcdc4a613..faf0f1039 100644 --- a/api/server/volume_test.go +++ b/api/server/volume_test.go @@ -127,7 +127,7 @@ func TestVolumeNoAuth(t *testing.T) { assert.Nil(t, resp) // INSPECT - res, err := driverclient.Inspect([]string{id}) + res, err := driverclient.Inspect(context.TODO(), []string{id}) assert.Nil(t, err) assert.NotNil(t, res) assert.NotEmpty(t, res) @@ -382,46 +382,46 @@ func TestVolumeCreateFailedToAuthenticate(t *testing.T) { /* func TestVolumeCreateGetNodeIdFromIpFailed(t *testing.T) { - var err error + var err error - ts, testVolDriver := testRestServer(t) + ts, testVolDriver := testRestServer(t) - defer ts.Close() - defer testVolDriver.Stop() + defer ts.Close() + defer testVolDriver.Stop() - client, err := volumeclient.NewDriverClient(ts.URL, mockDriverName, version, mockDriverName) - assert.Nil(t, err) - assert.NotNil(t, client) + client, err := volumeclient.NewDriverClient(ts.URL, mockDriverName, version, mockDriverName) + assert.Nil(t, err) + assert.NotNil(t, client) - nodeIp := "192.168.1.1" + nodeIp := "192.168.1.1" - // Create a new global test cluster - tc := newTestCluster(t) - defer tc.Finish() + // Create a new global test cluster + tc := newTestCluster(t) + defer tc.Finish() - // Mock cluster - tc.MockCluster(). - EXPECT(). - GetNodeIdFromIp(nodeIp). - Return(nodeIp, fmt.Errorf("Failed to locate IP in this cluster.")) + // Mock cluster + tc.MockCluster(). + EXPECT(). + GetNodeIdFromIp(nodeIp). + Return(nodeIp, fmt.Errorf("Failed to locate IP in this cluster.")) - // create a volume client with Replica IPs - name := "myvol" - size := uint64(1234) - req := &api.VolumeCreateRequest{ - Locator: &api.VolumeLocator{Name: name}, - Source: &api.Source{}, - Spec: &api.VolumeSpec{Size: size, ReplicaSet: &api.ReplicaSet{Nodes: []string{nodeIp}}}, - } + // create a volume client with Replica IPs + name := "myvol" + size := uint64(1234) + req := &api.VolumeCreateRequest{ + Locator: &api.VolumeLocator{Name: name}, + Source: &api.Source{}, + Spec: &api.VolumeSpec{Size: size, ReplicaSet: &api.ReplicaSet{Nodes: []string{nodeIp}}}, + } - // create a volume client - driverclient := volumeclient.VolumeDriver(client) + // create a volume client + driverclient := volumeclient.VolumeDriver(client) - res, err := driverclient.Create(context.TODO(), req.GetLocator(), req.GetSource(), req.GetSpec()) - assert.NotNil(t, err) - assert.EqualValues(t, "", res) - assert.Contains(t, err.Error(), "Failed to locate IP") -} + res, err := driverclient.Create(context.TODO(), req.GetLocator(), req.GetSource(), req.GetSpec()) + assert.NotNil(t, err) + assert.EqualValues(t, "", res) + assert.Contains(t, err.Error(), "Failed to locate IP") + } */ func TestVolumeSnapshotCreateSuccess(t *testing.T) { @@ -575,7 +575,7 @@ func TestVolumeInspectSuccess(t *testing.T) { assert.Nil(t, err) assert.NotEmpty(t, id) - res, err := driverclient.Inspect([]string{id}) + res, err := driverclient.Inspect(context.TODO(), []string{id}) assert.Nil(t, err) assert.NotNil(t, res) assert.NotEmpty(t, res) @@ -632,7 +632,7 @@ func TestVolumeInspectFailed(t *testing.T) { assert.Nil(t, err) assert.NotEmpty(t, id) - res, err := driverclient.Inspect([]string{"myid"}) + res, err := driverclient.Inspect(context.TODO(), []string{"myid"}) assert.Nil(t, err) assert.Equal(t, len(res), 0) @@ -1329,7 +1329,7 @@ func TestVolumeStatsSuccess(t *testing.T) { assert.NoError(t, err) assert.NotEmpty(t, id) - _, err = driverclient.Stats(id, true) + _, err = driverclient.Stats(context.TODO(), id, true) assert.NoError(t, err) // Assert volume information is correct @@ -1378,7 +1378,7 @@ func TestVolumeStatsFailed(t *testing.T) { assert.Nil(t, err) assert.NotEmpty(t, id) - _, err = driverclient.Stats("12345", true) + _, err = driverclient.Stats(context.TODO(), "12345", true) assert.NotNil(t, err) // Assert volume information is correct volumes := api.NewOpenStorageVolumeClient(testVolDriver.Conn()) @@ -1504,111 +1504,113 @@ func TestVolumeUnmountFailed(t *testing.T) { /* func TestVolumeQuiesceSuccess(t *testing.T) { - var err error - ts, testVolDriver := testRestServer(t) + var err error + ts, testVolDriver := testRestServer(t) - defer ts.Close() - defer testVolDriver.Stop() + defer ts.Close() + defer testVolDriver.Stop() - client, err := volumeclient.NewDriverClient(ts.URL, mockDriverName, version, mockDriverName) - assert.Nil(t, err) + client, err := volumeclient.NewDriverClient(ts.URL, mockDriverName, version, mockDriverName) + assert.Nil(t, err) - id := "myid" - quiesceid := "qid" - timeout := uint64(5) + id := "myid" + quiesceid := "qid" + timeout := uint64(5) - testVolDriver.MockDriver(). - EXPECT(). - Quiesce(id, timeout, quiesceid). - Return(nil) + testVolDriver.MockDriver(). + EXPECT(). + Quiesce(id, timeout, quiesceid). + Return(nil) - // create client - driverclient := volumeclient.VolumeDriver(client) - res := driverclient.Quiesce(id, timeout, quiesceid) + // create client + driverclient := volumeclient.VolumeDriver(client) + res := driverclient.Quiesce(id, timeout, quiesceid) + + assert.Nil(t, res) + } - assert.Nil(t, res) -} func TestVolumeQuiesceFailed(t *testing.T) { - var err error - ts, testVolDriver := testRestServer(t) + var err error + ts, testVolDriver := testRestServer(t) - defer ts.Close() - defer testVolDriver.Stop() + defer ts.Close() + defer testVolDriver.Stop() - client, err := volumeclient.NewDriverClient(ts.URL, mockDriverName, version, mockDriverName) - assert.Nil(t, err) + client, err := volumeclient.NewDriverClient(ts.URL, mockDriverName, version, mockDriverName) + assert.Nil(t, err) - // volume instance - id := "myid" - quiesceid := "qid" - timeout := uint64(5) + // volume instance + id := "myid" + quiesceid := "qid" + timeout := uint64(5) - testVolDriver.MockDriver(). - EXPECT(). - Quiesce(id, timeout, quiesceid). - Return(fmt.Errorf("error in quiesce")) + testVolDriver.MockDriver(). + EXPECT(). + Quiesce(id, timeout, quiesceid). + Return(fmt.Errorf("error in quiesce")) - // create client - driverclient := volumeclient.VolumeDriver(client) - res := driverclient.Quiesce(id, timeout, quiesceid) + // create client + driverclient := volumeclient.VolumeDriver(client) + res := driverclient.Quiesce(id, timeout, quiesceid) - assert.NotNil(t, res) - assert.Contains(t, res.Error(), "error in quiesce") -} + assert.NotNil(t, res) + assert.Contains(t, res.Error(), "error in quiesce") + } * TODO(ram-infrac) : Test case is failing, recheck func TestVolumeUnquiesceSuccess(t *testing.T) { - ts, testVolDriver := testRestServer(t) + ts, testVolDriver := testRestServer(t) - ts.Close() - testVolDriver.Stop() - var err error + ts.Close() + testVolDriver.Stop() + var err error - client, err := volumeclient.NewDriverClient(ts.URL, mockDriverName, version, mockDriverName) - assert.Nil(t, err) + client, err := volumeclient.NewDriverClient(ts.URL, mockDriverName, version, mockDriverName) + assert.Nil(t, err) - id := "myid" + id := "myid" - testVolDriver.MockDriver(). - EXPECT(). - Unquiesce(id). - Return(nil) + testVolDriver.MockDriver(). + EXPECT(). + Unquiesce(id). + Return(nil) - // create client - driverclient := volumeclient.VolumeDriver(client) - res := driverclient.Unquiesce(id) + // create client + driverclient := volumeclient.VolumeDriver(client) + res := driverclient.Unquiesce(id) + + assert.Nil(t, res) + } - assert.Nil(t, res) -} * func TestVolumeUnquiesceFailed(t *testing.T) { - var err error - ts, testVolDriver := testRestServer(t) + var err error + ts, testVolDriver := testRestServer(t) - defer ts.Close() - defer testVolDriver.Stop() + defer ts.Close() + defer testVolDriver.Stop() - client, err := volumeclient.NewDriverClient(ts.URL, mockDriverName, version, mockDriverName) - assert.Nil(t, err) + client, err := volumeclient.NewDriverClient(ts.URL, mockDriverName, version, mockDriverName) + assert.Nil(t, err) - id := "myid" + id := "myid" - testVolDriver.MockDriver(). - EXPECT(). - Unquiesce(id). - Return(fmt.Errorf("error in unquiesce")) + testVolDriver.MockDriver(). + EXPECT(). + Unquiesce(id). + Return(fmt.Errorf("error in unquiesce")) - // create client - driverclient := volumeclient.VolumeDriver(client) - res := driverclient.Unquiesce(id) + // create client + driverclient := volumeclient.VolumeDriver(client) + res := driverclient.Unquiesce(id) - assert.NotNil(t, res) - assert.Contains(t, res.Error(), "error in unquiesce") -} + assert.NotNil(t, res) + assert.Contains(t, res.Error(), "error in unquiesce") + } */ func TestVolumeRestoreSuccess(t *testing.T) { @@ -2573,7 +2575,7 @@ func TestMiddlewareVolumeInspectFailureVolumeNotFound(t *testing.T) { // Confirm that the inspect on secret error returns to the client the correct object, // which should be an empty list - ret, err := driverclient.Inspect([]string{id}) + ret, err := driverclient.Inspect(context.TODO(), []string{id}) assert.Nil(t, err) assert.NotNil(t, ret) assert.Empty(t, ret) @@ -2797,7 +2799,7 @@ func TestStorkVolumeInspect(t *testing.T) { err = driverclient.Delete(context.TODO(), id) assert.Nil(t, err) - vols, err := driverclient.Inspect([]string{id}) + vols, err := driverclient.Inspect(context.TODO(), []string{id}) assert.Equal(t, len(vols), 0) assert.Nil(t, err) /* diff --git a/cli/volumes.go b/cli/volumes.go index ed261f470..b3a2a56f6 100644 --- a/cli/volumes.go +++ b/cli/volumes.go @@ -3,6 +3,7 @@ package cli import ( "context" "fmt" + "github.com/libopenstorage/openstorage/pkg/correlation" "os" "strings" "time" @@ -213,7 +214,7 @@ func (v *volDriver) volumeInspect(cliContext *cli.Context) { d[i] = string(v) } - volumes, err := v.volDriver.Inspect(d) + volumes, err := v.volDriver.Inspect(correlation.TODO(), d) if err != nil { cmdError(cliContext, fn, err) return @@ -230,7 +231,7 @@ func (v *volDriver) volumeStats(cliContext *cli.Context) { return } - stats, err := v.volDriver.Stats(string(cliContext.Args()[0]), true) + stats, err := v.volDriver.Stats(correlation.TODO(), string(cliContext.Args()[0]), true) if err != nil { cmdError(cliContext, fn, err) return diff --git a/csi/controller_test.go b/csi/controller_test.go index 51fa05598..f6671cf29 100644 --- a/csi/controller_test.go +++ b/csi/controller_test.go @@ -112,7 +112,7 @@ func TestControllerGetVolume(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{id}). + Inspect(gomock.Any(), []string{id}). Return([]*api.Volume{ vol, }, nil). @@ -947,7 +947,7 @@ func TestControllerCreateVolumeFoundByVolumeFromNameConflict(t *testing.T) { mockCalls: []*gomock.Call{ s.MockDriver(). EXPECT(). - Inspect([]string{"size"}). + Inspect(gomock.Any(), []string{"size"}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -970,7 +970,7 @@ func TestControllerCreateVolumeFoundByVolumeFromNameConflict(t *testing.T) { s.MockDriver(). EXPECT(). - Inspect([]string{"size"}). + Inspect(gomock.Any(), []string{"size"}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1024,7 +1024,7 @@ func TestControllerCreateVolumeNoCapacity(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1102,7 +1102,7 @@ func TestControllerCreateVolumeFoundByVolumeFromName(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1125,7 +1125,7 @@ func TestControllerCreateVolumeFoundByVolumeFromName(t *testing.T) { s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1242,7 +1242,7 @@ func TestControllerCreateVolumeBadParentId(t *testing.T) { // VolFromName (name) s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1255,7 +1255,7 @@ func TestControllerCreateVolumeBadParentId(t *testing.T) { // VolFromName (parent) s.MockDriver(). EXPECT(). - Inspect([]string{parent}). + Inspect(gomock.Any(), []string{parent}). Return(nil, fmt.Errorf("not found")). Times(1), s.MockDriver(). @@ -1311,7 +1311,7 @@ func TestControllerCreateVolumeBadSnapshot(t *testing.T) { // VolFromName (name) s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1324,7 +1324,7 @@ func TestControllerCreateVolumeBadSnapshot(t *testing.T) { // VolFromName (parent) s.MockDriver(). EXPECT(). - Inspect([]string{parent}). + Inspect(gomock.Any(), []string{parent}). Return([]*api.Volume{{Id: parent}}, nil). Times(1), @@ -1379,7 +1379,7 @@ func TestControllerCreateVolumeWithSharedv4Volume(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return([]*api.Volume{}, nil). Times(1), @@ -1463,7 +1463,7 @@ func TestControllerCreateVolumeWithSharedVolume(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return([]*api.Volume{}, nil). Times(1), @@ -1534,7 +1534,7 @@ func TestControllerCreateVolumeFails(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1584,7 +1584,7 @@ func TestControllerCreateVolumeNoNewVolumeInfo(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1658,7 +1658,7 @@ func TestControllerCreateVolumeFailedRemoteConn(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1736,7 +1736,7 @@ func TestControllerCreateVolume(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1813,7 +1813,7 @@ func TestControllerCreateVolumeRoundUp(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1914,7 +1914,7 @@ func TestControllerCreateVolumeFromSnapshot(t *testing.T) { // VolFromName (name) s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -1927,7 +1927,7 @@ func TestControllerCreateVolumeFromSnapshot(t *testing.T) { //VolFromName parent s.MockDriver(). EXPECT(). - Inspect(gomock.Any()). + Inspect(gomock.Any(), gomock.Any()). Return( []*api.Volume{{ Id: mockParentID, @@ -2020,7 +2020,7 @@ func TestControllerCreateVolumeSnapshotThroughParameters(t *testing.T) { //VolFromName name s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -2033,7 +2033,7 @@ func TestControllerCreateVolumeSnapshotThroughParameters(t *testing.T) { // VolFromName parent s.MockDriver(). EXPECT(). - Inspect([]string{mockParentID}). + Inspect(gomock.Any(), []string{mockParentID}). Return([]*api.Volume{ { Id: mockParentID, @@ -2162,7 +2162,7 @@ func TestControllerCreateVolumeBlock(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -2280,7 +2280,7 @@ func TestControllerCreateVolumeWithoutTopology(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -2345,7 +2345,7 @@ func TestControllerCreateVolumeWithoutTopology(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -2436,7 +2436,7 @@ func TestControllerCreateVolumeWithTopology(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -2507,7 +2507,7 @@ func TestControllerCreateVolumeWithTopology(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -2530,7 +2530,7 @@ func TestControllerCreateVolumeWithTopology(t *testing.T) { s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -2738,7 +2738,7 @@ func TestControllerExpandVolume(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{myid}). + Inspect(gomock.Any(), []string{myid}). Return([]*api.Volume{ vol, }, nil). diff --git a/csi/csi.go b/csi/csi.go index 64b358c69..467152223 100644 --- a/csi/csi.go +++ b/csi/csi.go @@ -169,7 +169,7 @@ func (s *OsdCsiServer) getRemoteConn(ctx context.Context) (*grpc.ClientConn, err // PX security authentication and should be used only when a CSI request // does not support secrets as a field func (s *OsdCsiServer) driverGetVolume(ctx context.Context, id string) (*api.Volume, error) { - vols, err := s.driver.Inspect([]string{id}) + vols, err := s.driver.Inspect(correlation.TODO(), []string{id}) if err != nil || len(vols) < 1 { if err == kvdb.ErrNotFound { clogger.WithContext(ctx).Infof("Volume %s cannot be found: %s", id, err.Error()) diff --git a/csi/node_test.go b/csi/node_test.go index 25fa6ae13..52202f9d4 100644 --- a/csi/node_test.go +++ b/csi/node_test.go @@ -690,7 +690,7 @@ func TestNodePublishVolumeEphemeralEnabled(t *testing.T) { Times(1), s.MockDriver(). EXPECT(). - Inspect([]string{name}). + Inspect(gomock.Any(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), s.MockDriver(). @@ -1082,7 +1082,7 @@ func TestNodeGetVolumeStats(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{id}). + Inspect(gomock.Any(), []string{id}). Return([]*api.Volume{ vol, }, nil). @@ -1153,7 +1153,7 @@ func TestNodeGetVolumeStats_NotFound(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{id}). + Inspect(gomock.Any(), []string{id}). Return([]*api.Volume{}, nil). Times(1), ) @@ -1169,7 +1169,7 @@ func TestNodeGetVolumeStats_NotFound(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{id}). + Inspect(gomock.Any(), []string{id}). Return([]*api.Volume{}, kvdb.ErrNotFound). Times(1), ) @@ -1185,7 +1185,7 @@ func TestNodeGetVolumeStats_NotFound(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{id}). + Inspect(gomock.Any(), []string{id}). Return([]*api.Volume{{ Id: id, AttachPath: []string{"bad-test", "test-2"}, diff --git a/pkg/sanity/backup_restore.go b/pkg/sanity/backup_restore.go index 32e9f11c4..3b640e6d9 100644 --- a/pkg/sanity/backup_restore.go +++ b/pkg/sanity/backup_restore.go @@ -449,7 +449,7 @@ var _ = Describe("Volume [Backup Restore Tests]", func() { By("Inspecting the restored volume") - volumes, err := volumedriver.Inspect([]string{bkpRestoreResp.RestoreVolumeID}) + volumes, err := volumedriver.Inspect(context.TODO(), []string{bkpRestoreResp.RestoreVolumeID}) Expect(err).NotTo(HaveOccurred()) Expect(len(volumes)).To(BeEquivalentTo(1)) Expect(volumes[0].Locator.Name).To(BeEquivalentTo(restoredVolume)) diff --git a/pkg/sanity/osd_test_util.go b/pkg/sanity/osd_test_util.go index 1f8e18842..ad9ed0a1f 100644 --- a/pkg/sanity/osd_test_util.go +++ b/pkg/sanity/osd_test_util.go @@ -17,6 +17,7 @@ limitations under the License. package sanity import ( + "context" "math/rand" "time" @@ -53,7 +54,7 @@ func testIfVolumeCreatedSuccessfully( By("Inspecting the created volume") inspectVolumes := []string{volumeID} - volumesList, err := volumedriver.Inspect(inspectVolumes) + volumesList, err := volumedriver.Inspect(context.TODO(), inspectVolumes) Expect(err).NotTo(HaveOccurred()) Expect(volumesList).NotTo(BeEmpty()) Expect(len(volumesList)).Should(BeEquivalentTo(1)) @@ -89,7 +90,7 @@ func testIfVolumeCreatedSuccessfully( Expect(volumesList[0].GetSpec().GetReadahead()).To(BeEquivalentTo(vr.GetSpec().GetReadahead())) } -//Returns an in between min and max. Min - included, Max excluded. So mathematically [min, max) +// Returns an in between min and max. Min - included, Max excluded. So mathematically [min, max) func random(min, max int) int { if max == min { return max diff --git a/pkg/sanity/snapshot.go b/pkg/sanity/snapshot.go index 493fc31ff..2def3186d 100644 --- a/pkg/sanity/snapshot.go +++ b/pkg/sanity/snapshot.go @@ -121,7 +121,7 @@ var _ = Describe("Volume [Snapshot Tests]", func() { By("Checking the Parent field of the created snapshot") - volumes, err := volumedriver.Inspect([]string{loc.GetName()}) + volumes, err := volumedriver.Inspect(context.TODO(), []string{loc.GetName()}) Expect(err).NotTo(HaveOccurred()) Expect(volumes).NotTo(BeEmpty()) @@ -213,7 +213,7 @@ var _ = Describe("Volume [Snapshot Tests]", func() { By("Checking the Parent field of the created snapshot") - volumes, err := volumedriver.Inspect(snapIDs) + volumes, err := volumedriver.Inspect(context.TODO(), snapIDs) Expect(err).NotTo(HaveOccurred()) Expect(volumes).NotTo(BeEmpty()) @@ -304,7 +304,7 @@ var _ = Describe("Volume [Snapshot Tests]", func() { By("Checking the Parent field of the created snapshot") - volumes, err := volumedriver.Inspect([]string{loc.GetName()}) + volumes, err := volumedriver.Inspect(context.TODO(), []string{loc.GetName()}) Expect(err).NotTo(HaveOccurred()) Expect(volumes).NotTo(BeEmpty()) diff --git a/pkg/sanity/volume.go b/pkg/sanity/volume.go index 349d11d19..6227dfaf4 100644 --- a/pkg/sanity/volume.go +++ b/pkg/sanity/volume.go @@ -246,7 +246,7 @@ var _ = Describe("Volume [Volume Tests]", func() { // REST endpoint doesn't throw any error where cli throws an error By("Inspecting a volume that doesn't exist") volumesToCreate = 0 - volumes, err := volumedriver.Inspect([]string{"volume-id-doesnt-exist"}) + volumes, err := volumedriver.Inspect(context.TODO(), []string{"volume-id-doesnt-exist"}) Expect(err).To(BeNil()) Expect(volumes).To(BeEmpty()) @@ -446,7 +446,7 @@ var _ = Describe("Volume [Volume Tests]", func() { By("Inspecting the volume and checking attached_on field is not empty ") - volumes, err := volumedriver.Inspect([]string{volumeID}) + volumes, err := volumedriver.Inspect(context.TODO(), []string{volumeID}) Expect(err).NotTo(HaveOccurred()) Expect(volumes[0].GetAttachedOn()).ToNot(BeEquivalentTo("")) @@ -622,7 +622,7 @@ var _ = Describe("Volume [Volume Tests]", func() { By("Inspecting the volume for new updates") - volumes, err := volumedriver.Inspect([]string{volumeID}) + volumes, err := volumedriver.Inspect(context.TODO(), []string{volumeID}) Expect(err).NotTo(HaveOccurred()) Expect(volumes[0].GetSpec().GetSize()).To(BeEquivalentTo(set.GetSpec().GetSize())) @@ -685,7 +685,7 @@ var _ = Describe("Volume [Volume Tests]", func() { By("Inspecting the volume for new updates") time.Sleep(time.Second * 10) - volumes, err := volumedriver.Inspect([]string{volumeID}) + volumes, err := volumedriver.Inspect(context.TODO(), []string{volumeID}) Expect(err).NotTo(HaveOccurred()) Expect(volumes[0].Spec.HaLevel).To(BeEquivalentTo(newHALevel)) }) @@ -753,7 +753,7 @@ var _ = Describe("Volume [Volume Tests]", func() { By("Getting the stats") - stats, err := volumedriver.Stats(volumeID, true) + stats, err := volumedriver.Stats(context.TODO(), volumeID, true) Expect(err).NotTo(HaveOccurred()) Expect(stats.String()).To(Not(BeNil())) diff --git a/pkg/util/volume.go b/pkg/util/volume.go index 90e80bc7c..3a6657d1f 100644 --- a/pkg/util/volume.go +++ b/pkg/util/volume.go @@ -19,24 +19,23 @@ package util import ( "context" "fmt" - "github.com/libopenstorage/openstorage/api" "github.com/libopenstorage/openstorage/volume" ) // VolumeFromName returns the volume object associated with the specified name. -func VolumeFromName(v volume.VolumeDriver, name string) (*api.Volume, error) { - vols, err := v.Inspect([]string{name}) +func VolumeFromName(ctx context.Context, v volume.VolumeDriver, name string) (*api.Volume, error) { + vols, err := v.Inspect(ctx, []string{name}) if err == nil && len(vols) == 1 { return vols[0], nil } vols, err = v.Enumerate(&api.VolumeLocator{Name: name}, nil) if err != nil { - return nil, fmt.Errorf("Failed to locate volume %s. Error: %s", name, err.Error()) + return nil, fmt.Errorf("failed to locate volume %s. Error: %s", name, err.Error()) } else if err == nil && len(vols) == 1 { return vols[0], nil } - return nil, fmt.Errorf("Cannot locate volume with name %s", name) + return nil, fmt.Errorf("cannot locate volume with name %s", name) } // VolumeFromIdSdk uses the SDK to fetch the volume object associated with the specified id. diff --git a/pkg/util/volume_test.go b/pkg/util/volume_test.go index e38a5dbc6..3afd49558 100644 --- a/pkg/util/volume_test.go +++ b/pkg/util/volume_test.go @@ -17,6 +17,7 @@ limitations under the License. package util import ( + "context" "fmt" "testing" @@ -40,7 +41,7 @@ func TestVolumeFromNameFailedToLocateDueToTooManyVolumes(t *testing.T) { // Too many driver. EXPECT(). - Inspect([]string{name}). + Inspect(context.TODO(), []string{name}). Return([]*api.Volume{ &api.Volume{ Id: name, @@ -64,16 +65,16 @@ func TestVolumeFromNameFailedToLocateDueToTooManyVolumes(t *testing.T) { ) // Expect not found - _, err := VolumeFromName(driver, name) + _, err := VolumeFromName(context.TODO(), driver, name) assert.NotNil(t, err) - assert.Contains(t, err.Error(), "Cannot locate") + assert.Contains(t, err.Error(), "cannot locate") // Setup calls gomock.InOrder( // Return that it was not found driver. EXPECT(). - Inspect([]string{name}). + Inspect(context.TODO(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -99,15 +100,15 @@ func TestVolumeFromNameFailedToLocateDueToTooManyVolumes(t *testing.T) { ) // Expect not found - _, err = VolumeFromName(driver, name) + _, err = VolumeFromName(context.TODO(), driver, name) assert.NotNil(t, err) - assert.Contains(t, err.Error(), "Cannot locate") + assert.Contains(t, err.Error(), "cannot locate") // Setup calls gomock.InOrder( driver. EXPECT(). - Inspect([]string{name}). + Inspect(context.TODO(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), @@ -119,9 +120,9 @@ func TestVolumeFromNameFailedToLocateDueToTooManyVolumes(t *testing.T) { ) // Expect not found - _, err = VolumeFromName(driver, name) + _, err = VolumeFromName(context.TODO(), driver, name) assert.NotNil(t, err) - assert.Contains(t, err.Error(), "Failed to locate") + assert.Contains(t, err.Error(), "failed to locate") } func TestVolumeFromNameFailedToLocate(t *testing.T) { @@ -136,7 +137,7 @@ func TestVolumeFromNameFailedToLocate(t *testing.T) { gomock.InOrder( driver. EXPECT(). - Inspect([]string{name}). + Inspect(context.TODO(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), driver. @@ -147,7 +148,7 @@ func TestVolumeFromNameFailedToLocate(t *testing.T) { ) // Expect not found - _, err := VolumeFromName(driver, name) + _, err := VolumeFromName(context.TODO(), driver, name) assert.NotNil(t, err) } @@ -162,9 +163,9 @@ func TestVolumeFromNameFoundFromInspect(t *testing.T) { name := "myvolume" driver. EXPECT(). - Inspect([]string{name}). + Inspect(context.TODO(), []string{name}). Return([]*api.Volume{ - &api.Volume{ + { Id: name, Locator: &api.VolumeLocator{ Name: "hello", @@ -174,7 +175,7 @@ func TestVolumeFromNameFoundFromInspect(t *testing.T) { Times(1) // Expect not found - v, err := VolumeFromName(driver, name) + v, err := VolumeFromName(context.TODO(), driver, name) assert.Nil(t, err) assert.NotNil(t, v) assert.Equal(t, v.Id, name) @@ -193,7 +194,7 @@ func TestVolumeFromNameFoundFromEnumerate(t *testing.T) { gomock.InOrder( driver. EXPECT(). - Inspect([]string{name}). + Inspect(context.TODO(), []string{name}). Return(nil, fmt.Errorf("not found")). Times(1), driver. @@ -211,7 +212,7 @@ func TestVolumeFromNameFoundFromEnumerate(t *testing.T) { ) // Expect not found - v, err := VolumeFromName(driver, name) + v, err := VolumeFromName(context.TODO(), driver, name) assert.Nil(t, err) assert.NotNil(t, v) assert.Equal(t, v.Id, "myid") diff --git a/volume/drivers/buse/buse.go b/volume/drivers/buse/buse.go index 50fe9799b..4af9b72d0 100644 --- a/volume/drivers/buse/buse.go +++ b/volume/drivers/buse/buse.go @@ -327,7 +327,7 @@ func (d *driver) Unmount(ctx context.Context, volumeID string, mountpath string, func (d *driver) Snapshot(volumeID string, readonly bool, locator *api.VolumeLocator, noRetry bool) (string, error) { volIDs := make([]string, 1) volIDs[0] = volumeID - vols, err := d.Inspect(volIDs) + vols, err := d.Inspect(nil, volIDs) if err != nil { return "", nil } @@ -349,7 +349,7 @@ func (d *driver) Snapshot(volumeID string, readonly bool, locator *api.VolumeLoc } func (d *driver) Restore(volumeID string, snapID string) error { - if _, err := d.Inspect([]string{volumeID, snapID}); err != nil { + if _, err := d.Inspect(correlation.TODO(), []string{volumeID, snapID}); err != nil { return err } diff --git a/volume/drivers/common/default_store_enumerator.go b/volume/drivers/common/default_store_enumerator.go index 8d151a4f5..a22996c25 100644 --- a/volume/drivers/common/default_store_enumerator.go +++ b/volume/drivers/common/default_store_enumerator.go @@ -1,6 +1,7 @@ package common import ( + "context" "encoding/json" "fmt" @@ -86,7 +87,7 @@ func (e *defaultStoreEnumerator) DeleteVol(volumeID string) error { // Inspect specified volumes. // Returns slice of volumes that were found. -func (e *defaultStoreEnumerator) Inspect(ids []string) ([]*api.Volume, error) { +func (e *defaultStoreEnumerator) Inspect(ctx context.Context, ids []string) ([]*api.Volume, error) { volumes := make([]*api.Volume, 0, len(ids)) for _, id := range ids { volume, err := e.GetVol(id) diff --git a/volume/drivers/common/default_store_enumerator_test.go b/volume/drivers/common/default_store_enumerator_test.go index 25f8de390..756cf838b 100644 --- a/volume/drivers/common/default_store_enumerator_test.go +++ b/volume/drivers/common/default_store_enumerator_test.go @@ -1,6 +1,7 @@ package common import ( + "context" "testing" "github.com/sirupsen/logrus" @@ -32,7 +33,7 @@ func TestInspect(t *testing.T) { volume := newTestVolume("TestVolume") err := testEnumerator.CreateVol(volume) assert.NoError(t, err, "Failed in CreateVol") - volumes, err := testEnumerator.Inspect([]string{volume.Id}) + volumes, err := testEnumerator.Inspect(context.TODO(), []string{volume.Id}) assert.NoError(t, err, "Failed in Inspect") assert.Equal(t, len(volumes), 1, "Number of volumes returned in inspect should be 1") if len(volumes) == 1 { @@ -40,7 +41,7 @@ func TestInspect(t *testing.T) { } err = testEnumerator.DeleteVol(volume.Id) assert.NoError(t, err, "Failed in Delete") - volumes, err = testEnumerator.Inspect([]string{volume.Id}) + volumes, err = testEnumerator.Inspect(context.TODO(), []string{volume.Id}) assert.NotNil(t, volumes, "Inspect returned nil volumes") assert.Equal(t, len(volumes), 0, "Number of volumes returned in inspect should be 0") } diff --git a/volume/drivers/fake/fake.go b/volume/drivers/fake/fake.go index d99be781a..dd90ceb92 100644 --- a/volume/drivers/fake/fake.go +++ b/volume/drivers/fake/fake.go @@ -30,6 +30,7 @@ import ( "github.com/libopenstorage/openstorage/api" "github.com/libopenstorage/openstorage/cluster" clustermanager "github.com/libopenstorage/openstorage/cluster/manager" + "github.com/libopenstorage/openstorage/pkg/correlation" "github.com/libopenstorage/openstorage/volume" "github.com/libopenstorage/openstorage/volume/drivers/common" "github.com/pborman/uuid" @@ -183,8 +184,8 @@ func (d *driver) Status() [][2]string { return [][2]string{} } -func (d *driver) Inspect(volumeIDs []string) ([]*api.Volume, error) { - volumes, err := d.StoreEnumerator.Inspect(volumeIDs) +func (d *driver) Inspect(ctx context.Context, volumeIDs []string) ([]*api.Volume, error) { + volumes, err := d.StoreEnumerator.Inspect(nil, volumeIDs) if err != nil { return nil, err } else if err == nil && len(volumes) == 0 { @@ -283,7 +284,7 @@ func (d *driver) Snapshot(volumeID string, readonly bool, locator *api.VolumeLoc } volIDs := []string{volumeID} - vols, err := d.Inspect(volIDs) + vols, err := d.Inspect(nil, volIDs) if err != nil { return "", nil } @@ -298,7 +299,7 @@ func (d *driver) Snapshot(volumeID string, readonly bool, locator *api.VolumeLoc } func (d *driver) Restore(volumeID string, snapID string) error { - if _, err := d.Inspect([]string{volumeID, snapID}); err != nil { + if _, err := d.Inspect(correlation.TODO(), []string{volumeID, snapID}); err != nil { return err } @@ -394,7 +395,7 @@ func (d *driver) Set(volumeID string, locator *api.VolumeLocator, spec *api.Volu func (d *driver) Shutdown() {} func (d *driver) UsedSize(volumeID string) (uint64, error) { - vols, err := d.Inspect([]string{volumeID}) + vols, err := d.Inspect(correlation.TODO(), []string{volumeID}) if err == kvdb.ErrNotFound { return 0, fmt.Errorf("Volume not found") } else if err != nil { @@ -416,10 +417,8 @@ func (d *driver) VolumeBytesUsedByNode(nodeMID string, volumes []uint64) (*api.V VolUsage: volusage, }, nil } - -func (d *driver) Stats(volumeID string, cumulative bool) (*api.Stats, error) { - - vols, err := d.Inspect([]string{volumeID}) +func (d *driver) Stats(ctx context.Context, volumeID string, cumulative bool) (*api.Stats, error) { + vols, err := d.Inspect(correlation.TODO(), []string{volumeID}) if err == kvdb.ErrNotFound { return nil, fmt.Errorf("Volume not found") } else if err != nil { @@ -445,7 +444,7 @@ func (d *driver) Stats(volumeID string, cumulative bool) (*api.Stats, error) { func (d *driver) CapacityUsage( volumeID string, ) (*api.CapacityUsageResponse, error) { - vols, err := d.Inspect([]string{volumeID}) + vols, err := d.Inspect(correlation.TODO(), []string{volumeID}) if err == kvdb.ErrNotFound { return nil, fmt.Errorf("Volume not found") } else if err != nil { @@ -540,7 +539,7 @@ func (d *driver) cloudBackupCreate(input *api.CloudBackupCreateRequest) (string, } // Get volume info - vols, err := d.Inspect([]string{input.VolumeID}) + vols, err := d.Inspect(correlation.TODO(), []string{input.VolumeID}) if err != nil { return "", "", fmt.Errorf("Volume id not found") } @@ -636,7 +635,7 @@ func (d *driver) CloudBackupRestore( if err != nil { return nil, err } - vols, err := d.Inspect([]string{volid}) + vols, err := d.Inspect(correlation.TODO(), []string{volid}) if err != nil { return nil, fmt.Errorf("Volume id not found") } @@ -740,7 +739,7 @@ func (d *driver) CloudBackupDeleteAll(input *api.CloudBackupDeleteAllRequest) er // Get volume info if len(input.SrcVolumeID) != 0 { - vols, err := d.Inspect([]string{input.SrcVolumeID}) + vols, err := d.Inspect(correlation.TODO(), []string{input.SrcVolumeID}) if err != nil { return fmt.Errorf("Volume id not found") } @@ -940,7 +939,7 @@ func (d *driver) CloudBackupSchedCreate( } // Check volume - vols, err := d.Inspect([]string{input.SrcVolumeID}) + vols, err := d.Inspect(correlation.TODO(), []string{input.SrcVolumeID}) if err != nil { return nil, fmt.Errorf("Volume id not found") } diff --git a/volume/drivers/fake/fake_test.go b/volume/drivers/fake/fake_test.go index d91da4b19..fcb47cbb6 100644 --- a/volume/drivers/fake/fake_test.go +++ b/volume/drivers/fake/fake_test.go @@ -102,7 +102,7 @@ func TestFakeCreateVolume(t *testing.T) { assert.NoError(t, err) assert.NotEmpty(t, vid) - vols, err := d.Inspect([]string{vid}) + vols, err := d.Inspect(context.TODO(), []string{vid}) assert.NoError(t, err) assert.NotNil(t, vols) assert.Len(t, vols, 1) @@ -115,7 +115,7 @@ func TestFakeInspect(t *testing.T) { d, err := newFakeDriver(map[string]string{}) assert.NoError(t, err) - v, err := d.Inspect([]string{"asdf"}) + v, err := d.Inspect(context.TODO(), []string{"asdf"}) assert.NotNil(t, err) assert.Error(t, err) assert.Equal(t, err, kvdb.ErrNotFound) @@ -210,7 +210,7 @@ func testInitForCloudBackups(t *testing.T, d *driver) (string, string, *api.Clou assert.NotEmpty(t, id) assert.NotEmpty(t, name) - origvols, err := d.Inspect([]string{volid}) + origvols, err := d.Inspect(context.TODO(), []string{volid}) assert.NoError(t, err) assert.Len(t, origvols, 1) origvol := origvols[0] @@ -231,7 +231,7 @@ func TestFakeCloudBackupRestore(t *testing.T) { assert.NoError(t, err) assert.NotEmpty(t, resp.RestoreVolumeID) - vols, err := d.Inspect([]string{resp.RestoreVolumeID}) + vols, err := d.Inspect(context.TODO(), []string{resp.RestoreVolumeID}) assert.NoError(t, err) assert.Len(t, vols, 1) vol := vols[0] @@ -728,7 +728,7 @@ func TestFakeSet(t *testing.T) { assert.NoError(t, err) // Verify - vols, err := d.Inspect([]string{volid}) + vols, err := d.Inspect(context.TODO(), []string{volid}) assert.NoError(t, err) assert.Len(t, vols, 1) assert.NotNil(t, vols[0]) diff --git a/volume/drivers/mock/driver.mock.go b/volume/drivers/mock/driver.mock.go index 964956e5c..47950a579 100644 --- a/volume/drivers/mock/driver.mock.go +++ b/volume/drivers/mock/driver.mock.go @@ -757,18 +757,18 @@ func (mr *MockVolumeDriverMockRecorder) GetVolumeWatcher(arg0, arg1 interface{}) } // Inspect mocks base method. -func (m *MockVolumeDriver) Inspect(arg0 []string) ([]*api.Volume, error) { +func (m *MockVolumeDriver) Inspect(arg0 context.Context, arg1 []string) ([]*api.Volume, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Inspect", arg0) + ret := m.ctrl.Call(m, "Inspect", arg0, arg1) ret0, _ := ret[0].([]*api.Volume) ret1, _ := ret[1].(error) return ret0, ret1 } // Inspect indicates an expected call of Inspect. -func (mr *MockVolumeDriverMockRecorder) Inspect(arg0 interface{}) *gomock.Call { +func (mr *MockVolumeDriverMockRecorder) Inspect(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Inspect", reflect.TypeOf((*MockVolumeDriver)(nil).Inspect), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Inspect", reflect.TypeOf((*MockVolumeDriver)(nil).Inspect), arg0, arg1) } // Mount mocks base method. @@ -955,18 +955,18 @@ func (mr *MockVolumeDriverMockRecorder) StartVolumeWatcher() *gomock.Call { } // Stats mocks base method. -func (m *MockVolumeDriver) Stats(arg0 string, arg1 bool) (*api.Stats, error) { +func (m *MockVolumeDriver) Stats(arg0 context.Context, arg1 string, arg2 bool) (*api.Stats, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Stats", arg0, arg1) + ret := m.ctrl.Call(m, "Stats", arg0, arg1, arg2) ret0, _ := ret[0].(*api.Stats) ret1, _ := ret[1].(error) return ret0, ret1 } // Stats indicates an expected call of Stats. -func (mr *MockVolumeDriverMockRecorder) Stats(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockVolumeDriverMockRecorder) Stats(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stats", reflect.TypeOf((*MockVolumeDriver)(nil).Stats), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stats", reflect.TypeOf((*MockVolumeDriver)(nil).Stats), arg0, arg1, arg2) } // Status mocks base method. @@ -1143,18 +1143,18 @@ func (mr *MockVolumeDriverMockRecorder) VolumeBytesUsedByNode(arg0, arg1 interfa } // VolumeUsageByNode mocks base method. -func (m *MockVolumeDriver) VolumeUsageByNode(arg0 string) (*api.VolumeUsageByNode, error) { +func (m *MockVolumeDriver) VolumeUsageByNode(arg0 context.Context, arg1 string) (*api.VolumeUsageByNode, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "VolumeUsageByNode", arg0) + ret := m.ctrl.Call(m, "VolumeUsageByNode", arg0, arg1) ret0, _ := ret[0].(*api.VolumeUsageByNode) ret1, _ := ret[1].(error) return ret0, ret1 } // VolumeUsageByNode indicates an expected call of VolumeUsageByNode. -func (mr *MockVolumeDriverMockRecorder) VolumeUsageByNode(arg0 interface{}) *gomock.Call { +func (mr *MockVolumeDriverMockRecorder) VolumeUsageByNode(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VolumeUsageByNode", reflect.TypeOf((*MockVolumeDriver)(nil).VolumeUsageByNode), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VolumeUsageByNode", reflect.TypeOf((*MockVolumeDriver)(nil).VolumeUsageByNode), arg0, arg1) } // Write mocks base method. diff --git a/volume/drivers/nfs/nfs.go b/volume/drivers/nfs/nfs.go index cc4ab8f34..3d08d832f 100644 --- a/volume/drivers/nfs/nfs.go +++ b/volume/drivers/nfs/nfs.go @@ -22,6 +22,7 @@ import ( "github.com/libopenstorage/openstorage/api" "github.com/libopenstorage/openstorage/config" + "github.com/libopenstorage/openstorage/pkg/correlation" "github.com/libopenstorage/openstorage/pkg/mount" "github.com/libopenstorage/openstorage/pkg/seed" "github.com/libopenstorage/openstorage/pkg/util" @@ -675,7 +676,7 @@ func (d *driver) clone(newVolumeID, volumeID string) error { func (d *driver) Snapshot(volumeID string, readonly bool, locator *api.VolumeLocator, noRetry bool) (string, error) { volIDs := []string{volumeID} - vols, err := d.Inspect(volIDs) + vols, err := d.Inspect(nil, volIDs) if err != nil { return "", nil } @@ -685,7 +686,7 @@ func (d *driver) Snapshot(volumeID string, readonly bool, locator *api.VolumeLoc } func (d *driver) Restore(volumeID string, snapID string) error { - if _, err := d.Inspect([]string{volumeID, snapID}); err != nil { + if _, err := d.Inspect(correlation.TODO(), []string{volumeID, snapID}); err != nil { return err } @@ -720,7 +721,7 @@ func (d *driver) Attach(ctx context.Context, volumeID string, attachOptions map[ blockFile := path.Join(nfsPath, volumeID+nfsBlockFile) // Check if it is block - v, err := util.VolumeFromName(d, volumeID) + v, err := util.VolumeFromName(ctx, d, volumeID) if err != nil { return "", err } @@ -753,7 +754,7 @@ func (d *driver) Attach(ctx context.Context, volumeID string, attachOptions map[ func (d *driver) Detach(ctx context.Context, volumeID string, options map[string]string) error { // Get volume info - v, err := util.VolumeFromName(d, volumeID) + v, err := util.VolumeFromName(ctx, d, volumeID) if err != nil { return err } diff --git a/volume/drivers/test/driver.go b/volume/drivers/test/driver.go index d03e70d26..3b2aa4b3c 100644 --- a/volume/drivers/test/driver.go +++ b/volume/drivers/test/driver.go @@ -3,6 +3,7 @@ package test import ( "context" "fmt" + "github.com/libopenstorage/openstorage/pkg/correlation" "os" "os/exec" "path" @@ -128,20 +129,20 @@ func create(t *testing.T, ctx *Context) { func inspect(t *testing.T, ctx *Context) { fmt.Println("inspect") - vols, err := ctx.Inspect([]string{ctx.volID}) + vols, err := ctx.Inspect(correlation.TODO(), []string{ctx.volID}) require.NoError(t, err, "Failed in Inspect") require.NotNil(t, vols, "Nil vols") require.Equal(t, len(vols), 1, "Expect 1 volume actual %v volumes", len(vols)) require.Equal(t, vols[0].Id, ctx.volID, "Expect volID %v actual %v", ctx.volID, vols[0].Id) - vols, err = ctx.Inspect([]string{string("shouldNotExist")}) + vols, err = ctx.Inspect(correlation.TODO(), []string{string("shouldNotExist")}) require.Equal(t, 0, len(vols), "Expect 0 volume actual %v volumes", len(vols)) } func set(t *testing.T, ctx *Context) { fmt.Println("update") - vols, err := ctx.Inspect([]string{ctx.volID}) + vols, err := ctx.Inspect(correlation.TODO(), []string{ctx.volID}) require.NoError(t, err, "Failed in Inspect") require.NotNil(t, vols, "Nil vols") require.Equal(t, len(vols), 1, "Expect 1 volume actual %v volumes", len(vols)) @@ -151,7 +152,7 @@ func set(t *testing.T, ctx *Context) { err = ctx.Set(ctx.volID, vols[0].Locator, nil) if err != volume.ErrNotSupported { require.NoError(t, err, "Failed in Update") - vols, err = ctx.Inspect([]string{ctx.volID}) + vols, err = ctx.Inspect(correlation.TODO(), []string{ctx.volID}) require.NoError(t, err, "Failed in Inspect") require.NotNil(t, vols, "Nil vols") require.Equal(t, len(vols), 1, "Expect 1 volume actual %v volumes", len(vols)) @@ -183,11 +184,11 @@ func waitReady(t *testing.T, ctx *Context) error { total := time.Minute * 5 inc := time.Second * 2 elapsed := time.Second * 0 - vols, err := ctx.Inspect([]string{ctx.volID}) + vols, err := ctx.Inspect(correlation.TODO(), []string{ctx.volID}) for err == nil && len(vols) == 1 && vols[0].Status != api.VolumeStatus_VOLUME_STATUS_UP && elapsed < total { time.Sleep(inc) elapsed += inc - vols, err = ctx.Inspect([]string{ctx.volID}) + vols, err = ctx.Inspect(correlation.TODO(), []string{ctx.volID}) } if err != nil { return err @@ -330,13 +331,13 @@ func snap(t *testing.T, ctx *Context) { func snapInspect(t *testing.T, ctx *Context) { fmt.Println("snapInspect") - snaps, err := ctx.Inspect([]string{ctx.snapID}) + snaps, err := ctx.Inspect(correlation.TODO(), []string{ctx.snapID}) require.NoError(t, err, "Failed in Inspect") require.NotNil(t, snaps, "Nil snaps") require.Equal(t, len(snaps), 1, "Expect 1 snaps actual %v snaps", len(snaps)) require.Equal(t, snaps[0].Id, ctx.snapID, "Expect snapID %v actual %v", ctx.snapID, snaps[0].Id) - snaps, err = ctx.Inspect([]string{string("shouldNotExist")}) + snaps, err = ctx.Inspect(correlation.TODO(), []string{string("shouldNotExist")}) require.Equal(t, 0, len(snaps), "Expect 0 snaps actual %v snaps", len(snaps)) } diff --git a/volume/volume.go b/volume/volume.go index 00c389f79..ce9a4349d 100644 --- a/volume/volume.go +++ b/volume/volume.go @@ -3,7 +3,6 @@ package volume import ( "context" "errors" - "github.com/libopenstorage/openstorage/api" ) @@ -136,7 +135,7 @@ type StatsDriver interface { // cumulative stats are /proc/diskstats style stats. // nonCumulative stats are stats for specific duration. // Errors ErrEnoEnt may be returned - Stats(volumeID string, cumulative bool) (*api.Stats, error) + Stats(ctx context.Context, volumeID string, cumulative bool) (*api.Stats, error) // UsedSize returns currently used volume size. // Errors ErrEnoEnt may be returned. UsedSize(volumeID string) (uint64, error) @@ -147,7 +146,7 @@ type StatsDriver interface { CapacityUsage(ID string) (*api.CapacityUsageResponse, error) // VolumeUsageByNode returns capacity usage of all volumes and snaps for a // given node - VolumeUsageByNode(nodeID string) (*api.VolumeUsageByNode, error) + VolumeUsageByNode(ctx context.Context, nodeID string) (*api.VolumeUsageByNode, error) // RelaxedReclaimPurge triggers the purge of RelaxedReclaim queue for a // given node RelaxedReclaimPurge(nodeID string) (*api.RelaxedReclaimPurge, error) @@ -308,7 +307,7 @@ type ProtoDriver interface { type Enumerator interface { // Inspect specified volumes. // Returns slice of volumes that were found. - Inspect(volumeIDs []string) ([]*api.Volume, error) + Inspect(ctx context.Context, volumeIDs []string) ([]*api.Volume, error) // Enumerate volumes that map to the volumeLocator. Locator fields may be regexp. // If locator fields are left blank, this will return all volumes. Enumerate(locator *api.VolumeLocator, labels map[string]string) ([]*api.Volume, error) diff --git a/volume/volume_not_supported.go b/volume/volume_not_supported.go index 9f0aba3f2..d230029b4 100644 --- a/volume/volume_not_supported.go +++ b/volume/volume_not_supported.go @@ -2,7 +2,6 @@ package volume import ( "context" - "github.com/libopenstorage/openstorage/api" ) @@ -82,10 +81,7 @@ func (i *ioNotSupported) Flush(volumeID string) error { type statsNotSupported struct{} // Stats returns stats -func (s *statsNotSupported) Stats( - volumeID string, - cumulative bool, -) (*api.Stats, error) { +func (s *statsNotSupported) Stats(ctx context.Context, volumeID string, cumulative bool) (*api.Stats, error) { return nil, ErrNotSupported } @@ -109,9 +105,7 @@ func (s *statsNotSupported) CapacityUsage( // VolumeUsageByNode returns capacity usage of all volumes/snaps belonging to // a node -func (s *statsNotSupported) VolumeUsageByNode( - nodeID string, -) (*api.VolumeUsageByNode, error) { +func (s *statsNotSupported) VolumeUsageByNode(ctx context.Context, nodeID string) (*api.VolumeUsageByNode, error) { return nil, ErrNotSupported } From 548d38fe77e8ac9708b2f4239813e6a862862c80 Mon Sep 17 00:00:00 2001 From: alice-px Date: Wed, 24 Jan 2024 12:54:55 -0800 Subject: [PATCH 2/3] add ctx to Set function (#2405) --- .travis.yml | 2 +- api/client/volume/client.go | 3 +-- api/server/middleware_auth.go | 2 +- api/server/sdk/volume_ops.go | 2 +- api/server/sdk/volume_ops_test.go | 12 ++++++------ api/server/sdk/volume_snapshot_test.go | 7 ++++--- api/server/volume_test.go | 22 ++++++++++------------ csi/controller_test.go | 6 +++--- go.mod | 2 +- pkg/sanity/volume.go | 4 ++-- volume/drivers/buse/buse.go | 2 +- volume/drivers/fake/fake.go | 2 +- volume/drivers/fake/fake_test.go | 2 +- volume/drivers/fuse/volume_driver.go | 2 +- volume/drivers/mock/driver.mock.go | 8 ++++---- volume/drivers/nfs/nfs.go | 2 +- volume/drivers/test/driver.go | 2 +- volume/drivers/vfs/vfs.go | 2 +- volume/volume.go | 2 +- 19 files changed, 42 insertions(+), 44 deletions(-) diff --git a/.travis.yml b/.travis.yml index e37364e49..06186aaf2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ services: - docker language: go go: - - 1.18.x + - 1.19.x install: - go install github.com/vbatts/git-validation@v1.1.0 - curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl diff --git a/api/client/volume/client.go b/api/client/volume/client.go index 696f20a8b..22e9073f9 100644 --- a/api/client/volume/client.go +++ b/api/client/volume/client.go @@ -460,8 +460,7 @@ func (v *volumeClient) Unmount(ctx context.Context, volumeID string, mountPath s } // Update volume -func (v *volumeClient) Set(volumeID string, locator *api.VolumeLocator, - spec *api.VolumeSpec) error { +func (v *volumeClient) Set(ctx context.Context, volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error { return v.doVolumeSet(correlation.TODO(), volumeID, &api.VolumeSetRequest{ diff --git a/api/server/middleware_auth.go b/api/server/middleware_auth.go index 0d7ac8b05..9ba1e4bd5 100644 --- a/api/server/middleware_auth.go +++ b/api/server/middleware_auth.go @@ -205,7 +205,7 @@ func (a *authMiddleware) setWithAuth(w http.ResponseWriter, r *http.Request, nex if req.Spec != nil && req.Spec.Size > 0 { isOpDone = true - err = d.Set(volumeID, req.Locator, req.Spec) + err = d.Set(ctx, volumeID, req.Locator, req.Spec) } for err == nil && req.Action != nil { diff --git a/api/server/sdk/volume_ops.go b/api/server/sdk/volume_ops.go index c84f030a6..e3cbebfb8 100644 --- a/api/server/sdk/volume_ops.go +++ b/api/server/sdk/volume_ops.go @@ -729,7 +729,7 @@ func (s *VolumeServer) Update( maskUnModified(updatedSpec, req.GetSpec()) // Send to driver - if err := s.driver(ctx).Set(req.GetVolumeId(), locator, updatedSpec); err != nil { + if err := s.driver(ctx).Set(ctx, req.GetVolumeId(), locator, updatedSpec); err != nil { return nil, status.Errorf(codes.Internal, "Failed to update volume: %v", err) } diff --git a/api/server/sdk/volume_ops_test.go b/api/server/sdk/volume_ops_test.go index efd9c4c84..a4b86f85d 100644 --- a/api/server/sdk/volume_ops_test.go +++ b/api/server/sdk/volume_ops_test.go @@ -647,7 +647,7 @@ func TestSdkVolumeUpdate(t *testing.T) { AnyTimes() s.MockDriver(). EXPECT(). - Set(id, &api.VolumeLocator{VolumeLabels: newlabels}, &api.VolumeSpec{SnapshotInterval: math.MaxUint32}). + Set(gomock.Any(), id, &api.VolumeLocator{VolumeLabels: newlabels}, &api.VolumeSpec{SnapshotInterval: math.MaxUint32}). Return(nil). Times(1) @@ -668,7 +668,7 @@ func TestSdkVolumeUpdate(t *testing.T) { s.MockDriver(). EXPECT(). - Set(id, nil, &api.VolumeSpec{Size: 1234, SnapshotInterval: math.MaxUint32}). + Set(gomock.Any(), id, nil, &api.VolumeSpec{Size: 1234, SnapshotInterval: math.MaxUint32}). Return(nil). Times(1) _, err = c.Update(context.Background(), req) @@ -687,7 +687,7 @@ func TestSdkVolumeUpdate(t *testing.T) { s.MockDriver(). EXPECT(). - Set( + Set(gomock.Any(), id, &api.VolumeLocator{VolumeLabels: newlabels}, &api.VolumeSpec{Size: 1234, SnapshotInterval: math.MaxUint32}, @@ -1156,7 +1156,7 @@ func TestSdkCloneOwnership(t *testing.T) { Times(1), mv. EXPECT(). - Set(id, nil, &api.VolumeSpec{ + Set(gomock.Any(), id, nil, &api.VolumeSpec{ Size: 1234, Ownership: &api.Ownership{ Owner: user2, @@ -1283,7 +1283,7 @@ func TestSdkCloneOwnership(t *testing.T) { Times(1), mv. EXPECT(). - Set(id, nil, &api.VolumeSpec{ + Set(gomock.Any(), id, nil, &api.VolumeSpec{ Size: 1234, Ownership: &api.Ownership{ Owner: user2, @@ -1803,7 +1803,7 @@ func TestSdkVolumeUpdatePolicyOwnership(t *testing.T) { AnyTimes() mv. EXPECT(). - Set(id, nil, volPolSpec). + Set(gomock.Any(), id, nil, volPolSpec). Return(nil). Times(1) diff --git a/api/server/sdk/volume_snapshot_test.go b/api/server/sdk/volume_snapshot_test.go index 25e1d27e6..3e432582e 100644 --- a/api/server/sdk/volume_snapshot_test.go +++ b/api/server/sdk/volume_snapshot_test.go @@ -6,7 +6,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -18,6 +18,7 @@ package sdk import ( "context" + "github.com/golang/mock/gomock" "math" "testing" @@ -311,7 +312,7 @@ func TestSdkVolumeSnapshotScheduleUpdate(t *testing.T) { Times(1) s.MockDriver(). EXPECT(). - Set(volid, nil, &api.VolumeSpec{ + Set(gomock.Any(), volid, nil, &api.VolumeSpec{ SnapshotSchedule: "policy=mypolicy", SnapshotInterval: math.MaxUint32, }). @@ -348,7 +349,7 @@ func TestSdkVolumeSnapshotScheduleUpdateDelete(t *testing.T) { AnyTimes() s.MockDriver(). EXPECT(). - Set(volid, nil, &api.VolumeSpec{ + Set(gomock.Any(), volid, nil, &api.VolumeSpec{ SnapshotSchedule: "", SnapshotInterval: math.MaxUint32, }). diff --git a/api/server/volume_test.go b/api/server/volume_test.go index faf0f1039..f0ecec172 100644 --- a/api/server/volume_test.go +++ b/api/server/volume_test.go @@ -123,7 +123,7 @@ func TestVolumeNoAuth(t *testing.T) { newspec := req.GetSpec() newspec.Size = newsize - resp := driverclient.Set(id, req.GetLocator(), newspec) + resp := driverclient.Set(context.TODO(), id, req.GetLocator(), newspec) assert.Nil(t, resp) // INSPECT @@ -793,7 +793,7 @@ func TestVolumeSetSuccess(t *testing.T) { Spec: &api.VolumeSpec{Size: newsize}, } - res := driverclient.Set(id, req.GetLocator(), req2.GetSpec()) + res := driverclient.Set(context.TODO(), id, req.GetLocator(), req2.GetSpec()) assert.Nil(t, res) // Assert volume information is correct @@ -808,13 +808,11 @@ func TestVolumeSetSuccess(t *testing.T) { assert.Equal(t, newsize, r.GetVolume().GetSpec().GetSize()) // Send HA request - res = driverclient.Set(id, - nil, - &api.VolumeSpec{ - HaLevel: 2, - ReplicaSet: &api.ReplicaSet{Nodes: []string{}}, - SnapshotInterval: math.MaxUint32, - }) + res = driverclient.Set(context.TODO(), id, nil, &api.VolumeSpec{ + HaLevel: 2, + ReplicaSet: &api.ReplicaSet{Nodes: []string{}}, + SnapshotInterval: math.MaxUint32, + }) assert.Nil(t, res, fmt.Sprintf("Error: %v", res)) // Assert volume information is correct @@ -884,7 +882,7 @@ func TestVolumeSetFailed(t *testing.T) { Spec: &api.VolumeSpec{Size: size, HaLevel: halevel}, } // Cannot get this to fail.... - err = driverclient.Set("doesnotexist", req2.GetLocator(), req2.GetSpec()) + err = driverclient.Set(context.TODO(), "doesnotexist", req2.GetLocator(), req2.GetSpec()) // assert.NotNil(t, err) // Assert volume information is correct @@ -929,7 +927,7 @@ func TestMiddlewareVolumeSetSizeSuccess(t *testing.T) { // Not setting mock secrets - err = driverclient.Set(id, nil, req.GetSpec()) + err = driverclient.Set(context.TODO(), id, nil, req.GetSpec()) assert.NoError(t, err, "Unexpected error on Set") // Assert volume information is correct @@ -976,7 +974,7 @@ func TestMiddlewareVolumeSetFailure(t *testing.T) { // Not setting mock secrets - err = driverclient.Set(id, &api.VolumeLocator{Name: "myvol"}, req.GetSpec()) + err = driverclient.Set(context.TODO(), id, &api.VolumeLocator{Name: "myvol"}, req.GetSpec()) assert.Error(t, err, "Unexpected error on Set") } diff --git a/csi/controller_test.go b/csi/controller_test.go index f6671cf29..6bf9d242d 100644 --- a/csi/controller_test.go +++ b/csi/controller_test.go @@ -1955,7 +1955,7 @@ func TestControllerCreateVolumeFromSnapshot(t *testing.T) { s.MockDriver(). EXPECT(). - Set(gomock.Any(), gomock.Any(), gomock.Any()). + Set(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). Return(nil). Times(1), @@ -2092,7 +2092,7 @@ func TestControllerCreateVolumeSnapshotThroughParameters(t *testing.T) { Times(1), s.MockDriver(). EXPECT(). - Set(gomock.Any(), gomock.Any(), gomock.Any()). + Set(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). Return(nil). Times(1), // final inspect @@ -2750,7 +2750,7 @@ func TestControllerExpandVolume(t *testing.T) { AnyTimes(), s.MockDriver(). EXPECT(). - Set(gomock.Any(), gomock.Any(), &api.VolumeSpec{ + Set(gomock.Any(), gomock.Any(), gomock.Any(), &api.VolumeSpec{ Size: 46 * units.GiB, // Round up from 45.5 to 46 SnapshotInterval: math.MaxUint32, }). diff --git a/go.mod b/go.mod index e3524dbac..60eb6e379 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,6 @@ require ( github.com/libopenstorage/gossip v0.0.0-20220309192431-44c895e0923e github.com/libopenstorage/secrets v0.0.0-20200207034622-cdb443738c67 github.com/libopenstorage/systemutils v0.0.0-20160208220149-44ac83be3ce1 - github.com/moby/sys/mount v0.2.0 github.com/moby/sys/mountinfo v0.4.0 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 github.com/onsi/ginkgo v1.16.5 @@ -105,6 +104,7 @@ require ( github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.3.3 // indirect github.com/moby/locker v1.0.1 // indirect + github.com/moby/sys/mount v0.2.0 // indirect github.com/moby/sys/symlink v0.1.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect diff --git a/pkg/sanity/volume.go b/pkg/sanity/volume.go index 6227dfaf4..e923bdd81 100644 --- a/pkg/sanity/volume.go +++ b/pkg/sanity/volume.go @@ -617,7 +617,7 @@ var _ = Describe("Volume [Volume Tests]", func() { }, } - err = volumedriver.Set(volumeID, set.GetLocator(), set.GetSpec()) + err = volumedriver.Set(context.TODO(), volumeID, set.GetLocator(), set.GetSpec()) Expect(err).NotTo(HaveOccurred()) By("Inspecting the volume for new updates") @@ -679,7 +679,7 @@ var _ = Describe("Volume [Volume Tests]", func() { }, } - err = volumedriver.Set(volumeID, set.Locator, set.Spec) + err = volumedriver.Set(context.TODO(), volumeID, set.Locator, set.Spec) Expect(err).NotTo(HaveOccurred()) By("Inspecting the volume for new updates") diff --git a/volume/drivers/buse/buse.go b/volume/drivers/buse/buse.go index 4af9b72d0..8cc136837 100644 --- a/volume/drivers/buse/buse.go +++ b/volume/drivers/buse/buse.go @@ -362,7 +362,7 @@ func (d *driver) SnapshotGroup(groupID string, labels map[string]string, volumeI return nil, volume.ErrNotSupported } -func (d *driver) Set(volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error { +func (d *driver) Set(ctx context.Context, volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error { if spec != nil { return volume.ErrNotSupported } diff --git a/volume/drivers/fake/fake.go b/volume/drivers/fake/fake.go index dd90ceb92..6fd57c8bf 100644 --- a/volume/drivers/fake/fake.go +++ b/volume/drivers/fake/fake.go @@ -336,7 +336,7 @@ func (d *driver) CloudMigrateStatus(request *api.CloudMigrateStatusRequest) (*ap }, nil } -func (d *driver) Set(volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error { +func (d *driver) Set(ctx context.Context, volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error { v, err := d.GetVol(volumeID) if err != nil { return err diff --git a/volume/drivers/fake/fake_test.go b/volume/drivers/fake/fake_test.go index fcb47cbb6..af013c5bc 100644 --- a/volume/drivers/fake/fake_test.go +++ b/volume/drivers/fake/fake_test.go @@ -715,7 +715,7 @@ func TestFakeSet(t *testing.T) { assert.NotEmpty(t, volid) // Set values - err = d.Set(volid, &api.VolumeLocator{ + err = d.Set(context.TODO(), volid, &api.VolumeLocator{ Name: "newname", VolumeLabels: map[string]string{ "hello": "world", diff --git a/volume/drivers/fuse/volume_driver.go b/volume/drivers/fuse/volume_driver.go index c96fd539e..c509101fe 100644 --- a/volume/drivers/fuse/volume_driver.go +++ b/volume/drivers/fuse/volume_driver.go @@ -180,7 +180,7 @@ func (v *volumeDriver) Unmount(ctx context.Context, volumeID string, mountpath s return v.UpdateVol(volume) } -func (v *volumeDriver) Set(volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error { +func (v *volumeDriver) Set(ctx context.Context, volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error { return volume.ErrNotSupported } diff --git a/volume/drivers/mock/driver.mock.go b/volume/drivers/mock/driver.mock.go index 47950a579..ed286c982 100644 --- a/volume/drivers/mock/driver.mock.go +++ b/volume/drivers/mock/driver.mock.go @@ -872,17 +872,17 @@ func (mr *MockVolumeDriverMockRecorder) Restore(arg0, arg1 interface{}) *gomock. } // Set mocks base method. -func (m *MockVolumeDriver) Set(arg0 string, arg1 *api.VolumeLocator, arg2 *api.VolumeSpec) error { +func (m *MockVolumeDriver) Set(arg0 context.Context, arg1 string, arg2 *api.VolumeLocator, arg3 *api.VolumeSpec) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Set", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "Set", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(error) return ret0 } // Set indicates an expected call of Set. -func (mr *MockVolumeDriverMockRecorder) Set(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockVolumeDriverMockRecorder) Set(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Set", reflect.TypeOf((*MockVolumeDriver)(nil).Set), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Set", reflect.TypeOf((*MockVolumeDriver)(nil).Set), arg0, arg1, arg2, arg3) } // Shutdown mocks base method. diff --git a/volume/drivers/nfs/nfs.go b/volume/drivers/nfs/nfs.go index 3d08d832f..0cc8a5002 100644 --- a/volume/drivers/nfs/nfs.go +++ b/volume/drivers/nfs/nfs.go @@ -789,7 +789,7 @@ func (d *driver) Detach(ctx context.Context, volumeID string, options map[string return nil } -func (d *driver) Set(volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error { +func (d *driver) Set(ctx context.Context, volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error { if spec != nil { return volume.ErrNotSupported } diff --git a/volume/drivers/test/driver.go b/volume/drivers/test/driver.go index 3b2aa4b3c..5e867b402 100644 --- a/volume/drivers/test/driver.go +++ b/volume/drivers/test/driver.go @@ -149,7 +149,7 @@ func set(t *testing.T, ctx *Context) { require.Equal(t, vols[0].Id, ctx.volID, "Expect volID %v actual %v", ctx.volID, vols[0].Id) vols[0].Locator.VolumeLabels["UpdateTest"] = "Success" - err = ctx.Set(ctx.volID, vols[0].Locator, nil) + err = ctx.Set(correlation.TODO(), ctx.volID, vols[0].Locator, nil) if err != volume.ErrNotSupported { require.NoError(t, err, "Failed in Update") vols, err = ctx.Inspect(correlation.TODO(), []string{ctx.volID}) diff --git a/volume/drivers/vfs/vfs.go b/volume/drivers/vfs/vfs.go index 28cf9181d..1e903929f 100644 --- a/volume/drivers/vfs/vfs.go +++ b/volume/drivers/vfs/vfs.go @@ -171,7 +171,7 @@ func (d *driver) Unmount(ctx context.Context, volumeID string, mountpath string, return d.UpdateVol(v) } -func (d *driver) Set(volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error { +func (d *driver) Set(ctx context.Context, volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error { if spec != nil { return volume.ErrNotSupported } diff --git a/volume/volume.go b/volume/volume.go index ce9a4349d..cbd70c12d 100644 --- a/volume/volume.go +++ b/volume/volume.go @@ -291,7 +291,7 @@ type ProtoDriver interface { Unmount(ctx context.Context, volumeID string, mountPath string, options map[string]string) error // Update not all fields of the spec are supported, ErrNotSupported will be thrown for unsupported // updates. - Set(volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error + Set(ctx context.Context, volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error // Status returns a set of key-value pairs which give low // level diagnostic status about this driver. Status() [][2]string From e65dddd192ef9944ec997f96ecfe61bc02e67d1f Mon Sep 17 00:00:00 2001 From: alice-px Date: Thu, 25 Jan 2024 16:27:35 -0800 Subject: [PATCH 3/3] PWX-35577: correlation tracing for Snapshot function (#2407) --- api/client/volume/client.go | 6 +----- api/server/sdk/volume_ops.go | 2 +- api/server/sdk/volume_ops_test.go | 10 +++++----- api/server/sdk/volume_snapshot.go | 2 +- api/server/sdk/volume_snapshot_test.go | 2 +- api/server/volume_test.go | 12 ++++++------ cli/volumes.go | 2 +- csi/controller_test.go | 8 ++++---- pkg/sanity/snapshot.go | 6 +++--- volume/drivers/btrfs/btrfs.go | 4 ++-- volume/drivers/buse/buse.go | 2 +- volume/drivers/fake/fake.go | 2 +- volume/drivers/mock/driver.mock.go | 8 ++++---- volume/drivers/nfs/nfs.go | 2 +- volume/drivers/test/driver.go | 6 ++---- volume/volume.go | 2 +- volume/volume_not_supported.go | 2 +- 17 files changed, 36 insertions(+), 42 deletions(-) diff --git a/api/client/volume/client.go b/api/client/volume/client.go index 22e9073f9..5a03c06f2 100644 --- a/api/client/volume/client.go +++ b/api/client/volume/client.go @@ -200,11 +200,7 @@ func (v *volumeClient) Delete(ctx context.Context, volumeID string) error { // Snap specified volume. IO to the underlying volume should be quiesced before // calling this function. // Errors ErrEnoEnt may be returned -func (v *volumeClient) Snapshot(volumeID string, - readonly bool, - locator *api.VolumeLocator, - noRetry bool, -) (string, error) { +func (v *volumeClient) Snapshot(ctx context.Context, volumeID string, readonly bool, locator *api.VolumeLocator, noRetry bool) (string, error) { response := &api.SnapCreateResponse{} request := &api.SnapCreateRequest{ Id: volumeID, diff --git a/api/server/sdk/volume_ops.go b/api/server/sdk/volume_ops.go index e3cbebfb8..12931d788 100644 --- a/api/server/sdk/volume_ops.go +++ b/api/server/sdk/volume_ops.go @@ -171,7 +171,7 @@ func (s *VolumeServer) create( } // Create a snapshot from the parent - id, err = s.driver(ctx).Snapshot(parent.GetId(), false, &api.VolumeLocator{ + id, err = s.driver(ctx).Snapshot(ctx, parent.GetId(), false, &api.VolumeLocator{ Name: volName, }, false) if err != nil { diff --git a/api/server/sdk/volume_ops_test.go b/api/server/sdk/volume_ops_test.go index a4b86f85d..00a66d13d 100644 --- a/api/server/sdk/volume_ops_test.go +++ b/api/server/sdk/volume_ops_test.go @@ -313,7 +313,7 @@ func TestSdkVolumeClone(t *testing.T) { s.MockDriver(). EXPECT(). - Snapshot(parentid, false, &api.VolumeLocator{Name: name}, false). + Snapshot(gomock.Any(), parentid, false, &api.VolumeLocator{Name: name}, false). Return(id, nil). Times(1), @@ -1087,7 +1087,7 @@ func TestSdkCloneOwnership(t *testing.T) { mv. EXPECT(). - Snapshot(parentid, false, &api.VolumeLocator{Name: name}, false). + Snapshot(gomock.Any(), parentid, false, &api.VolumeLocator{Name: name}, false). Return(id, nil). Times(1), @@ -1134,7 +1134,7 @@ func TestSdkCloneOwnership(t *testing.T) { mv. EXPECT(). - Snapshot(parentid, false, &api.VolumeLocator{Name: name}, false). + Snapshot(gomock.Any(), parentid, false, &api.VolumeLocator{Name: name}, false). Return(id, nil). Times(1), @@ -1205,7 +1205,7 @@ func TestSdkCloneOwnership(t *testing.T) { mv. EXPECT(). - Snapshot(parentid, false, &api.VolumeLocator{Name: name}, false). + Snapshot(gomock.Any(), parentid, false, &api.VolumeLocator{Name: name}, false). Return(id, nil). Times(1), @@ -1261,7 +1261,7 @@ func TestSdkCloneOwnership(t *testing.T) { mv. EXPECT(). - Snapshot(parentid, false, &api.VolumeLocator{Name: name}, false). + Snapshot(gomock.Any(), parentid, false, &api.VolumeLocator{Name: name}, false). Return(id, nil). Times(1), diff --git a/api/server/sdk/volume_snapshot.go b/api/server/sdk/volume_snapshot.go index fdf0b323a..3d2cd72fb 100644 --- a/api/server/sdk/volume_snapshot.go +++ b/api/server/sdk/volume_snapshot.go @@ -47,7 +47,7 @@ func (s *VolumeServer) SnapshotCreate( } readonly := true - snapshotID, err := s.driver(ctx).Snapshot(req.GetVolumeId(), readonly, &api.VolumeLocator{ + snapshotID, err := s.driver(ctx).Snapshot(ctx, req.GetVolumeId(), readonly, &api.VolumeLocator{ Name: req.GetName(), VolumeLabels: req.GetLabels(), }, false) diff --git a/api/server/sdk/volume_snapshot_test.go b/api/server/sdk/volume_snapshot_test.go index 3e432582e..b93c3e620 100644 --- a/api/server/sdk/volume_snapshot_test.go +++ b/api/server/sdk/volume_snapshot_test.go @@ -78,7 +78,7 @@ func TestSdkVolumeSnapshotCreate(t *testing.T) { Times(1) s.MockDriver(). EXPECT(). - Snapshot(req.GetVolumeId(), true, &api.VolumeLocator{ + Snapshot(gomock.Any(), req.GetVolumeId(), true, &api.VolumeLocator{ Name: snapName, }, false). Return(snapid, nil). diff --git a/api/server/volume_test.go b/api/server/volume_test.go index f0ecec172..aedacf861 100644 --- a/api/server/volume_test.go +++ b/api/server/volume_test.go @@ -471,7 +471,7 @@ func TestVolumeSnapshotCreateSuccess(t *testing.T) { Readonly: true, } - _, err = driverclient.Snapshot(id, req2.GetReadonly(), req2.GetLocator(), req2.GetNoRetry()) + _, err = driverclient.Snapshot(context.TODO(), id, req2.GetReadonly(), req2.GetLocator(), req2.GetNoRetry()) assert.Nil(t, err) _, err = volumes.Delete(ctx, &api.SdkVolumeDeleteRequest{ @@ -529,7 +529,7 @@ func TestVolumeSnapshotCreateFailed(t *testing.T) { Readonly: true, } - res, _ := driverclient.Snapshot("doesnotexist", req2.GetReadonly(), req2.GetLocator(), req2.GetNoRetry()) + res, _ := driverclient.Snapshot(context.TODO(), "doesnotexist", req2.GetReadonly(), req2.GetLocator(), req2.GetNoRetry()) assert.Equal(t, "", res) _, err = volumes.Delete(ctx, &api.SdkVolumeDeleteRequest{ @@ -696,7 +696,7 @@ func TestVolumeSnapshotList(t *testing.T) { Readonly: true, } - _, err = driverclient.Snapshot(id, req2.GetReadonly(), req2.GetLocator(), req2.GetNoRetry()) + _, err = driverclient.Snapshot(context.TODO(), id, req2.GetReadonly(), req2.GetLocator(), req2.GetNoRetry()) assert.Nil(t, err) res, err := driverclient.SnapEnumerate([]string{id}, nil) @@ -704,7 +704,7 @@ func TestVolumeSnapshotList(t *testing.T) { assert.NotNil(t, res) assert.Len(t, res, 1) - _, err = driverclient.Snapshot(id, req2.GetReadonly(), req2.GetLocator(), req2.GetNoRetry()) + _, err = driverclient.Snapshot(context.TODO(), id, req2.GetReadonly(), req2.GetLocator(), req2.GetNoRetry()) assert.Nil(t, err) res, err = driverclient.SnapEnumerate([]string{id}, nil) @@ -1651,7 +1651,7 @@ func TestVolumeRestoreSuccess(t *testing.T) { Readonly: true, } - res, err := driverclient.Snapshot(req2.GetId(), req2.GetReadonly(), req2.GetLocator(), req2.GetNoRetry()) + res, err := driverclient.Snapshot(context.TODO(), req2.GetId(), req2.GetReadonly(), req2.GetLocator(), req2.GetNoRetry()) assert.Nil(t, err) // create client @@ -1712,7 +1712,7 @@ func TestVolumeRestoreFailed(t *testing.T) { Readonly: true, } - _, err = driverclient.Snapshot(req2.GetId(), req2.GetReadonly(), req2.GetLocator(), req2.GetNoRetry()) + _, err = driverclient.Snapshot(context.TODO(), req2.GetId(), req2.GetReadonly(), req2.GetLocator(), req2.GetNoRetry()) assert.Nil(t, err) // create client diff --git a/cli/volumes.go b/cli/volumes.go index b3a2a56f6..956df1082 100644 --- a/cli/volumes.go +++ b/cli/volumes.go @@ -304,7 +304,7 @@ func (v *volDriver) snapCreate(cliContext *cli.Context) { } readonly := cliContext.Bool("readonly") noRetry := cliContext.Bool("noretry") - id, err := v.volDriver.Snapshot(volumeID, readonly, locator, noRetry) + id, err := v.volDriver.Snapshot(context.TODO(), volumeID, readonly, locator, noRetry) if err != nil { cmdError(cliContext, fn, err) return diff --git a/csi/controller_test.go b/csi/controller_test.go index 6bf9d242d..cac51e16b 100644 --- a/csi/controller_test.go +++ b/csi/controller_test.go @@ -1331,7 +1331,7 @@ func TestControllerCreateVolumeBadSnapshot(t *testing.T) { // Return an error from snapshot s.MockDriver(). EXPECT(). - Snapshot(parent, false, &api.VolumeLocator{Name: name}, false). + Snapshot(gomock.Any(), parent, false, &api.VolumeLocator{Name: name}, false). Return("", fmt.Errorf("snapshoterr")). Times(1), ) @@ -1937,7 +1937,7 @@ func TestControllerCreateVolumeFromSnapshot(t *testing.T) { // create s.MockDriver(). EXPECT(). - Snapshot(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + Snapshot(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). Return(snapID, nil). Times(1), s.MockDriver(). @@ -2044,7 +2044,7 @@ func TestControllerCreateVolumeSnapshotThroughParameters(t *testing.T) { // create snap s.MockDriver(). EXPECT(). - Snapshot(mockParentID, false, &api.VolumeLocator{ + Snapshot(gomock.Any(), mockParentID, false, &api.VolumeLocator{ Name: name, }, false). @@ -2933,7 +2933,7 @@ func TestControllerCreateSnapshot(t *testing.T) { // snapshot s.MockDriver(). EXPECT(). - Snapshot(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + Snapshot(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). Return(snapId, nil). Times(1), diff --git a/pkg/sanity/snapshot.go b/pkg/sanity/snapshot.go index 2def3186d..9d6180c9e 100644 --- a/pkg/sanity/snapshot.go +++ b/pkg/sanity/snapshot.go @@ -115,7 +115,7 @@ var _ = Describe("Volume [Snapshot Tests]", func() { Name: "snapshot-of-" + volumeID, } - snapID, err = volumedriver.Snapshot(volumeID, true, loc, false) + snapID, err = volumedriver.Snapshot(context.TODO(), volumeID, true, loc, false) Expect(err).NotTo(HaveOccurred()) Expect(snapID).To(Not(BeNil())) @@ -204,7 +204,7 @@ var _ = Describe("Volume [Snapshot Tests]", func() { Name: "snapshot-" + strconv.Itoa(i) + "-of-" + volumeID, } - snapID, err = volumedriver.Snapshot(volumeID, true, loc, false) + snapID, err = volumedriver.Snapshot(context.TODO(), volumeID, true, loc, false) Expect(err).NotTo(HaveOccurred()) Expect(snapID).To(Not(BeNil())) @@ -298,7 +298,7 @@ var _ = Describe("Volume [Snapshot Tests]", func() { Name: "snapshot-of-" + volumeID, } - snapID, err = volumedriver.Snapshot(volumeID, true, loc, false) + snapID, err = volumedriver.Snapshot(context.TODO(), volumeID, true, loc, false) Expect(err).NotTo(HaveOccurred()) Expect(snapID).To(Not(BeNil())) diff --git a/volume/drivers/btrfs/btrfs.go b/volume/drivers/btrfs/btrfs.go index ffcfe8a31..e93ae23bb 100644 --- a/volume/drivers/btrfs/btrfs.go +++ b/volume/drivers/btrfs/btrfs.go @@ -145,7 +145,7 @@ func (d *driver) Unmount(ctx context.Context, volumeID string, mountpath string) return d.UpdateVol(v) } -func (d *driver) Set(volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error { +func (d *driver) Set(ctx context.Context, volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error { if spec != nil { return volume.ErrNotSupported } @@ -160,7 +160,7 @@ func (d *driver) Set(volumeID string, locator *api.VolumeLocator, spec *api.Volu } // Snapshot create new subvolume from volume -func (d *driver) Snapshot(volumeID string, readonly bool, locator *api.VolumeLocator, noRetry bool) (string, error) { +func (d *driver) Snapshot(ctx context.Context, volumeID string, readonly bool, locator *api.VolumeLocator, noRetry bool) (string, error) { vols, err := d.Inspect([]string{volumeID}) if err != nil { return "", err diff --git a/volume/drivers/buse/buse.go b/volume/drivers/buse/buse.go index 8cc136837..b76fe7bb5 100644 --- a/volume/drivers/buse/buse.go +++ b/volume/drivers/buse/buse.go @@ -324,7 +324,7 @@ func (d *driver) Unmount(ctx context.Context, volumeID string, mountpath string, return d.UpdateVol(v) } -func (d *driver) Snapshot(volumeID string, readonly bool, locator *api.VolumeLocator, noRetry bool) (string, error) { +func (d *driver) Snapshot(ctx context.Context, volumeID string, readonly bool, locator *api.VolumeLocator, noRetry bool) (string, error) { volIDs := make([]string, 1) volIDs[0] = volumeID vols, err := d.Inspect(nil, volIDs) diff --git a/volume/drivers/fake/fake.go b/volume/drivers/fake/fake.go index 6fd57c8bf..9eb20e561 100644 --- a/volume/drivers/fake/fake.go +++ b/volume/drivers/fake/fake.go @@ -277,7 +277,7 @@ func (d *driver) Unmount(ctx context.Context, volumeID string, mountpath string, return d.UpdateVol(v) } -func (d *driver) Snapshot(volumeID string, readonly bool, locator *api.VolumeLocator, noRetry bool) (string, error) { +func (d *driver) Snapshot(ctx context.Context, volumeID string, readonly bool, locator *api.VolumeLocator, noRetry bool) (string, error) { if len(locator.GetName()) == 0 { return "", fmt.Errorf("Name for snapshot must be provided") diff --git a/volume/drivers/mock/driver.mock.go b/volume/drivers/mock/driver.mock.go index ed286c982..02132118f 100644 --- a/volume/drivers/mock/driver.mock.go +++ b/volume/drivers/mock/driver.mock.go @@ -913,18 +913,18 @@ func (mr *MockVolumeDriverMockRecorder) SnapEnumerate(arg0, arg1 interface{}) *g } // Snapshot mocks base method. -func (m *MockVolumeDriver) Snapshot(arg0 string, arg1 bool, arg2 *api.VolumeLocator, arg3 bool) (string, error) { +func (m *MockVolumeDriver) Snapshot(arg0 context.Context, arg1 string, arg2 bool, arg3 *api.VolumeLocator, arg4 bool) (string, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Snapshot", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "Snapshot", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } // Snapshot indicates an expected call of Snapshot. -func (mr *MockVolumeDriverMockRecorder) Snapshot(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +func (mr *MockVolumeDriverMockRecorder) Snapshot(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Snapshot", reflect.TypeOf((*MockVolumeDriver)(nil).Snapshot), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Snapshot", reflect.TypeOf((*MockVolumeDriver)(nil).Snapshot), arg0, arg1, arg2, arg3, arg4) } // SnapshotGroup mocks base method. diff --git a/volume/drivers/nfs/nfs.go b/volume/drivers/nfs/nfs.go index 0cc8a5002..ea4558735 100644 --- a/volume/drivers/nfs/nfs.go +++ b/volume/drivers/nfs/nfs.go @@ -674,7 +674,7 @@ func (d *driver) clone(newVolumeID, volumeID string) error { return nil } -func (d *driver) Snapshot(volumeID string, readonly bool, locator *api.VolumeLocator, noRetry bool) (string, error) { +func (d *driver) Snapshot(ctx context.Context, volumeID string, readonly bool, locator *api.VolumeLocator, noRetry bool) (string, error) { volIDs := []string{volumeID} vols, err := d.Inspect(nil, volIDs) if err != nil { diff --git a/volume/drivers/test/driver.go b/volume/drivers/test/driver.go index 5e867b402..7138dc314 100644 --- a/volume/drivers/test/driver.go +++ b/volume/drivers/test/driver.go @@ -149,7 +149,7 @@ func set(t *testing.T, ctx *Context) { require.Equal(t, vols[0].Id, ctx.volID, "Expect volID %v actual %v", ctx.volID, vols[0].Id) vols[0].Locator.VolumeLabels["UpdateTest"] = "Success" - err = ctx.Set(correlation.TODO(), ctx.volID, vols[0].Locator, nil) + err = ctx.Set(context.TODO(), ctx.volID, vols[0].Locator, nil) if err != volume.ErrNotSupported { require.NoError(t, err, "Failed in Update") vols, err = ctx.Inspect(correlation.TODO(), []string{ctx.volID}) @@ -321,9 +321,7 @@ func snap(t *testing.T, ctx *Context) { attach(t, ctx) labels := map[string]string{"oh": "snap"} require.NotEqual(t, ctx.volID, "", "invalid volume ID") - id, err := ctx.Snapshot(ctx.volID, false, - &api.VolumeLocator{Name: "snappy", VolumeLabels: labels}, - false) + id, err := ctx.Snapshot(context.TODO(), ctx.volID, false, &api.VolumeLocator{Name: "snappy", VolumeLabels: labels}, false) require.NoError(t, err, "Failed in creating a snapshot") ctx.snapID = id } diff --git a/volume/volume.go b/volume/volume.go index cbd70c12d..e86817117 100644 --- a/volume/volume.go +++ b/volume/volume.go @@ -118,7 +118,7 @@ type IODriver interface { type SnapshotDriver interface { // Snapshot create volume snapshot. // Errors ErrEnoEnt may be returned - Snapshot(volumeID string, readonly bool, locator *api.VolumeLocator, noRetry bool) (string, error) + Snapshot(ctx context.Context, volumeID string, readonly bool, locator *api.VolumeLocator, noRetry bool) (string, error) // Restore restores volume to specified snapshot. Restore(volumeID string, snapshotID string) error // SnapshotGroup takes a snapshot of a group of volumes that can be specified with either of the following diff --git a/volume/volume_not_supported.go b/volume/volume_not_supported.go index d230029b4..7a344d483 100644 --- a/volume/volume_not_supported.go +++ b/volume/volume_not_supported.go @@ -52,7 +52,7 @@ func (b *blockNotSupported) Detach(ctx context.Context, volumeID string, options type snapshotNotSupported struct{} -func (s *snapshotNotSupported) Snapshot(volumeID string, readonly bool, locator *api.VolumeLocator, noRetry bool) (string, error) { +func (s *snapshotNotSupported) Snapshot(ctx context.Context, volumeID string, readonly bool, locator *api.VolumeLocator, noRetry bool) (string, error) { return "", ErrNotSupported }