Skip to content

Commit d69832f

Browse files
authored
acc: Add ACC_REPLS feature (#3330)
## Changes Support ACC_REPLS in acceptance test scrips. ## Why This allows scripts to add dynamic ids to replacement set. Currently resource ids are replaced by a generic replacement like [NUMID] which does not allow to test if it's changed, e.g. in recreation case. ## Tests New selftest; update a few tests to use this to highlight resource ids.
1 parent a5d0248 commit d69832f

File tree

11 files changed

+89
-34
lines changed

11 files changed

+89
-34
lines changed

acceptance/acceptance_test.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ const (
8080
// e.g. ENVFILTER=SERVERLESS=yes will run all tests that run SERVERLESS to "yes"
8181
// The tests the don't set SERVERLESS variable or set to empty string will also be run.
8282
EnvFilterVar = "ENVFILTER"
83+
84+
// File where scripts can output custom replacements
85+
// export $job_id=100200300
86+
// $ echo "$job_id:MY_JOB" >> ACC_REPLS # This will replace 100200300 with [MY_JOB] in the output
87+
// TODO: this should be merged with repls.json functionality, currently these replacements are not parsed by diff.py
88+
userReplacementsFilename = "ACC_REPLS"
8389
)
8490

8591
// On CI, we want to increase timeout, to account for slower environment
@@ -101,7 +107,8 @@ var Scripts = map[string]bool{
101107
}
102108

103109
var Ignored = map[string]bool{
104-
ReplsFile: true,
110+
ReplsFile: true,
111+
userReplacementsFilename: true,
105112
}
106113

107114
func TestAccept(t *testing.T) {
@@ -605,6 +612,8 @@ func runTest(t *testing.T,
605612
formatOutput(out, err)
606613
require.NoError(t, out.Close())
607614

615+
loadUserReplacements(t, &repls, tmpDir)
616+
608617
printedRepls := false
609618

610619
// Compare expected outputs
@@ -1208,3 +1217,26 @@ func BuildYamlfmt(t *testing.T) {
12081217
}
12091218
RunCommand(t, args, "..")
12101219
}
1220+
1221+
func loadUserReplacements(t *testing.T, repls *testdiff.ReplacementsContext, tmpDir string) {
1222+
b, err := os.ReadFile(filepath.Join(tmpDir, userReplacementsFilename))
1223+
if os.IsNotExist(err) {
1224+
return
1225+
}
1226+
require.NoError(t, err)
1227+
lines := strings.Split(string(b), "\n")
1228+
for _, line := range lines {
1229+
line = strings.TrimSpace(line)
1230+
if len(line) == 0 {
1231+
continue
1232+
}
1233+
items := strings.Split(line, ":")
1234+
if len(items) <= 1 {
1235+
t.Errorf("Error parsing %s: %#v", userReplacementsFilename, line)
1236+
continue
1237+
}
1238+
repl := items[len(items)-1]
1239+
old := line[:len(line)-len(repl)-1]
1240+
repls.SetWithOrder(old, "["+repl+"]", -100)
1241+
}
1242+
}

acceptance/bundle/deploy/jobs/check-metadata/output.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Deployment complete!
4747
},
4848
"edit_mode": "UI_LOCKED",
4949
"format": "MULTI_TASK",
50-
"id": "[NUMID]",
50+
"id": "[JOB_1_ID]",
5151
"max_concurrent_runs": 1,
5252
"name": "test-job-metadata-1-[UNIQUE_NAME]",
5353
"permissions": [],
@@ -67,7 +67,7 @@ Deployment complete!
6767
"task_key": "my_notebook_task"
6868
}
6969
],
70-
"url": "[DATABRICKS_URL]/jobs/[NUMID]"
70+
"url": "[DATABRICKS_URL]/jobs/[JOB_1_ID]"
7171
}
7272

