From 9331b6edb4bb078c323e397b2b3d057edb834af0 Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Thu, 12 Dec 2024 09:37:25 +0100 Subject: [PATCH 1/2] Remove try-except from cli command The message should be handled inside the verify progress tracking class --- src/databricks/labs/ucx/cli.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/databricks/labs/ucx/cli.py b/src/databricks/labs/ucx/cli.py index 4b37e81165..f4aece8f8a 100644 --- a/src/databricks/labs/ucx/cli.py +++ b/src/databricks/labs/ucx/cli.py @@ -687,16 +687,7 @@ def migrate_tables( for workspace_context in workspace_contexts: deployed_workflows = workspace_context.deployed_workflows - try: - workspace_context.verify_progress_tracking.verify() - except RuntimeWarning: - logger.warning( - "We couldn't detect a successful run of the assessment workflow." - "The assessment workflow is a prerequisite for the migrate-tables workflow." - "It can be run by using the `ensure-assessment-run` command." - ) - return - + workspace_context.verify_progress_tracking.verify() deployed_workflows.run_workflow("migrate-tables") tables = list(workspace_context.tables_crawler.snapshot()) From 385ee6c5051bc3f9bcca248ed26e0f8dfdabf26d Mon Sep 17 00:00:00 2001 From: Cor Zuurmond Date: Thu, 12 Dec 2024 09:54:37 +0100 Subject: [PATCH 2/2] Fix unit test about verification progress failing before migrate tables --- tests/unit/test_cli.py | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index 30943fc3f6..0477f55767 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -1028,28 +1028,15 @@ def test_migrate_tables_calls_migrate_table_job_run_now( workspace_client.jobs.wait_get_run_job_terminated_or_skipped.assert_called_once() -@pytest.mark.parametrize("run_as_collection", [False, True]) -def test_migrate_tables_errors_out_before_assessment( - run_as_collection, - workspace_clients, - acc_client, -) -> None: - if not run_as_collection: - workspace_clients = [workspace_clients[0]] - run = Run( - state=RunState(result_state=RunResultState.SUCCESS), - start_time=0, - end_time=1000, - run_duration=1000, - ) - for workspace_client in workspace_clients: - workspace_client.jobs.wait_get_run_job_terminated_or_skipped.return_value = run - workspace_client.jobs.list_runs.return_value = [Run(state=RunState(result_state=RunResultState.FAILED))] +def test_migrate_tables_errors_out_before_assessment(ws, acc_client) -> None: + verify_progress_tracking = create_autospec(VerifyProgressTracking) + verify_progress_tracking.verify.side_effect = RuntimeWarning("Verification failed") + ctx = WorkspaceContext(ws).replace(verify_progress_tracking=verify_progress_tracking) - migrate_tables(workspace_clients[0], MockPrompts({}), run_as_collection=run_as_collection, a=acc_client) + with pytest.raises(RuntimeWarning, match="Verification failed"): + migrate_tables(ws, MockPrompts({}), ctx=ctx, a=acc_client) - for workspace_client in workspace_clients: - workspace_client.jobs.run_now.assert_not_called() + ws.jobs.run_now.assert_not_called() def test_migrate_tables_calls_external_hiveserde_tables_job_run_now(ws) -> None: