Skip to content

Commit 87e590d

Browse files
authored
Fixed auto-purged cluster behaviour for databricks_library (#1745)
1 parent d95c89d commit 87e590d

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

libraries/libraries_api.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,16 @@ func (a LibrariesAPI) UpdateLibraries(clusterID string, add, remove ClusterLibra
7878
func (a LibrariesAPI) WaitForLibrariesInstalled(wait Wait) (result *ClusterLibraryStatuses, err error) {
7979
err = resource.RetryContext(a.context, wait.Timeout, func() *resource.RetryError {
8080
libsClusterStatus, err := a.ClusterStatus(wait.ClusterID)
81-
if common.IsMissing(err) {
82-
// eventual consistency error
83-
return resource.RetryableError(err)
84-
}
8581
if err != nil {
86-
return resource.NonRetryableError(err)
82+
apiErr, ok := err.(common.APIError)
83+
if !ok {
84+
return resource.NonRetryableError(err)
85+
}
86+
if apiErr.StatusCode != 404 && strings.Contains(apiErr.Message,
87+
fmt.Sprintf("Cluster %s does not exist", wait.ClusterID)) {
88+
apiErr.StatusCode = 404
89+
}
90+
return resource.NonRetryableError(apiErr)
8791
}
8892
if !wait.IsRunning {
8993
log.Printf("[INFO] Cluster %s is currently not running, so just returning list of %d libraries",

libraries/libraries_api_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ func TestWaitForLibrariesInstalled(t *testing.T) {
2929
Message: "internal error",
3030
},
3131
},
32+
{
33+
Method: "GET",
34+
Resource: "/api/2.0/libraries/cluster-status?cluster_id=1005-abcd",
35+
ReuseRequest: true,
36+
Status: 400,
37+
Response: common.APIError{
38+
Message: "Cluster 1005-abcd does not exist",
39+
},
40+
},
3241
{
3342
Method: "GET",
3443
Resource: "/api/2.0/libraries/cluster-status?cluster_id=still-installing",
@@ -114,6 +123,15 @@ func TestWaitForLibrariesInstalled(t *testing.T) {
114123
"failed-wheel", 50 * time.Millisecond, true, true,
115124
})
116125
assert.NoError(t, err, "library should have been uninstalled and work proceeded")
126+
127+
// Cluster not available or doesn't exist
128+
_, err = libs.WaitForLibrariesInstalled(Wait{
129+
"1005-abcd", 50 * time.Millisecond, false, false,
130+
})
131+
132+
ae, _ := err.(common.APIError)
133+
assert.Equal(t, 404, ae.StatusCode)
134+
assert.Equal(t, "Cluster 1005-abcd does not exist", ae.Message)
117135
})
118136
}
119137

0 commit comments

Comments
 (0)