Skip to content

Commit 3fe4174

Browse files
larsgeorge-dbnfx
andauthored
Replace warehouse fixture with the new one (#170)
Co-authored-by: Serge Smertin <[email protected]> Co-authored-by: Serge Smertin <[email protected]>
1 parent 76319a4 commit 3fe4174

File tree

3 files changed

+43
-42
lines changed

3 files changed

+43
-42
lines changed

src/databricks/labs/ucx/providers/mixins/fixtures.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from databricks.sdk import AccountClient, WorkspaceClient
1212
from databricks.sdk.core import DatabricksError
1313
from databricks.sdk.service import compute, iam, jobs, pipelines, workspace
14+
from databricks.sdk.service.sql import CreateWarehouseRequestWarehouseType
1415

1516
_LOG = logging.getLogger(__name__)
1617

@@ -473,6 +474,36 @@ def create(**kwargs) -> pipelines.CreatePipelineResponse:
473474
yield from factory("delta live table", create, lambda item: ws.pipelines.delete(item.pipeline_id))
474475

475476

477+
@pytest.fixture
478+
def make_warehouse(ws, make_random):
479+
def create(
480+
*,
481+
warehouse_name: str | None = None,
482+
warehouse_type: CreateWarehouseRequestWarehouseType | None = None,
483+
cluster_size: str | None = None,
484+
max_num_clusters: int = 1,
485+
enable_serverless_compute: bool = False,
486+
**kwargs,
487+
):
488+
if warehouse_name is None:
489+
warehouse_name = f"sdk-{make_random(4)}"
490+
if warehouse_type is None:
491+
warehouse_type = CreateWarehouseRequestWarehouseType.PRO
492+
if cluster_size is None:
493+
cluster_size = "2X-Small"
494+
495+
return ws.warehouses.create(
496+
name=warehouse_name,
497+
cluster_size=cluster_size,
498+
warehouse_type=warehouse_type,
499+
max_num_clusters=max_num_clusters,
500+
enable_serverless_compute=enable_serverless_compute,
501+
**kwargs,
502+
)
503+
504+
yield from factory("warehouse", create, lambda item: ws.warehouses.delete(item.id))
505+
506+
476507
def load_debug_env_if_runs_from_ide(key) -> bool:
477508
if not _is_in_debug():
478509
return False

tests/integration/conftest.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
from databricks.sdk.service.iam import AccessControlRequest, PermissionLevel
1414
from databricks.sdk.service.ml import CreateExperimentResponse, ModelDatabricks
1515
from databricks.sdk.service.ml import PermissionLevel as ModelPermissionLevel
16-
from databricks.sdk.service.sql import (
17-
CreateWarehouseRequestWarehouseType,
18-
GetWarehouseResponse,
19-
)
2016
from databricks.sdk.service.workspace import ObjectInfo, ObjectType
2117

2218
from databricks.labs.ucx.config import InventoryTable
@@ -42,7 +38,6 @@
4238
NUM_TEST_CLUSTER_POLICIES = int(os.environ.get("NUM_TEST_CLUSTER_POLICIES", 3))
4339
NUM_TEST_EXPERIMENTS = int(os.environ.get("NUM_TEST_EXPERIMENTS", 3))
4440
NUM_TEST_MODELS = int(os.environ.get("NUM_TEST_MODELS", 3))
45-
NUM_TEST_WAREHOUSES = int(os.environ.get("NUM_TEST_WAREHOUSES", 3))
4641
NUM_TEST_TOKENS = int(os.environ.get("NUM_TEST_TOKENS", 3))
4742

4843
NUM_THREADS = int(os.environ.get("NUM_TEST_THREADS", 20))
@@ -352,41 +347,6 @@ def models(ws: WorkspaceClient, env: EnvironmentInfo) -> list[ModelDatabricks]:
352347
logger.debug("Test models deleted")
353348

354349

355-
@pytest.fixture
356-
def warehouses(ws: WorkspaceClient, env: EnvironmentInfo) -> list[GetWarehouseResponse]:
357-
logger.debug("Creating warehouses")
358-
359-
creators = [
360-
partial(
361-
ws.warehouses.create,
362-
name=f"{env.test_uid}-test-{i}",
363-
cluster_size="2X-Small",
364-
warehouse_type=CreateWarehouseRequestWarehouseType.PRO,
365-
max_num_clusters=1,
366-
enable_serverless_compute=False,
367-
)
368-
for i in range(NUM_TEST_WAREHOUSES)
369-
]
370-
371-
test_warehouses: list[GetWarehouseResponse] = Threader(creators).run()
372-
373-
_set_random_permissions(
374-
test_warehouses,
375-
"id",
376-
RequestObjectType.SQL_WAREHOUSES,
377-
env,
378-
ws,
379-
permission_levels=[PermissionLevel.CAN_USE, PermissionLevel.CAN_MANAGE],
380-
)
381-
382-
yield test_warehouses
383-
384-
logger.debug("Deleting test warehouses")
385-
executables = [partial(ws.warehouses.delete, w.id) for w in test_warehouses]
386-
Threader(executables).run()
387-
logger.debug("Test warehouses deleted")
388-
389-
390350
@pytest.fixture
391351
def tokens(ws: WorkspaceClient, env: EnvironmentInfo) -> list[AccessControlRequest]:
392352
logger.debug("Adding token-level permissions to groups")
@@ -465,7 +425,6 @@ def verifiable_objects(
465425
cluster_policies,
466426
experiments,
467427
models,
468-
warehouses,
469428
tokens,
470429
workspace_objects,
471430
) -> list[tuple[list, str, RequestObjectType | None]]:
@@ -475,7 +434,6 @@ def verifiable_objects(
475434
(cluster_policies, "policy_id", RequestObjectType.CLUSTER_POLICIES),
476435
(experiments, "experiment_id", RequestObjectType.EXPERIMENTS),
477436
(models, "id", RequestObjectType.REGISTERED_MODELS),
478-
(warehouses, "id", RequestObjectType.SQL_WAREHOUSES),
479437
]
480438
yield _verifiable_objects
481439

tests/integration/test_e2e.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ def test_e2e(
140140
make_pipeline_permissions,
141141
make_secret_scope,
142142
make_secret_scope_acl,
143+
make_warehouse,
144+
make_warehouse_permissions,
143145
):
144146
logger.debug(f"Test environment: {env.test_uid}")
145147
ws_group = env.groups[0][0]
@@ -190,6 +192,16 @@ def test_e2e(
190192
make_secret_scope_acl(scope=scope, principal=ws_group.display_name, permission=workspace.AclPermission.WRITE)
191193
verifiable_objects.append(([scope], "secret_scopes", None))
192194

195+
warehouse = make_warehouse()
196+
make_warehouse_permissions(
197+
object_id=warehouse.id,
198+
permission_level=random.choice([PermissionLevel.CAN_USE, PermissionLevel.CAN_MANAGE]),
199+
group_name=ws_group.display_name,
200+
)
201+
verifiable_objects.append(
202+
([warehouse], "id", RequestObjectType.SQL_WAREHOUSES),
203+
)
204+
193205
config = MigrationConfig(
194206
connect=ConnectConfig.from_databricks_config(ws.config),
195207
inventory=InventoryConfig(table=inventory_table),

0 commit comments

Comments
 (0)