Skip to content

Commit 4162cc6

Browse files
authored
Handle exception in create-missing-principals because there are no UC roles (#4373)
## Changes Handle exception in `create-missing-principals` because there are no UC roles, exit gracefully with an informative message instead of failing. ### Linked issues Resolves #4372
1 parent d39e426 commit 4162cc6

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/databricks/labs/ucx/aws/access.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from databricks.labs.blueprint.parallel import Threads
1010
from databricks.labs.blueprint.tui import Prompts
1111
from databricks.sdk import WorkspaceClient
12-
from databricks.sdk.errors import NotFound, ResourceDoesNotExist, PermissionDenied
12+
from databricks.sdk.errors import NotFound, PermissionDenied
1313
from databricks.sdk.service.catalog import Privilege
1414
from databricks.sdk.service.compute import Policy
1515
from databricks.sdk.service.sql import SetWorkspaceWarehouseConfigRequestSecurityPolicy
@@ -155,7 +155,7 @@ def save_uc_compatible_roles(self):
155155
def load_uc_compatible_roles(self, *, resource_type: AWSResourceType | None = None) -> list[AWSRoleAction]:
156156
try:
157157
role_actions = self._installation.load(list[AWSRoleAction], filename=self.UC_ROLES_FILE_NAME)
158-
except ResourceDoesNotExist:
158+
except NotFound:
159159
self.save_uc_compatible_roles()
160160
role_actions = self._installation.load(list[AWSRoleAction], filename=self.UC_ROLES_FILE_NAME)
161161
if resource_type:
@@ -236,7 +236,11 @@ def _get_role_access_task(self, arn: str, role_name: str):
236236

237237
def _identify_missing_paths(self):
238238
external_locations = self._locations.external_locations_with_root()
239-
compatible_roles = self.load_uc_compatible_roles()
239+
try:
240+
compatible_roles = self.load_uc_compatible_roles()
241+
except NotFound:
242+
logger.warning(f"{self.UC_ROLES_FILE_NAME} not found.")
243+
compatible_roles = []
240244
missing_paths = set()
241245
for external_location in external_locations:
242246
matching_role = False

tests/unit/aws/test_access.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def installation_multiple_roles():
132132

133133
@pytest.fixture
134134
def installation_no_roles():
135-
return MockInstallation(DEFAULT_CONFIG | {"uc_roles_access.csv": []})
135+
return MockInstallation(DEFAULT_CONFIG | {})
136136

137137

138138
@pytest.fixture

0 commit comments

Comments
 (0)