ensure windows-ized paths for node operations on windows
Signed-off-by: Travis Glenn Hansen <travisghansen@yahoo.com>
This commit is contained in:
		
							parent
							
								
									e960cf4b6d
								
							
						
					
					
						commit
						7d25f82d9d
					
				|  | @ -273,6 +273,7 @@ jobs: | ||||||
|           TEMPLATE_CONFIG_FILE: "./ci/configs/${{ matrix.config }}" |           TEMPLATE_CONFIG_FILE: "./ci/configs/${{ matrix.config }}" | ||||||
|           SERVER_HOST: ${{ secrets.SANITY_ZFS_GENERIC_HOST }} |           SERVER_HOST: ${{ secrets.SANITY_ZFS_GENERIC_HOST }} | ||||||
|           SHARE_NAME: tank_client_smb |           SHARE_NAME: tank_client_smb | ||||||
|  |           CSI_SANITY_SKIP: "should fail when requesting to create a snapshot with already existing name and different source volume ID|should fail when requesting to create a volume with already existing name and different capacity" | ||||||
| 
 | 
 | ||||||
|   # zfs-local drivers |   # zfs-local drivers | ||||||
|   csi-sanity-zfs-local: |   csi-sanity-zfs-local: | ||||||
|  |  | ||||||
|  | @ -1242,6 +1242,10 @@ class CsiBaseDriver { | ||||||
| 
 | 
 | ||||||
|         switch (node_attach_driver) { |         switch (node_attach_driver) { | ||||||
|           case "smb": |           case "smb": | ||||||
|  |             let win_staging_target_path = | ||||||
|  |               filesystem.covertUnixSeparatorToWindowsSeparator( | ||||||
|  |                 staging_target_path | ||||||
|  |               ); | ||||||
|             device = `//${volume_context.server}/${volume_context.share}`; |             device = `//${volume_context.server}/${volume_context.share}`; | ||||||
|             const username = driver.getMountFlagValue(mount_flags, "username"); |             const username = driver.getMountFlagValue(mount_flags, "username"); | ||||||
|             const password = driver.getMountFlagValue(mount_flags, "password"); |             const password = driver.getMountFlagValue(mount_flags, "password"); | ||||||
|  | @ -1257,7 +1261,7 @@ class CsiBaseDriver { | ||||||
|              * if path exists but is NOT symlink delete it |              * if path exists but is NOT symlink delete it | ||||||
|              */ |              */ | ||||||
|             try { |             try { | ||||||
|               fs.statSync(staging_target_path); |               fs.statSync(win_staging_target_path); | ||||||
|               result = true; |               result = true; | ||||||
|             } catch (err) { |             } catch (err) { | ||||||
|               if (err.code === "ENOENT") { |               if (err.code === "ENOENT") { | ||||||
|  | @ -1268,11 +1272,11 @@ class CsiBaseDriver { | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             if (result) { |             if (result) { | ||||||
|               result = fs.lstatSync(staging_target_path); |               result = fs.lstatSync(win_staging_target_path); | ||||||
|               if (!result.isSymbolicLink()) { |               if (!result.isSymbolicLink()) { | ||||||
|                 fs.rmdirSync(staging_target_path); |                 fs.rmdirSync(win_staging_target_path); | ||||||
|               } else { |               } else { | ||||||
|                 result = await wutils.GetItem(staging_target_path); |                 result = await wutils.GetItem(win_staging_target_path); | ||||||
|                 // UNC\172.29.0.111\tank_k8s_test_PVC_111\
 |                 // UNC\172.29.0.111\tank_k8s_test_PVC_111\
 | ||||||
|                 let target = _.get(result, "Target.[0]", ""); |                 let target = _.get(result, "Target.[0]", ""); | ||||||
|                 let parts = target.split("\\"); |                 let parts = target.split("\\"); | ||||||
|  | @ -1281,7 +1285,7 @@ class CsiBaseDriver { | ||||||
|                   parts[2] != volume_context.share |                   parts[2] != volume_context.share | ||||||
|                 ) { |                 ) { | ||||||
|                   throw new Error( |                   throw new Error( | ||||||
|                     `${target} mounted already at ${staging_target_path}` |                     `${target} mounted already at ${win_staging_target_path}` | ||||||
|                   ); |                   ); | ||||||
|                 } else { |                 } else { | ||||||
|                   // finish early, assured we have what we need
 |                   // finish early, assured we have what we need
 | ||||||
|  | @ -1310,14 +1314,14 @@ class CsiBaseDriver { | ||||||
|             try { |             try { | ||||||
|               await wutils.NewSmbLink( |               await wutils.NewSmbLink( | ||||||
|                 filesystem.covertUnixSeparatorToWindowsSeparator(device), |                 filesystem.covertUnixSeparatorToWindowsSeparator(device), | ||||||
|                 staging_target_path |                 win_staging_target_path | ||||||
|               ); |               ); | ||||||
|             } catch (e) { |             } catch (e) { | ||||||
|               let details = _.get(e, "stderr", ""); |               let details = _.get(e, "stderr", ""); | ||||||
|               if (!details.includes("ResourceExists")) { |               if (!details.includes("ResourceExists")) { | ||||||
|                 throw e; |                 throw e; | ||||||
|               } else { |               } else { | ||||||
|                 result = fs.lstatSync(staging_target_path); |                 result = fs.lstatSync(win_staging_target_path); | ||||||
|                 if (!result.isSymbolicLink()) { |                 if (!result.isSymbolicLink()) { | ||||||
|                   throw new Error("staging path exists but is not symlink"); |                   throw new Error("staging path exists but is not symlink"); | ||||||
|                 } |                 } | ||||||
|  | @ -1565,20 +1569,20 @@ class CsiBaseDriver { | ||||||
|                   await wutils.FormatVolume(volume.UniqueId); |                   await wutils.FormatVolume(volume.UniqueId); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 result = await wutils.GetItem(staging_target_path); |                 result = await wutils.GetItem(win_staging_target_path); | ||||||
|                 if (!result) { |                 if (!result) { | ||||||
|                   fs.mkdirSync(staging_target_path, { |                   fs.mkdirSync(win_staging_target_path, { | ||||||
|                     recursive: true, |                     recursive: true, | ||||||
|                     mode: "755", |                     mode: "755", | ||||||
|                   }); |                   }); | ||||||
|                   result = await wutils.GetItem(staging_target_path); |                   result = await wutils.GetItem(win_staging_target_path); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 if (!volume.UniqueId.includes(result.Target[0])) { |                 if (!volume.UniqueId.includes(result.Target[0])) { | ||||||
|                   // mount up!
 |                   // mount up!
 | ||||||
|                   await wutils.MountVolume( |                   await wutils.MountVolume( | ||||||
|                     volume.UniqueId, |                     volume.UniqueId, | ||||||
|                     staging_target_path |                     win_staging_target_path | ||||||
|                   ); |                   ); | ||||||
|                 } |                 } | ||||||
|                 break; |                 break; | ||||||
|  | @ -2182,6 +2186,11 @@ class CsiBaseDriver { | ||||||
|         const WindowsUtils = require("../utils/windows").Windows; |         const WindowsUtils = require("../utils/windows").Windows; | ||||||
|         const wutils = new WindowsUtils(); |         const wutils = new WindowsUtils(); | ||||||
| 
 | 
 | ||||||
|  |         let win_normalized_staging_path = | ||||||
|  |           filesystem.covertUnixSeparatorToWindowsSeparator( | ||||||
|  |             normalized_staging_path | ||||||
|  |           ); | ||||||
|  | 
 | ||||||
|         async function removePath(p) { |         async function removePath(p) { | ||||||
|           // remove staging path
 |           // remove staging path
 | ||||||
|           try { |           try { | ||||||
|  | @ -2196,7 +2205,7 @@ class CsiBaseDriver { | ||||||
|         let node_attach_driver; |         let node_attach_driver; | ||||||
|         let win_volume_id; |         let win_volume_id; | ||||||
| 
 | 
 | ||||||
|         result = await wutils.GetItem(normalized_staging_path); |         result = await wutils.GetItem(win_normalized_staging_path); | ||||||
|         if (result) { |         if (result) { | ||||||
|           let target = _.get(result, "Target.[0]", ""); |           let target = _.get(result, "Target.[0]", ""); | ||||||
|           if (target.startsWith("UNC")) { |           if (target.startsWith("UNC")) { | ||||||
|  | @ -2229,7 +2238,7 @@ class CsiBaseDriver { | ||||||
|               // unmount volume
 |               // unmount volume
 | ||||||
|               await wutils.UnmountVolume( |               await wutils.UnmountVolume( | ||||||
|                 win_volume_id, |                 win_volume_id, | ||||||
|                 normalized_staging_path |                 win_normalized_staging_path | ||||||
|               ); |               ); | ||||||
| 
 | 
 | ||||||
|               // find sessions associated with volume/disks
 |               // find sessions associated with volume/disks
 | ||||||
|  | @ -2258,7 +2267,7 @@ class CsiBaseDriver { | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // remove staging path
 |         // remove staging path
 | ||||||
|         await removePath(normalized_staging_path); |         await removePath(win_normalized_staging_path); | ||||||
|         break; |         break; | ||||||
|       } |       } | ||||||
|       case NODE_OS_DRIVER_CSI_PROXY: |       case NODE_OS_DRIVER_CSI_PROXY: | ||||||
|  | @ -2578,6 +2587,11 @@ class CsiBaseDriver { | ||||||
|                 normalized_staging_path = staging_target_path; |                 normalized_staging_path = staging_target_path; | ||||||
|               } |               } | ||||||
| 
 | 
 | ||||||
|  |               normalized_staging_path = | ||||||
|  |                 filesystem.covertUnixSeparatorToWindowsSeparator( | ||||||
|  |                   normalized_staging_path | ||||||
|  |                 ); | ||||||
|  | 
 | ||||||
|               // source path
 |               // source path
 | ||||||
|               result = await wutils.GetItem(normalized_staging_path); |               result = await wutils.GetItem(normalized_staging_path); | ||||||
|               if (!result) { |               if (!result) { | ||||||
|  | @ -2786,8 +2800,10 @@ class CsiBaseDriver { | ||||||
|       case NODE_OS_DRIVER_WINDOWS: |       case NODE_OS_DRIVER_WINDOWS: | ||||||
|         const WindowsUtils = require("../utils/windows").Windows; |         const WindowsUtils = require("../utils/windows").Windows; | ||||||
|         const wutils = new WindowsUtils(); |         const wutils = new WindowsUtils(); | ||||||
|  |         let win_target_path = | ||||||
|  |           filesystem.covertUnixSeparatorToWindowsSeparator(target_path); | ||||||
| 
 | 
 | ||||||
|         result = await wutils.GetItem(target_path); |         result = await wutils.GetItem(win_target_path); | ||||||
|         if (!result) { |         if (!result) { | ||||||
|           return {}; |           return {}; | ||||||
|         } |         } | ||||||
|  | @ -2795,11 +2811,11 @@ class CsiBaseDriver { | ||||||
|         if (_.get(result, "LinkType") != "SymbolicLink") { |         if (_.get(result, "LinkType") != "SymbolicLink") { | ||||||
|           throw new GrpcError( |           throw new GrpcError( | ||||||
|             grpc.status.FAILED_PRECONDITION, |             grpc.status.FAILED_PRECONDITION, | ||||||
|             `target path is not a symlink ${target_path}` |             `target path is not a symlink ${win_target_path}` | ||||||
|           ); |           ); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         fs.rmdirSync(target_path); |         fs.rmdirSync(win_target_path); | ||||||
|         break; |         break; | ||||||
|       case NODE_OS_DRIVER_CSI_PROXY: |       case NODE_OS_DRIVER_CSI_PROXY: | ||||||
|         const csiProxyClient = driver.getDefaultCsiProxyClientInstance(); |         const csiProxyClient = driver.getDefaultCsiProxyClientInstance(); | ||||||
|  | @ -2929,19 +2945,20 @@ class CsiBaseDriver { | ||||||
|       case NODE_OS_DRIVER_WINDOWS: { |       case NODE_OS_DRIVER_WINDOWS: { | ||||||
|         const WindowsUtils = require("../utils/windows").Windows; |         const WindowsUtils = require("../utils/windows").Windows; | ||||||
|         const wutils = new WindowsUtils(); |         const wutils = new WindowsUtils(); | ||||||
| 
 |         let win_volume_path = | ||||||
|  |           filesystem.covertUnixSeparatorToWindowsSeparator(volume_path); | ||||||
|         // ensure path is mounted
 |         // ensure path is mounted
 | ||||||
|         result = await wutils.GetItem(volume_path); |         result = await wutils.GetItem(win_volume_path); | ||||||
|         if (!result) { |         if (!result) { | ||||||
|           throw new GrpcError( |           throw new GrpcError( | ||||||
|             grpc.status.NOT_FOUND, |             grpc.status.NOT_FOUND, | ||||||
|             `volume_path ${volume_path} is not currently mounted` |             `volume_path ${win_volume_path} is not currently mounted` | ||||||
|           ); |           ); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         let node_attach_driver; |         let node_attach_driver; | ||||||
| 
 | 
 | ||||||
|         let target = await wutils.GetRealTarget(volume_path); |         let target = await wutils.GetRealTarget(win_volume_path); | ||||||
|         if (target.startsWith("\\\\")) { |         if (target.startsWith("\\\\")) { | ||||||
|           node_attach_driver = "smb"; |           node_attach_driver = "smb"; | ||||||
|         } |         } | ||||||
|  | @ -3180,17 +3197,19 @@ class CsiBaseDriver { | ||||||
|         const wutils = new WindowsUtils(); |         const wutils = new WindowsUtils(); | ||||||
| 
 | 
 | ||||||
|         let node_attach_driver; |         let node_attach_driver; | ||||||
|  |         let win_volume_path = | ||||||
|  |           filesystem.covertUnixSeparatorToWindowsSeparator(volume_path); | ||||||
| 
 | 
 | ||||||
|         // ensure path is mounted
 |         // ensure path is mounted
 | ||||||
|         result = await wutils.GetItem(volume_path); |         result = await wutils.GetItem(win_volume_path); | ||||||
|         if (!result) { |         if (!result) { | ||||||
|           throw new GrpcError( |           throw new GrpcError( | ||||||
|             grpc.status.NOT_FOUND, |             grpc.status.NOT_FOUND, | ||||||
|             `volume_path ${volume_path} is not currently mounted` |             `volume_path ${win_volume_path} is not currently mounted` | ||||||
|           ); |           ); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         let target = await wutils.GetRealTarget(volume_path); |         let target = await wutils.GetRealTarget(win_volume_path); | ||||||
|         if (target.startsWith("\\\\")) { |         if (target.startsWith("\\\\")) { | ||||||
|           node_attach_driver = "smb"; |           node_attach_driver = "smb"; | ||||||
|         } |         } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue