Skip to content

Commit e20eb0d

Browse files
authored
workspace server mock: import and delete files updated (#3217)
## Changes Modify import command use overwrite flag Modify delete command to parse JSON for parameters ## Why Needed for follow-up below. - testing --force-lock on pipelines: using import commands in uploading lock file - properly deleting lock file in delete command afterwards ## Tests Acceptance test for deploy in follow-up: #3250
1 parent 9ec55d5 commit e20eb0d

File tree

12 files changed

+128
-10
lines changed

12 files changed

+128
-10
lines changed

acceptance/internal/handlers.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,21 @@ func addDefaultHandlers(server *testserver.Server) {
102102
})
103103

104104
server.Handle("POST", "/api/2.0/workspace/delete", func(req testserver.Request) any {
105-
path := req.URL.Query().Get("path")
106-
recursive := req.URL.Query().Get("recursive") == "true"
107-
req.Workspace.WorkspaceDelete(path, recursive)
105+
var request workspace.Delete
106+
if err := json.Unmarshal(req.Body, &request); err != nil {
107+
return testserver.Response{
108+
Body: fmt.Sprintf("internal error: %s", err),
109+
StatusCode: 500,
110+
}
111+
}
112+
req.Workspace.WorkspaceDelete(request.Path, request.Recursive)
108113
return ""
109114
})
110115

111116
server.Handle("POST", "/api/2.0/workspace-files/import-file/{path:.*}", func(req testserver.Request) any {
112117
path := req.Vars["path"]
113-
req.Workspace.WorkspaceFilesImportFile(path, req.Body)
114-
return ""
118+
overwrite := req.URL.Query().Get("overwrite") == "true"
119+
return req.Workspace.WorkspaceFilesImportFile(path, req.Body, overwrite)
115120
})
116121

117122
server.Handle("POST", "/api/2.0/workspace/import", func(req testserver.Request) any {
@@ -141,8 +146,7 @@ func addDefaultHandlers(server *testserver.Server) {
141146
}
142147
}
143148

144-
req.Workspace.WorkspaceFilesImportFile(request.Path, decoded)
145-
return ""
149+
return req.Workspace.WorkspaceFilesImportFile(request.Path, decoded, request.Overwrite)
146150
})
147151

148152
server.Handle("GET", "/api/2.0/workspace-files/{path:.*}", func(req testserver.Request) any {
@@ -158,8 +162,8 @@ func addDefaultHandlers(server *testserver.Server) {
158162

159163
server.Handle("PUT", "/api/2.0/fs/files/{path:.*}", func(req testserver.Request) any {
160164
path := req.Vars["path"]
161-
req.Workspace.WorkspaceFilesImportFile(path, req.Body)
162-
return ""
165+
overwrite := req.URL.Query().Get("overwrite") == "true"
166+
return req.Workspace.WorkspaceFilesImportFile(path, req.Body, overwrite)
163167
})
164168

165169
server.Handle("GET", "/api/2.1/unity-catalog/current-metastore-assignment", func(req testserver.Request) any {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bundle:
2+
name: test-pipeline-force-lock
3+
4+
resources:
5+
pipelines:
6+
foo:
7+
name: test-pipeline-force-lock
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ID": "12345678-1234-1234-1234-123456789abc",
3+
"AcquisitionTime": "2024-01-15T15:40:00Z",
4+
"IsForced": false,
5+
"User": "user-with-lock@databricks.com"
6+
}
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
=== upload lock file
3+
>>> [CLI] workspace import /Workspace/Users/[USERNAME]/.bundle/test-pipeline-force-lock/default/state/deploy.lock --format AUTO --file ./deploy.lock
4+
5+
=== test deployment without force-lock (should fail)
6+
>>> errcode [PIPELINES] deploy
7+
Error: Failed to acquire deployment lock: deploy lock acquired by user-with-lock@databricks.com at [TIMESTAMP] +0000 UTC. Use --force-lock to override
8+
Error: deploy lock acquired by user-with-lock@databricks.com at [TIMESTAMP] +0000 UTC. Use --force-lock to override
9+
10+
11+
Exit code: 1
12+
13+
=== test deployment with force-lock (should succeed)
14+
>>> [PIPELINES] deploy --force-lock
15+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-pipeline-force-lock/default/files...
16+
Deploying resources...
17+
Updating deployment state...
18+
Deployment complete!
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export username=$($CLI current-user me | jq -r .userName)
2+
export MSYS_NO_PATHCONV=1
3+
title "upload lock file"
4+
trace $CLI workspace import /Workspace/Users/$username/.bundle/test-pipeline-force-lock/default/state/deploy.lock --format AUTO --file ./deploy.lock
5+
6+
title "test deployment without force-lock (should fail)"
7+
trace errcode $PIPELINES deploy
8+
9+
title "test deployment with force-lock (should succeed)"
10+
trace $PIPELINES deploy --force-lock
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bundle:
2+
name: test-pipeline-force-lock
3+
4+
resources:
5+
pipelines:
6+
foo:
7+
name: test-pipeline-force-lock
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ID": "12345678-1234-1234-1234-123456789abc",
3+
"AcquisitionTime": "2024-01-15T15:40:00Z",
4+
"IsForced": false,
5+
"User": "user-with-lock@databricks.com"
6+
}
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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
>>> errcode [PIPELINES] deploy
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-pipeline-force-lock/default/files...
4+
Deploying resources...
5+
Updating deployment state...
6+
Deployment complete!
7+
8+
=== upload lock file
9+
>>> [CLI] workspace import /Workspace/Users/[USERNAME]/.bundle/test-pipeline-force-lock/default/state/deploy.lock --format AUTO --file ./deploy.lock
10+
11+
=== test deployment without force-lock (should fail)
12+
>>> errcode [PIPELINES] destroy --auto-approve
13+
Error: Failed to acquire deployment lock: deploy lock acquired by user-with-lock@databricks.com at [TIMESTAMP] +0000 UTC. Use --force-lock to override
14+
Error: deploy lock acquired by user-with-lock@databricks.com at [TIMESTAMP] +0000 UTC. Use --force-lock to override
15+
16+
17+
Exit code: 1
18+
19+
=== test deployment with force-lock (should succeed)
20+
>>> [PIPELINES] destroy --force-lock --auto-approve
21+
The following resources will be deleted:
22+
delete pipeline foo
23+
24+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-pipeline-force-lock/default
25+
26+
Deleting files...
27+
Destroy complete!

0 commit comments

Comments
 (0)