Skip to content

Commit

Permalink
Fixed auto-purged cluster behaviour for databricks_library (#1745)
Browse files Browse the repository at this point in the history
  • Loading branch information
yugireddy-db committed Nov 10, 2022
1 parent d95c89d commit 87e590d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
14 changes: 9 additions & 5 deletions libraries/libraries_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,16 @@ func (a LibrariesAPI) UpdateLibraries(clusterID string, add, remove ClusterLibra
func (a LibrariesAPI) WaitForLibrariesInstalled(wait Wait) (result *ClusterLibraryStatuses, err error) {
err = resource.RetryContext(a.context, wait.Timeout, func() *resource.RetryError {
libsClusterStatus, err := a.ClusterStatus(wait.ClusterID)
if common.IsMissing(err) {
// eventual consistency error
return resource.RetryableError(err)
}
if err != nil {
return resource.NonRetryableError(err)
apiErr, ok := err.(common.APIError)
if !ok {
return resource.NonRetryableError(err)
}
if apiErr.StatusCode != 404 && strings.Contains(apiErr.Message,
fmt.Sprintf("Cluster %s does not exist", wait.ClusterID)) {
apiErr.StatusCode = 404
}
return resource.NonRetryableError(apiErr)
}
if !wait.IsRunning {
log.Printf("[INFO] Cluster %s is currently not running, so just returning list of %d libraries",
Expand Down
18 changes: 18 additions & 0 deletions libraries/libraries_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ func TestWaitForLibrariesInstalled(t *testing.T) {
Message: "internal error",
},
},
{
Method: "GET",
Resource: "/api/2.0/libraries/cluster-status?cluster_id=1005-abcd",
ReuseRequest: true,
Status: 400,
Response: common.APIError{
Message: "Cluster 1005-abcd does not exist",
},
},
{
Method: "GET",
Resource: "/api/2.0/libraries/cluster-status?cluster_id=still-installing",
Expand Down Expand Up @@ -114,6 +123,15 @@ func TestWaitForLibrariesInstalled(t *testing.T) {
"failed-wheel", 50 * time.Millisecond, true, true,
})
assert.NoError(t, err, "library should have been uninstalled and work proceeded")

// Cluster not available or doesn't exist
_, err = libs.WaitForLibrariesInstalled(Wait{
"1005-abcd", 50 * time.Millisecond, false, false,
})

ae, _ := err.(common.APIError)
assert.Equal(t, 404, ae.StatusCode)
assert.Equal(t, "Cluster 1005-abcd does not exist", ae.Message)
})
}

Expand Down

0 comments on commit 87e590d

Please sign in to comment.