@@ -158,7 +158,7 @@ def test_install_cluster_override_jobs(ws, mock_installation, any_prompt):
158158 sql_backend = MockBackend ()
159159 wheels = create_autospec (WheelsV2 )
160160 workspace_installation = WorkspaceInstallation (
161- WorkspaceConfig (inventory_database = 'ucx' , override_clusters = {"main" : 'one' , "tacl" : 'two' }),
161+ WorkspaceConfig (inventory_database = 'ucx' , override_clusters = {"main" : 'one' , "tacl" : 'two' }, policy_id = '123' ),
162162 mock_installation ,
163163 sql_backend ,
164164 wheels ,
@@ -190,7 +190,7 @@ def test_write_protected_dbfs(ws, tmp_path, mock_installation):
190190 )
191191
192192 workspace_installation = WorkspaceInstallation (
193- WorkspaceConfig (inventory_database = 'ucx' ),
193+ WorkspaceConfig (inventory_database = 'ucx' , policy_id = '123' ),
194194 mock_installation ,
195195 sql_backend ,
196196 wheels ,
@@ -214,6 +214,7 @@ def test_write_protected_dbfs(ws, tmp_path, mock_installation):
214214 'log_level' : 'INFO' ,
215215 'num_threads' : 10 ,
216216 'override_clusters' : {'main' : '2222-999999-nosecuri' , 'tacl' : '3333-999999-legacytc' },
217+ 'policy_id' : '123' ,
217218 'renamed_group_prefix' : 'ucx-renamed-' ,
218219 'workspace_start_path' : '/' ,
219220 },
@@ -225,7 +226,7 @@ def test_writeable_dbfs(ws, tmp_path, mock_installation, any_prompt):
225226 sql_backend = MockBackend ()
226227 wheels = create_autospec (WheelsV2 )
227228 workspace_installation = WorkspaceInstallation (
228- WorkspaceConfig (inventory_database = 'ucx' ),
229+ WorkspaceConfig (inventory_database = 'ucx' , policy_id = '123' ),
229230 mock_installation ,
230231 sql_backend ,
231232 wheels ,
@@ -452,6 +453,47 @@ def test_save_config_strip_group_names(ws, mock_installation):
452453 )
453454
454455
456+ def test_cluster_policy_definition_present_reuse (ws , mock_installation ):
457+ ws .config .is_aws = False
458+ ws .config .is_azure = True
459+ ws .config .is_gcp = False
460+ ws .cluster_policies .list .return_value = [
461+ Policy (
462+ policy_id = "foo1" ,
463+ name = "Unity Catalog Migration (ucx) ([email protected] )" ,
464+ definition = json .dumps ({}),
465+ description = "Custom cluster policy for Unity Catalog Migration (UCX)" ,
466+ )
467+ ]
468+ prompts = MockPrompts (
469+ {
470+ r".*PRO or SERVERLESS SQL warehouse.*" : "1" ,
471+ r"Choose how to map the workspace groups.*" : "2" , # specify names
472+ r".*workspace group names.*" : "g1, g2, g99" ,
473+ r".*We have identified one or more cluster.*" : "No" ,
474+ r".*Choose a cluster policy.*" : "0" ,
475+ r".*" : "" ,
476+ }
477+ )
478+ install = WorkspaceInstaller (prompts , mock_installation , ws )
479+ install .configure ()
480+ mock_installation .assert_file_written (
481+ 'config.yml' ,
482+ {
483+ 'version' : 2 ,
484+ 'default_catalog' : 'ucx_default' ,
485+ 'include_group_names' : ['g1' , 'g2' , 'g99' ],
486+ 'inventory_database' : 'ucx' ,
487+ 'log_level' : 'INFO' ,
488+ 'num_threads' : 8 ,
489+ 'policy_id' : 'foo1' ,
490+ 'renamed_group_prefix' : 'db-temp-' ,
491+ 'warehouse_id' : 'abc' ,
492+ 'workspace_start_path' : '/' ,
493+ },
494+ )
495+
496+
455497def test_cluster_policy_definition_azure_hms (ws , mock_installation ):
456498 ws .config .is_aws = False
457499 ws .config .is_azure = True
@@ -498,7 +540,7 @@ def test_cluster_policy_definition_azure_hms(ws, mock_installation):
498540 "azure_attributes.availability" : {"type" : "fixed" , "value" : "ON_DEMAND_AZURE" },
499541 }
500542 ws .cluster_policies .create .assert_called_with (
501- name = "Unity Catalog Migration (ucx)" ,
543+ name = "Unity Catalog Migration (ucx) ([email protected] ) " ,
502544 definition = json .dumps (policy_definition_actual ),
503545 description = "Custom cluster policy for Unity Catalog Migration (UCX)" ,
504546 )
@@ -541,7 +583,7 @@ def test_cluster_policy_definition_aws_glue(ws, mock_installation):
541583 "aws_attributes.instance_profile_arn" : {"type" : "fixed" , "value" : "role_arn_1" },
542584 }
543585 ws .cluster_policies .create .assert_called_with (
544- name = "Unity Catalog Migration (ucx)" ,
586+ name = "Unity Catalog Migration (ucx) ([email protected] ) " ,
545587 definition = json .dumps (policy_definition_actual ),
546588 description = "Custom cluster policy for Unity Catalog Migration (UCX)" ,
547589 )
@@ -592,7 +634,7 @@ def test_cluster_policy_definition_gcp(ws, mock_installation):
592634 "gcp_attributes.availability" : {"type" : "fixed" , "value" : "ON_DEMAND_GCP" },
593635 }
594636 ws .cluster_policies .create .assert_called_with (
595- name = "Unity Catalog Migration (ucx)" ,
637+ name = "Unity Catalog Migration (ucx) ([email protected] ) " ,
596638 definition = json .dumps (policy_definition_actual ),
597639 description = "Custom cluster policy for Unity Catalog Migration (UCX)" ,
598640 )
@@ -611,17 +653,19 @@ def test_install_edit_policy_with_library(ws, mock_installation, any_prompt):
611653 timedelta (seconds = 1 ),
612654 )
613655 wheels .upload_to_wsfs .return_value = "path1"
614- ws .cluster_policies .get .return_value = Policy (policy_id = "foo" )
656+ ws .cluster_policies .get .return_value = Policy (
657+ policy_id = "foo" ,
name = "Unity Catalog Migration (ucx) ([email protected] )" 658+ )
615659 workspace_installation .create_jobs ()
616660 ws .cluster_policies .edit .assert_called_with (
617- name = "Unity Catalog Migration (ucx)" ,
661+ name = "Unity Catalog Migration (ucx) ([email protected] ) " ,
618662 policy_id = "foo" ,
619663 definition = None ,
620664 libraries = [compute .Library (whl = "dbfs:path1" )],
621665 )
622666
623667
624- def test_install_edit_policy_not_present (ws , mock_installation , any_prompt ):
668+ def test_install_edit_policy_not_found (ws , mock_installation , any_prompt ):
625669 sql_backend = MockBackend ()
626670 wheels = create_autospec (WheelsV2 )
627671 workspace_installation = WorkspaceInstallation (
@@ -638,6 +682,22 @@ def test_install_edit_policy_not_present(ws, mock_installation, any_prompt):
638682 workspace_installation .create_jobs ()
639683
640684
685+ def test_install_edit_policy_not_present (ws , mock_installation , any_prompt ):
686+ sql_backend = MockBackend ()
687+ wheels = create_autospec (WheelsV2 )
688+ workspace_installation = WorkspaceInstallation (
689+ WorkspaceConfig (inventory_database = 'ucx' , override_clusters = {"main" : 'one' , "tacl" : 'two' }),
690+ mock_installation ,
691+ sql_backend ,
692+ wheels ,
693+ ws ,
694+ any_prompt ,
695+ timedelta (seconds = 1 ),
696+ )
697+ with pytest .raises (InvalidParameterValue ):
698+ workspace_installation .create_jobs ()
699+
700+
641701def test_save_config_with_custom_policy (ws , mock_installation ):
642702 policy_def = b"""{
643703 "aws_attributes.instance_profile_arn": {
@@ -750,7 +810,7 @@ def test_main_with_existing_conf_does_not_recreate_config(ws, mocker, mock_insta
750810 }
751811 )
752812 workspace_installation = WorkspaceInstallation (
753- WorkspaceConfig (inventory_database = "..." ),
813+ WorkspaceConfig (inventory_database = "..." , policy_id = '123' ),
754814 mock_installation ,
755815 sql_backend ,
756816 create_autospec (WheelsV2 ),
0 commit comments