@@ -38,6 +38,7 @@ import (
3838 "github.com/netapp/trident/storage_drivers/ontap/api/rest/client/svm"
3939 "github.com/netapp/trident/storage_drivers/ontap/api/rest/models"
4040 "github.com/netapp/trident/utils/errors"
41+ "github.com/netapp/trident/utils/filesystem"
4142 tridentmodels "github.com/netapp/trident/utils/models"
4243)
4344
@@ -6762,7 +6763,8 @@ func TestPublishLun(t *testing.T) {
67626763 assert .NoError (t , err )
67636764 assert .Equal (t , tempFormatOptions , publishInfo .FormatOptions )
67646765
6765- // Test 11 - volume FileSystem (volConfig) is "xfs", LunGetFSType should NOT be called
6766+ // Test 11 - volConfig is "xfs" and LUN attribute also returns "xfs" (normal Trident-created volume).
6767+ // LunGetFSType is now always called; the LUN attribute matches volConfig so the result is unchanged.
67666768 mockAPI = mockapi .NewMockOntapAPI (mockCtrl )
67676769 publishInfo = & tridentmodels.VolumePublishInfo {
67686770 BackendUUID : "fakeBackendUUID" ,
@@ -6772,6 +6774,7 @@ func TestPublishLun(t *testing.T) {
67726774 HostIQN : []string {"host_iqn" },
67736775 }
67746776 config .FileSystemType = ""
6777+ mockAPI .EXPECT ().LunGetFSType (ctx , lunPath ).Return ("xfs" , nil )
67756778 mockAPI .EXPECT ().LunGetAttribute (ctx , lunPath , "formatOptions" ).Return ("formatOptions" , nil )
67766779 mockAPI .EXPECT ().LunGetByName (ctx , lunPath ).Return (dummyLun , nil )
67776780 mockAPI .EXPECT ().EnsureIgroupAdded (ctx , igroupName , publishInfo .HostIQN [0 ])
@@ -6786,7 +6789,8 @@ func TestPublishLun(t *testing.T) {
67866789 assert .Equal (t , "xfs" , publishInfo .FilesystemType )
67876790 assert .Contains (t , publishInfo .MountOptions , "nouuid" )
67886791
6789- // Test 11b - FileSystem and FormatOptions from vol (as after Create); no LunGetFSType or LunGetAttribute
6792+ // Test 11b - volConfig has both FileSystem and FormatOptions (as set after Create); LunGetFSType is
6793+ // called (always) and returns matching "xfs". LunGetAttribute is skipped because FormatOptions is set.
67906794 mockAPI = mockapi .NewMockOntapAPI (mockCtrl )
67916795 publishInfo = & tridentmodels.VolumePublishInfo {
67926796 BackendUUID : "fakeBackendUUID" ,
@@ -6796,6 +6800,7 @@ func TestPublishLun(t *testing.T) {
67966800 HostIQN : []string {"host_iqn" },
67976801 }
67986802 volFmtOpts := "-b 4096 -T stride=256"
6803+ mockAPI .EXPECT ().LunGetFSType (ctx , lunPath ).Return ("xfs" , nil )
67996804 mockAPI .EXPECT ().LunGetByName (ctx , lunPath ).Return (dummyLun , nil )
68006805 mockAPI .EXPECT ().EnsureIgroupAdded (ctx , igroupName , publishInfo .HostIQN [0 ])
68016806 mockAPI .EXPECT ().EnsureLunMapped (ctx , igroupName , lunPath ).Return (1111 , nil )
@@ -6854,6 +6859,125 @@ func TestPublishLun(t *testing.T) {
68546859
68556860 assert .NoError (t , err )
68566861 assert .Equal (t , drivers .DefaultFileSystemType , publishInfo .FilesystemType )
6862+
6863+ // Test 14 - volConfig "raw", LUN attribute returns "ext4": LUN attribute wins.
6864+ // Surfaces the real on-disk fstype so the node-side mismatch guard can fire.
6865+ mockAPI = mockapi .NewMockOntapAPI (mockCtrl )
6866+ publishInfo = & tridentmodels.VolumePublishInfo {
6867+ BackendUUID : "fakeBackendUUID" ,
6868+ Localhost : false ,
6869+ Unmanaged : true ,
6870+ Nodes : nodeList ,
6871+ HostIQN : []string {"host_iqn" },
6872+ }
6873+ mockAPI .EXPECT ().LunGetFSType (ctx , lunPath ).Return ("ext4" , nil )
6874+ mockAPI .EXPECT ().LunGetAttribute (ctx , lunPath , "formatOptions" ).Return ("" , nil )
6875+ mockAPI .EXPECT ().LunGetByName (ctx , lunPath ).Return (dummyLun , nil )
6876+ mockAPI .EXPECT ().EnsureIgroupAdded (ctx , igroupName , publishInfo .HostIQN [0 ])
6877+ mockAPI .EXPECT ().EnsureLunMapped (ctx , igroupName , lunPath ).Return (1111 , nil )
6878+ mockAPI .EXPECT ().LunMapGetReportingNodes (ctx , igroupName , lunPath ).Return ([]string {"Node1" }, nil )
6879+ mockAPI .EXPECT ().GetSLMDataLifs (ctx , ips , []string {"Node1" }).Return ([]string {}, nil )
6880+
6881+ err = PublishLUN (ctx , mockAPI , config , ips , publishInfo , lunPath , igroupName , iSCSINodeName ,
6882+ publishVolCfg (filesystem .Raw , "" ))
6883+
6884+ assert .NoError (t , err )
6885+ assert .Equal (t , "ext4" , publishInfo .FilesystemType )
6886+
6887+ // Test 15 - volConfig "xfs", LUN attribute returns "ext4": LUN attribute wins (fstype mismatch on import).
6888+ mockAPI = mockapi .NewMockOntapAPI (mockCtrl )
6889+ publishInfo = & tridentmodels.VolumePublishInfo {
6890+ BackendUUID : "fakeBackendUUID" ,
6891+ Localhost : false ,
6892+ Unmanaged : true ,
6893+ Nodes : nodeList ,
6894+ HostIQN : []string {"host_iqn" },
6895+ }
6896+ mockAPI .EXPECT ().LunGetFSType (ctx , lunPath ).Return ("ext4" , nil )
6897+ mockAPI .EXPECT ().LunGetAttribute (ctx , lunPath , "formatOptions" ).Return ("" , nil )
6898+ mockAPI .EXPECT ().LunGetByName (ctx , lunPath ).Return (dummyLun , nil )
6899+ mockAPI .EXPECT ().EnsureIgroupAdded (ctx , igroupName , publishInfo .HostIQN [0 ])
6900+ mockAPI .EXPECT ().EnsureLunMapped (ctx , igroupName , lunPath ).Return (1111 , nil )
6901+ mockAPI .EXPECT ().LunMapGetReportingNodes (ctx , igroupName , lunPath ).Return ([]string {"Node1" }, nil )
6902+ mockAPI .EXPECT ().GetSLMDataLifs (ctx , ips , []string {"Node1" }).Return ([]string {}, nil )
6903+
6904+ err = PublishLUN (ctx , mockAPI , config , ips , publishInfo , lunPath , igroupName , iSCSINodeName ,
6905+ publishVolCfg ("xfs" , "" ))
6906+
6907+ assert .NoError (t , err )
6908+ assert .Equal (t , "ext4" , publishInfo .FilesystemType )
6909+
6910+ // Test 16 - volConfig "raw", LUN has no attribute (externally-created LUN).
6911+ // LunGetFSType returns empty: fall back to volConfig "raw", preserving raw block intent.
6912+ mockAPI = mockapi .NewMockOntapAPI (mockCtrl )
6913+ publishInfo = & tridentmodels.VolumePublishInfo {
6914+ BackendUUID : "fakeBackendUUID" ,
6915+ Localhost : false ,
6916+ Unmanaged : true ,
6917+ Nodes : nodeList ,
6918+ HostIQN : []string {"host_iqn" },
6919+ }
6920+ mockAPI .EXPECT ().LunGetFSType (ctx , lunPath ).Return ("" , nil )
6921+ mockAPI .EXPECT ().LunGetAttribute (ctx , lunPath , "formatOptions" ).Return ("" , nil )
6922+ mockAPI .EXPECT ().LunGetByName (ctx , lunPath ).Return (dummyLun , nil )
6923+ mockAPI .EXPECT ().EnsureIgroupAdded (ctx , igroupName , publishInfo .HostIQN [0 ])
6924+ mockAPI .EXPECT ().EnsureLunMapped (ctx , igroupName , lunPath ).Return (1111 , nil )
6925+ mockAPI .EXPECT ().LunMapGetReportingNodes (ctx , igroupName , lunPath ).Return ([]string {"Node1" }, nil )
6926+ mockAPI .EXPECT ().GetSLMDataLifs (ctx , ips , []string {"Node1" }).Return ([]string {}, nil )
6927+
6928+ err = PublishLUN (ctx , mockAPI , config , ips , publishInfo , lunPath , igroupName , iSCSINodeName ,
6929+ publishVolCfg (filesystem .Raw , "" ))
6930+
6931+ assert .NoError (t , err )
6932+ assert .Equal (t , filesystem .Raw , publishInfo .FilesystemType )
6933+
6934+ // Test 17 - volConfig "raw", LunGetFSType returns error (externally-created LUN, API failure).
6935+ // Fall back to volConfig "raw", preserving raw block intent.
6936+ mockAPI = mockapi .NewMockOntapAPI (mockCtrl )
6937+ publishInfo = & tridentmodels.VolumePublishInfo {
6938+ BackendUUID : "fakeBackendUUID" ,
6939+ Localhost : false ,
6940+ Unmanaged : true ,
6941+ Nodes : nodeList ,
6942+ HostIQN : []string {"host_iqn" },
6943+ }
6944+ mockAPI .EXPECT ().LunGetFSType (ctx , lunPath ).Return ("" , errors .New ("LunGetFSType returned error" ))
6945+ mockAPI .EXPECT ().LunGetAttribute (ctx , lunPath , "formatOptions" ).Return ("" , nil )
6946+ mockAPI .EXPECT ().LunGetByName (ctx , lunPath ).Return (dummyLun , nil )
6947+ mockAPI .EXPECT ().EnsureIgroupAdded (ctx , igroupName , publishInfo .HostIQN [0 ])
6948+ mockAPI .EXPECT ().EnsureLunMapped (ctx , igroupName , lunPath ).Return (1111 , nil )
6949+ mockAPI .EXPECT ().LunMapGetReportingNodes (ctx , igroupName , lunPath ).Return ([]string {"Node1" }, nil )
6950+ mockAPI .EXPECT ().GetSLMDataLifs (ctx , ips , []string {"Node1" }).Return ([]string {}, nil )
6951+
6952+ err = PublishLUN (ctx , mockAPI , config , ips , publishInfo , lunPath , igroupName , iSCSINodeName ,
6953+ publishVolCfg (filesystem .Raw , "" ))
6954+
6955+ assert .NoError (t , err )
6956+ assert .Equal (t , filesystem .Raw , publishInfo .FilesystemType )
6957+
6958+ // Test 18 - volConfig "ext4", LUN has no attribute (externally-created LUN).
6959+ // LunGetFSType returns empty: fall back to volConfig "ext4".
6960+ mockAPI = mockapi .NewMockOntapAPI (mockCtrl )
6961+ publishInfo = & tridentmodels.VolumePublishInfo {
6962+ BackendUUID : "fakeBackendUUID" ,
6963+ Localhost : false ,
6964+ Unmanaged : true ,
6965+ Nodes : nodeList ,
6966+ HostIQN : []string {"host_iqn" },
6967+ }
6968+ mockAPI .EXPECT ().LunGetFSType (ctx , lunPath ).Return ("" , nil )
6969+ mockAPI .EXPECT ().LunGetAttribute (ctx , lunPath , "formatOptions" ).Return ("" , nil )
6970+ mockAPI .EXPECT ().LunGetByName (ctx , lunPath ).Return (dummyLun , nil )
6971+ mockAPI .EXPECT ().EnsureIgroupAdded (ctx , igroupName , publishInfo .HostIQN [0 ])
6972+ mockAPI .EXPECT ().EnsureLunMapped (ctx , igroupName , lunPath ).Return (1111 , nil )
6973+ mockAPI .EXPECT ().LunMapGetReportingNodes (ctx , igroupName , lunPath ).Return ([]string {"Node1" }, nil )
6974+ mockAPI .EXPECT ().GetSLMDataLifs (ctx , ips , []string {"Node1" }).Return ([]string {}, nil )
6975+
6976+ err = PublishLUN (ctx , mockAPI , config , ips , publishInfo , lunPath , igroupName , iSCSINodeName ,
6977+ publishVolCfg ("ext4" , "" ))
6978+
6979+ assert .NoError (t , err )
6980+ assert .Equal (t , "ext4" , publishInfo .FilesystemType )
68576981}
68586982
68596983func TestValidateSANDriver (t * testing.T ) {
0 commit comments