Skip to content

Commit 5ee7fc3

Browse files
authored
Fix integration test: test_running_real_assessment_job_ext_hms (#3421)
## Changes This PR updates the `test_running_real_assessment_job_ext_hms` integration test: - It ensures that the workflow runs on a cluster with an external HMS, instead of faking it. (The previous method was insufficient once we switched to the fast table crawler and the Python4J bridge became needed.) - Update the test fixture so that the resources it creates to be crawled are created in the external HMS, not the main one. Without this the assessment crawlers partially fail because the resources they are configured to crawl do not exist on the external HMS. ### Linked issues Resolves #3134. Resolves #3246. ### Tests - updated integration test
1 parent c1cb7a5 commit 5ee7fc3

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

tests/integration/assessment/test_ext_hms.py

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
import dataclasses
22

3-
from databricks.labs.lsql.backends import CommandExecutionBackend
3+
import pytest
4+
5+
from databricks.labs.lsql.backends import CommandExecutionBackend, SqlBackend
6+
from databricks.sdk.service.compute import CreatePolicyResponse
47
from databricks.sdk.service.iam import PermissionLevel
58

69

7-
def test_running_real_assessment_job_ext_hms(
8-
ws,
9-
installation_ctx,
10-
env_or_skip,
11-
make_cluster_policy,
12-
make_cluster_policy_permissions,
13-
) -> None:
14-
cluster_id = env_or_skip('TEST_EXT_HMS_CLUSTER_ID')
15-
ws_group, _ = installation_ctx.make_ucx_group(wait_for_provisioning=True)
16-
# TODO: Move `make_cluster_policy` and `make_cluster_policy_permissions` to context like other `make_` methods
17-
cluster_policy = make_cluster_policy()
18-
make_cluster_policy_permissions(
19-
object_id=cluster_policy.policy_id,
20-
permission_level=PermissionLevel.CAN_USE,
21-
group_name=ws_group.display_name,
22-
)
10+
@pytest.fixture
11+
def sql_backend(ws, env_or_skip) -> SqlBackend:
12+
"""Ensure the SQL backend used during fixture setup is attached to the external HMS.
13+
14+
Various resources are created during setup of the installation context: this ensures that
15+
they are created in the external HMS where the assessment workflow will be run. (Otherwise they will not be found.)
16+
"""
17+
cluster_id = env_or_skip("TEST_EXT_HMS_CLUSTER_ID")
18+
return CommandExecutionBackend(ws, cluster_id)
19+
20+
21+
def test_running_real_assessment_job_ext_hms(installation_ctx, env_or_skip) -> None:
22+
main_cluster_id = env_or_skip("TEST_EXT_HMS_NOUC_CLUSTER_ID")
2323
ext_hms_ctx = installation_ctx.replace(
24-
sql_backend=CommandExecutionBackend(ws, cluster_id),
2524
config_transform=lambda wc: dataclasses.replace(
2625
wc,
27-
override_clusters=None,
26+
override_clusters={
27+
"main": main_cluster_id,
28+
},
2829
include_object_permissions=[f"cluster-policies:{cluster_policy.policy_id}"],
2930
),
3031
extend_prompts={
@@ -34,14 +35,23 @@ def test_running_real_assessment_job_ext_hms(
3435
r"Choose a cluster policy": "0",
3536
},
3637
)
38+
del installation_ctx # Use ext_hms_ctx from now on instead of installation_ctx to ensure the external HMS is used.
39+
ws_group, _ = ext_hms_ctx.make_ucx_group(wait_for_provisioning=True)
40+
cluster_policy: CreatePolicyResponse = ext_hms_ctx.make_cluster_policy()
41+
ext_hms_ctx.make_cluster_policy_permissions(
42+
object_id=cluster_policy.policy_id,
43+
permission_level=PermissionLevel.CAN_USE,
44+
group_name=ws_group.display_name,
45+
)
3746
ext_hms_ctx.make_linting_resources()
3847
source_schema = ext_hms_ctx.make_schema(catalog_name="hive_metastore")
3948
ext_hms_ctx.make_table(schema_name=source_schema.name)
4049
ext_hms_ctx.workspace_installation.run()
4150

4251
workflow = "assessment"
43-
ext_hms_ctx.deployed_workflows.run_workflow(workflow)
44-
assert ext_hms_ctx.deployed_workflows.validate_step(workflow), f"Workflow failed: {workflow}"
52+
ext_hms_ctx.deployed_workflows.run_workflow(workflow, skip_job_wait=True)
53+
workflow_completed_successfully = ext_hms_ctx.deployed_workflows.validate_step(workflow)
54+
assert workflow_completed_successfully, f"Workflow failed: {workflow}"
4555

4656
after = ext_hms_ctx.generic_permissions_support.load_as_dict("cluster-policies", cluster_policy.policy_id)
4757
assert ws_group.display_name in after, f"Group {ws_group.display_name} not found in cluster policy"

tests/integration/hive_metastore/test_ext_hms.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313

1414
@pytest.fixture
1515
def sql_backend(ws, env_or_skip) -> SqlBackend:
16+
"""Ensure the SQL backend used during fixture setup is attached to the external HMS.
17+
18+
Various resources are created during setup of the installation context: this ensures that
19+
they are created in the external HMS where the assessment workflow will be run. (Otherwise they will not be found.)
20+
"""
1621
cluster_id = env_or_skip("TEST_EXT_HMS_CLUSTER_ID")
1722
return CommandExecutionBackend(ws, cluster_id)
1823

0 commit comments

Comments
 (0)