Skip to content

Commit 1a7fe3f

Browse files
authored
direct: volumes: fix updating the name (#3349)
## Changes - Add missing setting for volumes: UpdateUpdatesID. Without it, updating the name fails with internal error. - Update testserver to properly handle name updates. ## Why Follow up to #3342 ## Tests New acceptance test.
1 parent 7cab8e7 commit 1a7fe3f

File tree

9 files changed

+129
-17
lines changed

9 files changed

+129
-17
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
Ignore = [
2-
"tmp.summary.txt",
32
".databricks",
43
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
resources:
2+
volumes:
3+
volume1:
4+
catalog_name: main
5+
schema_name: myschema
6+
name: myvolume
7+
comment: COMMENT1
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: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
>>> [CLI] bundle deploy
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
4+
Deploying resources...
5+
Updating deployment state...
6+
Deployment complete!
7+
8+
>>> print_requests
9+
{
10+
"method": "POST",
11+
"path": "/api/2.1/unity-catalog/volumes",
12+
"body": {
13+
"catalog_name": "main",
14+
"comment": "COMMENT1",
15+
"name": "myvolume",
16+
"schema_name": "myschema",
17+
"volume_type": "MANAGED"
18+
}
19+
}
20+
21+
=== Summary should now show id and url
22+
{
23+
"volumes": {
24+
"volume1": {
25+
"catalog_name": "main",
26+
"comment": "COMMENT1",
27+
"id": "main.myschema.myvolume",
28+
"name": "myvolume",
29+
"schema_name": "myschema",
30+
"url": "[DATABRICKS_URL]/explore/data/volumes/main/myschema/myvolume?o=[NUMID]",
31+
"volume_type": "MANAGED"
32+
}
33+
}
34+
}
35+
36+
=== Update name
37+
>>> update_file.py databricks.yml myvolume mynewvolume
38+
39+
>>> [CLI] bundle plan
40+
update volumes.volume1
41+
42+
>>> [CLI] bundle deploy
43+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
44+
Deploying resources...
45+
Updating deployment state...
46+
Deployment complete!
47+
48+
>>> print_requests
49+
{
50+
"method": "PATCH",
51+
"path": "/api/2.1/unity-catalog/volumes/main.myschema.myvolume",
52+
"body": {
53+
"comment": "COMMENT1",
54+
"new_name": "mynewvolume"
55+
}
56+
}
57+
58+
>>> [CLI] volumes read main.myschema.mynewvolume
59+
{
60+
"catalog_name":"main",
61+
"comment":"COMMENT1",
62+
"full_name":"main.myschema.mynewvolume",
63+
"name":"mynewvolume",
64+
"schema_name":"myschema",
65+
"volume_type":"MANAGED"
66+
}
67+
68+
>>> musterr [CLI] volumes read main.myschema.myvolume
69+
Error: Resource catalog.VolumeInfo not found: main.myschema.myvolume
70+
71+
Exit code (musterr): 1
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
trace $CLI bundle deploy
2+
3+
print_requests() {
4+
jq 'select(.method != "GET" and (.path | contains("/unity")))' < out.requests.txt
5+
rm out.requests.txt
6+
}
7+
8+
trace print_requests
9+
10+
title "Summary should now show id and url\n"
11+
$CLI bundle summary -o json | jq .resources
12+
13+
title "Update name"
14+
trace update_file.py databricks.yml myvolume mynewvolume
15+
16+
trace $CLI bundle plan
17+
trace $CLI bundle deploy
18+
trace print_requests
19+
20+
trace $CLI volumes read main.myschema.mynewvolume
21+
trace musterr $CLI volumes read main.myschema.myvolume
22+
rm out.requests.txt
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Ignore = [
2+
".databricks",
3+
]
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
Ignore = [
2-
"tmp.summary.txt",
32
".databricks",
43
]

bundle/terranova/resource.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ var SupportedResources = map[string]ResourceSettings{
9494
),
9595
},
9696
"volumes": {
97-
New: reflect.ValueOf(tnresources.NewResourceVolume),
98-
ConfigType: TypeOfConfig(&tnresources.ResourceVolume{}),
99-
DeleteFN: tnresources.DeleteVolume,
97+
New: reflect.ValueOf(tnresources.NewResourceVolume),
98+
ConfigType: TypeOfConfig(&tnresources.ResourceVolume{}),
99+
DeleteFN: tnresources.DeleteVolume,
100+
UpdateUpdatesID: true,
100101
// TF: https://github.com/databricks/terraform-provider-databricks/blob/f5fce0f/catalog/resource_volume.go#L19
101102
RecreateFields: mkMap(
102103
".catalog_name",

libs/testserver/volumes.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"net/http"
77

8-
"dario.cat/mergo"
98
"github.com/databricks/databricks-sdk-go/service/catalog"
109
)
1110

@@ -29,34 +28,40 @@ func (s *FakeWorkspace) VolumesCreate(req Request) Response {
2928
}
3029
}
3130

32-
func (s *FakeWorkspace) VolumesUpdate(req Request, name string) Response {
31+
func (s *FakeWorkspace) VolumesUpdate(req Request, fullname string) Response {
3332
defer s.LockUnlock()()
3433

35-
existing, ok := s.Volumes[name]
34+
existing, ok := s.Volumes[fullname]
3635
if !ok {
3736
return Response{
3837
StatusCode: 404,
3938
}
4039
}
4140

42-
var volume catalog.VolumeInfo
41+
var request catalog.UpdateVolumeRequestContent
4342

44-
if err := json.Unmarshal(req.Body, &volume); err != nil {
43+
if err := json.Unmarshal(req.Body, &request); err != nil {
4544
return Response{
4645
Body: fmt.Sprintf("internal error: %s", err),
4746
StatusCode: http.StatusInternalServerError,
4847
}
4948
}
5049

51-
err := mergo.Merge(&existing, volume, mergo.WithOverride)
52-
if err != nil {
53-
return Response{
54-
Body: fmt.Sprintf("mergo error: %s", err),
55-
StatusCode: http.StatusInternalServerError,
56-
}
50+
if request.Comment != "" {
51+
existing.Comment = request.Comment
52+
}
53+
54+
if request.Owner != "" {
55+
existing.Owner = request.Owner
56+
}
57+
58+
if request.NewName != "" {
59+
delete(s.Volumes, fullname)
60+
existing.Name = request.NewName
61+
existing.FullName = existing.CatalogName + "." + existing.SchemaName + "." + request.NewName
5762
}
5863

59-
s.Volumes[name] = existing
64+
s.Volumes[existing.FullName] = existing
6065
return Response{
6166
Body: existing,
6267
}

0 commit comments

Comments
 (0)