diff --git a/acceptance/bin/generate_from_state.py b/acceptance/bin/generate_from_state.py new file mode 100755 index 00000000000..38cdcda6044 --- /dev/null +++ b/acceptance/bin/generate_from_state.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +""" +Run `bundle generate` for every top-level resource recorded in the deployment state. + + generate_from_state.py [-t TARGET] --bundle-dir DIR + +State is read from the current directory; each resource is generated into the bundle at DIR +under its own key with `--existing-id `, so downloaded files land inside that bundle. +Prints nothing on success so the output is identical across configs; on failure prints the +command and its output and exits non-zero. +""" + +import argparse +import json +import subprocess +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).parent)) +from print_state import CLI, get_state_file + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("-t", "--target") + parser.add_argument("--bundle-dir", required=True) + args = parser.parse_args() + + state = json.loads(Path(get_state_file(args.target, False)).read_text())["state"] + for key in sorted(state): + parts = key.split(".") + # Sub-resources such as resources.jobs.foo.permissions are generated with their parent. + if len(parts) != 3: + continue + _, group, name = parts + cmd = [CLI, "bundle", "generate", group, "--existing-id", state[key]["__id__"], "--key", name] + result = subprocess.run( + cmd, cwd=args.bundle_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8" + ) + if result.returncode != 0: + print(f"{' '.join(cmd[1:])} failed with exit code {result.returncode}:\n{result.stdout}", flush=True) + sys.exit(result.returncode) + + +if __name__ == "__main__": + main() diff --git a/acceptance/bundle/invariant/generate/generated/databricks.yml b/acceptance/bundle/invariant/generate/generated/databricks.yml new file mode 100644 index 00000000000..645527b39f0 --- /dev/null +++ b/acceptance/bundle/invariant/generate/generated/databricks.yml @@ -0,0 +1,5 @@ +bundle: + name: generated + +include: + - resources/*.yml diff --git a/acceptance/bundle/invariant/generate/notebook.py b/acceptance/bundle/invariant/generate/notebook.py new file mode 100644 index 00000000000..4914a7436d9 --- /dev/null +++ b/acceptance/bundle/invariant/generate/notebook.py @@ -0,0 +1,2 @@ +# Databricks notebook source +print("hello") diff --git a/acceptance/bundle/invariant/generate/out.test.toml b/acceptance/bundle/invariant/generate/out.test.toml new file mode 100644 index 00000000000..484617003ff --- /dev/null +++ b/acceptance/bundle/invariant/generate/out.test.toml @@ -0,0 +1,61 @@ +Cloud = false +EnvMatrix.DMS = [] +EnvMatrix.INPUT_CONFIG = [ + "alert.yml.tmpl", + "catalog.yml.tmpl", + "catalog_optional_fields.yml.tmpl", + "cluster.yml.tmpl", + "cluster_apply_policy_default_values.yml.tmpl", + "cluster_libraries.yml.tmpl", + "cluster_policy.yml.tmpl", + "dashboard.yml.tmpl", + "job_apply_policy_default_values_job_cluster.yml.tmpl", + "job_apply_policy_default_values_task_cluster.yml.tmpl", + "job_apply_policy_default_values_for_each_task.yml.tmpl", + "data_quality_monitor.yml.tmpl", + "database_catalog.yml.tmpl", + "database_instance.yml.tmpl", + "experiment.yml.tmpl", + "external_location.yml.tmpl", + "feature.yml.tmpl", + "genie_space.yml.tmpl", + "instance_pool.yml.tmpl", + "job.yml.tmpl", + "job_pydabs_10_tasks.yml.tmpl", + "job_pydabs_1000_tasks.yml.tmpl", + "job_cross_resource_ref.yml.tmpl", + "job_escaped_refs.yml.tmpl", + "job_permission_ref.yml.tmpl", + "job_table_update_trigger.yml.tmpl", + "job_with_depends_on.yml.tmpl", + "job_with_task.yml.tmpl", + "model.yml.tmpl", + "model_with_permissions.yml.tmpl", + "model_serving_endpoint.yml.tmpl", + "model_serving_endpoint_telemetry.yml.tmpl", + "pipeline.yml.tmpl", + "pipeline_allow_duplicate_names.yml.tmpl", + "pipeline_apply_policy_default_values.yml.tmpl", + "pipeline_config_dots.yml.tmpl", + "postgres_branch.yml.tmpl", + "postgres_catalog.yml.tmpl", + "postgres_database.yml.tmpl", + "postgres_project.yml.tmpl", + "postgres_role.yml.tmpl", + "postgres_synced_table.yml.tmpl", + "registered_model.yml.tmpl", + "schema.yml.tmpl", + "schema_tf_compat.yml.tmpl", + "schema_empty_grants.yml.tmpl", + "schema_grant_ref.yml.tmpl", + "schema_uppercase_name.yml.tmpl", + "sql_warehouse.yml.tmpl", + "synced_database_table.yml.tmpl", + "uc_trailing_slash.yml.tmpl", + "vector_search_endpoint.yml.tmpl", + "volume.yml.tmpl", + "volume_external.yml.tmpl", + "volume_path_job_ref.yml.tmpl", + "volume_uppercase_name.yml.tmpl", + "model_service.yml.tmpl" +] diff --git a/acceptance/bundle/invariant/generate/output.txt b/acceptance/bundle/invariant/generate/output.txt new file mode 100644 index 00000000000..4dbd78b33e5 --- /dev/null +++ b/acceptance/bundle/invariant/generate/output.txt @@ -0,0 +1,2 @@ +INPUT_CONFIG_OK +GENERATE_OK diff --git a/acceptance/bundle/invariant/generate/script b/acceptance/bundle/invariant/generate/script new file mode 100644 index 00000000000..e244931eb03 --- /dev/null +++ b/acceptance/bundle/invariant/generate/script @@ -0,0 +1,18 @@ +# Invariant to test: every deployed resource can be generated back into a bundle that validates. + +invariant_setup + +invariant_deploy LOG.deploy $CLI bundle deploy + +# The job generator downloads the notebooks a job references; the configs point at this path. +MSYS_NO_PATHCONV=1 $CLI workspace mkdirs /Shared +MSYS_NO_PATHCONV=1 $CLI workspace import /Shared/notebook --format SOURCE --language PYTHON --file notebook.py > LOG.import + +generate_from_state.py --bundle-dir generated +echo GENERATE_OK + +cd generated +$CLI bundle validate > ../LOG.validate +cd .. + +rm -rf generated/resources generated/src generated/.databricks diff --git a/acceptance/bundle/invariant/generate/test.toml b/acceptance/bundle/invariant/generate/test.toml new file mode 100644 index 00000000000..acb16be8de4 --- /dev/null +++ b/acceptance/bundle/invariant/generate/test.toml @@ -0,0 +1,26 @@ +# This invariant checks the CLI's own round-trip from deployment state to configuration, +# which the fake server exercises as well as a workspace would; no_drift covers the deploy. +Cloud = false + +# Generate does not touch deployment history, so one deploy per config is enough. +EnvMatrix.DMS = [] + +# Job runs have no generate command: a run is triggered, not imported. +EnvMatrixExclude.no_job_run = ["INPUT_CONFIG=job_run.yml.tmpl"] +EnvMatrixExclude.no_job_run_job_ref = ["INPUT_CONFIG=job_run_job_ref.yml.tmpl"] + +# The app generator downloads the app's source files, which the fake workspace does not serve. +EnvMatrixExclude.no_app_sources_locally = ["INPUT_CONFIG=app.yml.tmpl"] + +# TODO: these types fail generate because the deployment engine state does not map onto the +# bundle resource. Fix the adapters, then drop the exclusion. +# Secret scopes: state uses scope/scope_backend_type, the resource name/backend_type. +EnvMatrixExclude.secret_scope_todo = ["INPUT_CONFIG=secret_scope.yml.tmpl"] +EnvMatrixExclude.secret_scope_default_backend_todo = ["INPUT_CONFIG=secret_scope_default_backend_type.yml.tmpl"] +# Secrets: PrepareState clears the metadata fields that RemapState keeps from the remote. +EnvMatrixExclude.secret_todo = ["INPUT_CONFIG=secret.yml.tmpl"] +# Vector search indexes: PrepareState clears endpoint_uuid, RemapState keeps it. +EnvMatrixExclude.vector_search_index_todo = ["INPUT_CONFIG=vector_search_index.yml.tmpl"] +# Postgres endpoints: GET does not return the spec, so the generated endpoint_type is empty +# and validate warns. +EnvMatrixExclude.postgres_endpoint_todo = ["INPUT_CONFIG=postgres_endpoint.yml.tmpl"] diff --git a/acceptance/selftest/selection/output.txt b/acceptance/selftest/selection/output.txt index 7e2c55b1c1d..f918b2ba138 100644 --- a/acceptance/selftest/selection/output.txt +++ b/acceptance/selftest/selection/output.txt @@ -28,11 +28,12 @@ Selected 2 changed tests (limit=50, 0 not selected) === Touching an invariant config runs every invariant test, for that config only >>> selection M:acceptance/bundle/invariant/configs/job.yml.tmpl -Selected 6 changed tests (limit=50, 0 not selected) +Selected 7 changed tests (limit=50, 0 not selected) 5 ^bundle$/^invariant$/^auto-migrate$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$ 5 ^bundle$/^invariant$/^continue_293$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$ 5 ^bundle$/^invariant$/^delete_idempotent$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$ 5 ^bundle$/^invariant$/^destroy_idempotent$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$ + 5 ^bundle$/^invariant$/^generate$/^INPUT_CONFIG=job\.yml\.tmpl$ 5 ^bundle$/^invariant$/^migrate$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$ 5 ^bundle$/^invariant$/^no_drift$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$ 5 ^bundle$/^invariant$/^no_drift$/^DMS=true$/^INPUT_CONFIG=job\.yml\.tmpl$ @@ -40,11 +41,12 @@ Selected 6 changed tests (limit=50, 0 not selected) === Adding one invariant config and touching another: only the new variant is new >>> selection A:acceptance/bundle/invariant/configs/pipeline.yml.tmpl M:acceptance/bundle/invariant/configs/job.yml.tmpl -Selected 12 changed tests (limit=50, 0 not selected) +Selected 14 changed tests (limit=50, 0 not selected) 10 ^bundle$/^invariant$/^auto-migrate$/^DMS=$/^INPUT_CONFIG=pipeline\.yml\.tmpl$ 10 ^bundle$/^invariant$/^continue_293$/^DMS=$/^INPUT_CONFIG=pipeline\.yml\.tmpl$ 10 ^bundle$/^invariant$/^delete_idempotent$/^DMS=$/^INPUT_CONFIG=pipeline\.yml\.tmpl$ 10 ^bundle$/^invariant$/^destroy_idempotent$/^DMS=$/^INPUT_CONFIG=pipeline\.yml\.tmpl$ + 10 ^bundle$/^invariant$/^generate$/^INPUT_CONFIG=pipeline\.yml\.tmpl$ 10 ^bundle$/^invariant$/^migrate$/^DMS=$/^INPUT_CONFIG=pipeline\.yml\.tmpl$ 10 ^bundle$/^invariant$/^no_drift$/^DMS=$/^INPUT_CONFIG=pipeline\.yml\.tmpl$ 10 ^bundle$/^invariant$/^no_drift$/^DMS=true$/^INPUT_CONFIG=pipeline\.yml\.tmpl$ @@ -52,6 +54,7 @@ Selected 12 changed tests (limit=50, 0 not selected) 5 ^bundle$/^invariant$/^continue_293$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$ 5 ^bundle$/^invariant$/^delete_idempotent$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$ 5 ^bundle$/^invariant$/^destroy_idempotent$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$ + 5 ^bundle$/^invariant$/^generate$/^INPUT_CONFIG=job\.yml\.tmpl$ 5 ^bundle$/^invariant$/^migrate$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$ 5 ^bundle$/^invariant$/^no_drift$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$ 5 ^bundle$/^invariant$/^no_drift$/^DMS=true$/^INPUT_CONFIG=job\.yml\.tmpl$ @@ -74,7 +77,7 @@ Selected 1 changed tests (limit=50, 0 not selected) === The limit keeps the highest scoring tests >>> selection -limit 3 A:acceptance/selftest/basic/script M:acceptance/selftest/diff/script M:acceptance/bundle/invariant/configs/job.yml.tmpl -Selected 3 changed tests (limit=3, 5 not selected) +Selected 3 changed tests (limit=3, 6 not selected) 10 ^selftest$/^basic$ 5 ^bundle$/^invariant$/^auto-migrate$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$ 5 ^bundle$/^invariant$/^continue_293$/^DMS=$/^INPUT_CONFIG=job\.yml\.tmpl$