From 50629d97337f0b100669ad6e01850767703241c3 Mon Sep 17 00:00:00 2001 From: alice-px Date: Mon, 22 Jan 2024 13:55:08 -0800 Subject: [PATCH] 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 | 614 ++++++++++-------- 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 | 36 +- volume/drivers/fake/fake_test.go | 10 +- volume/drivers/mock/driver.mock.go | 36 +- volume/drivers/nfs/nfs.go | 9 +- volume/drivers/test/driver.go | 17 +- volume/volume.go | 6 +- volume/volume_not_supported.go | 10 +- 31 files changed, 650 insertions(+), 582 deletions(-) diff --git a/api/client/volume/client.go b/api/client/volume/client.go index 2759aeebe..23af1a878 100644 --- a/api/client/volume/client.go +++ b/api/client/volume/client.go @@ -167,13 +167,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 { @@ -244,10 +244,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)) @@ -304,9 +301,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 168c1c56d..6a261978d 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 261a56342..845c85b2f 100644 --- a/api/server/sdk/node.go +++ b/api/server/sdk/node.go @@ -197,7 +197,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 olumeUsageByNode :%v", err.Error()) } diff --git a/api/server/sdk/node_test.go b/api/server/sdk/node_test.go index b68d2ec00..08c1b5955 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 e11f47b2b..e3a6b9fea 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 2f9e0f195..956efd8be 100644 --- a/api/server/sdk/volume_ops.go +++ b/api/server/sdk/volume_ops.go @@ -30,6 +30,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 f3c6b6fbd..44b251ccb 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 @@ -688,16 +690,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 @@ -767,20 +771,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 @@ -820,7 +826,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: @@ -828,38 +834,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 @@ -955,32 +963,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 @@ -1040,20 +1050,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 @@ -1109,38 +1121,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 @@ -1216,22 +1230,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 } @@ -1239,10 +1255,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 { @@ -1256,7 +1271,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 @@ -1324,16 +1339,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 @@ -1406,16 +1423,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 @@ -1467,6 +1486,35 @@ func (vd *volAPI) volumeusage(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(capacityInfo) } +func (vd *volAPI) volumeBytesUsedByNode(w http.ResponseWriter, r *http.Request) { + var err error + + method := "volumeBytesUsedByNode" + var req api.SdkVolumeBytesUsedRequest + if err := json.NewDecoder(r.Body).Decode(&req); err != nil { + vd.sendError(vd.name, method, w, err.Error(), http.StatusBadRequest) + return + } + d, err := vd.getVolDriver(r) + if err != nil { + notFound(w, r) + return + } + + volUtilInfo, err := d.VolumeBytesUsedByNode(req.NodeId, req.Ids) + if err != nil { + var e error + if err != nil { + e = fmt.Errorf("Failed to get volumeBytesUsedByNode: %s", err.Error()) + } + vd.sendError(vd.name, method, w, e.Error(), http.StatusInternalServerError) + return + } + var result api.SdkVolumeBytesUsedResponse + result.VolUtilInfo = volUtilInfo + json.NewEncoder(w).Encode(&result) +} + // swagger:operation GET /osd-volumes/quiesce/{id} volume quiesceVolume // // Quiesce volume with specified id. @@ -1475,20 +1523,22 @@ func (vd *volAPI) volumeusage(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 @@ -1540,20 +1590,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 @@ -1580,27 +1632,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 -// schema: -// "$ref": "#/definitions/GroupSnapCreateResponse" -// default: -// description: unexpected error +// - name: groupspec +// in: body +// description: GroupSnap create request +// required: true // 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 @@ -1632,12 +1686,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, @@ -1655,26 +1710,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 @@ -1717,29 +1774,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 @@ -1778,32 +1836,32 @@ func (vd *volAPI) VolService(w http.ResponseWriter, r *http.Request) { } func (vd *volAPI) volumeBytesUsedByNode(w http.ResponseWriter, r *http.Request) { - var err error - - method := "volumeBytesUsedByNode" - var req api.SdkVolumeBytesUsedRequest - if err := json.NewDecoder(r.Body).Decode(&req); err != nil { - vd.sendError(vd.name, method, w, err.Error(), http.StatusBadRequest) - return - } - d, err := vd.getVolDriver(r) - if err != nil { - notFound(w, r) - return - } - - volUtilInfo, err := d.VolumeBytesUsedByNode(req.NodeId, req.Ids) - if err != nil { - var e error - if err != nil { - e = fmt.Errorf("Failed to get volumeBytesUsedByNode: %s", err.Error()) - } - vd.sendError(vd.name, method, w, e.Error(), http.StatusInternalServerError) - return - } - var result api.SdkVolumeBytesUsedResponse - result.VolUtilInfo = volUtilInfo - json.NewEncoder(w).Encode(&result) + var err error + + method := "volumeBytesUsedByNode" + var req api.SdkVolumeBytesUsedRequest + if err := json.NewDecoder(r.Body).Decode(&req); err != nil { + vd.sendError(vd.name, method, w, err.Error(), http.StatusBadRequest) + return + } + d, err := vd.getVolDriver(r) + if err != nil { + notFound(w, r) + return + } + + volUtilInfo, err := d.VolumeBytesUsedByNode(req.NodeId, req.Ids) + if err != nil { + var e error + if err != nil { + e = fmt.Errorf("Failed to get volumeBytesUsedByNode: %s", err.Error()) + } + vd.sendError(vd.name, method, w, e.Error(), http.StatusInternalServerError) + return + } + var result api.SdkVolumeBytesUsedResponse + result.VolUtilInfo = volUtilInfo + json.NewEncoder(w).Encode(&result) } func volVersion(route, version string) string { diff --git a/api/server/volume_test.go b/api/server/volume_test.go index 04c7f5fe7..df791c574 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) @@ -1328,7 +1328,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 @@ -1377,7 +1377,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()) @@ -1503,111 +1503,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) { @@ -2572,7 +2574,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) @@ -2796,7 +2798,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 210adc7aa..6f9284bf9 100644 --- a/csi/controller_test.go +++ b/csi/controller_test.go @@ -105,7 +105,7 @@ func TestControllerGetVolume(t *testing.T) { gomock.InOrder( s.MockDriver(). EXPECT(). - Inspect([]string{id}). + Inspect(gomock.Any(), []string{id}). Return([]*api.Volume{ vol, }, nil). @@ -940,7 +940,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), @@ -963,7 +963,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), @@ -1017,7 +1017,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), @@ -1095,7 +1095,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), @@ -1118,7 +1118,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), @@ -1235,7 +1235,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), @@ -1248,7 +1248,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(). @@ -1304,7 +1304,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), @@ -1317,7 +1317,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), @@ -1372,7 +1372,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), @@ -1456,7 +1456,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), @@ -1527,7 +1527,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), @@ -1577,7 +1577,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), @@ -1651,7 +1651,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), @@ -1729,7 +1729,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), @@ -1806,7 +1806,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), @@ -1906,7 +1906,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), @@ -1919,7 +1919,7 @@ func TestControllerCreateVolumeFromSnapshot(t *testing.T) { //VolFromName parent s.MockDriver(). EXPECT(). - Inspect(gomock.Any()). + Inspect(gomock.Any(), gomock.Any()). Return( []*api.Volume{{ Id: mockParentID, @@ -2012,7 +2012,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), @@ -2025,7 +2025,7 @@ func TestControllerCreateVolumeSnapshotThroughParameters(t *testing.T) { // VolFromName parent s.MockDriver(). EXPECT(). - Inspect([]string{mockParentID}). + Inspect(gomock.Any(), []string{mockParentID}). Return([]*api.Volume{ { Id: mockParentID, @@ -2154,7 +2154,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), @@ -2272,7 +2272,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), @@ -2337,7 +2337,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), @@ -2428,7 +2428,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), @@ -2499,7 +2499,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), @@ -2522,7 +2522,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), @@ -2730,7 +2730,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 d4949e612..827e48da2 100644 --- a/csi/csi.go +++ b/csi/csi.go @@ -167,7 +167,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 0688f100d..b40dc37c1 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 5d517555f..468f3a677 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 d951a7713..265bfd085 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)) @@ -88,7 +89,7 @@ func testIfVolumeCreatedSuccessfully( Expect(volumesList[0].GetSpec().GetIoThrottle()).To(BeEquivalentTo(vr.GetSpec().GetIoThrottle())) } -//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 6d48ca079..eb7ef4bc4 100644 --- a/volume/drivers/buse/buse.go +++ b/volume/drivers/buse/buse.go @@ -325,7 +325,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 } @@ -347,7 +347,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 920bbfa43..a817c020c 100644 --- a/volume/drivers/fake/fake.go +++ b/volume/drivers/fake/fake.go @@ -35,6 +35,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" ) @@ -182,8 +183,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 { @@ -282,7 +283,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 } @@ -297,7 +298,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 } @@ -393,7 +394,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 { @@ -405,9 +406,18 @@ func (d *driver) UsedSize(volumeID string) (uint64, error) { return uint64(12345), nil } -func (d *driver) Stats(volumeID string, cumulative bool) (*api.Stats, error) { - - vols, err := d.Inspect([]string{volumeID}) +func (d *driver) VolumeBytesUsedByNode(nodeMID string, volumes []uint64) (*api.VolumeBytesUsedByNode, error) { + volusage := []*api.VolumeBytesUsed{} + for _, id := range volumes { + volusage = append(volusage, &api.VolumeBytesUsed{VolumeId: strconv.FormatUint(id, 10), TotalBytes: 12345}) + } + return &api.VolumeBytesUsedByNode{ + NodeId: nodeMID, + VolUsage: volusage, + }, nil +} +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 { @@ -444,7 +454,7 @@ func (d *driver) VolumeBytesUsedByNode(nodeMID string, volumes []uint64) (*api.V 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 { @@ -539,7 +549,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") } @@ -635,7 +645,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") } @@ -739,7 +749,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") } @@ -939,7 +949,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 b072ed6f1..3892678f1 100644 --- a/volume/drivers/mock/driver.mock.go +++ b/volume/drivers/mock/driver.mock.go @@ -710,19 +710,19 @@ func (mr *MockVolumeDriverMockRecorder) GetVolumeWatcher(arg0, arg1 interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVolumeWatcher", reflect.TypeOf((*MockVolumeDriver)(nil).GetVolumeWatcher), arg0, arg1) } -// Inspect mocks base method -func (m *MockVolumeDriver) Inspect(arg0 []string) ([]*api.Volume, error) { +// Inspect mocks base method. +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 { +// Inspect indicates an expected call of Inspect. +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 @@ -893,19 +893,19 @@ func (mr *MockVolumeDriverMockRecorder) StartVolumeWatcher() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartVolumeWatcher", reflect.TypeOf((*MockVolumeDriver)(nil).StartVolumeWatcher)) } -// Stats mocks base method -func (m *MockVolumeDriver) Stats(arg0 string, arg1 bool) (*api.Stats, error) { +// Stats mocks base method. +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 { +// Stats indicates an expected call of Stats. +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 @@ -1036,19 +1036,19 @@ func (mr *MockVolumeDriverMockRecorder) VolumeBytesUsedByNode(arg0, arg1 interfa return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VolumeBytesUsedByNode", reflect.TypeOf((*MockVolumeDriver)(nil).VolumeBytesUsedByNode), arg0, arg1) } -// VolumeUsageByNode mocks base method -func (m *MockVolumeDriver) VolumeUsageByNode(arg0 string) (*api.VolumeUsageByNode, error) { +// VolumeUsageByNode mocks base method. +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 { +// VolumeUsageByNode indicates an expected call of VolumeUsageByNode. +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 31833ff07..5422917e2 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" @@ -673,7 +674,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 } @@ -683,7 +684,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 } @@ -718,7 +719,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 } @@ -751,7 +752,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 df82032d2..b5930ae98 100644 --- a/volume/volume.go +++ b/volume/volume.go @@ -136,7 +136,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 +147,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) // VolumeBytesUsedByNode returns currently used volume util of multiple volumes // on a given node VolumeBytesUsedByNode(nodeID string, ids []uint64) (*api.VolumeBytesUsedByNode, error) @@ -298,7 +298,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 69469770d..b50bc1ab2 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" ) @@ -79,10 +78,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 } @@ -112,9 +108,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 }