@@ -861,6 +861,7 @@ func TestOntapNasStorageDriverVolumeClone(t *testing.T) {
861861 pool1 := storage .NewStoragePool (nil , "pool1" )
862862 pool1 .SetInternalAttributes (map [string ]string {
863863 "tieringPolicy" : "none" ,
864+ "exportPolicy" : "default" ,
864865 })
865866 pool1 .Attributes ()["labels" ] = sa .NewLabelOffer (map [string ]string {
866867 "type" : "clone" ,
@@ -899,6 +900,7 @@ func TestOntapNasStorageDriverVolumeClone(t *testing.T) {
899900 mockAPI .EXPECT ().VolumeSetComment (ctx , volConfig .InternalName , volConfig .InternalName , "{\" provisioning\" :{\" type\" :\" clone\" }}" ).
900901 Return (nil )
901902 mockAPI .EXPECT ().VolumeMount (ctx , volConfig .InternalName , "/" + volConfig .InternalName ).Return (nil )
903+ mockAPI .EXPECT ().VolumeModifyExportPolicy (ctx , volConfig .InternalName , "default" ).Return (nil )
902904
903905 if test .NasType == sa .SMB {
904906 driver .Config .NASType = sa .SMB
@@ -1024,6 +1026,7 @@ func TestOntapNasStorageDriverVolumeClone_NameTemplateStoragePoolUnset(t *testin
10241026 })
10251027 pool1 .InternalAttributes ()[NameTemplate ] = "{{.config.StorageDriverName}}_{{.labels.Cluster}}_{{.volume.Namespace}}_{{.volume." +
10261028 "RequestName}}"
1029+ pool1 .InternalAttributes ()[ExportPolicy ] = "default"
10271030 driver .physicalPools = map [string ]storage.Pool {"pool1" : pool1 }
10281031 driver .Config .SplitOnClone = "false"
10291032 driver .Config .Labels = pool1 .GetLabels (ctx , "" )
@@ -1039,8 +1042,104 @@ func TestOntapNasStorageDriverVolumeClone_NameTemplateStoragePoolUnset(t *testin
10391042 mockAPI .EXPECT ().VolumeSetComment (ctx , volConfig .InternalName , volConfig .InternalName , "{\" provisioning\" :{\" type\" :\" clone\" }}" ).
10401043 Return (nil )
10411044 mockAPI .EXPECT ().VolumeMount (ctx , volConfig .InternalName , "/" + volConfig .InternalName ).Return (nil )
1045+ mockAPI .EXPECT ().VolumeModifyExportPolicy (ctx , volConfig .InternalName , "default" ).Return (nil )
10421046
1043- result := driver .CreateClone (ctx , nil , volConfig , nil )
1047+ result := driver .CreateClone (ctx , nil , volConfig , pool1 )
1048+
1049+ assert .NoError (t , result )
1050+ }
1051+
1052+ func TestOntapNasStorageDriverVolumeClone_AutoExportPolicy_On (t * testing.T ) {
1053+ mockAPI , driver := newMockOntapNASDriver (t )
1054+ volConfig := & storage.VolumeConfig {
1055+ Size : "1g" ,
1056+ Encryption : "false" ,
1057+ FileSystem : "nfs" ,
1058+ }
1059+
1060+ flexVol := api.Volume {
1061+ Name : "flexvol" ,
1062+ Comment : "flexvol" ,
1063+ }
1064+
1065+ pool1 := storage .NewStoragePool (nil , "pool1" )
1066+ pool1 .SetInternalAttributes (map [string ]string {
1067+ "tieringPolicy" : "none" ,
1068+ })
1069+ pool1 .Attributes ()["labels" ] = sa .NewLabelOffer (map [string ]string {
1070+ "type" : "clone" ,
1071+ })
1072+ pool1 .InternalAttributes ()[ExportPolicy ] = "<automatic>"
1073+
1074+ driver .physicalPools = map [string ]storage.Pool {"pool1" : pool1 }
1075+ driver .Config .SplitOnClone = "false"
1076+ driver .Config .Labels = pool1 .GetLabels (ctx , "" )
1077+ driver .Config .AutoExportPolicy = true
1078+ prefix := "trident-"
1079+ driver .Config .StoragePrefix = & prefix
1080+
1081+ mockAPI .EXPECT ().SVMName ().AnyTimes ().Return ("SVM1" )
1082+ mockAPI .EXPECT ().VolumeInfo (ctx , volConfig .CloneSourceVolumeInternal ).Return (& flexVol , nil )
1083+ mockAPI .EXPECT ().VolumeExists (ctx , "" ).Return (false , nil )
1084+ mockAPI .EXPECT ().VolumeSnapshotCreate (ctx , gomock .Any (), gomock .Any ()).Return (nil )
1085+ mockAPI .EXPECT ().VolumeCloneCreate (ctx , volConfig .InternalName , volConfig .CloneSourceVolumeInternal ,
1086+ gomock .Any (), false ).Return (nil )
1087+ mockAPI .EXPECT ().VolumeWaitForStates (ctx , volConfig .InternalName , gomock .Any (), gomock .Any (),
1088+ maxFlexvolCloneWait ).Return ("online" , nil )
1089+ mockAPI .EXPECT ().VolumeSetComment (ctx , volConfig .InternalName , volConfig .InternalName , "{\" provisioning\" :{\" type\" :\" clone\" }}" ).
1090+ Return (nil )
1091+ mockAPI .EXPECT ().VolumeMount (ctx , volConfig .InternalName , "/" + volConfig .InternalName ).Return (nil )
1092+ mockAPI .EXPECT ().ExportPolicyCreate (ctx , "trident-empty" ).Return (nil )
1093+ mockAPI .EXPECT ().VolumeModifyExportPolicy (ctx , volConfig .InternalName , "trident-empty" ).Return (nil )
1094+
1095+ result := driver .CreateClone (ctx , nil , volConfig , pool1 )
1096+
1097+ assert .NoError (t , result )
1098+ }
1099+
1100+ func TestOntapNasStorageDriverVolumeClone_AutoExportPolicy_Off (t * testing.T ) {
1101+ mockAPI , driver := newMockOntapNASDriver (t )
1102+ volConfig := & storage.VolumeConfig {
1103+ Size : "1g" ,
1104+ Encryption : "false" ,
1105+ FileSystem : "nfs" ,
1106+ }
1107+
1108+ flexVol := api.Volume {
1109+ Name : "flexvol" ,
1110+ Comment : "flexvol" ,
1111+ }
1112+
1113+ pool1 := storage .NewStoragePool (nil , "pool1" )
1114+ pool1 .SetInternalAttributes (map [string ]string {
1115+ "tieringPolicy" : "none" ,
1116+ })
1117+ pool1 .Attributes ()["labels" ] = sa .NewLabelOffer (map [string ]string {
1118+ "type" : "clone" ,
1119+ })
1120+ pool1 .InternalAttributes ()[ExportPolicy ] = "default"
1121+
1122+ driver .physicalPools = map [string ]storage.Pool {"pool1" : pool1 }
1123+ driver .Config .SplitOnClone = "false"
1124+ driver .Config .Labels = pool1 .GetLabels (ctx , "" )
1125+ driver .Config .AutoExportPolicy = false
1126+ prefix := "trident-"
1127+ driver .Config .StoragePrefix = & prefix
1128+
1129+ mockAPI .EXPECT ().SVMName ().AnyTimes ().Return ("SVM1" )
1130+ mockAPI .EXPECT ().VolumeInfo (ctx , volConfig .CloneSourceVolumeInternal ).Return (& flexVol , nil )
1131+ mockAPI .EXPECT ().VolumeExists (ctx , "" ).Return (false , nil )
1132+ mockAPI .EXPECT ().VolumeSnapshotCreate (ctx , gomock .Any (), gomock .Any ()).Return (nil )
1133+ mockAPI .EXPECT ().VolumeCloneCreate (ctx , volConfig .InternalName , volConfig .CloneSourceVolumeInternal ,
1134+ gomock .Any (), false ).Return (nil )
1135+ mockAPI .EXPECT ().VolumeWaitForStates (ctx , volConfig .InternalName , gomock .Any (), gomock .Any (),
1136+ maxFlexvolCloneWait ).Return ("online" , nil )
1137+ mockAPI .EXPECT ().VolumeSetComment (ctx , volConfig .InternalName , volConfig .InternalName , "{\" provisioning\" :{\" type\" :\" clone\" }}" ).
1138+ Return (nil )
1139+ mockAPI .EXPECT ().VolumeMount (ctx , volConfig .InternalName , "/" + volConfig .InternalName ).Return (nil )
1140+ mockAPI .EXPECT ().VolumeModifyExportPolicy (ctx , volConfig .InternalName , "default" ).Return (nil )
1141+
1142+ result := driver .CreateClone (ctx , nil , volConfig , pool1 )
10441143
10451144 assert .NoError (t , result )
10461145}
@@ -1157,6 +1256,7 @@ func TestOntapNasStorageDriverVolumeClone_NameTemplate(t *testing.T) {
11571256 pool1 .SetAttributes (map [string ]sa.Offer {
11581257 sa .Labels : sa .NewLabelOffer (driver .Config .Labels ),
11591258 })
1259+ pool1 .InternalAttributes ()[ExportPolicy ] = "default"
11601260 driver .physicalPools = map [string ]storage.Pool {"pool1" : pool1 }
11611261
11621262 mockAPI .EXPECT ().SVMName ().AnyTimes ().Return ("SVM1" )
@@ -1169,6 +1269,7 @@ func TestOntapNasStorageDriverVolumeClone_NameTemplate(t *testing.T) {
11691269 mockAPI .EXPECT ().VolumeSetComment (ctx , volConfig .InternalName , volConfig .InternalName , test .expectedLabel ).
11701270 Return (nil )
11711271 mockAPI .EXPECT ().VolumeMount (ctx , volConfig .InternalName , "/" + volConfig .InternalName ).Return (nil )
1272+ mockAPI .EXPECT ().VolumeModifyExportPolicy (ctx , volConfig .InternalName , "default" ).Return (nil )
11721273
11731274 result := driver .CreateClone (ctx , nil , volConfig , pool1 )
11741275
@@ -1329,6 +1430,7 @@ func TestOntapNasStorageDriverVolumeClone_SMBShareCreateFail(t *testing.T) {
13291430 pool1 := storage .NewStoragePool (nil , "pool1" )
13301431 pool1 .SetInternalAttributes (map [string ]string {
13311432 "tieringPolicy" : "none" ,
1433+ "exportPolicy" : "default" ,
13321434 })
13331435 pool1 .Attributes ()["labels" ] = sa .NewLabelOffer (map [string ]string {
13341436 "type" : "clone" ,
@@ -1361,6 +1463,7 @@ func TestOntapNasStorageDriverVolumeClone_SMBShareCreateFail(t *testing.T) {
13611463 mockAPI .EXPECT ().SMBShareExists (ctx , volConfig .InternalName ).Return (false , nil )
13621464 mockAPI .EXPECT ().SMBShareCreate (ctx , volConfig .InternalName ,
13631465 "/" + volConfig .InternalName ).Return (fmt .Errorf ("cannot create volume" ))
1466+ mockAPI .EXPECT ().VolumeModifyExportPolicy (ctx , volConfig .InternalName , "default" ).Return (nil )
13641467
13651468 result := driver .CreateClone (ctx , nil , volConfig , pool1 )
13661469
0 commit comments