Skip to content

Commit 109759d

Browse files
authored
Set empty policy on nas volume import
1 parent 5246b28 commit 109759d

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

storage_drivers/ontap/ontap_nas.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,16 @@ func (d *NASStorageDriver) Import(
746746
}
747747
}
748748

749+
// If autoExportPolicy is turned on and trident is managing the volume, set volume to empty export policy so that
750+
// subsequent volume publish will set the correct per-volume export policy.
751+
if d.Config.AutoExportPolicy && !volConfig.ImportNotManaged {
752+
if err = d.setVolToEmptyPolicy(ctx, volConfig.InternalName); err != nil {
753+
return err
754+
}
755+
756+
volConfig.ExportPolicy = getEmptyExportPolicyName(*d.Config.StoragePrefix)
757+
}
758+
749759
// Update the volume labels if Trident will manage its lifecycle
750760
if !volConfig.ImportNotManaged {
751761
if storage.AllowPoolLabelOverwrite(storage.ProvisioningLabelTag, flexvol.Comment) {

storage_drivers/ontap/ontap_nas_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5339,6 +5339,70 @@ func TestOntapNasStorageDriverVolumeImport_NameTemplateLabelLengthExceeding(t *t
53395339
assert.Error(t, result)
53405340
}
53415341

5342+
func TestOntapNasStorageDriverVolumeImport_EmptyPolicy(t *testing.T) {
5343+
mockAPI, driver := newMockOntapNASDriver(t)
5344+
volConfig := &storage.VolumeConfig{
5345+
Size: "1g",
5346+
Encryption: "false",
5347+
FileSystem: "nfs",
5348+
InternalName: "vol2",
5349+
PeerVolumeHandle: "SVM1:vol1",
5350+
ImportNotManaged: false,
5351+
UnixPermissions: DefaultUnixPermissions,
5352+
}
5353+
flexVol := &api.Volume{
5354+
Name: "flexvol",
5355+
Comment: "flexvol",
5356+
Size: "1",
5357+
JunctionPath: "/nfs/vol1",
5358+
}
5359+
5360+
tests := []struct {
5361+
name string
5362+
autoExportPolicy bool
5363+
importNotManaged bool
5364+
emptyPolicyShouldBeSet bool
5365+
}{
5366+
{name: "autoExportPolicyFalse", autoExportPolicy: false, importNotManaged: false, emptyPolicyShouldBeSet: false},
5367+
{name: "setEmptyPolicy", autoExportPolicy: true, importNotManaged: false, emptyPolicyShouldBeSet: true},
5368+
{name: "importNotManaged", autoExportPolicy: true, importNotManaged: true, emptyPolicyShouldBeSet: false},
5369+
}
5370+
5371+
for _, test := range tests {
5372+
t.Run(test.name, func(t *testing.T) {
5373+
driver.Config.NASType = sa.NFS
5374+
driver.Config.SecurityStyle = "mixed"
5375+
driver.Config.AutoExportPolicy = test.autoExportPolicy
5376+
5377+
volConfig.ImportNotManaged = test.importNotManaged
5378+
volConfig.ExportPolicy = ""
5379+
5380+
mockAPI.EXPECT().SVMName().AnyTimes().Return("SVM1")
5381+
mockAPI.EXPECT().VolumeInfo(ctx, "vol1").Return(flexVol, nil)
5382+
5383+
if !test.importNotManaged {
5384+
mockAPI.EXPECT().VolumeRename(ctx, "vol1", "vol2").Return(nil)
5385+
mockAPI.EXPECT().VolumeModifyUnixPermissions(ctx, "vol2",
5386+
"vol1", DefaultUnixPermissions).Return(nil)
5387+
}
5388+
5389+
if test.emptyPolicyShouldBeSet {
5390+
mockAPI.EXPECT().ExportPolicyExists(ctx, "test_empty").Return(true, nil)
5391+
mockAPI.EXPECT().VolumeModifyExportPolicy(ctx, "vol2", "test_empty").
5392+
Return(nil)
5393+
}
5394+
5395+
result := driver.Import(ctx, volConfig, "vol1")
5396+
assert.Nil(t, result)
5397+
if test.emptyPolicyShouldBeSet {
5398+
assert.Equal(t, volConfig.ExportPolicy, "test_empty")
5399+
} else {
5400+
assert.Equal(t, volConfig.ExportPolicy, "")
5401+
}
5402+
})
5403+
}
5404+
}
5405+
53425406
func TestOntapNasStorageDriverVolumePublish_NASType_None(t *testing.T) {
53435407
mockAPI, driver := newMockOntapNASDriver(t)
53445408
volConfig := &storage.VolumeConfig{

0 commit comments

Comments
 (0)