-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a command to create account level groups if they do not exist (#763)
Attempt to fix - #17 - #649 Adds a command to create groups at account level by crawling all workspaces configured in the account and in scope of the migration This pull request adds several new methods to the `account.py` file in the `databricks/labs/ucx` directory. The main method added is `create_account_level_groups`, which crawls all workspaces in an account and creates account-level groups if a workspace-local group is not present in the account. The method `get_valid_workspaces_groups` is added to retrieve a dictionary of all valid workspace groups, while `has_not_same_members` checks if two groups have the same members. The method `get_account_groups` retrieves a dictionary of all account groups. Regarding the tests, the `test_account.py` file has been updated to include new tests for the `create_account_level_groups` method. The test `test_create_acc_groups_should_create_acc_group_if_no_group_found` verifies that an account-level group is created if no group with the same name is found. The test `test_create_acc_groups_should_filter_groups_in_other_workspaces` checks that the method filters groups present in other workspaces and only creates groups that are not present in the account. Additionally, the `cli.py` file has been updated to include a new command, `create_account_level_groups`, which uploads workspace config to all workspaces in the account where ucx is installed.
- Loading branch information
1 parent
76bdff9
commit f4efea5
Showing
7 changed files
with
627 additions
and
10 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from databricks.labs.blueprint.tui import MockPrompts | ||
from databricks.sdk import AccountClient | ||
from databricks.sdk.errors import NotFound | ||
|
||
from databricks.labs.ucx.account import AccountWorkspaces | ||
|
||
|
||
def test_create_account_level_groups(make_ucx_group, make_group, make_user, acc, ws, make_random): | ||
suffix = make_random() | ||
make_ucx_group(f"test_ucx_migrate_invalid_{suffix}", f"test_ucx_migrate_invalid_{suffix}") | ||
|
||
make_group(display_name=f"regular_group_{suffix}", members=[make_user().id]) | ||
AccountWorkspaces(acc).create_account_level_groups(MockPrompts({}), [ws.get_workspace_id()]) | ||
|
||
results = [] | ||
for grp in acc.groups.list(): | ||
if grp.display_name in {f"regular_group_{suffix}"}: | ||
results.append(grp) | ||
try_delete_group(acc, grp.id) # Avoids flakiness for future runs | ||
|
||
assert len(results) == 1 | ||
|
||
|
||
def try_delete_group(acc: AccountClient, grp_id: str): | ||
try: | ||
acc.groups.delete(grp_id) | ||
except NotFound: | ||
pass |
Oops, something went wrong.