-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically retrying with
auth_type=azure-cli
when constructing `…
…workspace_clients` on Azure (#1650) ## Changes - Automatically retrying with `auth_type=azure-cli` when constructing `workspace_clients` on Azure - Resolved TODO items for `AccountWorkspaces` - Added relevant suggestions in `troubleshooting.md` ### Linked issues <!-- DOC: Link issue with a keyword: close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved. See https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword --> Closes #1574, closes #1430 ### Functionality - [x] added relevant user documentation ### Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] manually tested - [x] verified on staging environment (screenshot attached)
- Loading branch information
Showing
6 changed files
with
126 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import logging | ||
from unittest.mock import create_autospec | ||
|
||
from databricks.sdk import Workspace, WorkspaceClient | ||
from databricks.sdk.service import iam, sql | ||
|
||
from databricks.labs.ucx.account.aggregate import AccountAggregate | ||
from databricks.labs.ucx.account.workspaces import AccountWorkspaces | ||
|
||
from databricks.labs.ucx.config import WorkspaceConfig | ||
from databricks.labs.ucx.contexts.workspace_cli import WorkspaceContext | ||
from databricks.sdk.service import sql | ||
|
||
|
||
def test_basic_readiness_report_no_workspaces(acc_client, caplog): | ||
|
@@ -67,6 +68,7 @@ def test_readiness_report_ucx_installed(acc_client, caplog): | |
), | ||
statement_id='123', | ||
) | ||
ws.current_user.me.return_value = iam.User(user_name="[email protected]", groups=[iam.ComplexValue(display="admins")]) | ||
|
||
ctx = WorkspaceContext(ws).replace(config=WorkspaceConfig(inventory_database="something", warehouse_id="1234")) | ||
account_aggregate_obj = AccountAggregate(account_ws, workspace_context_factory=lambda _: ctx) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import io | ||
import json | ||
|
||
from unittest.mock import create_autospec | ||
import pytest | ||
|
||
import pytest | ||
from databricks.labs.blueprint.installation import Installation, MockInstallation | ||
from databricks.labs.blueprint.tui import MockPrompts | ||
from databricks.sdk import WorkspaceClient | ||
from databricks.sdk import AccountClient, WorkspaceClient | ||
from databricks.sdk.errors import NotFound, ResourceConflict | ||
from databricks.sdk.service import iam | ||
from databricks.sdk.service.iam import ComplexValue, Group, ResourceMeta, User | ||
|
@@ -448,3 +447,50 @@ def test_create_acc_groups_should_not_throw_if_acc_grp_exists(acc_client): | |
|
||
acc_client.groups.create.assert_called_with(display_name="de") | ||
acc_client.groups.patch.assert_not_called() | ||
|
||
|
||
def test_get_accessible_workspaces(): | ||
acc = create_autospec(AccountClient) | ||
acc.workspaces.list.return_value = [ | ||
Workspace(workspace_name="foo", workspace_id=123, workspace_status_message="Running", deployment_name="abc"), | ||
Workspace(workspace_name="bar", workspace_id=456, workspace_status_message="Running", deployment_name="def"), | ||
Workspace(workspace_name="bar", workspace_id=789, workspace_status_message="Running", deployment_name="def"), | ||
Workspace(workspace_name="bar", workspace_id=000, workspace_status_message="Running", deployment_name="def"), | ||
] | ||
acc.config.is_azure = True | ||
acc.config.auth_type = "databricks-cli" | ||
|
||
# admin in workspace 1 | ||
ws1 = create_autospec(WorkspaceClient) | ||
ws1.current_user.me.return_value = iam.User(user_name="[email protected]", groups=[iam.ComplexValue(display="admins")]) | ||
# not an admin in workspace 2 | ||
ws2 = create_autospec(WorkspaceClient) | ||
ws2.current_user.me.return_value = iam.User(user_name="[email protected]") | ||
# not an admin in workspace 3 | ||
ws3 = create_autospec(WorkspaceClient) | ||
ws3.current_user.me.return_value = iam.User(user_name="[email protected]", groups=[iam.ComplexValue(display="users")]) | ||
|
||
def get_workspace_client(workspace) -> WorkspaceClient: | ||
match workspace.workspace_id: | ||
case 123: | ||
return ws1 | ||
case 456: | ||
return ws2 | ||
case 789: | ||
return ws3 | ||
case _: | ||
raise ValueError("unexpected workspace id") | ||
|
||
acc.get_workspace_client.side_effect = get_workspace_client | ||
|
||
account_workspaces = AccountWorkspaces(acc) | ||
assert len(account_workspaces.get_accessible_workspaces()) == 1 | ||
ws1.current_user.me.assert_called_once() | ||
ws2.current_user.me.assert_called_once() | ||
# get_workspace_client should be called once for 123, 456, 789, then twice for workspace 000 | ||
assert acc.get_workspace_client.call_count == 5 | ||
|
||
acc.config.is_azure = False | ||
acc.config.auth_type = "databricks-cli" | ||
account_workspaces = AccountWorkspaces(acc) | ||
assert len(account_workspaces.get_accessible_workspaces()) == 1 |