Skip to content

Commit 518b428

Browse files
authored
Fix issues with grants tests (#4868)
## Changes - Fix non-deterministic order of grants in the recorded plan - Add METASTORE_NAME replacement to capture AWS/Azure differences. - Add --repl option to sort_lines.py to sort according to replaced values to prevent UUID from affecting the sort order (`aaa...` vs `deco...` vs `fff...`).
1 parent e2ec2ea commit 518b428

File tree

25 files changed

+70
-43
lines changed

25 files changed

+70
-43
lines changed

acceptance/bin/sort_lines.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
11
#!/usr/bin/env python3
22
"""
33
Helper to sort lines in text file. Similar to 'sort' but no dependence on locale or presence of 'sort' in PATH.
4+
With --repl, applies TEST_TMP_DIR/repls.json replacements as sort key for stable output across different environments.
45
"""
56

67
import sys
8+
import os
9+
import json
10+
import re
11+
from pathlib import Path
12+
13+
use_repl = "--repl" in sys.argv[1:]
714

815
lines = sys.stdin.readlines()
9-
lines.sort()
16+
17+
if use_repl:
18+
repls = json.loads((Path(os.environ["TEST_TMP_DIR"]) / "repls.json").read_text())
19+
patterns = []
20+
for r in repls:
21+
try:
22+
patterns.append((re.compile(r["Old"]), r["New"]))
23+
except re.error as e:
24+
print(f"Regex error for pattern {r}: {e}", file=sys.stderr)
25+
26+
def sort_key(line):
27+
for comp, new in patterns:
28+
line = comp.sub(new, line)
29+
return line
30+
31+
lines.sort(key=sort_key)
32+
else:
33+
lines.sort()
34+
1035
sys.stdout.write("".join(lines))

acceptance/bundle/migrate/basic/out.new_state.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"myjob_timeout": "0",
5252
"myvolume_id": "mycat.myschema.myvol",
5353
"volume_catalog_name": "mycat",
54-
"volume_storage_location": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/[UUID]/volumes/[UUID]"
54+
"volume_storage_location": "s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]"
5555
}
5656
},
5757
"depends_on": [

acceptance/bundle/migrate/basic/out.original_state.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@
222222
"myjob_timeout": "0",
223223
"myvolume_id": "mycat.myschema.myvol",
224224
"volume_catalog_name": "mycat",
225-
"volume_storage_location": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/[UUID]/volumes/[UUID]"
225+
"volume_storage_location": "s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]"
226226
},
227227
"target": null,
228228
"timeouts": null,
@@ -255,7 +255,7 @@
255255
"owner": "[USERNAME]",
256256
"provider_config": [],
257257
"schema_name": "myschema",
258-
"storage_location": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/[UUID]/volumes/[UUID]",
258+
"storage_location": "s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]",
259259
"volume_path": "/Volumes/mycat/myschema/myvol",
260260
"volume_type": "MANAGED"
261261
},

acceptance/bundle/migrate/basic/out.plan_update.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
"myjob_timeout": "${resources.jobs.test_job.timeout_seconds}",
156156
"myvolume_id": "mycat.myschema.myvol",
157157
"volume_catalog_name": "mycat",
158-
"volume_storage_location": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/[UUID]/volumes/[UUID]"
158+
"volume_storage_location": "s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]"
159159
}
160160
},
161161
"vars": {
@@ -191,7 +191,7 @@
191191
"myjob_timeout": "0",
192192
"myvolume_id": "mycat.myschema.myvol",
193193
"volume_catalog_name": "mycat",
194-
"volume_storage_location": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/[UUID]/volumes/[UUID]"
194+
"volume_storage_location": "s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]"
195195
}
196196
},
197197
"changes": {
@@ -230,7 +230,7 @@
230230
"name": "myvol",
231231
"owner": "[USERNAME]",
232232
"schema_name": "myschema",
233-
"storage_location": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/[UUID]/volumes/[UUID]",
233+
"storage_location": "s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]",
234234
"updated_at": [UNIX_TIME_MILLIS][2],
235235
"volume_id": "[UUID]",
236236
"volume_type": "MANAGED"
@@ -239,7 +239,7 @@
239239
"storage_location": {
240240
"action": "skip",
241241
"reason": "backend_default",
242-
"remote": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/[UUID]/volumes/[UUID]"
242+
"remote": "s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]"
243243
}
244244
}
245245
}

acceptance/bundle/migrate/basic/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/dev/resources.js
2525
>>> diff out.original_state.json out.backup_state.json
2626

2727
>>> jq .state."resources.pipelines.test_pipeline".state.tags.volume_storage_location out.new_state.json
28-
"s3://deco-uc-prod-isolated-aws-us-east-1/metastore/[UUID]/volumes/[UUID]"
28+
"s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]"
2929

3030
>>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle plan
3131
Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged

acceptance/bundle/migrate/grants/out.original_state.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@
212212
"owner": "[USERNAME]",
213213
"provider_config": [],
214214
"schema_name": "schema_grants",
215-
"storage_location": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/[UUID]/volumes/[UUID]",
215+
"storage_location": "s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]",
216216
"volume_path": "/Volumes/main/schema_grants/volume_name",
217217
"volume_type": "MANAGED"
218218
},

acceptance/bundle/resource_deps/remote_field_storage_location/out.deploy.requests.direct.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"path": "/api/2.1/unity-catalog/volumes",
2222
"body": {
2323
"catalog_name": "main",
24-
"comment": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/[UUID]/volumes/[UUID]",
24+
"comment": "s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]",
2525
"name": "volumefoo-[UNIQUE_NAME]",
2626
"schema_name": "myschema-[UNIQUE_NAME]",
2727
"volume_type": "MANAGED"

acceptance/bundle/resource_deps/remote_field_storage_location/out.deploy.terraform.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ When expanding the plan for databricks_volume.foo to include new values
1010
learned so far during apply, provider
1111
"registry.terraform.io/databricks/databricks" produced an invalid new value
1212
for .comment: was null, but now
13-
cty.StringVal("s3://deco-uc-prod-isolated-aws-us-east-1/metastore/[UUID]/volumes/[UUID]").
13+
cty.StringVal("s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]").
1414

1515
This is a bug in the provider, which should be reported in the provider's own
1616
issue tracker.

acceptance/bundle/resources/grants/schemas/duplicate_principals/out.plan.direct.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"created_at": [UNIX_TIME_MILLIS][0],
1414
"created_by": "[USERNAME]",
1515
"effective_predictive_optimization_flag": {
16-
"inherited_from_name": "deco-uc-prod-isolated-aws-us-east-1",
16+
"inherited_from_name": "[METASTORE_NAME]",
1717
"inherited_from_type": "METASTORE",
1818
"value": "ENABLE"
1919
},
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
json[].principal = "[USERNAME]";
2+
json[].principal = "deco-test-user@databricks.com";
3+
json[].privileges[] = "CREATE_TABLE";
4+
json[].privileges[] = "USE_SCHEMA";

0 commit comments

Comments
 (0)