Skip to content

Commit 784ba01

Browse files
Fixing groups in config file not considered for group migration job (#943)
1 parent f951aac commit 784ba01

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/databricks/labs/ucx/workspace_access/groups.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,24 @@ def delete_original_workspace_groups(self):
394394
raise ManyError(errors)
395395

396396
def _fetcher(self) -> Iterable[MigratedGroup]:
397+
state = []
397398
for row in self._backend.fetch(f"SELECT * FROM {self._full_name}"):
398-
yield MigratedGroup(*row)
399+
state.append(MigratedGroup(*row))
400+
401+
if not self._include_group_names:
402+
return state
403+
404+
new_state = []
405+
group_name_with_state = {migrated_group.name_in_workspace: migrated_group for migrated_group in state}
406+
for group_name in self._include_group_names:
407+
if group_name in group_name_with_state:
408+
new_state.append(group_name_with_state[group_name])
409+
else:
410+
logger.warning(
411+
f"Group {group_name} defined in configuration does not exist on the groups table. "
412+
"Consider checking if the group exist in the workspace or re-running the assessment."
413+
)
414+
return new_state
399415

400416
def _crawler(self) -> Iterable[MigratedGroup]:
401417
workspace_groups_in_workspace = self._workspace_groups_in_workspace()

tests/unit/workspace_access/test_groups.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,3 +1031,32 @@ def do_api_side_effect(*args, **kwargs):
10311031
backend, wsclient, inventory_database="inv", workspace_group_regex=r"\(([1-9]+)\)", account_group_regex="[1-9]+"
10321032
).validate_group_membership()
10331033
assert grp_membership == []
1034+
1035+
1036+
def test_migration_state_with_filtered_group():
1037+
backend = MockBackend(
1038+
rows={
1039+
"SELECT": [
1040+
("", "de", "de", "test-group-de", "", "", "", ""),
1041+
("", "ds", "ds", "test-group-ds", "", "", "", ""),
1042+
]
1043+
}
1044+
)
1045+
wsclient = MagicMock()
1046+
grp_membership = GroupManager(
1047+
backend, wsclient, inventory_database="inv", include_group_names=["ds", "irrelevant_group"]
1048+
).get_migration_state()
1049+
1050+
assert len(grp_membership.groups) == 1
1051+
assert grp_membership.groups == [
1052+
MigratedGroup(
1053+
id_in_workspace='',
1054+
name_in_workspace='ds',
1055+
name_in_account='ds',
1056+
temporary_name='test-group-ds',
1057+
members='',
1058+
entitlements='',
1059+
external_id='',
1060+
roles='',
1061+
)
1062+
]

0 commit comments

Comments
 (0)