diff --git a/src/databricks/labs/ucx/providers/groups_info.py b/src/databricks/labs/ucx/providers/groups_info.py index 9c1e54cc46..5f3dbb048f 100644 --- a/src/databricks/labs/ucx/providers/groups_info.py +++ b/src/databricks/labs/ucx/providers/groups_info.py @@ -19,6 +19,12 @@ def __init__(self): def add(self, group: MigrationGroupInfo): self.groups.append(group) + def is_in_scope(self, attr: str, group: Group) -> bool: + for info in self.groups: + if getattr(info, attr).id == group.id: + return True + return False + def get_by_workspace_group_name(self, workspace_group_name: str) -> MigrationGroupInfo | None: found = [g for g in self.groups if g.workspace.display_name == workspace_group_name] if len(found) == 0: diff --git a/tests/integration/test_e2e.py b/tests/integration/test_e2e.py index 459a24a104..997e83687e 100644 --- a/tests/integration/test_e2e.py +++ b/tests/integration/test_e2e.py @@ -181,7 +181,8 @@ def test_e2e( toolkit = GroupMigrationToolkit(config) toolkit.prepare_environment() - for _info in toolkit.group_manager.migration_groups_provider.groups: + group_migration_state = toolkit.group_manager.migration_groups_provider + for _info in group_migration_state.groups: _ws = ws.groups.get(id=_info.workspace.id) _backup = ws.groups.get(id=_info.backup.id) _ws_members = sorted([m.value for m in _ws.members]) @@ -202,12 +203,12 @@ def test_e2e( for _objects, id_attribute, request_object_type in verifiable_objects: _verify_group_permissions(_objects, id_attribute, request_object_type, ws, toolkit, "backup") - _verify_roles_and_entitlements(toolkit.group_manager.migration_groups_provider, ws, "backup") + _verify_roles_and_entitlements(group_migration_state, ws, "backup") toolkit.replace_workspace_groups_with_account_groups() - new_groups = list(ws.groups.list(filter=f"displayName sw '{env.test_uid}'", attributes="displayName,meta")) - assert len(new_groups) == len(toolkit.group_manager.migration_groups_provider.groups) + new_groups = [_ for _ in ws.groups.list(attributes="displayName,meta") if group_migration_state.is_in_scope('account', _)] + assert len(new_groups) == len(group_migration_state.groups) assert all(g.meta.resource_type == "Group" for g in new_groups) toolkit.apply_permissions_to_account_groups() @@ -215,15 +216,11 @@ def test_e2e( for _objects, id_attribute, request_object_type in verifiable_objects: _verify_group_permissions(_objects, id_attribute, request_object_type, ws, toolkit, "account") - _verify_roles_and_entitlements(toolkit.group_manager.migration_groups_provider, ws, "account") + _verify_roles_and_entitlements(group_migration_state, ws, "account") toolkit.delete_backup_groups() - backup_groups = list( - ws.groups.list( - filter=f"displayName sw '{config.groups.backup_group_prefix}{env.test_uid}'", attributes="displayName,meta" - ) - ) + backup_groups = [_ for _ in ws.groups.list(attributes="displayName,meta") if group_migration_state.is_in_scope('backup', _)] assert len(backup_groups) == 0 toolkit.cleanup_inventory_table()