1- from databricks .labs .ucx .progress .install import ProgressTrackingInstallation
1+ import datetime as dt
2+ from unittest .mock import create_autospec
3+
4+ import pytest
5+
6+ from databricks .labs .ucx .hive_metastore .verification import MetastoreNotFoundError , VerifyHasCatalog , VerifyHasMetastore
7+ from databricks .labs .ucx .installer .workflows import DeployedWorkflows
8+ from databricks .labs .ucx .progress .install import ProgressTrackingInstallation , VerifyProgressTracking
29
310
411def test_progress_tracking_installation_run_creates_progress_tracking_schema (mock_backend ) -> None :
@@ -12,3 +19,74 @@ def test_progress_tracking_installation_run_creates_tables(mock_backend) -> None
1219 installation .run ()
1320 # Dataclass to schema conversion is tested within the lsql package
1421 assert sum ("CREATE TABLE IF NOT EXISTS" in query for query in mock_backend .queries ) == 2
22+
23+
24+ def test_verify_progress_tracking_valid_prerequisites () -> None :
25+ verify_has_metastore = create_autospec (VerifyHasMetastore )
26+ verify_has_catalog = create_autospec (VerifyHasCatalog )
27+ deployed_workflows = create_autospec (DeployedWorkflows )
28+ verify_progress_tracking = VerifyProgressTracking (verify_has_metastore , verify_has_catalog , deployed_workflows )
29+ timeout = dt .timedelta (hours = 1 )
30+ try :
31+ verify_progress_tracking .verify (timeout = timeout )
32+ except RuntimeError as e :
33+ assert False , f"Verify progress tracking raises: { e } "
34+ else :
35+ assert True , "Valid prerequisites found"
36+ verify_has_metastore .verify_metastore .assert_called_once ()
37+ verify_has_catalog .verify .assert_called_once ()
38+ deployed_workflows .validate_step .assert_called_once_with ("assessment" , timeout = timeout )
39+
40+
41+ def test_verify_progress_tracking_raises_runtime_error_if_metastore_not_attached_to_workspace (
42+ mock_installation ,
43+ ) -> None :
44+ verify_has_metastore = create_autospec (VerifyHasMetastore )
45+ verify_has_metastore .verify_metastore .side_effect = MetastoreNotFoundError
46+ verify_has_catalog = create_autospec (VerifyHasCatalog )
47+ deployed_workflows = create_autospec (DeployedWorkflows )
48+ verify_progress_tracking = VerifyProgressTracking (verify_has_metastore , verify_has_catalog , deployed_workflows )
49+ with pytest .raises (RuntimeWarning , match = "Metastore not attached to workspace" ):
50+ verify_progress_tracking .verify ()
51+ verify_has_metastore .verify_metastore .assert_called_once ()
52+ verify_has_catalog .assert_not_called ()
53+ deployed_workflows .assert_not_called ()
54+
55+
56+ def test_verify_progress_tracking_raises_runtime_error_if_no_metastore (mock_installation ) -> None :
57+ verify_has_metastore = create_autospec (VerifyHasMetastore )
58+ verify_has_metastore .verify_metastore .return_value = False
59+ verify_has_catalog = create_autospec (VerifyHasCatalog )
60+ deployed_workflows = create_autospec (DeployedWorkflows )
61+ verify_progress_tracking = VerifyProgressTracking (verify_has_metastore , verify_has_catalog , deployed_workflows )
62+ with pytest .raises (RuntimeWarning , match = "Metastore not attached to workspace" ):
63+ verify_progress_tracking .verify ()
64+ verify_has_metastore .verify_metastore .assert_called_once ()
65+ verify_has_catalog .assert_not_called ()
66+ deployed_workflows .assert_not_called ()
67+
68+
69+ def test_verify_progress_tracking_raises_runtime_error_if_missing_ucx_catalog (mock_installation ) -> None :
70+ verify_has_metastore = create_autospec (VerifyHasMetastore )
71+ verify_has_catalog = create_autospec (VerifyHasCatalog )
72+ verify_has_catalog .verify .return_value = False
73+ deployed_workflows = create_autospec (DeployedWorkflows )
74+ verify_progress_tracking = VerifyProgressTracking (verify_has_metastore , verify_has_catalog , deployed_workflows )
75+ with pytest .raises (RuntimeWarning , match = "UCX catalog not configured." ):
76+ verify_progress_tracking .verify ()
77+ verify_has_metastore .verify_metastore .assert_called_once ()
78+ verify_has_catalog .verify .assert_called_once ()
79+ deployed_workflows .assert_not_called ()
80+
81+
82+ def test_verify_progress_tracking_raises_runtime_error_if_assessment_workflow_did_not_run (mock_installation ) -> None :
83+ verify_has_metastore = create_autospec (VerifyHasMetastore )
84+ verify_has_catalog = create_autospec (VerifyHasCatalog )
85+ deployed_workflows = create_autospec (DeployedWorkflows )
86+ deployed_workflows .validate_step .return_value = False
87+ verify_progress_tracking = VerifyProgressTracking (verify_has_metastore , verify_has_catalog , deployed_workflows )
88+ with pytest .raises (RuntimeWarning , match = "Assessment workflow did not complete successfully yet." ):
89+ verify_progress_tracking .verify ()
90+ verify_has_metastore .verify_metastore .assert_called_once ()
91+ verify_has_catalog .verify .assert_called_once ()
92+ deployed_workflows .validate_step .assert_called_once_with ("assessment" , timeout = dt .timedelta (seconds = 0 ))
0 commit comments