@@ -14,13 +14,17 @@ import (
1414 "github.com/container-storage-interface/spec/lib/go/csi/v0"
1515)
1616
17+ const (
18+ MaxStorageCapacity = tib
19+ )
20+
1721func (s * service ) CreateVolume (
1822 ctx context.Context ,
1923 req * csi.CreateVolumeRequest ) (
2024 * csi.CreateVolumeResponse , error ) {
2125
2226 if len (req .Name ) == 0 {
23- return nil , status .Error (codes .InvalidArgument , "Volume Name canot be empty" )
27+ return nil , status .Error (codes .InvalidArgument , "Volume Name cannot be empty" )
2428 }
2529 if req .VolumeCapabilities == nil {
2630 return nil , status .Error (codes .InvalidArgument , "Volume Capabilities cannot be empty" )
@@ -41,12 +45,23 @@ func (s *service) CreateVolume(
4145 capacity = lb
4246 }
4347 }
44-
48+ // Check for maximum available capacity
49+ if capacity >= MaxStorageCapacity {
50+ return nil , status .Errorf (codes .OutOfRange , "Requested capacity %d exceeds maximum allowed %d" , capacity , MaxStorageCapacity )
51+ }
4552 // Create the volume and add it to the service's in-mem volume slice.
4653 v := s .newVolume (req .Name , capacity )
4754 s .volsRWL .Lock ()
4855 defer s .volsRWL .Unlock ()
4956 s .vols = append (s .vols , v )
57+ MockVolumes [v .Id ] = Volume {
58+ VolumeCSI : v ,
59+ NodeID : "" ,
60+ ISStaged : false ,
61+ ISPublished : false ,
62+ StageTargetPath : "" ,
63+ TargetPath : "" ,
64+ }
5065
5166 return & csi.CreateVolumeResponse {Volume : & v }, nil
5267}
@@ -59,6 +74,11 @@ func (s *service) DeleteVolume(
5974 s .volsRWL .Lock ()
6075 defer s .volsRWL .Unlock ()
6176
77+ // If the volume is not specified, return error
78+ if len (req .VolumeId ) == 0 {
79+ return nil , status .Error (codes .InvalidArgument , "Volume ID cannot be empty" )
80+ }
81+
6282 // If the volume does not exist then return an idempotent response.
6383 i , _ := s .findVolNoLock ("id" , req .VolumeId )
6484 if i < 0 {
@@ -80,6 +100,20 @@ func (s *service) ControllerPublishVolume(
80100 req * csi.ControllerPublishVolumeRequest ) (
81101 * csi.ControllerPublishVolumeResponse , error ) {
82102
103+ if len (req .VolumeId ) == 0 {
104+ return nil , status .Error (codes .InvalidArgument , "Volume ID cannot be empty" )
105+ }
106+ if len (req .NodeId ) == 0 {
107+ return nil , status .Error (codes .InvalidArgument , "Node ID cannot be empty" )
108+ }
109+ if req .VolumeCapability == nil {
110+ return nil , status .Error (codes .InvalidArgument , "Volume Capabilities cannot be empty" )
111+ }
112+
113+ if req .NodeId != s .nodeID {
114+ return nil , status .Errorf (codes .NotFound , "Not matching Node ID %s to Mock Node ID %s" , req .NodeId , s .nodeID )
115+ }
116+
83117 s .volsRWL .Lock ()
84118 defer s .volsRWL .Unlock ()
85119
@@ -149,11 +183,14 @@ func (s *service) ValidateVolumeCapabilities(
149183 req * csi.ValidateVolumeCapabilitiesRequest ) (
150184 * csi.ValidateVolumeCapabilitiesResponse , error ) {
151185
152- i , _ := s .findVolNoLock ("id" , req .VolumeId )
153- if i < 0 {
154- return nil , status .Error (codes .NotFound , req .VolumeId )
186+ if len (req .GetVolumeId ()) == 0 {
187+ return nil , status .Error (codes .InvalidArgument , "Volume ID cannot be empty" )
155188 }
156189 if len (req .VolumeCapabilities ) == 0 {
190+ return nil , status .Error (codes .InvalidArgument , req .VolumeId )
191+ }
192+ i , _ := s .findVolNoLock ("id" , req .VolumeId )
193+ if i < 0 {
157194 return nil , status .Error (codes .NotFound , req .VolumeId )
158195 }
159196
0 commit comments