7373
=== Assert job 1 is created
@@ -98,11 +98,11 @@ Deployment complete!
9898
"resources": {
9999
"jobs": {
100100
"bar": {
101-
"id": "[NUMID]",
101+
"id": "[JOB_2_ID]",
102102
"relative_path": "a/b/resources.yml"
103103
},
104104
"foo": {
105-
"id": "[NUMID]",
105+
"id": "[JOB_1_ID]",
106106
"relative_path": "databricks.yml"
107107
}
108108
}
@@ -111,10 +111,10 @@ Deployment complete!
111111
}
112112
=== Check that metadata contains created job ids
113113
>>> cat metadata.json
114-
"id": "[NUMID]",
114+
"id": "[JOB_1_ID]",
115115

116116
>>> cat metadata.json
117-
"id": "[NUMID]",
117+
"id": "[JOB_2_ID]",
118118

119119
>>> [CLI] bundle destroy --auto-approve
120120
The following resources will be deleted:

acceptance/bundle/deploy/jobs/check-metadata/script

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ title "Second summary, should have id and modified status should be absent"
1414
trace $CLI bundle summary -o json | jq '.resources.jobs.foo' > out.summary.json
1515
trace cat out.summary.json
1616
JOB_1_ID=$(jq -r '.id' out.summary.json)
17+
echo "$JOB_1_ID:JOB_1_ID" >> ACC_REPLS
1718
rm out.summary.json
1819
title "Assert job 1 is created\n"
1920
$CLI jobs get "${JOB_1_ID}" | jq '{name: .settings.name}'
2021

2122
title "Assert job 2 is created\n"
2223
JOB_2_ID=$($CLI bundle summary -o json | jq -r '.resources.jobs.bar.id')
24+
echo "$JOB_2_ID:JOB_2_ID" >> ACC_REPLS
2325
$CLI jobs get "${JOB_2_ID}" | jq '{name: .settings.name}'
2426

2527
title "Read metadata object from the workspace"

acceptance/bundle/resources/jobs/update/output.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Deployment complete!
3939
"method": "POST",
4040
"path": "/api/2.2/jobs/create"
4141
}
42-
jobs foo id='[NUMID]' name='foo'
42+
jobs foo id='[JOB_ID]' name='foo'
4343

