Skip to content

Commit

Permalink
make mock driver support pv healthy monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
fengzixu committed May 31, 2020
1 parent e89bc15 commit 80e8f1b
Show file tree
Hide file tree
Showing 10 changed files with 741 additions and 274 deletions.
7 changes: 7 additions & 0 deletions driver/driver.mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/kubernetes-csi/csi-test/v3
go 1.12

require (
github.com/container-storage-interface/spec v1.2.0
github.com/container-storage-interface/spec v1.2.0-rc1.0.20200530102742-4c5274ab4e5e
github.com/golang/mock v1.3.1
github.com/golang/protobuf v1.3.2
github.com/google/uuid v1.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/container-storage-interface/spec v1.2.0 h1:bD9KIVgaVKKkQ/UbVUY9kCaH/CJbhNxe0eeB4JeJV2s=
github.com/container-storage-interface/spec v1.2.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=
github.com/container-storage-interface/spec v1.2.0-rc1.0.20200530102742-4c5274ab4e5e h1:TU8q3C7x6pJ5FiC5It+mVuxZ0uBKB/fwJbwvrTRpu8g=
github.com/container-storage-interface/spec v1.2.0-rc1.0.20200530102742-4c5274ab4e5e/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down
57 changes: 57 additions & 0 deletions mock/service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,38 @@ func (s *service) ValidateVolumeCapabilities(
}, nil
}

func (s *service) ControllerGetVolume(
ctx context.Context,
req *csi.ControllerGetVolumeRequest) (
*csi.ControllerGetVolumeResponse, error) {

if hookVal, hookMsg := s.execHook("GetVolumeStart"); hookVal != codes.OK {
return nil, status.Errorf(hookVal, hookMsg)
}

i, v := s.findVolByID(ctx, req.VolumeId)
if i < 0 {
return nil, status.Error(codes.NotFound, req.VolumeId)
}

resp := &csi.ControllerGetVolumeResponse{
Volume: &v,
Status: &csi.ControllerGetVolumeResponse_VolumeStatus{},
}

volumeStatus, err := s.NodeGetVolumeStats(ctx, &csi.NodeGetVolumeStatsRequest{})
if err != nil {
return resp, err
}

resp.Status.VolumeCondition = volumeStatus.GetVolumeCondition()
if hookVal, hookMsg := s.execHook("GetVolumeEnd"); hookVal != codes.OK {
return nil, status.Errorf(hookVal, hookMsg)
}

return resp, nil
}

func (s *service) ListVolumes(
ctx context.Context,
req *csi.ListVolumesRequest) (
Expand Down Expand Up @@ -388,8 +420,19 @@ func (s *service) ListVolumes(
)

for i = 0; i < len(entries); i++ {
volumeStatus, err := s.NodeGetVolumeStats(ctx, &csi.NodeGetVolumeStatsRequest{
VolumeId: vols[j].VolumeId,
})

if err != nil {
return nil, err
}

entries[i] = &csi.ListVolumesResponse_Entry{
Volume: &vols[j],
Status: &csi.ListVolumesResponse_VolumeStatus{
VolumeCondition: volumeStatus.GetVolumeCondition(),
},
}
j++
}
Expand Down Expand Up @@ -482,6 +525,20 @@ func (s *service) ControllerGetCapabilities(
},
},
},
{
Type: &csi.ControllerServiceCapability_Rpc{
Rpc: &csi.ControllerServiceCapability_RPC{
Type: csi.ControllerServiceCapability_RPC_GET_VOLUME,
},
},
},
{
Type: &csi.ControllerServiceCapability_Rpc{
Rpc: &csi.ControllerServiceCapability_RPC{
Type: csi.ControllerServiceCapability_RPC_VOLUME_CONDITION,
},
},
},
}

if !s.config.DisableAttach {
Expand Down
11 changes: 11 additions & 0 deletions mock/service/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,13 @@ func (s *service) NodeGetCapabilities(
},
},
},
{
Type: &csi.NodeServiceCapability_Rpc{
Rpc: &csi.NodeServiceCapability_RPC{
Type: csi.NodeServiceCapability_RPC_VOLUME_CONDITION,
},
},
},
}
if s.config.NodeExpansionRequired {
capabilities = append(capabilities, &csi.NodeServiceCapability{
Expand Down Expand Up @@ -427,6 +434,10 @@ func (s *service) NodeGetVolumeStats(ctx context.Context,
Unit: csi.VolumeUsage_BYTES,
},
},
VolumeCondition: &csi.VolumeCondition{
Abnormal: false,
Message: "",
},
}, nil
}

Expand Down
6 changes: 6 additions & 0 deletions mock/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ func (s *service) findVolByName(
return s.findVol("name", name)
}

func (s *service) findVolByID(
ctx context.Context, id string) (int, csi.Volume) {

return s.findVol("id", id)
}

func (s *service) newSnapshot(name, sourceVolumeId string, parameters map[string]string) cache.Snapshot {

ptime := ptypes.TimestampNow()
Expand Down
2 changes: 2 additions & 0 deletions pkg/sanity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
case csi.ControllerServiceCapability_RPC_CLONE_VOLUME:
case csi.ControllerServiceCapability_RPC_EXPAND_VOLUME:
case csi.ControllerServiceCapability_RPC_LIST_VOLUMES_PUBLISHED_NODES:
case csi.ControllerServiceCapability_RPC_GET_VOLUME:
case csi.ControllerServiceCapability_RPC_VOLUME_CONDITION:
default:
Fail(fmt.Sprintf("Unknown capability: %v\n", cap.GetRpc().GetType()))
}
Expand Down
1 change: 1 addition & 0 deletions pkg/sanity/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
case csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME:
case csi.NodeServiceCapability_RPC_GET_VOLUME_STATS:
case csi.NodeServiceCapability_RPC_EXPAND_VOLUME:
case csi.NodeServiceCapability_RPC_VOLUME_CONDITION:
default:
Fail(fmt.Sprintf("Unknown capability: %v\n", cap.GetRpc().GetType()))
}
Expand Down
Loading

0 comments on commit 80e8f1b

Please sign in to comment.