Skip to content

Commit

Permalink
fix issue causing mount to error on read
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Storey committed Jun 15, 2020
1 parent b8b4d86 commit a0ad67e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
24 changes: 11 additions & 13 deletions databricks/mounts.go
Expand Up @@ -3,10 +3,11 @@ package databricks
import (
"errors"
"fmt"
"github.com/databrickslabs/databricks-terraform/client/service"
"log"
"net/url"
"strings"

"github.com/databrickslabs/databricks-terraform/client/service"
)

// Mount interface describes the functionality of any mount which is create, read and delete
Expand Down Expand Up @@ -164,11 +165,10 @@ dbutils.notebook.exit("success")
// Read verifies a azure blob storage mount given a cluster id
func (m AzureBlobMount) Read(client *service.DBApiClient, clusterID string) (string, error) {
iamMountCommand := fmt.Sprintf(`
dbutils.fs.ls("/mnt/%s")
for mount in dbutils.fs.mounts():
if mount.mountPoint == "/mnt/%s":
dbutils.notebook.exit(mount.source)
`, m.MountName, m.MountName)
if mount.mountPoint == "/mnt/%s":
dbutils.notebook.exit(mount.source)
`, m.MountName)
resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand)
if err != nil {
return "", err
Expand Down Expand Up @@ -266,11 +266,10 @@ dbutils.notebook.exit("success")
// Read verifies the azure datalake gen 1 storage mount given a cluster id
func (m AzureADLSGen1Mount) Read(client *service.DBApiClient, clusterID string) (string, error) {
iamMountCommand := fmt.Sprintf(`
dbutils.fs.ls("/mnt/%s")
for mount in dbutils.fs.mounts():
if mount.mountPoint == "/mnt/%s":
dbutils.notebook.exit(mount.source)
`, m.MountName, m.MountName)
if mount.mountPoint == "/mnt/%s":
dbutils.notebook.exit(mount.source)
`, m.MountName)
resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand)
if err != nil {
return "", err
Expand Down Expand Up @@ -373,11 +372,10 @@ dbutils.notebook.exit("success")
// Read verifies the azure datalake gen 2 storage mount
func (m AzureADLSGen2Mount) Read(client *service.DBApiClient, clusterID string) (string, error) {
iamMountCommand := fmt.Sprintf(`
dbutils.fs.ls("/mnt/%s")
for mount in dbutils.fs.mounts():
if mount.mountPoint == "/mnt/%s":
dbutils.notebook.exit(mount.source)
`, m.MountName, m.MountName)
if mount.mountPoint == "/mnt/%s":
dbutils.notebook.exit(mount.source)
`, m.MountName)
resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand)
if err != nil {
return "", err
Expand Down
37 changes: 37 additions & 0 deletions databricks/mounts_test.go
@@ -0,0 +1,37 @@
package databricks

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestProcessAzureWasbAbfssUrisCorrectlySplitsURI(t *testing.T) {
testCases := []struct {
URI string
ExpectedContainer string
ExpectedStorageAcc string
ExpectedDirectory string
}{
{
URI: "abfss://wibble@mystorage.dfs.core.windows.net/wobble",
ExpectedContainer: "wibble",
ExpectedStorageAcc: "mystorage",
ExpectedDirectory: "/wobble",
},
{
URI: "abfss://wibble@mystorage.dfs.core.windows.net",
ExpectedContainer: "wibble",
ExpectedStorageAcc: "mystorage",
ExpectedDirectory: "",
},
}

for _, tc := range testCases {
container, storageAcc, dir, err := ProcessAzureWasbAbfssUris(tc.URI)
assert.Equal(t, tc.ExpectedContainer, container)
assert.Equal(t, tc.ExpectedStorageAcc, storageAcc)
assert.Equal(t, tc.ExpectedDirectory, dir)
assert.Nil(t, err)
}
}

0 comments on commit a0ad67e

Please sign in to comment.