-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
184 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import logging | ||
from dataclasses import dataclass | ||
|
||
from databricks.sdk import WorkspaceClient | ||
|
||
from databricks.labs.ucx.framework.crawlers import CrawlerBase, SqlBackend | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@dataclass | ||
class Mount: | ||
name: str | ||
source: str | ||
|
||
|
||
class Mounts(CrawlerBase): | ||
def __init__(self, backend: SqlBackend, ws: WorkspaceClient, inventory_database: str): | ||
super().__init__(backend, "hive_metastore", inventory_database, "mounts") | ||
self._dbutils = ws.dbutils | ||
|
||
def inventorize_mounts(self): | ||
self._append_records(self._list_mounts()) | ||
|
||
def _list_mounts(self): | ||
mounts = [] | ||
for mount_point, source, _ in self._dbutils.fs.mounts(): | ||
mounts.append(Mount(mount_point, source)) | ||
return mounts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import pytest | ||
|
||
from databricks.labs.ucx.hive_metastore.list_mounts import Mount | ||
from databricks.labs.ucx.mixins.compute import CommandExecutor | ||
|
||
|
||
@pytest.mark.skip(reason="Needs to have mountpoints already created ") | ||
def test_mount_listing(ws, wsfs_wheel, make_schema, sql_fetch_all): | ||
_, inventory_database = make_schema(catalog="hive_metastore").split(".") | ||
commands = CommandExecutor(ws) | ||
commands.install_notebook_library(f"/Workspace{wsfs_wheel}") | ||
|
||
commands.run( | ||
f""" | ||
from databricks.labs.ucx.hive_metastore.list_mounts import Mounts | ||
from databricks.labs.ucx.config import MigrationConfig, GroupsConfig, TaclConfig | ||
from databricks.sdk import WorkspaceClient | ||
from databricks.labs.ucx.framework.crawlers import RuntimeBackend | ||
cfg = MigrationConfig( | ||
inventory_database="{inventory_database}", | ||
groups=GroupsConfig(auto=True), | ||
tacl=TaclConfig(databases=["default"])) | ||
ws = WorkspaceClient(config=cfg.to_databricks_config()) | ||
mounts = Mounts(backend=RuntimeBackend(), ws=ws, inventory_database=cfg.inventory_database) | ||
mounts.inventorize_mounts() | ||
""" | ||
) | ||
mounts = sql_fetch_all(f"SELECT * FROM hive_metastore.{inventory_database}.mounts") | ||
results = [] | ||
|
||
for mount in mounts: | ||
mount_info = Mount(*mount) | ||
results.append(mount_info) | ||
|
||
assert len(results) > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from unittest.mock import MagicMock | ||
|
||
from databricks.sdk.dbutils import MountInfo | ||
|
||
from databricks.labs.ucx.hive_metastore.list_mounts import Mount, Mounts | ||
from tests.unit.framework.mocks import MockBackend | ||
|
||
|
||
def test_list_mounts_should_return_a_list_of_mount_without_encryption_type(): | ||
client = MagicMock() | ||
client.dbutils.fs.mounts.return_value = [ | ||
MountInfo("mp_1", "path_1", "info_1"), | ||
MountInfo("mp_2", "path_2", "info_2"), | ||
] | ||
|
||
backend = MockBackend() | ||
instance = Mounts(backend, client, "test") | ||
|
||
instance.inventorize_mounts() | ||
|
||
expected = [Mount("mp_1", "path_1"), Mount("mp_2", "path_2")] | ||
assert backend.rows_written_for("hive_metastore.test.mounts", "append") == expected |