Skip to content

Commit ff85929

Browse files
denikIsaac
andauthored
acc: add invariant/auto-migrate test (databricks#6806)
## Changes Add an invariant target that deploys on terraform, then deploys on the direct default (which auto-migrates the state), then asserts no drift — across every resource config. Mirrors `invariant/migrate` but exercises the deploy-triggered auto path rather than the explicit `bundle deployment migrate` command. ## Why Prep for databricks#6749 (move terraform→direct state migration before deploy): landing the auto-migration drift coverage first, off main, so that PR stays focused on the behavior change. This pull request and its description were written by Isaac. --------- Co-authored-by: Isaac <no-reply@databricks.com>
1 parent f2b05e9 commit ff85929

5 files changed

Lines changed: 136 additions & 4 deletions

File tree

‎acceptance/bundle/invariant/auto-migrate/out.test.toml‎

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
INPUT_CONFIG_OK
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Invariant to test: auto-migration on deploy is successful, no drift after deploy
2+
# Additional checks: no internal errors / panics in any commands
3+
4+
unset DATABRICKS_BUNDLE_ENGINE
5+
6+
invariant_setup
7+
8+
invariant_deploy LOG.deploy DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy
9+
10+
# Deploy on the direct default (engine unset): this migrates the terraform state to the
11+
# direct engine before deploying, exercising the auto path. Not invariant_deploy -- the
12+
# config was already validated by the terraform deploy above, so a failure here is a bug,
13+
# not an invalid config (and it must not re-emit the INPUT_CONFIG_OK marker).
14+
trace $CLI bundle deploy &> LOG.migrate
15+
cat LOG.migrate | contains.py '!panic:' '!internal error' > /dev/null
16+
17+
invariant_verify_no_drift
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Recording needs a bundle it has seen from the start. This test seeds a state file,
2+
# so recording refuses it. TODO(DMS): drop this once existing state can be
3+
# handed over to the service (see the TODO in dstate.Open).
4+
EnvMatrix.DMS = [""]
5+
6+
# schema.yml sets custom_max_retention_hours, which the terraform databricks_schema resource cannot
7+
# set (only direct does), so a terraform-first migrate would drift. schema_tf_compat.yml keeps migrate
8+
# coverage for schemas.
9+
EnvMatrixExclude.no_schema_custom_retention = ["INPUT_CONFIG=schema.yml.tmpl"]
10+
11+
# vector_search_endpoints and vector_search_indexes have no terraform converter
12+
EnvMatrixExclude.no_vector_search_endpoint = ["INPUT_CONFIG=vector_search_endpoint.yml.tmpl"]
13+
EnvMatrixExclude.no_vector_search_index = ["INPUT_CONFIG=vector_search_index.yml.tmpl"]
14+
15+
# job_runs is a direct-only resource with no terraform converter, so the
16+
# terraform deploy that seeds the migration fails for it.
17+
EnvMatrixExclude.no_job_run = ["INPUT_CONFIG=job_run.yml.tmpl"]
18+
19+
# Error: Catalog resources are only supported with direct deployment mode
20+
EnvMatrixExclude.no_catalog = ["INPUT_CONFIG=catalog.yml.tmpl"]
21+
EnvMatrixExclude.no_catalog_optional_fields = ["INPUT_CONFIG=catalog_optional_fields.yml.tmpl"]
22+
EnvMatrixExclude.no_external_location = ["INPUT_CONFIG=external_location.yml.tmpl"]
23+
# uc_trailing_slash includes a catalog, which is direct-only (see above).
24+
EnvMatrixExclude.no_uc_trailing_slash = ["INPUT_CONFIG=uc_trailing_slash.yml.tmpl"]
25+
# Genie spaces are direct-only too; the terraform deploy that seeds the migration fails for them.
26+
EnvMatrixExclude.no_genie_space = ["INPUT_CONFIG=genie_space.yml.tmpl"]
27+
# Instance pools are direct-only; the terraform deploy that seeds the migration fails for them.
28+
EnvMatrixExclude.no_instance_pool = ["INPUT_CONFIG=instance_pool.yml.tmpl"]
29+
# Cluster policies are direct-only; the terraform deploy that seeds the migration fails for them.
30+
EnvMatrixExclude.no_cluster_policy = ["INPUT_CONFIG=cluster_policy.yml.tmpl"]
31+
# Cluster libraries are direct-only; the terraform deploy that seeds the migration fails for them.
32+
EnvMatrixExclude.no_cluster_libraries = ["INPUT_CONFIG=cluster_libraries.yml.tmpl"]
33+
# AI Gateway securables are direct-only; the terraform deploy that seeds the migration fails for them.
34+
EnvMatrixExclude.no_model_service = ["INPUT_CONFIG=model_service.yml.tmpl"]
35+
36+
# Cross-resource permission references (e.g. ${resources.jobs.job_b.permissions[0].level})
37+
# don't work in terraform mode: the terraform interpolator converts the path to
38+
# ${databricks_job.job_b.permissions[0].level}, but Terraform's databricks_job resource
39+
# does not expose permissions as output attributes (permissions are a separate
40+
# databricks_permissions resource in terraform), so the literal unresolved string
41+
# ends up as the permission level value.
42+
EnvMatrixExclude.no_permission_ref = ["INPUT_CONFIG=job_permission_ref.yml.tmpl"]
43+
EnvMatrixExclude.no_cross_resource_ref = ["INPUT_CONFIG=job_cross_resource_ref.yml.tmpl"]
44+
45+
# Grant cross-references require the EmbeddedSlice pattern not present in terraform mode.
46+
EnvMatrixExclude.no_grant_ref = ["INPUT_CONFIG=schema_grant_ref.yml.tmpl"]
47+
48+
# SQL warehouses currently failing with migration with permanent drift. TODO: fix this.
49+
EnvMatrixExclude.no_sql_warehouse = ["INPUT_CONFIG=sql_warehouse.yml.tmpl"]
50+
51+
# The 1000-task scale case is covered by no_drift. Running it here adds ~1.5 min
52+
# per variant (deploy + migrate + plan at 1000 tasks) without incremental coverage.
53+
EnvMatrixExclude.no_pydabs_1000_tasks = ["INPUT_CONFIG=job_pydabs_1000_tasks.yml.tmpl"]
54+
55+
# migrate deploys via Terraform first, and the TF provider rejects an uppercase
56+
# volume schema_name ("inconsistent final plan"). Covered by no_drift on direct.
57+
EnvMatrixExclude.no_volume_uppercase = ["INPUT_CONFIG=volume_uppercase_name.yml.tmpl"]
58+
59+
# UC secrets are direct-only (no terraform converter), so the terraform deploy that seeds
60+
# the migration fails for them.
61+
EnvMatrixExclude.no_secret = ["INPUT_CONFIG=secret.yml.tmpl"]
62+
63+
# Terraform types sampling_fraction as an integer and truncates 0.5; covered by no_drift.
64+
EnvMatrixExclude.no_model_serving_endpoint_telemetry = ["INPUT_CONFIG=model_serving_endpoint_telemetry.yml.tmpl"]

‎acceptance/selftest/selection/output.txt‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ Selected 2 changed tests (limit=50, 0 not selected)
2828
=== Touching an invariant config runs every invariant test, for that config only
2929

3030
>>> selection M:acceptance/bundle/invariant/configs/job.yml.tmpl
31-
Selected 5 changed tests (limit=50, 0 not selected)
31+
Selected 6 changed tests (limit=50, 0 not selected)
32+
5 ^bundle$/^invariant$/^auto-migrate$/^DATABRICKS_BUNDLE_ENGINE=direct$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$
3233
5 ^bundle$/^invariant$/^continue_293$/^DATABRICKS_BUNDLE_ENGINE=direct$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$
3334
5 ^bundle$/^invariant$/^delete_idempotent$/^DATABRICKS_BUNDLE_ENGINE=direct$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$
3435
5 ^bundle$/^invariant$/^destroy_idempotent$/^DATABRICKS_BUNDLE_ENGINE=direct$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$
@@ -39,13 +40,15 @@ Selected 5 changed tests (limit=50, 0 not selected)
3940
=== Adding one invariant config and touching another: only the new variant is new
4041

4142
>>> selection A:acceptance/bundle/invariant/configs/pipeline.yml.tmpl M:acceptance/bundle/invariant/configs/job.yml.tmpl
42-
Selected 10 changed tests (limit=50, 0 not selected)
43+
Selected 12 changed tests (limit=50, 0 not selected)
44+
10 ^bundle$/^invariant$/^auto-migrate$/^DATABRICKS_BUNDLE_ENGINE=direct$/^DMS=$/^INPUT_CONFIG=pipeline\.yml\.tmpl$
4345
10 ^bundle$/^invariant$/^continue_293$/^DATABRICKS_BUNDLE_ENGINE=direct$/^DMS=$/^INPUT_CONFIG=pipeline\.yml\.tmpl$
4446
10 ^bundle$/^invariant$/^delete_idempotent$/^DATABRICKS_BUNDLE_ENGINE=direct$/^DMS=$/^INPUT_CONFIG=pipeline\.yml\.tmpl$
4547
10 ^bundle$/^invariant$/^destroy_idempotent$/^DATABRICKS_BUNDLE_ENGINE=direct$/^DMS=$/^INPUT_CONFIG=pipeline\.yml\.tmpl$
4648
10 ^bundle$/^invariant$/^migrate$/^DATABRICKS_BUNDLE_ENGINE=direct$/^DMS=$/^INPUT_CONFIG=pipeline\.yml\.tmpl$
4749
10 ^bundle$/^invariant$/^no_drift$/^DATABRICKS_BUNDLE_ENGINE=direct$/^DMS=$/^INPUT_CONFIG=pipeline\.yml\.tmpl$
4850
10 ^bundle$/^invariant$/^no_drift$/^DATABRICKS_BUNDLE_ENGINE=direct$/^DMS=true$/^INPUT_CONFIG=pipeline\.yml\.tmpl$
51+
5 ^bundle$/^invariant$/^auto-migrate$/^DATABRICKS_BUNDLE_ENGINE=direct$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$
4952
5 ^bundle$/^invariant$/^continue_293$/^DATABRICKS_BUNDLE_ENGINE=direct$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$
5053
5 ^bundle$/^invariant$/^delete_idempotent$/^DATABRICKS_BUNDLE_ENGINE=direct$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$
5154
5 ^bundle$/^invariant$/^destroy_idempotent$/^DATABRICKS_BUNDLE_ENGINE=direct$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$
@@ -71,7 +74,7 @@ Selected 1 changed tests (limit=50, 0 not selected)
7174
=== The limit keeps the highest scoring tests
7275

7376
>>> selection -limit 3 A:acceptance/selftest/basic/script M:acceptance/selftest/diff/script M:acceptance/bundle/invariant/configs/job.yml.tmpl
74-
Selected 3 changed tests (limit=3, 4 not selected)
77+
Selected 3 changed tests (limit=3, 5 not selected)
7578
10 ^selftest$/^basic$
79+
5 ^bundle$/^invariant$/^auto-migrate$/^DATABRICKS_BUNDLE_ENGINE=direct$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$
7680
5 ^bundle$/^invariant$/^continue_293$/^DATABRICKS_BUNDLE_ENGINE=direct$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$
77-
5 ^bundle$/^invariant$/^delete_idempotent$/^DATABRICKS_BUNDLE_ENGINE=direct$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$

0 commit comments

Comments
 (0)