Skip to content

Commit c8c0428

Browse files
authored
Log warnings when mounts are discovered on incorrect cluster type (#2929)
closes #2498
1 parent f5c8029 commit c8c0428

File tree

4 files changed

+67
-4
lines changed

4 files changed

+67
-4
lines changed

src/databricks/labs/ucx/cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,17 @@ def migrate_tables(
646646
workspace_contexts = _get_workspace_contexts(w, a, run_as_collection)
647647
for workspace_context in workspace_contexts:
648648
deployed_workflows = workspace_context.deployed_workflows
649+
650+
try:
651+
workspace_context.verify_progress_tracking.verify()
652+
except RuntimeWarning:
653+
logger.warning(
654+
"We couldn't detect a successful run of the assessment workflow."
655+
"The assessment workflow is a prerequisite for the migrate-tables workflow."
656+
"It can be run by using the `ensure-assessment-run` command."
657+
)
658+
return
659+
649660
deployed_workflows.run_workflow("migrate-tables")
650661

651662
tables = list(workspace_context.tables_crawler.snapshot())

src/databricks/labs/ucx/hive_metastore/locations.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,15 @@ def _deduplicate_mounts(mounts: list) -> list:
320320

321321
def _crawl(self) -> Iterable[Mount]:
322322
mounts = []
323-
for mount_point, source, _ in self._dbutils.fs.mounts():
324-
mounts.append(Mount(mount_point, source))
323+
try:
324+
for mount_point, source, _ in self._dbutils.fs.mounts():
325+
mounts.append(Mount(mount_point, source))
326+
except Exception as error: # pylint: disable=broad-except
327+
if "com.databricks.backend.daemon.dbutils.DBUtilsCore.mounts() is not whitelisted" in str(error):
328+
logger.warning(
329+
"dbutils.fs.mounts() is not whitelisted. Skipping mount point discovery."
330+
"Please make sure you run the assessment workflow."
331+
)
325332
return self._deduplicate_mounts(mounts)
326333

327334
def _try_fetch(self) -> Iterable[Mount]:

tests/unit/hive_metastore/test_locations.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ def test_mounts_inventory_should_contain_deduped_mounts_without_variable_volume_
139139
assert expected == backend.rows_written_for("hive_metastore.test.mounts", "overwrite")
140140

141141

142+
def test_mount_inventory_warning_on_incompatible_compute(caplog):
143+
client = create_autospec(WorkspaceClient)
144+
client.dbutils.fs.mounts.side_effect = Exception(
145+
"Blah Blah com.databricks.backend.daemon.dbutils.DBUtilsCore.mounts() is not whitelisted"
146+
)
147+
backend = MockBackend()
148+
instance = Mounts(backend, client, "test")
149+
150+
instance.snapshot()
151+
152+
expected_warning = "dbutils.fs.mounts() is not whitelisted"
153+
assert expected_warning in caplog.text
154+
155+
142156
def test_external_locations():
143157
row_factory = type("Row", (Row,), {"__columns__": ["location", "storage_properties"]})
144158
sql_backend = MockBackend(

tests/unit/test_cli.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
from databricks.labs.ucx.hive_metastore import TablesCrawler, ExternalLocations
6969
from databricks.labs.ucx.hive_metastore.locations import ExternalLocation
7070
from databricks.labs.ucx.hive_metastore.tables import Table
71+
from databricks.labs.ucx.progress.install import VerifyProgressTracking
7172
from databricks.labs.ucx.source_code.linters.files import LocalFileMigrator
7273

7374

@@ -929,6 +930,7 @@ def test_migrate_tables_calls_migrate_table_job_run_now(
929930
)
930931
for workspace_client in workspace_clients:
931932
workspace_client.jobs.wait_get_run_job_terminated_or_skipped.return_value = run
933+
workspace_client.jobs.list_runs.return_value = [Run(state=RunState(result_state=RunResultState.SUCCESS))]
932934

933935
migrate_tables(workspace_clients[0], MockPrompts({}), run_as_collection=run_as_collection, a=acc_client)
934936

@@ -937,6 +939,30 @@ def test_migrate_tables_calls_migrate_table_job_run_now(
937939
workspace_client.jobs.wait_get_run_job_terminated_or_skipped.assert_called_once()
938940

939941

942+
@pytest.mark.parametrize("run_as_collection", [False, True])
943+
def test_migrate_tables_errors_out_before_assessment(
944+
run_as_collection,
945+
workspace_clients,
946+
acc_client,
947+
) -> None:
948+
if not run_as_collection:
949+
workspace_clients = [workspace_clients[0]]
950+
run = Run(
951+
state=RunState(result_state=RunResultState.SUCCESS),
952+
start_time=0,
953+
end_time=1000,
954+
run_duration=1000,
955+
)
956+
for workspace_client in workspace_clients:
957+
workspace_client.jobs.wait_get_run_job_terminated_or_skipped.return_value = run
958+
workspace_client.jobs.list_runs.return_value = [Run(state=RunState(result_state=RunResultState.FAILED))]
959+
960+
migrate_tables(workspace_clients[0], MockPrompts({}), run_as_collection=run_as_collection, a=acc_client)
961+
962+
for workspace_client in workspace_clients:
963+
workspace_client.jobs.run_now.assert_not_called()
964+
965+
940966
def test_migrate_tables_calls_external_hiveserde_tables_job_run_now(ws) -> None:
941967
# TODO: Test for running on a collection when context injection for multiple workspaces is supported.
942968
tables_crawler = create_autospec(TablesCrawler)
@@ -948,7 +974,9 @@ def test_migrate_tables_calls_external_hiveserde_tables_job_run_now(ws) -> None:
948974
table_format="HIVE",
949975
)
950976
tables_crawler.snapshot.return_value = [table]
951-
ctx = WorkspaceContext(ws).replace(tables_crawler=tables_crawler)
977+
verify_progress_tracking = create_autospec(VerifyProgressTracking)
978+
verify_progress_tracking.verify.return_value = None
979+
ctx = WorkspaceContext(ws).replace(tables_crawler=tables_crawler, verify_progress_tracking=verify_progress_tracking)
952980
ws.jobs.wait_get_run_job_terminated_or_skipped.return_value = Run(
953981
state=RunState(result_state=RunResultState.SUCCESS),
954982
start_time=0,
@@ -979,7 +1007,10 @@ def test_migrate_tables_calls_external_tables_ctas_job_run_now(ws) -> None:
9791007
table_format="EXTERNAL",
9801008
)
9811009
tables_crawler.snapshot.return_value = [table]
982-
ctx = WorkspaceContext(ws).replace(tables_crawler=tables_crawler)
1010+
verify_progress_tracking = create_autospec(VerifyProgressTracking)
1011+
verify_progress_tracking.verify.return_value = None
1012+
ctx = WorkspaceContext(ws).replace(tables_crawler=tables_crawler, verify_progress_tracking=verify_progress_tracking)
1013+
9831014
ws.jobs.wait_get_run_job_terminated_or_skipped.return_value = Run(
9841015
state=RunState(result_state=RunResultState.SUCCESS),
9851016
start_time=0,

0 commit comments

Comments
 (0)