diff --git a/acceptance/bundle/migrate/script.prepare b/acceptance/bundle/migrate/script.prepare index 559d2cec52e..cbc9a0b8715 100644 --- a/acceptance/bundle/migrate/script.prepare +++ b/acceptance/bundle/migrate/script.prepare @@ -6,7 +6,13 @@ print_migration_telemetry() { print_telemetry_bool_values | grep '^direct_' || true } -# The replay fixtures and the generated out.* files live in the bundle root but are not bundle +# The replay fixtures and the generated out.* and LOG.* files live in the bundle root but are not bundle # files, so keep them out of `bundle deploy`'s upload. The list excludes .gitignore itself so it is # not uploaded either; test.toml adds .gitignore to Ignore so the harness does not flag it. -printf '%s\n' '.gitignore' 'out.*' 'terraform*.tfstate' 'terraform*-requests.json' > .gitignore +printf '%s\n' '.gitignore' 'out.*' 'LOG.*' 'terraform*.tfstate' 'terraform*-requests.json' > .gitignore + +# Per request: the engine tags in the User-Agent (MISSING if none), method and path. +# The sed strips uniq -c's padding, which differs between GNU and BSD (macOS). +print_engines() { + print_requests.py --get --oneline | jq -r 'select(.path | startswith("/__testserver/") | not) | ((.headers["User-Agent"][0] | [scan("engine/[a-z]+")] | join(",")) as $e | (if $e == "" then "MISSING" else $e end)) + " " + .method + " " + .path' | sort | uniq -c | sed -E 's/^ +//' +} diff --git a/acceptance/bundle/migrate/user-agent/bind-unbind/databricks.yml b/acceptance/bundle/migrate/user-agent/bind-unbind/databricks.yml new file mode 100644 index 00000000000..8eed9482e74 --- /dev/null +++ b/acceptance/bundle/migrate/user-agent/bind-unbind/databricks.yml @@ -0,0 +1,7 @@ +bundle: + name: test-bundle + +resources: + jobs: + test_job: + name: "Test Auto-Migrate Plan Failure" diff --git a/acceptance/bundle/migrate/user-agent/bind-unbind/out.test.toml b/acceptance/bundle/migrate/user-agent/bind-unbind/out.test.toml new file mode 100644 index 00000000000..19b5b15d11f --- /dev/null +++ b/acceptance/bundle/migrate/user-agent/bind-unbind/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/migrate/user-agent/bind-unbind/output.txt b/acceptance/bundle/migrate/user-agent/bind-unbind/output.txt new file mode 100644 index 00000000000..b482426fab4 --- /dev/null +++ b/acceptance/bundle/migrate/user-agent/bind-unbind/output.txt @@ -0,0 +1,35 @@ + +=== Replay a prior terraform deployment + +>>> replay_tfstate.py [TESTROOT]/bundle/migrate/user-agent/bind-unbind/../terraform-requests.json [TESTROOT]/bundle/migrate/user-agent/bind-unbind/../terraform.tfstate + +=== bind on a terraform state + +>>> musterr [CLI] bundle deployment bind test_job [TEST_JOB_ID] --auto-approve +Error: this deployment's state uses the Terraform engine, which has been removed in Databricks CLI v1.20.0 + +Run "databricks bundle deploy" to migrate the state to the direct engine, or install Databricks CLI v1.19.x + + +>>> print_engines +2 MISSING GET /api/2.0/workspace/export +2 engine/terraform GET /api/2.0/workspace/export +3 engine/terraform GET /api/2.0/workspace/get-status +1 engine/terraform GET /api/2.2/jobs/get +1 engine/terraform POST /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deploy.lock +1 engine/terraform POST /api/2.0/workspace/delete + +=== unbind on a terraform state + +>>> musterr [CLI] bundle deployment unbind test_job +Error: this deployment's state uses the Terraform engine, which has been removed in Databricks CLI v1.20.0 + +Run "databricks bundle deploy" to migrate the state to the direct engine, or install Databricks CLI v1.19.x + + +>>> print_engines +2 MISSING GET /api/2.0/workspace/export +2 engine/terraform GET /api/2.0/workspace/export +3 engine/terraform GET /api/2.0/workspace/get-status +1 engine/terraform POST /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deploy.lock +1 engine/terraform POST /api/2.0/workspace/delete diff --git a/acceptance/bundle/migrate/user-agent/bind-unbind/script b/acceptance/bundle/migrate/user-agent/bind-unbind/script new file mode 100644 index 00000000000..bfcd4457f18 --- /dev/null +++ b/acceptance/bundle/migrate/user-agent/bind-unbind/script @@ -0,0 +1,16 @@ +export DATABRICKS_BUNDLE_ENGINE= + +title "Replay a prior terraform deployment" +trace replay_tfstate.py "$TESTDIR/../terraform-requests.json" "$TESTDIR/../terraform.tfstate" +replace_ids.py +rm -f "$OUT_REQUESTS" +JOB_ID=$(read_id.py test_job) + +# bind and unbind only pull the state, so a terraform state is not migrated and they reject it. +title "bind on a terraform state" +trace musterr $CLI bundle deployment bind test_job "$JOB_ID" --auto-approve +trace print_engines + +title "unbind on a terraform state" +trace musterr $CLI bundle deployment unbind test_job +trace print_engines diff --git a/acceptance/bundle/migrate/user-agent/engine-pinned/databricks.yml b/acceptance/bundle/migrate/user-agent/engine-pinned/databricks.yml new file mode 100644 index 00000000000..8eed9482e74 --- /dev/null +++ b/acceptance/bundle/migrate/user-agent/engine-pinned/databricks.yml @@ -0,0 +1,7 @@ +bundle: + name: test-bundle + +resources: + jobs: + test_job: + name: "Test Auto-Migrate Plan Failure" diff --git a/acceptance/bundle/migrate/user-agent/engine-pinned/out.test.toml b/acceptance/bundle/migrate/user-agent/engine-pinned/out.test.toml new file mode 100644 index 00000000000..19b5b15d11f --- /dev/null +++ b/acceptance/bundle/migrate/user-agent/engine-pinned/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/migrate/user-agent/engine-pinned/output.txt b/acceptance/bundle/migrate/user-agent/engine-pinned/output.txt new file mode 100644 index 00000000000..1a6a4db4b1c --- /dev/null +++ b/acceptance/bundle/migrate/user-agent/engine-pinned/output.txt @@ -0,0 +1,43 @@ + +=== Replay a prior terraform deployment + +>>> replay_tfstate.py [TESTROOT]/bundle/migrate/user-agent/engine-pinned/../terraform-requests.json [TESTROOT]/bundle/migrate/user-agent/engine-pinned/../terraform.tfstate + +=== deploy with DATABRICKS_BUNDLE_ENGINE=terraform + +>>> DATABRICKS_BUNDLE_ENGINE=terraform musterr [CLI] bundle deploy +Error: the Terraform deployment engine has been removed in Databricks CLI v1.20.0 + +Unset the DATABRICKS_BUNDLE_ENGINE environment variable (or set it to "direct") to deploy with the direct engine; existing Terraform state is migrated automatically. To keep using Terraform, revert to Databricks CLI v1.19.x. +See https://docs.databricks.com/dev-tools/bundles/direct for details + +>>> print_engines +1 MISSING POST /telemetry-ext + +=== deploy with bundle.engine: terraform + +>>> musterr [CLI] bundle deploy +Error: the Terraform deployment engine has been removed in Databricks CLI v1.20.0 + in databricks.yml:3:11 + +Remove the "bundle.engine" setting (or set it to "direct") to deploy with the direct engine; existing Terraform state is migrated automatically. To keep using Terraform, revert to Databricks CLI v1.19.x. +See https://docs.databricks.com/dev-tools/bundles/direct for details + + +>>> print_engines +1 MISSING POST /telemetry-ext + +=== summary with bundle.engine: terraform + +>>> [CLI] bundle summary +Warning: the Terraform deployment engine has been removed in Databricks CLI v1.20.0 + in databricks.yml:3:11 + +Remove the "bundle.engine" setting (or set it to "direct") to deploy with the direct engine; existing Terraform state is migrated automatically. To keep using Terraform, revert to Databricks CLI v1.19.x. +See https://docs.databricks.com/dev-tools/bundles/direct for details + +Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). + +>>> print_engines +1 MISSING GET /api/2.2/jobs/get +1 engine/direct GET /api/2.0/preview/scim/v2/Me diff --git a/acceptance/bundle/migrate/user-agent/engine-pinned/script b/acceptance/bundle/migrate/user-agent/engine-pinned/script new file mode 100644 index 00000000000..11514a2eae7 --- /dev/null +++ b/acceptance/bundle/migrate/user-agent/engine-pinned/script @@ -0,0 +1,21 @@ +export DATABRICKS_BUNDLE_ENGINE= + +title "Replay a prior terraform deployment" +trace replay_tfstate.py "$TESTDIR/../terraform-requests.json" "$TESTDIR/../terraform.tfstate" +replace_ids.py +rm -f "$OUT_REQUESTS" + +title "deploy with DATABRICKS_BUNDLE_ENGINE=terraform" +trace DATABRICKS_BUNDLE_ENGINE=terraform musterr $CLI bundle deploy +trace print_engines + +title "deploy with bundle.engine: terraform" +update_file.py databricks.yml ' name: test-bundle' ' name: test-bundle + engine: terraform' +trace musterr $CLI bundle deploy +trace print_engines + +# summary allows a terraform bundle.engine (warning only) and migrates the state in memory. +title "summary with bundle.engine: terraform" +trace $CLI bundle summary > LOG.summary +trace print_engines diff --git a/acceptance/bundle/migrate/user-agent/race/databricks.yml b/acceptance/bundle/migrate/user-agent/race/databricks.yml new file mode 100644 index 00000000000..cd06518a480 --- /dev/null +++ b/acceptance/bundle/migrate/user-agent/race/databricks.yml @@ -0,0 +1,13 @@ +bundle: + name: test-bundle + +experimental: + scripts: + # Simulates a concurrent deploy migrating the state: postbuild runs after the state pull and + # before the auto-migration, so the migration finds no local terraform state. + postbuild: rm -f .databricks/bundle/default/terraform/terraform.tfstate + +resources: + jobs: + test_job: + name: "Test Auto-Migrate Plan Failure" diff --git a/acceptance/bundle/migrate/user-agent/race/out.test.toml b/acceptance/bundle/migrate/user-agent/race/out.test.toml new file mode 100644 index 00000000000..19b5b15d11f --- /dev/null +++ b/acceptance/bundle/migrate/user-agent/race/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/migrate/user-agent/race/output.txt b/acceptance/bundle/migrate/user-agent/race/output.txt new file mode 100644 index 00000000000..648a28750fb --- /dev/null +++ b/acceptance/bundle/migrate/user-agent/race/output.txt @@ -0,0 +1,16 @@ + +=== Replay a prior terraform deployment + +>>> replay_tfstate.py [TESTROOT]/bundle/migrate/user-agent/race/../terraform-requests.json [TESTROOT]/bundle/migrate/user-agent/race/../terraform.tfstate + +=== Deploy where the local terraform state disappears between the pull and the migration + +>>> print_engines +2 MISSING GET /api/2.0/workspace/export +3 engine/terraform GET /api/2.0/workspace/export +4 engine/terraform GET /api/2.0/workspace/get-status +1 engine/terraform POST /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/databricks.yml +1 engine/terraform POST /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deploy.lock +1 engine/terraform POST /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json +2 engine/terraform POST /api/2.0/workspace/delete +1 engine/terraform POST /api/2.0/workspace/mkdirs diff --git a/acceptance/bundle/migrate/user-agent/race/script b/acceptance/bundle/migrate/user-agent/race/script new file mode 100644 index 00000000000..49caea90aa1 --- /dev/null +++ b/acceptance/bundle/migrate/user-agent/race/script @@ -0,0 +1,11 @@ +export DATABRICKS_BUNDLE_ENGINE= + +title "Replay a prior terraform deployment" +trace replay_tfstate.py "$TESTDIR/../terraform-requests.json" "$TESTDIR/../terraform.tfstate" +replace_ids.py +rm -f "$OUT_REQUESTS" + +title "Deploy where the local terraform state disappears between the pull and the migration" +musterr $CLI bundle deploy &> LOG.deploy +contains.py 'Panic Payload: internal error: DeploymentState must be opened first' < LOG.deploy > /dev/null +trace print_engines diff --git a/acceptance/bundle/migrate/user-agent/terraform-requests.json b/acceptance/bundle/migrate/user-agent/terraform-requests.json new file mode 100644 index 00000000000..514877afead --- /dev/null +++ b/acceptance/bundle/migrate/user-agent/terraform-requests.json @@ -0,0 +1,19 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Test Auto-Migrate Plan Failure", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/user-agent/terraform.tfstate b/acceptance/bundle/migrate/user-agent/terraform.tfstate new file mode 100644 index 00000000000..5f749b73a1d --- /dev/null +++ b/acceptance/bundle/migrate/user-agent/terraform.tfstate @@ -0,0 +1,110 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "115ec518-3f72-3614-4e56-01411863558a", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790613902942848000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Auto-Migrate Plan Failure", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790613902942848000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } + ] + } + ], + "check_results": null +}