|
17 | 17 | manual_workspace_info, |
18 | 18 | move, |
19 | 19 | open_remote_config, |
| 20 | + principal_prefix_access, |
20 | 21 | repair_run, |
21 | 22 | revert_migrated_tables, |
22 | | - save_aws_iam_profiles, |
23 | | - save_azure_storage_accounts, |
24 | | - save_uc_compatible_roles, |
25 | 23 | skip, |
26 | 24 | sync_workspace_info, |
27 | 25 | validate_external_locations, |
@@ -231,91 +229,79 @@ def test_alias(ws): |
231 | 229 | ws.tables.list.assert_called_once() |
232 | 230 |
|
233 | 231 |
|
234 | | -def test_save_azure_storage_accounts_not_azure(ws, caplog): |
235 | | - ws.config.is_azure = False |
236 | | - |
237 | | - save_azure_storage_accounts(ws, "") |
238 | | - |
239 | | - assert 'Workspace is not on azure, please run this command on azure databricks workspaces.' in caplog.messages |
240 | | - |
241 | | - |
242 | | -def test_save_azure_storage_accounts_no_azure_cli(ws, caplog): |
| 232 | +def test_save_storage_and_principal_azure_no_azure_cli(ws, caplog): |
243 | 233 | ws.config.auth_type = "azure_clis" |
244 | | - |
245 | | - save_azure_storage_accounts(ws, "") |
| 234 | + ws.config.is_azure = True |
| 235 | + principal_prefix_access(ws, "") |
246 | 236 |
|
247 | 237 | assert 'In order to obtain AAD token, Please run azure cli to authenticate.' in caplog.messages |
248 | 238 |
|
249 | 239 |
|
250 | | -def test_save_azure_storage_accounts_no_subscription_id(ws, caplog): |
251 | | - ws.config.auth_type = "azure_cli" |
| 240 | +def test_save_storage_and_principal_azure_no_subscription_id(ws, caplog): |
| 241 | + ws.config.auth_type = "azure-cli" |
252 | 242 | ws.config.is_azure = True |
253 | 243 |
|
254 | | - save_azure_storage_accounts(ws, "") |
| 244 | + principal_prefix_access(ws, "") |
255 | 245 |
|
256 | 246 | assert "Please enter subscription id to scan storage account in." in caplog.messages |
257 | 247 |
|
258 | 248 |
|
259 | | -def test_save_azure_storage_accounts(ws, caplog): |
260 | | - ws.config.auth_type = "azure_cli" |
| 249 | +def test_save_storage_and_principal_azure(ws, caplog, mocker): |
| 250 | + ws.config.auth_type = "azure-cli" |
261 | 251 | ws.config.is_azure = True |
262 | | - save_azure_storage_accounts(ws, "test") |
263 | | - |
264 | | - ws.statement_execution.execute_statement.assert_called() |
| 252 | + azure_resource = mocker.patch("databricks.labs.ucx.azure.access.AzureResourcePermissions.save_spn_permissions") |
| 253 | + principal_prefix_access(ws, "test") |
| 254 | + azure_resource.assert_called_once() |
265 | 255 |
|
266 | 256 |
|
267 | 257 | def test_validate_groups_membership(ws): |
268 | 258 | validate_groups_membership(ws) |
269 | 259 | ws.groups.list.assert_called() |
270 | 260 |
|
271 | 261 |
|
272 | | -def test_save_aws_iam_profiles_no_profile(ws, caplog, mocker): |
| 262 | +def test_save_storage_and_principal_aws_no_profile(ws, caplog, mocker): |
273 | 263 | mocker.patch("shutil.which", return_value="/path/aws") |
274 | | - save_aws_iam_profiles(ws) |
| 264 | + ws.config.is_azure = False |
| 265 | + ws.config.is_aws = True |
| 266 | + principal_prefix_access(ws) |
275 | 267 | assert any({"AWS Profile is not specified." in message for message in caplog.messages}) |
276 | 268 |
|
277 | 269 |
|
278 | | -def test_save_aws_iam_profiles_no_connection(ws, mocker): |
| 270 | +def test_save_storage_and_principal_aws_no_connection(ws, mocker): |
279 | 271 | mocker.patch("shutil.which", return_value="/path/aws") |
280 | 272 | pop = create_autospec(subprocess.Popen) |
281 | | - |
| 273 | + ws.config.is_azure = False |
| 274 | + ws.config.is_aws = True |
282 | 275 | pop.communicate.return_value = (bytes("message", "utf-8"), bytes("error", "utf-8")) |
283 | 276 | pop.returncode = 127 |
284 | 277 | mocker.patch("subprocess.Popen.__init__", return_value=None) |
285 | 278 | mocker.patch("subprocess.Popen.__enter__", return_value=pop) |
286 | 279 | mocker.patch("subprocess.Popen.__exit__", return_value=None) |
287 | 280 |
|
288 | 281 | with pytest.raises(ResourceWarning, match="AWS CLI is not configured properly."): |
289 | | - save_aws_iam_profiles(ws, aws_profile="profile") |
| 282 | + principal_prefix_access(ws, aws_profile="profile") |
290 | 283 |
|
291 | 284 |
|
292 | | -def test_save_aws_iam_profiles_no_cli(ws, mocker, caplog): |
| 285 | +def test_save_storage_and_principal_aws_no_cli(ws, mocker, caplog): |
293 | 286 | mocker.patch("shutil.which", return_value=None) |
294 | | - save_aws_iam_profiles(ws, aws_profile="profile") |
| 287 | + ws.config.is_azure = False |
| 288 | + ws.config.is_aws = True |
| 289 | + principal_prefix_access(ws, aws_profile="profile") |
295 | 290 | assert any({"Couldn't find AWS" in message for message in caplog.messages}) |
296 | 291 |
|
297 | 292 |
|
298 | | -def test_save_uc_roles_no_profile(ws, caplog, mocker): |
299 | | - mocker.patch("shutil.which", return_value="/path/aws") |
300 | | - save_uc_compatible_roles(ws) |
301 | | - assert any({"AWS Profile is not specified." in message for message in caplog.messages}) |
302 | | - |
303 | | - |
304 | | -def test_save_uc_roles_no_connection(ws, mocker): |
305 | | - mocker.patch("shutil.which", return_value="/path/aws") |
306 | | - pop = create_autospec(subprocess.Popen) |
307 | | - |
308 | | - pop.communicate.return_value = (bytes("message", "utf-8"), bytes("error", "utf-8")) |
309 | | - pop.returncode = 127 |
310 | | - mocker.patch("subprocess.Popen.__init__", return_value=None) |
311 | | - mocker.patch("subprocess.Popen.__enter__", return_value=pop) |
312 | | - mocker.patch("subprocess.Popen.__exit__", return_value=None) |
313 | | - |
314 | | - with pytest.raises(ResourceWarning, match="AWS CLI is not configured properly."): |
315 | | - save_uc_compatible_roles(ws, aws_profile="profile") |
| 293 | +def test_save_storage_and_principal_aws(ws, mocker, caplog): |
| 294 | + mocker.patch("shutil.which", return_value=True) |
| 295 | + ws.config.is_azure = False |
| 296 | + ws.config.is_aws = True |
| 297 | + aws_resource = mocker.patch("databricks.labs.ucx.assessment.aws.AWSResourcePermissions.for_cli") |
| 298 | + principal_prefix_access(ws, aws_profile="profile") |
| 299 | + aws_resource.assert_called_once() |
316 | 300 |
|
317 | 301 |
|
318 | | -def test_save_uc_roles_no_cli(ws, mocker, caplog): |
319 | | - mocker.patch("shutil.which", return_value=None) |
320 | | - save_uc_compatible_roles(ws, aws_profile="profile") |
321 | | - assert any({"Couldn't find AWS" in message for message in caplog.messages}) |
| 302 | +def test_save_storage_and_principal_gcp(ws, caplog): |
| 303 | + ws.config.is_azure = False |
| 304 | + ws.config.is_aws = False |
| 305 | + ws.config.is_gcp = True |
| 306 | + principal_prefix_access(ws) |
| 307 | + assert "This cmd is only supported for azure and aws workspaces" in caplog.messages |
0 commit comments