@@ -32,11 +32,17 @@ def test_save_spn_permissions_no_external_table(caplog):
3232 location = ExternalLocations (w , backend , "ucx" )
3333 installation = MockInstallation ()
3434 azure_resources = create_autospec (AzureResources )
35- azure_resource_permission = AzureResourcePermissions (installation , w , azure_resources , location )
3635 azure_resources .storage_accounts .return_value = []
36+ azure_resource_permission = AzureResourcePermissions (installation , w , azure_resources , location )
3737 azure_resource_permission .save_spn_permissions ()
3838 msg = "There are no external table present with azure storage account. Please check if assessment job is run"
3939 assert [rec .message for rec in caplog .records if msg in rec .message ]
40+ w .cluster_policies .get .assert_not_called ()
41+ w .secrets .get_secret .assert_not_called ()
42+ w .secrets .create_scope .assert_not_called ()
43+ w .secrets .put_secret .assert_not_called ()
44+ w .cluster_policies .edit .assert_not_called ()
45+ w .get_workspace_id .assert_not_called ()
4046
4147
4248def test_save_spn_permissions_no_external_tables ():
@@ -49,6 +55,12 @@ def test_save_spn_permissions_no_external_tables():
4955 azure_resource_permission = AzureResourcePermissions (installation , w , azure_resources , location )
5056 azure_resources .storage_accounts .return_value = []
5157 assert not azure_resource_permission .save_spn_permissions ()
58+ w .cluster_policies .get .assert_not_called ()
59+ w .secrets .get_secret .assert_not_called ()
60+ w .secrets .create_scope .assert_not_called ()
61+ w .secrets .put_secret .assert_not_called ()
62+ w .cluster_policies .edit .assert_not_called ()
63+ w .get_workspace_id .assert_not_called ()
5264
5365
5466def test_save_spn_permissions_no_azure_storage_account ():
@@ -63,6 +75,12 @@ def test_save_spn_permissions_no_azure_storage_account():
6375 azure_resource_permission = AzureResourcePermissions (installation , w , azure_resources , location )
6476 azure_resources .storage_accounts .return_value = []
6577 assert not azure_resource_permission .save_spn_permissions ()
78+ w .cluster_policies .get .assert_not_called ()
79+ w .secrets .get_secret .assert_not_called ()
80+ w .secrets .create_scope .assert_not_called ()
81+ w .secrets .put_secret .assert_not_called ()
82+ w .cluster_policies .edit .assert_not_called ()
83+ w .get_workspace_id .assert_not_called ()
6684
6785
6886def test_save_spn_permissions_valid_azure_storage_account ():
@@ -111,6 +129,12 @@ def test_save_spn_permissions_valid_azure_storage_account():
111129 ]
112130 azure_resource_permission = AzureResourcePermissions (installation , w , azure_resources , location )
113131 azure_resource_permission .save_spn_permissions ()
132+ w .cluster_policies .get .assert_not_called ()
133+ w .secrets .get_secret .assert_not_called ()
134+ w .secrets .create_scope .assert_not_called ()
135+ w .secrets .put_secret .assert_not_called ()
136+ w .cluster_policies .edit .assert_not_called ()
137+ w .get_workspace_id .assert_not_called ()
114138 installation .assert_file_written (
115139 'azure_storage_account_info.csv' ,
116140 [
@@ -153,6 +177,16 @@ def test_create_global_spn_no_policy():
153177 prompts = MockPrompts ({"Enter a name for the uber service principal to be created*" : "UCXServicePrincipal" })
154178 with pytest .raises (ValueError ):
155179 azure_resource_permission .create_uber_principal (prompts )
180+ azure_resources .storage_accounts .assert_not_called ()
181+ azure_resources .create_or_update_access_connector .assert_not_called ()
182+ azure_resources .role_assignments .assert_not_called ()
183+ azure_resources .containers .assert_not_called ()
184+ w .cluster_policies .get .assert_not_called ()
185+ w .secrets .get_secret .assert_not_called ()
186+ w .secrets .create_scope .assert_not_called ()
187+ w .secrets .put_secret .assert_not_called ()
188+ w .cluster_policies .edit .assert_not_called ()
189+ w .get_workspace_id .assert_called_once ()
156190
157191
158192def test_create_global_spn_spn_present ():
@@ -175,6 +209,16 @@ def test_create_global_spn_spn_present():
175209 prompts = MockPrompts ({"Enter a name for the uber service principal to be created*" : "UCXServicePrincipal" })
176210 azure_resource_permission = AzureResourcePermissions (installation , w , azure_resources , location )
177211 assert not azure_resource_permission .create_uber_principal (prompts )
212+ azure_resources .storage_accounts .assert_not_called ()
213+ azure_resources .create_or_update_access_connector .assert_not_called ()
214+ azure_resources .role_assignments .assert_not_called ()
215+ azure_resources .containers .assert_not_called ()
216+ w .cluster_policies .get .assert_not_called ()
217+ w .secrets .get_secret .assert_not_called ()
218+ w .secrets .create_scope .assert_not_called ()
219+ w .secrets .put_secret .assert_not_called ()
220+ w .cluster_policies .edit .assert_not_called ()
221+ w .get_workspace_id .assert_called_once ()
178222
179223
180224def test_create_global_spn_no_storage ():
@@ -198,6 +242,16 @@ def test_create_global_spn_no_storage():
198242 azure_resources = create_autospec (AzureResources )
199243 azure_resource_permission = AzureResourcePermissions (installation , w , azure_resources , location )
200244 assert not azure_resource_permission .create_uber_principal (prompts )
245+ azure_resources .storage_accounts .assert_not_called ()
246+ azure_resources .create_or_update_access_connector .assert_not_called ()
247+ azure_resources .role_assignments .assert_not_called ()
248+ azure_resources .containers .assert_not_called ()
249+ w .cluster_policies .get .assert_not_called ()
250+ w .secrets .get_secret .assert_not_called ()
251+ w .secrets .create_scope .assert_not_called ()
252+ w .secrets .put_secret .assert_not_called ()
253+ w .cluster_policies .edit .assert_not_called ()
254+ w .get_workspace_id .assert_called_once ()
201255
202256
203257def test_create_global_spn_cluster_policy_not_found ():
@@ -224,6 +278,12 @@ def test_create_global_spn_cluster_policy_not_found():
224278 azure_resource_permission = AzureResourcePermissions (installation , w , azure_resources , location )
225279 with pytest .raises (NotFound ):
226280 azure_resource_permission .create_uber_principal (prompts )
281+ w .cluster_policies .get .assert_called_once ()
282+ w .secrets .get_secret .assert_not_called ()
283+ w .secrets .create_scope .assert_called_with ("ucx" )
284+ w .secrets .put_secret .assert_called_with ('ucx' , 'uber_principal_secret' , string_value = 'mypwd' )
285+ w .cluster_policies .edit .assert_not_called ()
286+ w .get_workspace_id .assert_called_once ()
227287
228288
229289def test_create_global_spn ():
@@ -302,6 +362,10 @@ def test_create_access_connectors_for_storage_accounts_logs_no_storage_accounts(
302362 azure_resource_permission = AzureResourcePermissions (installation , w , azure_resources , location )
303363
304364 azure_resource_permission .create_access_connectors_for_storage_accounts ()
365+
366+ w .cluster_policies .get .assert_not_called ()
367+ w .secrets .get_secret .assert_not_called ()
368+ w .secrets .create_scope .assert_not_called ()
305369 assert (
306370 "There are no external table present with azure storage account. Please check if assessment job is run"
307371 in caplog .messages
@@ -345,6 +409,11 @@ def test_create_access_connectors_for_storage_accounts_one_access_connector():
345409 azure_resource_permission = AzureResourcePermissions (installation , w , azure_resources , location )
346410
347411 access_connectors = azure_resource_permission .create_access_connectors_for_storage_accounts ()
412+
413+ w .cluster_policies .get .assert_not_called ()
414+ w .secrets .get_secret .assert_not_called ()
415+ w .secrets .create_scope .assert_not_called ()
416+
348417 assert len (access_connectors ) == 1
349418 assert access_connectors [0 ].name == "ac-test"
350419
@@ -388,3 +457,7 @@ def test_create_access_connectors_for_storage_accounts_log_permission_applied(ca
388457 with caplog .at_level (logging .DEBUG , logger = "databricks.labs.ucx" ):
389458 azure_resource_permission .create_access_connectors_for_storage_accounts ()
390459 assert any ("STORAGE_BLOB_DATA_CONTRIBUTOR" in message for message in caplog .messages )
460+
461+ w .cluster_policies .get .assert_not_called ()
462+ w .secrets .get_secret .assert_not_called ()
463+ w .secrets .create_scope .assert_not_called ()
0 commit comments