Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions acceptance/bin/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
Finds all files within current directory matching regex. The output is sorted and slashes are always forward.

If --expect N is provided, the number of matches must be N or error is printed.
If --include-dirs is provided, directories are matched and printed too (default: files only).
If --prune REGEX is provided, directories whose path matches REGEX are not descended into or printed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems odd that --prune only prunes directories. Should it be called --prune-dirs in that case? or should it prune files as well?

"""

import argparse
Expand All @@ -14,15 +16,25 @@
parser = argparse.ArgumentParser()
parser.add_argument("regex")
parser.add_argument("--expect", type=int)
parser.add_argument("--include-dirs", action="store_true")
parser.add_argument("--prune")
args = parser.parse_args()

regex = re.compile(args.regex)
prune = re.compile(args.prune) if args.prune else None
result = []

for root, _dirs, files in os.walk("."):
for filename in files:
path = os.path.join(root, filename).replace("\\", "/")
path = path.removeprefix("./")

def relpath(root, name):
return os.path.join(root, name).replace("\\", "/").removeprefix("./")


for root, dirs, files in os.walk("."):
if prune is not None:
dirs[:] = [d for d in dirs if not prune.search(relpath(root, d))]
names = files + dirs if args.include_dirs else files
for name in names:
path = relpath(root, name)
if regex.search(path):
result.append(path)

Expand Down
2 changes: 1 addition & 1 deletion acceptance/bundle/destroy/jobs-and-pipeline/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Exit code: 1

=== Assert destroy leaves the bundle state dir clean:

>>> find .databricks -name terraform -prune -o -print
>>> find.py --include-dirs --prune terraform$ ^\.databricks(/|$)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at this, I think find.py --dirs would be enough.

.databricks
.databricks/.gitignore
.databricks/bundle
Expand Down
2 changes: 1 addition & 1 deletion acceptance/bundle/destroy/jobs-and-pipeline/script
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cleanup() {
# which would make the golden fragile. The bundle scaffolding we care about lives
# directly under the target dir, so it is still covered.
title "Assert destroy leaves the bundle state dir clean:\n"
trace find .databricks -name terraform -prune -o -print | sort
trace find.py --include-dirs --prune 'terraform$' '^\.databricks(/|$)'

title "Assert bundle deployment path is deleted"
trace errcode $CLI workspace get-status "${DEPLOYMENT_PATH}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Destroy: 1 deleted

=== and leaves the bundle state dir clean, with no empty scaffolding directories:

>>> find .databricks -name terraform -prune -o -print
>>> find.py --include-dirs --prune terraform$ ^\.databricks(/|$)
.databricks
.databricks/.gitignore
.databricks/bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ trace find.py '^.databricks/bundle/default/(resources.json|terraform/terraform.t
# already asserted gone above). The bundle scaffolding we care about lives directly
# under the target dir, so it is still covered.
title "and leaves the bundle state dir clean, with no empty scaffolding directories:\n"
trace find .databricks -name terraform -prune -o -print | sort
trace find.py --include-dirs --prune 'terraform$' '^\.databricks(/|$)'

# Wipe whatever remains so the next deploy behaves like a fresh machine.
rm -rf .databricks
Expand Down
2 changes: 1 addition & 1 deletion acceptance/bundle/generate/job_nested_notebooks/script
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ test ! -f src/my_notebook.py && echo "src/my_notebook.py removed" || echo "src/m
test ! -f src/other_notebook.py && echo "src/other_notebook.py removed" || echo "src/other_notebook.py still exists"

echo "=== new nested files ==="
find src -type f | sort
find.py '^src/'
4 changes: 2 additions & 2 deletions acceptance/bundle/migrate/auto-migrate-clean/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ direct_migrated_via_config true

=== Direct-engine state is now in place; terraform state is backed up

>>> find .databricks/bundle -name resources.json -type f
>>> find.py ^\.databricks/bundle/.*resources\.json$

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just teach it to accept exact directories as parameter like find?

.databricks/bundle/default/resources.json

>>> find .databricks/bundle -name terraform.tfstate* -type f
>>> find.py ^\.databricks/bundle/.*terraform\.tfstate
.databricks/bundle/default/terraform/terraform.tfstate.backup

=== Remote state also reflects the migration (force-pull surfaces workspace state)
Expand Down
4 changes: 2 additions & 2 deletions acceptance/bundle/migrate/auto-migrate-clean/script
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ trace print_migration_telemetry
rm -f "$OUT_REQUESTS"

title "Direct-engine state is now in place; terraform state is backed up\n"
trace find .databricks/bundle -name "resources.json" -type f
trace find .databricks/bundle -name "terraform.tfstate*" -type f
trace find.py '^\.databricks/bundle/.*resources\.json$'
trace find.py '^\.databricks/bundle/.*terraform\.tfstate'

title "Remote state also reflects the migration (force-pull surfaces workspace state)\n"
trace $CLI bundle debug states --force-pull
Expand Down
4 changes: 2 additions & 2 deletions acceptance/bundle/migrate/auto-migrate-default/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ direct_migrated_via_default true

=== Direct-engine state is now in place; terraform state is backed up

>>> find .databricks/bundle -name resources.json -type f
>>> find.py ^\.databricks/bundle/.*resources\.json$
.databricks/bundle/default/resources.json

>>> find .databricks/bundle -name terraform.tfstate* -type f
>>> find.py ^\.databricks/bundle/.*terraform\.tfstate
.databricks/bundle/default/terraform/terraform.tfstate.backup

=== Remote state also reflects the migration (force-pull surfaces workspace state)
Expand Down
4 changes: 2 additions & 2 deletions acceptance/bundle/migrate/auto-migrate-default/script
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ trace print_migration_telemetry
rm -f "$OUT_REQUESTS"

title "Direct-engine state is now in place; terraform state is backed up\n"
trace find .databricks/bundle -name "resources.json" -type f
trace find .databricks/bundle -name "terraform.tfstate*" -type f
trace find.py '^\.databricks/bundle/.*resources\.json$'
trace find.py '^\.databricks/bundle/.*terraform\.tfstate'

title "Remote state also reflects the migration (force-pull surfaces workspace state)\n"
trace $CLI bundle debug states --force-pull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Removing empty terraform state; direct engine will be used on the next deploy (s

=== Terraform state is renamed to .backup; no resources.json (empty state, nothing to persist)

>>> find .databricks/bundle -name resources.json -type f
>>> find.py ^\.databricks/bundle/.*resources\.json$

>>> find .databricks/bundle -name terraform.tfstate* -type f
>>> find.py ^\.databricks/bundle/.*terraform\.tfstate
.databricks/bundle/default/terraform/terraform.tfstate.backup

=== Sweep is recorded in telemetry as via-config
Expand Down
4 changes: 2 additions & 2 deletions acceptance/bundle/migrate/auto-migrate-empty-tfstate/script
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ title "Deploy with bundle.engine: direct and an empty terraform state — sweep,
trace $CLI bundle deploy 2>&1 | contains.py 'Removing empty terraform state' '!Migrating state to direct'

title "Terraform state is renamed to .backup; no resources.json (empty state, nothing to persist)\n"
trace find .databricks/bundle -name "resources.json" -type f
trace find .databricks/bundle -name "terraform.tfstate*" -type f
trace find.py '^\.databricks/bundle/.*resources\.json$'
trace find.py '^\.databricks/bundle/.*terraform\.tfstate'

title "Sweep is recorded in telemetry as via-config\n"
trace print_migration_telemetry
Expand Down
4 changes: 2 additions & 2 deletions acceptance/bundle/migrate/auto-migrate-envvar/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ direct_migrated_via_env true

=== Direct-engine state is now in place; terraform state is backed up

>>> find .databricks/bundle -name resources.json -type f
>>> find.py ^\.databricks/bundle/.*resources\.json$
.databricks/bundle/default/resources.json

>>> find .databricks/bundle -name terraform.tfstate* -type f
>>> find.py ^\.databricks/bundle/.*terraform\.tfstate
.databricks/bundle/default/terraform/terraform.tfstate.backup

=== Remote state also reflects the migration (force-pull surfaces workspace state)
Expand Down
4 changes: 2 additions & 2 deletions acceptance/bundle/migrate/auto-migrate-envvar/script
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ trace print_migration_telemetry
rm -f "$OUT_REQUESTS"

title "Direct-engine state is now in place; terraform state is backed up\n"
trace find .databricks/bundle -name "resources.json" -type f
trace find .databricks/bundle -name "terraform.tfstate*" -type f
trace find.py '^\.databricks/bundle/.*resources\.json$'
trace find.py '^\.databricks/bundle/.*terraform\.tfstate'

title "Remote state also reflects the migration (force-pull surfaces workspace state)\n"
trace $CLI bundle debug states --force-pull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ Warn: Direct engine was selected but the migration reported issues; automatic mi
direct_migrate_plan_error true

=== Local state was NOT rewritten (still terraform)
>>> find .databricks/bundle -name resources.json -type f
>>> find.py ^\.databricks/bundle/.*resources\.json$

>>> find .databricks/bundle -name terraform.tfstate* -type f
>>> find.py ^\.databricks/bundle/.*terraform\.tfstate
.databricks/bundle/default/terraform/terraform.tfstate

=== Retry: plan check passes this time, migration succeeds
Expand All @@ -48,8 +48,8 @@ Migrated 1 resource to direct deployment engine.
direct_migrated_via_env true

=== Local state is now direct
>>> find .databricks/bundle -name resources.json -type f
>>> find.py ^\.databricks/bundle/.*resources\.json$
.databricks/bundle/default/resources.json

>>> find .databricks/bundle -name terraform.tfstate* -type f
>>> find.py ^\.databricks/bundle/.*terraform\.tfstate
.databricks/bundle/default/terraform/terraform.tfstate.backup
8 changes: 4 additions & 4 deletions acceptance/bundle/migrate/auto-migrate-plan-failure/script
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ trace print_migration_telemetry
rm -f "$OUT_REQUESTS"

title "Local state was NOT rewritten (still terraform)"
trace find .databricks/bundle -name "resources.json" -type f
trace find .databricks/bundle -name "terraform.tfstate*" -type f
trace find.py '^\.databricks/bundle/.*resources\.json$'
trace find.py '^\.databricks/bundle/.*terraform\.tfstate'

title "Retry: plan check passes this time, migration succeeds"
trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy
trace print_migration_telemetry
rm -f "$OUT_REQUESTS"

title "Local state is now direct"
trace find .databricks/bundle -name "resources.json" -type f
trace find .databricks/bundle -name "terraform.tfstate*" -type f
trace find.py '^\.databricks/bundle/.*resources\.json$'
trace find.py '^\.databricks/bundle/.*terraform\.tfstate'

rm -f "$OUT_REQUESTS"
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ direct_migrate_commit_error true

=== Local state was NOT rewritten (still terraform)

>>> find .databricks/bundle -name resources.json -type f
>>> find.py ^\.databricks/bundle/.*resources\.json$

>>> find .databricks/bundle -name terraform.tfstate* -type f
>>> find.py ^\.databricks/bundle/.*terraform\.tfstate
.databricks/bundle/default/terraform/terraform.tfstate

=== Retry: auto-migration succeeds this time
Expand All @@ -43,8 +43,8 @@ direct_migrated_via_env true

=== Local state is now direct

>>> find .databricks/bundle -name resources.json -type f
>>> find.py ^\.databricks/bundle/.*resources\.json$
.databricks/bundle/default/resources.json

>>> find .databricks/bundle -name terraform.tfstate* -type f
>>> find.py ^\.databricks/bundle/.*terraform\.tfstate
.databricks/bundle/default/terraform/terraform.tfstate.backup
8 changes: 4 additions & 4 deletions acceptance/bundle/migrate/auto-migrate-push-failure/script
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ trace print_migration_telemetry
rm -f "$OUT_REQUESTS"

title "Local state was NOT rewritten (still terraform)\n"
trace find .databricks/bundle -name "resources.json" -type f
trace find .databricks/bundle -name "terraform.tfstate*" -type f
trace find.py '^\.databricks/bundle/.*resources\.json$'
trace find.py '^\.databricks/bundle/.*terraform\.tfstate'

title "Retry: auto-migration succeeds this time"
trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy
trace print_migration_telemetry
rm -f "$OUT_REQUESTS"

title "Local state is now direct\n"
trace find .databricks/bundle -name "resources.json" -type f
trace find .databricks/bundle -name "terraform.tfstate*" -type f
trace find.py '^\.databricks/bundle/.*resources\.json$'
trace find.py '^\.databricks/bundle/.*terraform\.tfstate'

rm -f "$OUT_REQUESTS"
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ direct_migrate_commit_error true

=== Local state was NOT rewritten (still terraform)

>>> find .databricks/bundle -name resources.json -type f
>>> find.py ^\.databricks/bundle/.*resources\.json$

>>> find .databricks/bundle -name terraform.tfstate* -type f
>>> find.py ^\.databricks/bundle/.*terraform\.tfstate
.databricks/bundle/default/terraform/terraform.tfstate

=== Retry recovers: subsequent deploy re-does the backup and completes
Expand All @@ -39,8 +39,8 @@ Resources: 0 created, 0 changed, 0 deleted, 1 unchanged

=== Local state is now direct

>>> find .databricks/bundle -name resources.json -type f
>>> find.py ^\.databricks/bundle/.*resources\.json$
.databricks/bundle/default/resources.json

>>> find .databricks/bundle -name terraform.tfstate* -type f
>>> find.py ^\.databricks/bundle/.*terraform\.tfstate
.databricks/bundle/default/terraform/terraform.tfstate
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ trace print_migration_telemetry
rm -f "$OUT_REQUESTS"

title "Local state was NOT rewritten (still terraform)\n"
trace find .databricks/bundle -name "resources.json" -type f
trace find .databricks/bundle -name "terraform.tfstate*" -type f
trace find.py '^\.databricks/bundle/.*resources\.json$'
trace find.py '^\.databricks/bundle/.*terraform\.tfstate'

title "Retry recovers: subsequent deploy re-does the backup and completes"
trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy
trace print_migration_telemetry
rm -f "$OUT_REQUESTS"

title "Local state is now direct\n"
trace find .databricks/bundle -name "resources.json" -type f
trace find .databricks/bundle -name "terraform.tfstate*" -type f
trace find.py '^\.databricks/bundle/.*resources\.json$'
trace find.py '^\.databricks/bundle/.*terraform\.tfstate'

rm -f "$OUT_REQUESTS"
Loading