Skip to content

Commit bfc1a61

Browse files
authored
Fixing the issue in workspace id flag in create-account-group command (#1094)
1 parent fce42a4 commit bfc1a61

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/databricks/labs/ucx/cli.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def sync_workspace_info(a: AccountClient):
102102

103103
@ucx.command(is_account=True)
104104
def create_account_groups(
105-
a: AccountClient, prompts: Prompts, workspace_ids: list[int] | None = None, new_workspace_client=WorkspaceClient
105+
a: AccountClient, prompts: Prompts, workspace_ids: str | None = None, new_workspace_client=WorkspaceClient
106106
):
107107
"""
108108
Crawl all workspaces configured in workspace_ids, then creates account level groups if a WS local group is not present
@@ -115,9 +115,14 @@ def create_account_groups(
115115
- Exist in workspaces A,B,C. It has same members in A,B, but not in C. Then, X and C_X will be created in the
116116
account
117117
"""
118+
118119
logger.info(f"Account ID: {a.config.account_id}")
120+
if workspace_ids is not None:
121+
workspace_id_list = [int(x.strip()) for x in workspace_ids.split(",")]
122+
else:
123+
workspace_id_list = None
119124
workspaces = AccountWorkspaces(a, new_workspace_client)
120-
workspaces.create_account_level_groups(prompts, workspace_ids)
125+
workspaces.create_account_level_groups(prompts, workspace_id_list)
121126

122127

123128
@ucx.command

tests/unit/test_cli.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ def test_create_account_groups():
153153
a.groups.list.assert_called_with(attributes="id")
154154

155155

156+
def test_create_account_groups_with_id():
157+
a = create_autospec(AccountClient)
158+
w = create_autospec(WorkspaceClient)
159+
a.get_workspace_client.return_value = w
160+
w.get_workspace_id.return_value = None
161+
prompts = MockPrompts({})
162+
with pytest.raises(ValueError, match="No workspace ids provided in the configuration found in the account"):
163+
create_account_groups(a, prompts, workspace_ids="123,456", new_workspace_client=lambda: w)
164+
165+
156166
def test_manual_workspace_info(ws):
157167
prompts = MockPrompts({'Workspace name for 123': 'abc', 'Next workspace id': ''})
158168
manual_workspace_info(ws, prompts)

0 commit comments

Comments
 (0)