Skip to content

Commit 035320c

Browse files
Skip group migration when no groups are available after preparation step. (#363)
Fixes #360
1 parent 2b88750 commit 035320c

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

src/databricks/labs/ucx/runtime.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,12 @@ def migrate_permissions(cfg: WorkspaceConfig):
190190
See [interactive tutorial here](https://app.getreprise.com/launch/myM3VNn/)."""
191191
toolkit = GroupMigrationToolkit(cfg)
192192
toolkit.prepare_environment()
193-
toolkit.apply_permissions_to_backup_groups()
194-
toolkit.replace_workspace_groups_with_account_groups()
195-
toolkit.apply_permissions_to_account_groups()
193+
if toolkit.has_groups():
194+
toolkit.apply_permissions_to_backup_groups()
195+
toolkit.replace_workspace_groups_with_account_groups()
196+
toolkit.apply_permissions_to_account_groups()
197+
else:
198+
logger.info("Skipping group migration as no groups were found.")
196199

197200

198201
@task("migrate-groups-cleanup", depends_on=[migrate_permissions])

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ def prepare_groups_in_environment(self):
181181
self._set_migration_groups(group_names)
182182
logger.info("Environment prepared successfully")
183183

184+
def has_groups(self) -> bool:
185+
return len(self._migration_state.groups) > 0
186+
184187
@property
185188
def migration_groups_provider(self) -> GroupMigrationState:
186189
assert len(self._migration_state.groups) > 0, "Migration groups were not loaded or initialized"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ def _configure_logger(level: str):
114114
ucx_logger = logging.getLogger("databricks.labs.ucx")
115115
ucx_logger.setLevel(level)
116116

117+
def has_groups(self) -> bool:
118+
return self._group_manager.has_groups()
119+
117120
def prepare_environment(self):
118121
self._group_manager.prepare_groups_in_environment()
119122

tests/unit/workspace_access/test_groups.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,19 @@ def test_prepare_groups_in_environment_with_conf_in_auto_mode_should_populate_mi
286286
assert manager._migration_state.groups == [group_info]
287287

288288

289+
def test_prepare_groups_in_environment_with_no_groups():
290+
client = Mock()
291+
client.groups.list.return_value = iter([])
292+
client.api_client.do.return_value = {
293+
"Resources": [],
294+
}
295+
296+
group_conf = GroupsConfig(auto=True)
297+
manager = GroupManager(client, group_conf)
298+
manager.prepare_groups_in_environment()
299+
assert not manager.has_groups()
300+
301+
289302
def test_replace_workspace_groups_with_account_groups_should_call_delete_and_do():
290303
client = Mock()
291304

0 commit comments

Comments
 (0)