@@ -36,6 +36,12 @@ const (
3636 // setting Config.TestVolumeSize.
3737 DefTestVolumeSize int64 = 10 * 1024 * 1024 * 1024
3838
39+ // DefTestVolumeExpand defines the size increment for volume
40+ // expansion. It can be overriden by setting an
41+ // Config.TestVolumeExpandSize, which will be taken as absolute
42+ // value.
43+ DefTestExpandIncrement int64 = 1 * 1024 * 1024 * 1024
44+
3945 MaxNameLength int = 128
4046)
4147
@@ -46,6 +52,13 @@ func TestVolumeSize(sc *SanityContext) int64 {
4652 return DefTestVolumeSize
4753}
4854
55+ func TestVolumeExpandSize (sc * SanityContext ) int64 {
56+ if sc .Config .TestVolumeExpandSize > 0 {
57+ return sc .Config .TestVolumeExpandSize
58+ }
59+ return TestVolumeSize (sc ) + DefTestExpandIncrement
60+ }
61+
4962func verifyVolumeInfo (v * csi.Volume ) {
5063 Expect (v ).NotTo (BeNil ())
5164 Expect (v .GetVolumeId ()).NotTo (BeEmpty ())
@@ -150,7 +163,6 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
150163 // The value of zero is a possible value.
151164 })
152165 })
153-
154166 Describe ("ListVolumes" , func () {
155167 BeforeEach (func () {
156168 if ! isControllerCapabilitySupported (c , csi .ControllerServiceCapability_RPC_LIST_VOLUMES ) {
@@ -2053,6 +2065,109 @@ var _ = DescribeSanity("CreateSnapshot [Controller Server]", func(sc *SanityCont
20532065 })
20542066})
20552067
2068+ var _ = DescribeSanity ("ExpandVolume [Controller Server]" , func (sc * SanityContext ) {
2069+ var (
2070+ c csi.ControllerClient
2071+ cl * Cleanup
2072+ )
2073+
2074+ BeforeEach (func () {
2075+ c = csi .NewControllerClient (sc .ControllerConn )
2076+ if ! isControllerCapabilitySupported (c , csi .ControllerServiceCapability_RPC_EXPAND_VOLUME ) {
2077+ Skip ("ControllerExpandVolume not supported" )
2078+ }
2079+ cl = & Cleanup {
2080+ ControllerClient : c ,
2081+ Context : sc ,
2082+ }
2083+ })
2084+ AfterEach (func () {
2085+ cl .DeleteVolumes ()
2086+ })
2087+ It ("should fail if no volume id is given" , func () {
2088+ expReq := & csi.ControllerExpandVolumeRequest {
2089+ VolumeId : "" ,
2090+ CapacityRange : & csi.CapacityRange {
2091+ RequiredBytes : TestVolumeExpandSize (sc ),
2092+ },
2093+ }
2094+ rsp , err := c .ControllerExpandVolume (context .Background (), expReq )
2095+ Expect (err ).To (HaveOccurred ())
2096+ Expect (rsp ).To (BeNil ())
2097+
2098+ serverError , ok := status .FromError (err )
2099+ Expect (ok ).To (BeTrue ())
2100+ Expect (serverError .Code ()).To (Equal (codes .InvalidArgument ))
2101+ })
2102+
2103+ It ("should fail if no capacity range is given" , func () {
2104+ expReq := & csi.ControllerExpandVolumeRequest {
2105+ VolumeId : "" ,
2106+ }
2107+ rsp , err := c .ControllerExpandVolume (context .Background (), expReq )
2108+ Expect (err ).To (HaveOccurred ())
2109+ Expect (rsp ).To (BeNil ())
2110+
2111+ serverError , ok := status .FromError (err )
2112+ Expect (ok ).To (BeTrue ())
2113+ Expect (serverError .Code ()).To (Equal (codes .InvalidArgument ))
2114+ })
2115+
2116+ It ("should work" , func () {
2117+
2118+ By ("creating a new volume" )
2119+ name := UniqueString ("sanity-expand-volume" )
2120+
2121+ // Create a new volume.
2122+ req := & csi.CreateVolumeRequest {
2123+ Name : name ,
2124+ VolumeCapabilities : []* csi.VolumeCapability {
2125+ {
2126+ AccessType : & csi.VolumeCapability_Mount {
2127+ Mount : & csi.VolumeCapability_MountVolume {},
2128+ },
2129+ AccessMode : & csi.VolumeCapability_AccessMode {
2130+ Mode : csi .VolumeCapability_AccessMode_SINGLE_NODE_WRITER ,
2131+ },
2132+ },
2133+ },
2134+ Secrets : sc .Secrets .CreateVolumeSecret ,
2135+ CapacityRange : & csi.CapacityRange {
2136+ RequiredBytes : TestVolumeSize (sc ),
2137+ },
2138+ }
2139+
2140+ vol , err := c .CreateVolume (context .Background (), req )
2141+ Expect (err ).NotTo (HaveOccurred ())
2142+ Expect (vol ).NotTo (BeNil ())
2143+ Expect (vol .GetVolume ()).NotTo (BeNil ())
2144+ Expect (vol .GetVolume ().GetVolumeId ()).NotTo (BeEmpty ())
2145+ cl .RegisterVolume (name , VolumeInfo {VolumeID : vol .GetVolume ().GetVolumeId ()})
2146+ By ("expanding the volume" )
2147+ expReq := & csi.ControllerExpandVolumeRequest {
2148+ VolumeId : vol .GetVolume ().GetVolumeId (),
2149+ CapacityRange : & csi.CapacityRange {
2150+ RequiredBytes : TestVolumeExpandSize (sc ),
2151+ },
2152+ }
2153+ rsp , err := c .ControllerExpandVolume (context .Background (), expReq )
2154+ Expect (err ).NotTo (HaveOccurred ())
2155+ Expect (rsp ).NotTo (BeNil ())
2156+ Expect (rsp .GetCapacityBytes ()).To (Equal (TestVolumeExpandSize (sc )))
2157+
2158+ By ("cleaning up deleting the volume" )
2159+ _ , err = c .DeleteVolume (
2160+ context .Background (),
2161+ & csi.DeleteVolumeRequest {
2162+ VolumeId : vol .GetVolume ().GetVolumeId (),
2163+ Secrets : sc .Secrets .DeleteVolumeSecret ,
2164+ },
2165+ )
2166+ Expect (err ).NotTo (HaveOccurred ())
2167+ cl .UnregisterVolume (name )
2168+ })
2169+ })
2170+
20562171func MakeCreateVolumeReq (sc * SanityContext , name string ) * csi.CreateVolumeRequest {
20572172 size1 := TestVolumeSize (sc )
20582173
0 commit comments