@@ -22,6 +22,7 @@ import (
2222 . "github.com/netapp/trident/logging"
2323 mockacp "github.com/netapp/trident/mocks/mock_acp"
2424 mockapi "github.com/netapp/trident/mocks/mock_storage_drivers/mock_azure"
25+ "github.com/netapp/trident/pkg/capacity"
2526 "github.com/netapp/trident/pkg/convert"
2627 "github.com/netapp/trident/storage"
2728 storagefake "github.com/netapp/trident/storage/fake"
@@ -2632,7 +2633,7 @@ func TestCreate_ZeroSize(t *testing.T) {
26322633 assert .Equal (t , filesystem .ID , volConfig .InternalID , "internal ID not set on volConfig" )
26332634}
26342635
2635- func TestCreate_BelowAbsoluteMinimumSize (t * testing.T ) {
2636+ func TestCreate_BelowMinimumSize (t * testing.T ) {
26362637 mockAPI , driver := newMockANFDriver (t )
26372638 driver .Config .BackendName = "anf"
26382639 driver .Config .ServiceLevel = api .ServiceLevelUltra
@@ -2643,16 +2644,58 @@ func TestCreate_BelowAbsoluteMinimumSize(t *testing.T) {
26432644
26442645 storagePool := driver .pools ["anf_pool" ]
26452646
2646- volConfig , _ , _ , _ , _ := getStructsForCreateNFSVolume (ctx , driver , storagePool )
2647+ volConfig , capacityPool , subnet , createRequest , filesystem := getStructsForCreateNFSVolume (ctx , driver , storagePool )
26472648 volConfig .Size = "1k"
26482649
26492650 mockAPI .EXPECT ().RefreshAzureResources (ctx ).Return (nil ).Times (1 )
26502651 mockAPI .EXPECT ().VolumeExists (ctx , volConfig ).Return (false , nil , nil ).Times (1 )
2652+ mockAPI .EXPECT ().HasFeature (api .FeatureUnixPermissions ).Return (false ).Times (1 )
2653+ mockAPI .EXPECT ().RandomSubnetForStoragePool (ctx , storagePool ).Return (subnet ).Times (1 )
2654+ mockAPI .EXPECT ().CapacityPoolsForStoragePool (ctx , storagePool ,
2655+ api .ServiceLevelUltra , api .QOSAuto ).Return ([]* api.CapacityPool {capacityPool }).Times (1 )
2656+ mockAPI .EXPECT ().CreateVolume (ctx , createRequest ).Return (filesystem , nil ).Times (1 )
2657+ mockAPI .EXPECT ().WaitForVolumeState (ctx , filesystem , api .StateAvailable , []string {api .StateError },
2658+ driver .volumeCreateTimeout , api .Create ).Return (api .StateAvailable , nil ).Times (1 )
26512659
26522660 result := driver .Create (ctx , volConfig , storagePool , nil )
26532661
2654- assert .Error (t , result , "create did not fail" )
2655- assert .Equal (t , "" , volConfig .InternalID , "internal ID set on volConfig" )
2662+ assert .NoError (t , result , "create failed" )
2663+ assert .Equal (t , createRequest .QuotaInBytes , DefaultVolumeSize , "request size mismatch" )
2664+ assert .Equal (t , volConfig .Size , defaultVolumeSizeStr , "config size mismatch" )
2665+ assert .Equal (t , filesystem .ID , volConfig .InternalID , "internal ID not set on volConfig" )
2666+ }
2667+
2668+ func TestCreate_SizeNotGibMultiple (t * testing.T ) {
2669+ mockAPI , driver := newMockANFDriver (t )
2670+ driver .Config .BackendName = "anf"
2671+ driver .Config .ServiceLevel = api .ServiceLevelUltra
2672+
2673+ driver .populateConfigurationDefaults (ctx , & driver .Config )
2674+ driver .initializeStoragePools (ctx )
2675+ driver .initializeTelemetry (ctx , BackendUUID )
2676+
2677+ storagePool := driver .pools ["anf_pool" ]
2678+
2679+ volConfig , capacityPool , subnet , createRequest , filesystem := getStructsForCreateNFSVolume (ctx , driver , storagePool )
2680+ volConfig .Size = "107374182401" // 100 GiB + 1 byte
2681+ createRequest .QuotaInBytes = int64 (capacity .OneGiB * 101 ) // 101 GiB
2682+
2683+ mockAPI .EXPECT ().RefreshAzureResources (ctx ).Return (nil ).Times (1 )
2684+ mockAPI .EXPECT ().VolumeExists (ctx , volConfig ).Return (false , nil , nil ).Times (1 )
2685+ mockAPI .EXPECT ().HasFeature (api .FeatureUnixPermissions ).Return (false ).Times (1 )
2686+ mockAPI .EXPECT ().RandomSubnetForStoragePool (ctx , storagePool ).Return (subnet ).Times (1 )
2687+ mockAPI .EXPECT ().CapacityPoolsForStoragePool (ctx , storagePool ,
2688+ api .ServiceLevelUltra , api .QOSAuto ).Return ([]* api.CapacityPool {capacityPool }).Times (1 )
2689+ mockAPI .EXPECT ().CreateVolume (ctx , createRequest ).Return (filesystem , nil ).Times (1 )
2690+ mockAPI .EXPECT ().WaitForVolumeState (ctx , filesystem , api .StateAvailable , []string {api .StateError },
2691+ driver .volumeCreateTimeout , api .Create ).Return (api .StateAvailable , nil ).Times (1 )
2692+
2693+ result := driver .Create (ctx , volConfig , storagePool , nil )
2694+
2695+ assert .NoError (t , result , "create failed" )
2696+ assert .Equal (t , createRequest .QuotaInBytes , int64 (108447924224 ), "request size mismatch" )
2697+ assert .Equal (t , volConfig .Size , "108447924224" , "config size mismatch" ) // 101 GiB
2698+ assert .Equal (t , filesystem .ID , volConfig .InternalID , "internal ID not set on volConfig" )
26562699}
26572700
26582701func TestCreate_AboveMaximumSize (t * testing.T ) {
@@ -7552,6 +7595,26 @@ func TestResize(t *testing.T) {
75527595 assert .Equal (t , filesystem .ID , volConfig .InternalID , "internal ID not set on volConfig" )
75537596}
75547597
7598+ func TestResize_SizeNotGibMultiple (t * testing.T ) {
7599+ mockAPI , driver := newMockANFDriver (t )
7600+ driver .initializeTelemetry (ctx , BackendUUID )
7601+
7602+ volConfig , filesystem , _ , _ := getStructsForDestroyNFSVolume (ctx , driver )
7603+ volConfig .InternalID = ""
7604+ newSize := (capacity .OneGiB * 100 ) + 1 // 100 GiB + 1 byte
7605+ expectedSize := capacity .OneGiB * 101 // 101 GiB
7606+
7607+ mockAPI .EXPECT ().RefreshAzureResources (ctx ).Return (nil ).Times (1 )
7608+ mockAPI .EXPECT ().Volume (ctx , volConfig ).Return (filesystem , nil ).Times (1 )
7609+ mockAPI .EXPECT ().ResizeVolume (ctx , filesystem , int64 (expectedSize )).Return (nil ).Times (1 )
7610+
7611+ result := driver .Resize (ctx , volConfig , newSize )
7612+
7613+ assert .Nil (t , result , "not nil" )
7614+ assert .Equal (t , strconv .FormatUint (expectedSize , 10 ), volConfig .Size , "size mismatch" )
7615+ assert .Equal (t , filesystem .ID , volConfig .InternalID , "internal ID not set on volConfig" )
7616+ }
7617+
75557618func TestResize_DiscoveryFailed (t * testing.T ) {
75567619 mockAPI , driver := newMockANFDriver (t )
75577620 driver .initializeTelemetry (ctx , BackendUUID )
0 commit comments