@@ -31,7 +31,9 @@ func (s *service) CreateVolume(
3131 if req .VolumeCapabilities == nil {
3232 return nil , status .Error (codes .InvalidArgument , "Volume Capabilities cannot be empty" )
3333 }
34-
34+ if hookVal , hookMsg := s .execHook ("CreateVolumeStart" ); hookVal != codes .OK {
35+ return nil , status .Errorf (hookVal , hookMsg )
36+ }
3537 // Check to see if the volume already exists.
3638 if i , v := s .findVolByName (ctx , req .Name ); i >= 0 {
3739 // Requested volume name already exists, need to check if the existing volume's
@@ -96,6 +98,10 @@ func (s *service) CreateVolume(
9698 TargetPath : "" ,
9799 }
98100
101+ if hookVal , hookMsg := s .execHook ("CreateVolumeEnd" ); hookVal != codes .OK {
102+ return nil , status .Errorf (hookVal , hookMsg )
103+ }
104+
99105 return & csi.CreateVolumeResponse {Volume : & v }, nil
100106}
101107
@@ -112,6 +118,10 @@ func (s *service) DeleteVolume(
112118 return nil , status .Error (codes .InvalidArgument , "Volume ID cannot be empty" )
113119 }
114120
121+ if hookVal , hookMsg := s .execHook ("DeleteVolumeStart" ); hookVal != codes .OK {
122+ return nil , status .Errorf (hookVal , hookMsg )
123+ }
124+
115125 // If the volume does not exist then return an idempotent response.
116126 i , _ := s .findVolNoLock ("id" , req .VolumeId )
117127 if i < 0 {
@@ -125,6 +135,10 @@ func (s *service) DeleteVolume(
125135 s .vols [len (s .vols )- 1 ] = csi.Volume {}
126136 s .vols = s .vols [:len (s .vols )- 1 ]
127137 log .WithField ("volumeID" , req .VolumeId ).Debug ("mock delete volume" )
138+
139+ if hookVal , hookMsg := s .execHook ("DeleteVolumeEnd" ); hookVal != codes .OK {
140+ return nil , status .Errorf (hookVal , hookMsg )
141+ }
128142 return & csi.DeleteVolumeResponse {}, nil
129143}
130144
@@ -151,6 +165,10 @@ func (s *service) ControllerPublishVolume(
151165 return nil , status .Errorf (codes .NotFound , "Not matching Node ID %s to Mock Node ID %s" , req .NodeId , s .nodeID )
152166 }
153167
168+ if hookVal , hookMsg := s .execHook ("ControllerPublishVolumeStart" ); hookVal != codes .OK {
169+ return nil , status .Errorf (hookVal , hookMsg )
170+ }
171+
154172 s .volsRWL .Lock ()
155173 defer s .volsRWL .Unlock ()
156174
@@ -209,6 +227,10 @@ func (s *service) ControllerPublishVolume(
209227 v .VolumeContext [ReadOnlyKey ] = roVal
210228 s .vols [i ] = v
211229
230+ if hookVal , hookMsg := s .execHook ("ControllerPublishVolumeEnd" ); hookVal != codes .OK {
231+ return nil , status .Errorf (hookVal , hookMsg )
232+ }
233+
212234 return & csi.ControllerPublishVolumeResponse {
213235 PublishContext : map [string ]string {
214236 "device" : device ,
@@ -239,6 +261,10 @@ func (s *service) ControllerUnpublishVolume(
239261 return nil , status .Errorf (codes .NotFound , "Node ID %s does not match to expected Node ID %s" , req .NodeId , s .nodeID )
240262 }
241263
264+ if hookVal , hookMsg := s .execHook ("ControllerUnpublishVolumeStart" ); hookVal != codes .OK {
265+ return nil , status .Errorf (hookVal , hookMsg )
266+ }
267+
242268 s .volsRWL .Lock ()
243269 defer s .volsRWL .Unlock ()
244270
@@ -262,6 +288,10 @@ func (s *service) ControllerUnpublishVolume(
262288 delete (v .VolumeContext , ReadOnlyKey )
263289 s .vols [i ] = v
264290
291+ if hookVal , hookMsg := s .execHook ("ControllerUnpublishVolumeEnd" ); hookVal != codes .OK {
292+ return nil , status .Errorf (hookVal , hookMsg )
293+ }
294+
265295 return & csi.ControllerUnpublishVolumeResponse {}, nil
266296}
267297
@@ -281,6 +311,10 @@ func (s *service) ValidateVolumeCapabilities(
281311 return nil , status .Error (codes .NotFound , req .VolumeId )
282312 }
283313
314+ if hookVal , hookMsg := s .execHook ("ValidateVolumeCapabilities" ); hookVal != codes .OK {
315+ return nil , status .Errorf (hookVal , hookMsg )
316+ }
317+
284318 return & csi.ValidateVolumeCapabilitiesResponse {
285319 Confirmed : & csi.ValidateVolumeCapabilitiesResponse_Confirmed {
286320 VolumeContext : req .GetVolumeContext (),
@@ -295,6 +329,10 @@ func (s *service) ListVolumes(
295329 req * csi.ListVolumesRequest ) (
296330 * csi.ListVolumesResponse , error ) {
297331
332+ if hookVal , hookMsg := s .execHook ("ListVolumesStart" ); hookVal != codes .OK {
333+ return nil , status .Errorf (hookVal , hookMsg )
334+ }
335+
298336 // Copy the mock volumes into a new slice in order to avoid
299337 // locking the service's volume slice for the duration of the
300338 // ListVolumes RPC.
@@ -359,6 +397,10 @@ func (s *service) ListVolumes(
359397 nextToken = fmt .Sprintf ("%d" , n )
360398 }
361399
400+ if hookVal , hookMsg := s .execHook ("ListVolumesEnd" ); hookVal != codes .OK {
401+ return nil , status .Errorf (hookVal , hookMsg )
402+ }
403+
362404 return & csi.ListVolumesResponse {
363405 Entries : entries ,
364406 NextToken : nextToken ,
@@ -370,6 +412,10 @@ func (s *service) GetCapacity(
370412 req * csi.GetCapacityRequest ) (
371413 * csi.GetCapacityResponse , error ) {
372414
415+ if hookVal , hookMsg := s .execHook ("GetCapacity" ); hookVal != codes .OK {
416+ return nil , status .Errorf (hookVal , hookMsg )
417+ }
418+
373419 return & csi.GetCapacityResponse {
374420 AvailableCapacity : MaxStorageCapacity ,
375421 }, nil
@@ -380,6 +426,10 @@ func (s *service) ControllerGetCapabilities(
380426 req * csi.ControllerGetCapabilitiesRequest ) (
381427 * csi.ControllerGetCapabilitiesResponse , error ) {
382428
429+ if hookVal , hookMsg := s .execHook ("ControllerGetCapabilitiesStart" ); hookVal != codes .OK {
430+ return nil , status .Errorf (hookVal , hookMsg )
431+ }
432+
383433 caps := []* csi.ControllerServiceCapability {
384434 {
385435 Type : & csi.ControllerServiceCapability_Rpc {
@@ -452,6 +502,10 @@ func (s *service) ControllerGetCapabilities(
452502 })
453503 }
454504
505+ if hookVal , hookMsg := s .execHook ("ControllerGetCapabilitiesEnd" ); hookVal != codes .OK {
506+ return nil , status .Errorf (hookVal , hookMsg )
507+ }
508+
455509 return & csi.ControllerGetCapabilitiesResponse {
456510 Capabilities : caps ,
457511 }, nil
@@ -467,6 +521,10 @@ func (s *service) CreateSnapshot(ctx context.Context,
467521 return nil , status .Error (codes .InvalidArgument , "Snapshot SourceVolumeId cannot be empty" )
468522 }
469523
524+ if hookVal , hookMsg := s .execHook ("CreateSnapshotStart" ); hookVal != codes .OK {
525+ return nil , status .Errorf (hookVal , hookMsg )
526+ }
527+
470528 // Check to see if the snapshot already exists.
471529 if i , v := s .snapshots .FindSnapshot ("name" , req .GetName ()); i >= 0 {
472530 // Requested snapshot name already exists
@@ -481,6 +539,10 @@ func (s *service) CreateSnapshot(ctx context.Context,
481539 snapshot := s .newSnapshot (req .GetName (), req .GetSourceVolumeId (), req .GetParameters ())
482540 s .snapshots .Add (snapshot )
483541
542+ if hookVal , hookMsg := s .execHook ("CreateSnapshotEnd" ); hookVal != codes .OK {
543+ return nil , status .Errorf (hookVal , hookMsg )
544+ }
545+
484546 return & csi.CreateSnapshotResponse {Snapshot : & snapshot .SnapshotCSI }, nil
485547}
486548
@@ -492,6 +554,10 @@ func (s *service) DeleteSnapshot(ctx context.Context,
492554 return nil , status .Error (codes .InvalidArgument , "Snapshot ID cannot be empty" )
493555 }
494556
557+ if hookVal , hookMsg := s .execHook ("DeleteSnapshotStart" ); hookVal != codes .OK {
558+ return nil , status .Errorf (hookVal , hookMsg )
559+ }
560+
495561 // If the snapshot does not exist then return an idempotent response.
496562 i , _ := s .snapshots .FindSnapshot ("id" , req .SnapshotId )
497563 if i < 0 {
@@ -503,12 +569,21 @@ func (s *service) DeleteSnapshot(ctx context.Context,
503569 // themselves have fields that are.
504570 s .snapshots .Delete (i )
505571 log .WithField ("SnapshotId" , req .SnapshotId ).Debug ("mock delete snapshot" )
572+
573+ if hookVal , hookMsg := s .execHook ("DeleteSnapshotEnd" ); hookVal != codes .OK {
574+ return nil , status .Errorf (hookVal , hookMsg )
575+ }
576+
506577 return & csi.DeleteSnapshotResponse {}, nil
507578}
508579
509580func (s * service ) ListSnapshots (ctx context.Context ,
510581 req * csi.ListSnapshotsRequest ) (* csi.ListSnapshotsResponse , error ) {
511582
583+ if hookVal , hookMsg := s .execHook ("ListSnapshots" ); hookVal != codes .OK {
584+ return nil , status .Errorf (hookVal , hookMsg )
585+ }
586+
512587 // case 1: SnapshotId is not empty, return snapshots that match the snapshot id.
513588 if len (req .GetSnapshotId ()) != 0 {
514589 return getSnapshotById (s , req )
@@ -534,6 +609,10 @@ func (s *service) ControllerExpandVolume(
534609 return nil , status .Error (codes .InvalidArgument , "Request capacity cannot be empty" )
535610 }
536611
612+ if hookVal , hookMsg := s .execHook ("ControllerExpandVolumeStart" ); hookVal != codes .OK {
613+ return nil , status .Errorf (hookVal , hookMsg )
614+ }
615+
537616 s .volsRWL .Lock ()
538617 defer s .volsRWL .Unlock ()
539618
@@ -567,6 +646,10 @@ func (s *service) ControllerExpandVolume(
567646 v .CapacityBytes = requestBytes
568647 s .vols [i ] = v
569648
649+ if hookVal , hookMsg := s .execHook ("ControllerExpandVolumeEnd" ); hookVal != codes .OK {
650+ return nil , status .Errorf (hookVal , hookMsg )
651+ }
652+
570653 return resp , nil
571654}
572655
0 commit comments