4444
=== Update trigger.periodic.unit and re-deploy
4545
>>> update_file.py databricks.yml DAYS HOURS
@@ -53,7 +53,7 @@ Deployment complete!
5353
>>> print_requests
5454
{
5555
"body": {
56-
"job_id": [NUMID],
56+
"job_id": [JOB_ID],
5757
"new_settings": {
5858
"deployment": {
5959
"kind": "BUNDLE",
@@ -87,12 +87,12 @@ Deployment complete!
8787
"method": "POST",
8888
"path": "/api/2.2/jobs/reset"
8989
}
90-
jobs foo id='[NUMID]' name='foo'
90+
jobs foo id='[JOB_ID]' name='foo'
9191

9292
=== Fetch job ID and verify remote state
93-
>>> [CLI] jobs get [NUMID]
93+
>>> [CLI] jobs get [JOB_ID]
9494
{
95-
"job_id":[NUMID],
95+
"job_id":[JOB_ID],
9696
"settings": {
9797
"deployment": {
9898
"kind":"BUNDLE",
@@ -137,14 +137,14 @@ Destroy complete!
137137
>>> print_requests
138138
{
139139
"body": {
140-
"job_id": [NUMID]
140+
"job_id": [JOB_ID]
141141
},
142142
"method": "POST",
143143
"path": "/api/2.2/jobs/delete"
144144
}
145145
State not found for jobs.foo
146146

147-
>>> musterr [CLI] jobs get [NUMID]
147+
>>> musterr [CLI] jobs get [JOB_ID]
148148
Error: Not Found
149149

150150
Exit code (musterr): 1

acceptance/bundle/resources/jobs/update/script

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ trace print_requests
1717
title "Fetch job ID and verify remote state"
1818

1919
ppid=`read_id.py jobs foo`
20+
echo "$ppid:JOB_ID" >> ACC_REPLS
2021

2122
trace $CLI jobs get $ppid
2223
rm out.requests.txt

acceptance/bundle/resources/pipelines/output.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Deployment complete!
2626
"method": "POST",
2727
"path": "/api/2.0/pipelines"
2828
}
29-
pipelines my id='[UUID]' name='test-pipeline-[UNIQUE_NAME]'
29+
pipelines my id='[PIPELINE_ID]' name='test-pipeline-[UNIQUE_NAME]'
3030

3131
>>> update_file.py databricks.yml foo.py bar.py
3232

@@ -37,12 +37,12 @@ Updating deployment state...
3737
Deployment complete!
3838

3939
=== Fetch pipeline ID and verify remote state
40-
>>> [CLI] pipelines get [UUID]
40+
>>> [CLI] pipelines get [PIPELINE_ID]
4141
{
4242
"creator_user_name":"[USERNAME]",
4343
"last_modified":[UNIX_TIME_MILLIS],
4444
"name":"test-pipeline-[UNIQUE_NAME]",
45-
"pipeline_id":"[UUID]",
45+
"pipeline_id":"[PIPELINE_ID]",
4646
"run_as_user_name":"[USERNAME]",
4747
"spec": {
4848
"channel":"CURRENT",
@@ -51,7 +51,7 @@ Deployment complete!
5151
"metadata_file_path":"/Workspace/Users/[USERNAME]/.bundle/acc-[UNIQUE_NAME]/default/state/metadata.json"
5252
},
5353
"edition":"ADVANCED",
54-
"id":"[UUID]",
54+
"id":"[PIPELINE_ID]",
5555
"libraries": [
5656
{
5757
"file": {
@@ -60,7 +60,7 @@ Deployment complete!
6060
}
6161
],
6262
"name":"test-pipeline-[UNIQUE_NAME]",
63-
"storage":"dbfs:/pipelines/[UUID]"
63+
"storage":"dbfs:/pipelines/[PIPELINE_ID]"
6464
},
6565
"state":"IDLE"
6666
}
@@ -78,11 +78,11 @@ Destroy complete!
7878
>>> print_requests
7979
{
8080
"method": "DELETE",
81-
"path": "/api/2.0/pipelines/[UUID]"
81+
"path": "/api/2.0/pipelines/[PIPELINE_ID]"
8282
}
8383
State not found for pipelines.my
8484

85-
>>> musterr [CLI] pipelines get [UUID]
86-
Error: The specified pipeline [UUID] was not found.
85+
>>> musterr [CLI] pipelines get [PIPELINE_ID]
86+
Error: The specified pipeline [PIPELINE_ID] was not found.
8787

8888
Exit code (musterr): 1

acceptance/bundle/resources/pipelines/script

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ trace $CLI bundle deploy
1717
# fields that it previously received from the backend.
1818
# The get call below verifies that it does not matter -- the pipeline is the same in the end.
1919
#trace print_requests
20-
21-
ppid=`read_id.py pipelines my`
2220
rm out.requests.txt
2321

2422
title "Fetch pipeline ID and verify remote state"
2523

2624
ppid=`read_id.py pipelines my`
25+
echo "$ppid:PIPELINE_ID" >> ACC_REPLS
2726
trace $CLI pipelines get $ppid
2827
rm out.requests.txt
2928

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Local = true
2+
Cloud = false
3+
4+
[EnvMatrix]
5+
DATABRICKS_CLI_DEPLOYMENT = ["terraform", "direct-exp"]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
my job is [JOB_ID]
2+
echo "$job_id:JOB_ID" >> ACC_REPLS
3+
echo "[MY_TEXT]:MY_TEXT" >> ACC_REPLS
4+
grep ACC_REPLS script
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
job_id=100200300
2+
echo "my job is $job_id"
3+
echo "$job_id:JOB_ID" >> ACC_REPLS
4+
echo "ABCD:EFG:MY_TEXT" >> ACC_REPLS
5+
6+
grep ACC_REPLS script

0 commit comments

Comments
 (0)