Access File Service in the Azure Data Lake Storage Gen2
If you have an Azure Data Lake Storage Gen2 accessing the files in the File Sharing Service can be challenging when you need them in TestCases (like in the BI row by row comparison). There is an easy workaround which enables the users to have the File Sharing Service mounted as a network drive. With this method you can access all files with the familiarity of the usual file explorer tools (like Windows Explorer, etc.) and Windows will take care of the proper syncing of the files.
This article will explain how to mount this network drive. The assumption is that the ADLS Gen2 Storage is already up and running.
You have an ADLS Gen2 setup with a File Share (in the File Service section) up and running. Your files which are relevant to the TestCases (e.g. BI row by row comparison) are stored in the Azure Data Lake Storage and you want to use them during Execution. In the screenshot below, for example, we want to access the directory
There are several ways to access files on an ADLS Gen2. The most prominent ones are:
- Mount the File Sharing Service as a Network drive and access them directly (Recommended way)
- Use the Microsoft Azure Storage Explorer application, and use your credentials there to access the files via its GUI
- Use AzCopy tool from Microsoft to copy the files locally
- Use REST API calls to fetch the files using the API Engine
Considering the necessary setup, authentication, and automation possibilities of the aforementioned solutions, the recommended solution is to mount the ADLS File Sharing Service as a network drive. The advantage with this method is that Windows is taking care of the data access and files don't need to be duplicated. All other possibilities will have the disadvantage of data duplication, need for authentication each time you want to access the File Sharing Service, and more steps needed before the actual test to prepare the files necessary.
How to mount the ADLS File Sharing Service as a network drive:
First open your File Sharing Service by navigating to
All resources->(name of your resource)->Files->(name of your file share service)
Now that your File Sharing Service is open, you can press on
The right pane will open and, conveniently, contains the commands to mount the network drive.
Change the network drive to the desired letter, copy the second command if you are on Windows and run the commands in the Command Prompt of Windows. (The first command can be run in PowerShell but will not permanently mount it as a Network Drive.)
Basically, these are 2 important commands. The first one is:
cmdkey /add:adsl2.file.core.windows.net /user:Azure\adsl2 /pass:SsC5*********************(your individual access key)*****************************Dtzw==
It will add an authentication for the Azure Cloud to the Windows Credential Manager, so that after a reboot you will be authenticated again to use the network drive.
You can make sure the Access Key is stored as a Windows Credential when you open the Windows Credential Manager.
Now, the second command can be executed:
net use Z: \\adsl2.file.core.windows.net\filesystem /persistent:Yes
In this example, this will mount the network drive onto the letter Z:,. Please note the /persistent switch which will mount the network drive automatically after a restart.
You have now mounted the drive and you can access everything in the File Sharing Service via the network drive. All files are normally accessible, and you are free to use them normally as part of a path in any Test Step/Test Step Value, as seen in the screenshot below:
If you are copying the command from the aforementioned place in the Azure Portal, it will automatically contain your individual access key. Otherwise you need to copy your access key from the "Access Key" section in the "Resource" section of the Azure Portal. If the access key is changed at any point in time, the network drive will not work of course, and you need to add the new access key to the Windows Credential Manager again.