Skip to content

Commit 0352b19

Browse files
committed
Addressed Integration Tests Issues
1 parent 92e857d commit 0352b19

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

src/databricks/labs/ucx/contexts/application.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def static_table_ownership(self) -> StaticTableOwnership:
284284
self.administrator_locator,
285285
self.tables_crawler,
286286
self.config.default_owner_group,
287-
self.connect_config.username,
287+
self.workspace_client.current_user.me().user_name,
288288
)
289289

290290
@cached_property

src/databricks/labs/ucx/hive_metastore/ownership.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,16 @@ def __init__(
106106
super().__init__(administrator_locator)
107107

108108
def load(self) -> Iterable[Grant]:
109+
databases = set()
110+
owner = self._static_owner()
111+
if not owner:
112+
logger.warning("No owner found for tables and databases")
113+
return
109114
for table in self._tables_crawler.snapshot():
110-
owner = self._maybe_direct_owner(table)
111115
table_name, view_name = self._names(table)
112-
if not owner:
113-
logger.warning(f"No owner found for {table.key}")
114-
continue
116+
117+
if table.database not in databases:
118+
databases.add(table.database)
115119
yield Grant(
116120
principal=owner,
117121
action_type='OWN',
@@ -120,18 +124,30 @@ def load(self) -> Iterable[Grant]:
120124
table=table_name,
121125
view=view_name,
122126
)
127+
for database in databases:
128+
yield Grant(
129+
principal=owner,
130+
action_type='OWN',
131+
catalog="hive_metastore",
132+
database=database,
133+
table=None,
134+
view=None,
135+
)
123136

124137
@staticmethod
125138
def _names(table: Table) -> tuple[str | None, str | None]:
126139
if table.view_text:
127140
return None, table.name
128141
return table.name, None
129142

130-
def _maybe_direct_owner(self, record: Table) -> str | None:
143+
def _static_owner(self) -> str | None:
131144
if self._fixed_owner_group:
132145
return self._fixed_owner_group
133146
return self._application_principal
134147

148+
def _maybe_direct_owner(self, record: Table) -> str | None:
149+
return self._static_owner()
150+
135151

136152
class TableOwnershipGrantLoader:
137153
def __init__(self, tables_crawler: TablesCrawler, table_ownership: Ownership[Table]) -> None:

tests/integration/hive_metastore/test_catalog_schema.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ def test_create_catalog_schema_with_legacy_hive_metastore_privileges(
170170
def get_schema_permissions_list(full_name: str) -> PermissionsList:
171171
return ws.grants.get(SecurableType.SCHEMA, full_name)
172172

173-
assert ws.schemas.get(f"{dst_catalog_name}.{dst_schema_name}").owner == schema_owner.user_name
173+
assert (ws.schemas.get(f"{dst_catalog_name}.{dst_schema_name}").owner ==
174+
runtime_ctx.workspace_client.current_user.me().user_name)
174175
schema_grants = get_schema_permissions_list(f"{dst_catalog_name}.{dst_schema_name}")
175176
assert schema_grants.privilege_assignments is not None
176177
assert PrivilegeAssignment(table_owner.user_name, [Privilege.USE_SCHEMA]) in schema_grants.privilege_assignments

0 commit comments

Comments
 (0)