From 448fbf0dfb070698cca1258fd163d12afbfc70ad Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Thu, 26 Nov 2026 15:26:31 +0000 Subject: [PATCH 1/7] direct: treat a cluster's 400 "does not exist" as not found Co-authored-by: Isaac --- .nextchanges/bundles/cluster-missing-400.md | 1 + .../deleted-out-of-band/databricks.yml | 10 ++++ .../deleted-out-of-band/out.test.toml | 2 + .../clusters/deleted-out-of-band/output.txt | 21 +++++++ .../clusters/deleted-out-of-band/script | 29 ++++++++++ .../clusters/deleted-out-of-band/state.json | 17 ++++++ .../clusters/deleted-out-of-band/test.toml | 9 +++ bundle/direct/dresources/cluster.go | 49 +++++++++++----- bundle/direct/dresources/cluster_test.go | 56 +++++++++++++++++++ libs/testserver/clusters.go | 18 +++++- libs/testserver/libraries.go | 2 +- 11 files changed, 199 insertions(+), 15 deletions(-) create mode 100644 .nextchanges/bundles/cluster-missing-400.md create mode 100644 acceptance/bundle/resources/clusters/deleted-out-of-band/databricks.yml create mode 100644 acceptance/bundle/resources/clusters/deleted-out-of-band/out.test.toml create mode 100644 acceptance/bundle/resources/clusters/deleted-out-of-band/output.txt create mode 100644 acceptance/bundle/resources/clusters/deleted-out-of-band/script create mode 100644 acceptance/bundle/resources/clusters/deleted-out-of-band/state.json create mode 100644 acceptance/bundle/resources/clusters/deleted-out-of-band/test.toml diff --git a/.nextchanges/bundles/cluster-missing-400.md b/.nextchanges/bundles/cluster-missing-400.md new file mode 100644 index 00000000000..d2c6693ef88 --- /dev/null +++ b/.nextchanges/bundles/cluster-missing-400.md @@ -0,0 +1 @@ +* Fix `bundle deploy` and `bundle destroy` with the direct engine sometimes failing with "Cluster ... does not exist" when a cluster in the state was already deleted. diff --git a/acceptance/bundle/resources/clusters/deleted-out-of-band/databricks.yml b/acceptance/bundle/resources/clusters/deleted-out-of-band/databricks.yml new file mode 100644 index 00000000000..6a2aef3b6b3 --- /dev/null +++ b/acceptance/bundle/resources/clusters/deleted-out-of-band/databricks.yml @@ -0,0 +1,10 @@ +bundle: + name: test-bundle + +resources: + clusters: + foo: + cluster_name: foo + spark_version: 13.3.x-scala2.12 + node_type_id: i3.xlarge + num_workers: 1 diff --git a/acceptance/bundle/resources/clusters/deleted-out-of-band/out.test.toml b/acceptance/bundle/resources/clusters/deleted-out-of-band/out.test.toml new file mode 100644 index 00000000000..a927a5fbc06 --- /dev/null +++ b/acceptance/bundle/resources/clusters/deleted-out-of-band/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/clusters/deleted-out-of-band/output.txt b/acceptance/bundle/resources/clusters/deleted-out-of-band/output.txt new file mode 100644 index 00000000000..0b1b7dc9667 --- /dev/null +++ b/acceptance/bundle/resources/clusters/deleted-out-of-band/output.txt @@ -0,0 +1,21 @@ + +=== deploy: the cluster is removed from config + +>>> [CLI] bundle deploy --auto-approve +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Files: 3 uploaded, 0 deleted +Resources: 0 created, 0 changed, 0 deleted, 0 unchanged + +>>> print_state.py +[] + +=== destroy + +>>> [CLI] bundle destroy --auto-approve +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default + +Destroy: 0 deleted + +>>> print_state.py + +>>> print_requests.py //clusters/permanent-delete diff --git a/acceptance/bundle/resources/clusters/deleted-out-of-band/script b/acceptance/bundle/resources/clusters/deleted-out-of-band/script new file mode 100644 index 00000000000..af6f9cf8c1f --- /dev/null +++ b/acceptance/bundle/resources/clusters/deleted-out-of-band/script @@ -0,0 +1,29 @@ +# The state points at a cluster that was deleted out of band. The backend answers every +# cluster endpoint for it with 400 INVALID_PARAMETER_VALUE "does not exist"; the stub in +# test.toml delays the cluster GET so the library-status GET answers first. +seed_state() { + mkdir -p .databricks/bundle/default + cp state.json .databricks/bundle/default/resources.json + $CLI workspace mkdirs /Workspace/Users/$CURRENT_USER_NAME/.bundle/test-bundle/default +} + +title "deploy: the cluster is removed from config" +seed_state +cp databricks.yml databricks.yml.orig +update_file.py databricks.yml " clusters: + foo: + cluster_name: foo + spark_version: 13.3.x-scala2.12 + node_type_id: i3.xlarge + num_workers: 1 +" " {} +" +trace $CLI bundle deploy --auto-approve +trace print_state.py | jq -c ".state | keys" + +title "destroy" +mv databricks.yml.orig databricks.yml +seed_state +trace $CLI bundle destroy --auto-approve +trace print_state.py | jq -c ".state | keys" +trace print_requests.py //clusters/permanent-delete diff --git a/acceptance/bundle/resources/clusters/deleted-out-of-band/state.json b/acceptance/bundle/resources/clusters/deleted-out-of-band/state.json new file mode 100644 index 00000000000..8f23d562971 --- /dev/null +++ b/acceptance/bundle/resources/clusters/deleted-out-of-band/state.json @@ -0,0 +1,17 @@ +{ + "state_version": 3, + "lineage": "test-lineage", + "serial": 1, + "state": { + "resources.clusters.foo": { + "__id__": "1126-000000-deleted0", + "state": { + "autotermination_minutes": 60, + "cluster_name": "foo", + "node_type_id": "i3.xlarge", + "num_workers": 1, + "spark_version": "13.3.x-scala2.12" + } + } + } +} diff --git a/acceptance/bundle/resources/clusters/deleted-out-of-band/test.toml b/acceptance/bundle/resources/clusters/deleted-out-of-band/test.toml new file mode 100644 index 00000000000..578bacbb3f3 --- /dev/null +++ b/acceptance/bundle/resources/clusters/deleted-out-of-band/test.toml @@ -0,0 +1,9 @@ +Cloud = false +RecordRequests = true +Ignore = [".databricks/", "databricks.yml.orig"] + +[[Server]] +Pattern = "GET /api/2.1/clusters/get" +Delay = "300ms" +Response.StatusCode = 400 +Response.Body = '''{"error_code": "INVALID_PARAMETER_VALUE", "message": "Cluster 1126-000000-deleted0 does not exist"}''' diff --git a/bundle/direct/dresources/cluster.go b/bundle/direct/dresources/cluster.go index f1e85872cc7..79282e9b440 100644 --- a/bundle/direct/dresources/cluster.go +++ b/bundle/direct/dresources/cluster.go @@ -4,7 +4,10 @@ import ( "context" "errors" "fmt" + "net/http" + "regexp" "strings" + "sync" "time" "github.com/databricks/cli/bundle/config/resources" @@ -17,7 +20,6 @@ import ( "github.com/databricks/databricks-sdk-go/marshal" "github.com/databricks/databricks-sdk-go/retries" "github.com/databricks/databricks-sdk-go/service/compute" - "golang.org/x/sync/errgroup" ) // librariesWaitTimeout bounds how long we poll for libraries to finish installing. @@ -153,19 +155,24 @@ func (r *ResourceCluster) DoRead(ctx context.Context, id string) (*ClusterRemote var libraries []compute.Library // The cluster GET and the library-status GET are independent, so run them concurrently. - g, ctx := errgroup.WithContext(ctx) - g.Go(func() error { - var err error - details, err = r.client.Clusters.GetByClusterId(ctx, id) - return err + // The cluster GET error takes precedence: for a deleted cluster both endpoints fail with + // 400 INVALID_PARAMETER_VALUE, but the SDK maps only the cluster GET one to + // ErrResourceDoesNotExist, so returning whichever error came first would make a missing + // cluster look like a read failure at random. + var detailsErr, librariesErr error + var wg sync.WaitGroup + wg.Go(func() { + details, detailsErr = r.client.Clusters.GetByClusterId(ctx, id) }) - g.Go(func() error { - var err error - libraries, err = r.readLibraries(ctx, id) - return err + wg.Go(func() { + libraries, librariesErr = r.readLibraries(ctx, id) }) - if err := g.Wait(); err != nil { - return nil, err + wg.Wait() + if detailsErr != nil { + return nil, detailsErr + } + if librariesErr != nil { + return nil, librariesErr } remote := &ClusterRemote{ @@ -371,7 +378,23 @@ func (r *ResourceCluster) DoResize(ctx context.Context, id string, config *Clust } func (r *ResourceCluster) DoDelete(ctx context.Context, id string, _ *ClusterState) error { - return r.client.Clusters.PermanentDeleteByClusterId(ctx, id) + err := r.client.Clusters.PermanentDeleteByClusterId(ctx, id) + if isClusterDoesNotExist(err) { + // The backend reports a missing cluster as 400 INVALID_PARAMETER_VALUE, not 404. + return fmt.Errorf("%w: %w", apierr.ErrResourceDoesNotExist, err) + } + return err +} + +// clusterDoesNotExistMessage matches the backend message for a missing cluster; the SDK applies +// the same match to the cluster GET only. +var clusterDoesNotExistMessage = regexp.MustCompile(`Cluster .* does not exist`) + +func isClusterDoesNotExist(err error) bool { + apiErr, ok := errors.AsType[*apierr.APIError](err) + return ok && apiErr.StatusCode == http.StatusBadRequest && + apiErr.ErrorCode == "INVALID_PARAMETER_VALUE" && + clusterDoesNotExistMessage.MatchString(apiErr.Message) } func (r *ResourceCluster) OverrideChangeDesc(ctx context.Context, p *structpath.PathNode, change *ChangeDesc, remoteState *ClusterRemote) error { diff --git a/bundle/direct/dresources/cluster_test.go b/bundle/direct/dresources/cluster_test.go index 7d3af4440d4..bfa70ace89c 100644 --- a/bundle/direct/dresources/cluster_test.go +++ b/bundle/direct/dresources/cluster_test.go @@ -1,10 +1,16 @@ package dresources import ( + "encoding/json" + "net/http" "testing" + "time" "github.com/databricks/cli/bundle/deployplan" "github.com/databricks/cli/libs/structs/structpath" + "github.com/databricks/cli/libs/testserver" + "github.com/databricks/databricks-sdk-go" + "github.com/databricks/databricks-sdk-go/apierr" "github.com/databricks/databricks-sdk-go/service/compute" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -66,3 +72,53 @@ func TestClusterOverrideChangeDescLibraries(t *testing.T) { }) } } + +func clusterDoesNotExistResponse(id string) testserver.Response { + return testserver.Response{ + StatusCode: http.StatusBadRequest, + Body: map[string]string{ + "error_code": "INVALID_PARAMETER_VALUE", + "message": "Cluster " + id + " does not exist", + }, + } +} + +// For a deleted cluster the backend answers every cluster endpoint with 400 +// INVALID_PARAMETER_VALUE; only the cluster GET is mapped to not-found by the SDK. +func newMissingClusterResource(t *testing.T) *ResourceCluster { + server := testserver.New(t) + server.Handle("GET", "/api/2.1/clusters/get", func(req testserver.Request) any { + // Answer after the library-status GET, so its unmapped error comes first. + time.Sleep(100 * time.Millisecond) + return clusterDoesNotExistResponse(req.URL.Query().Get("cluster_id")) + }) + server.Handle("GET", "/api/2.0/libraries/cluster-status", func(req testserver.Request) any { + return clusterDoesNotExistResponse(req.URL.Query().Get("cluster_id")) + }) + server.Handle("POST", "/api/2.1/clusters/permanent-delete", func(req testserver.Request) any { + var request compute.PermanentDeleteCluster + require.NoError(t, json.Unmarshal(req.Body, &request)) + return clusterDoesNotExistResponse(request.ClusterId) + }) + + client, err := databricks.NewWorkspaceClient(&databricks.Config{ + Host: server.URL, + Token: "testtoken", + }) + require.NoError(t, err) + return (&ResourceCluster{}).New(client).(*ResourceCluster) +} + +func TestClusterDoReadMissingCluster(t *testing.T) { + r := newMissingClusterResource(t) + _, err := r.DoRead(t.Context(), "1126-000000-abcdefgh") + require.Error(t, err) + assert.True(t, apierr.IsMissing(err), "expected a not-found error, got %v", err) +} + +func TestClusterDoDeleteMissingCluster(t *testing.T) { + r := newMissingClusterResource(t) + err := r.DoDelete(t.Context(), "1126-000000-abcdefgh", nil) + require.Error(t, err) + assert.True(t, apierr.IsMissing(err), "expected a not-found error, got %v", err) +} diff --git a/libs/testserver/clusters.go b/libs/testserver/clusters.go index 1451efb9317..7e7952386c8 100644 --- a/libs/testserver/clusters.go +++ b/libs/testserver/clusters.go @@ -3,6 +3,7 @@ package testserver import ( "encoding/json" "fmt" + "net/http" "os" "github.com/databricks/cli/libs/structs/structaccess" @@ -208,7 +209,7 @@ func (s *FakeWorkspace) ClustersGet(req Request, clusterId string) any { cluster, ok := s.Clusters[clusterId] if !ok { - return Response{StatusCode: 404} + return clusterDoesNotExist(clusterId) } // Simulate cluster startup: transition PENDING → RUNNING so that WaitGetClusterRunning @@ -276,6 +277,21 @@ func (s *FakeWorkspace) ClustersPermanentDelete(req Request) any { } defer s.LockUnlock()() + if _, ok := s.Clusters[request.ClusterId]; !ok { + return clusterDoesNotExist(request.ClusterId) + } delete(s.Clusters, request.ClusterId) return Response{} } + +// clusterDoesNotExist is how the cloud answers cluster and library-status requests for a +// missing cluster: 400 INVALID_PARAMETER_VALUE rather than 404. +func clusterDoesNotExist(clusterId string) Response { + return Response{ + StatusCode: http.StatusBadRequest, + Body: map[string]string{ + "error_code": "INVALID_PARAMETER_VALUE", + "message": "Cluster " + clusterId + " does not exist", + }, + } +} diff --git a/libs/testserver/libraries.go b/libs/testserver/libraries.go index 63042ca8e66..6f58e05f9b9 100644 --- a/libs/testserver/libraries.go +++ b/libs/testserver/libraries.go @@ -57,7 +57,7 @@ func (s *FakeWorkspace) LibrariesClusterStatus(req Request, clusterId string) an defer s.LockUnlock()() if _, ok := s.Clusters[clusterId]; !ok { - return Response{StatusCode: http.StatusNotFound} + return clusterDoesNotExist(clusterId) } installed := s.ClusterLibraries[clusterId] From 0e93de10c90d0d4efb64cb4f41bc93a357a6451a Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Thu, 26 Nov 2026 15:28:30 +0000 Subject: [PATCH 2/7] Reuse the fake workspace in the cluster unit tests Co-authored-by: Isaac --- bundle/direct/dresources/cluster_test.go | 29 ++++-------------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/bundle/direct/dresources/cluster_test.go b/bundle/direct/dresources/cluster_test.go index bfa70ace89c..20790d16209 100644 --- a/bundle/direct/dresources/cluster_test.go +++ b/bundle/direct/dresources/cluster_test.go @@ -1,8 +1,6 @@ package dresources import ( - "encoding/json" - "net/http" "testing" "time" @@ -73,33 +71,16 @@ func TestClusterOverrideChangeDescLibraries(t *testing.T) { } } -func clusterDoesNotExistResponse(id string) testserver.Response { - return testserver.Response{ - StatusCode: http.StatusBadRequest, - Body: map[string]string{ - "error_code": "INVALID_PARAMETER_VALUE", - "message": "Cluster " + id + " does not exist", - }, - } -} - -// For a deleted cluster the backend answers every cluster endpoint with 400 -// INVALID_PARAMETER_VALUE; only the cluster GET is mapped to not-found by the SDK. +// The fake workspace answers library-status and permanent-delete for a missing cluster with the +// cloud's 400 INVALID_PARAMETER_VALUE, which the SDK does not map to not-found. The cluster GET +// (which the SDK does map) is delayed so the library-status error arrives first. func newMissingClusterResource(t *testing.T) *ResourceCluster { server := testserver.New(t) server.Handle("GET", "/api/2.1/clusters/get", func(req testserver.Request) any { - // Answer after the library-status GET, so its unmapped error comes first. time.Sleep(100 * time.Millisecond) - return clusterDoesNotExistResponse(req.URL.Query().Get("cluster_id")) - }) - server.Handle("GET", "/api/2.0/libraries/cluster-status", func(req testserver.Request) any { - return clusterDoesNotExistResponse(req.URL.Query().Get("cluster_id")) - }) - server.Handle("POST", "/api/2.1/clusters/permanent-delete", func(req testserver.Request) any { - var request compute.PermanentDeleteCluster - require.NoError(t, json.Unmarshal(req.Body, &request)) - return clusterDoesNotExistResponse(request.ClusterId) + return req.Workspace.ClustersGet(req, req.URL.Query().Get("cluster_id")) }) + testserver.AddDefaultHandlers(server) client, err := databricks.NewWorkspaceClient(&databricks.Config{ Host: server.URL, From ccb8a07b6f2442f253f4bf33a0ea84016aec76ea Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Thu, 26 Nov 2026 15:32:13 +0000 Subject: [PATCH 3/7] Update golden for the testserver's missing-cluster message Co-authored-by: Isaac --- acceptance/bundle/migrate/auto/artifacts/output.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/acceptance/bundle/migrate/auto/artifacts/output.txt b/acceptance/bundle/migrate/auto/artifacts/output.txt index 5266dc7ed21..9161f20d657 100644 --- a/acceptance/bundle/migrate/auto/artifacts/output.txt +++ b/acceptance/bundle/migrate/auto/artifacts/output.txt @@ -6,7 +6,7 @@ === Redeploy with direct default: auto-migration runs after the build, so library refs are resolved >>> [CLI] bundle deploy -Warn: unable to get spark version for cluster 0717-132531-5opeqon1, err: Not Found +Warn: unable to get spark version for cluster 0717-132531-5opeqon1, err: Cluster 0717-132531-5opeqon1 does not exist Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). Uploading dist/my_test_code-0.0.1-py3-none-any.whl... Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... @@ -39,7 +39,7 @@ ID Type Language Path === Subsequent deploy is a no-op on direct >>> [CLI] bundle deploy -Warn: unable to get spark version for cluster 0717-132531-5opeqon1, err: Not Found +Warn: unable to get spark version for cluster 0717-132531-5opeqon1, err: Cluster 0717-132531-5opeqon1 does not exist Uploading dist/my_test_code-0.0.1-py3-none-any.whl... Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... Files: 0 uploaded, 0 deleted From 6ead0980122d8a297be56c252c3242501db2acc4 Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Thu, 26 Nov 2026 15:47:37 +0000 Subject: [PATCH 4/7] Address review: exact match, cancel library read, map library-status 400, exercise destroy and saved-plan delete Co-authored-by: Isaac --- .../deleted-out-of-band-plan/databricks.yml | 10 ++++ .../deleted-out-of-band-plan/out.test.toml | 2 + .../deleted-out-of-band-plan/output.txt | 49 ++++++++++++++++ .../clusters/deleted-out-of-band-plan/script | 27 +++++++++ .../deleted-out-of-band-plan/test.toml | 3 + .../clusters/deleted-out-of-band/output.txt | 50 ++++++++++++---- .../clusters/deleted-out-of-band/script | 18 +++--- .../clusters/deleted-out-of-band/test.toml | 2 +- bundle/direct/dresources/cluster.go | 32 ++++++----- bundle/direct/dresources/cluster_test.go | 57 +++++++++++++++++++ 10 files changed, 216 insertions(+), 34 deletions(-) create mode 100644 acceptance/bundle/resources/clusters/deleted-out-of-band-plan/databricks.yml create mode 100644 acceptance/bundle/resources/clusters/deleted-out-of-band-plan/out.test.toml create mode 100644 acceptance/bundle/resources/clusters/deleted-out-of-band-plan/output.txt create mode 100644 acceptance/bundle/resources/clusters/deleted-out-of-band-plan/script create mode 100644 acceptance/bundle/resources/clusters/deleted-out-of-band-plan/test.toml diff --git a/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/databricks.yml b/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/databricks.yml new file mode 100644 index 00000000000..6a2aef3b6b3 --- /dev/null +++ b/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/databricks.yml @@ -0,0 +1,10 @@ +bundle: + name: test-bundle + +resources: + clusters: + foo: + cluster_name: foo + spark_version: 13.3.x-scala2.12 + node_type_id: i3.xlarge + num_workers: 1 diff --git a/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/out.test.toml b/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/out.test.toml new file mode 100644 index 00000000000..a927a5fbc06 --- /dev/null +++ b/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/output.txt b/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/output.txt new file mode 100644 index 00000000000..4b8b7942c36 --- /dev/null +++ b/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/output.txt @@ -0,0 +1,49 @@ + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Created clusters.foo +Files: 1 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +=== deploy: the cluster is still in config, so it is created again + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Created clusters.foo +Files: 0 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +>>> print_requests.py //clusters +{ + "method": "POST", + "path": "/api/2.1/clusters/create", + "body": { + "autotermination_minutes": 60, + "cluster_name": "foo", + "node_type_id": "[NODE_TYPE_ID]", + "num_workers": 1, + "spark_version": "13.3.x-scala2.12" + } +} + +=== saved plan: the delete was planned while the cluster existed + +>>> [CLI] bundle plan -o json + +>>> [CLI] bundle deploy --plan plan.json --auto-approve +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Deleted clusters.foo +Files: 2 uploaded, 0 deleted +Resources: 0 created, 0 changed, 1 deleted, 0 unchanged + +>>> print_state.py +[] + +>>> print_requests.py //clusters +{ + "method": "POST", + "path": "/api/2.1/clusters/permanent-delete", + "body": { + "cluster_id": "[FOO_ID_2]" + } +} diff --git a/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/script b/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/script new file mode 100644 index 00000000000..20766e4c2b0 --- /dev/null +++ b/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/script @@ -0,0 +1,27 @@ +# A cluster is permanently deleted out of band. The backend then answers the cluster GET, +# library-status and permanent-delete for it with 400 INVALID_PARAMETER_VALUE "does not exist". +trace $CLI bundle deploy +cluster_id=$(read_id.py foo) +print_requests.py > /dev/null + +title "deploy: the cluster is still in config, so it is created again" +$CLI clusters permanent-delete $cluster_id +print_requests.py > /dev/null +trace $CLI bundle deploy +trace print_requests.py //clusters + +title "saved plan: the delete was planned while the cluster existed" +update_file.py databricks.yml " clusters: + foo: + cluster_name: foo + spark_version: 13.3.x-scala2.12 + node_type_id: i3.xlarge + num_workers: 1 +" " {} +" +trace $CLI bundle plan -o json > plan.json +$CLI clusters permanent-delete $(read_id.py foo) +print_requests.py > /dev/null +trace $CLI bundle deploy --plan plan.json --auto-approve +trace print_state.py | jq -c ".state | keys" +trace print_requests.py //clusters diff --git a/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/test.toml b/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/test.toml new file mode 100644 index 00000000000..001bd467f66 --- /dev/null +++ b/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/test.toml @@ -0,0 +1,3 @@ +Cloud = false +RecordRequests = true +Ignore = [".databricks/", "plan.json"] diff --git a/acceptance/bundle/resources/clusters/deleted-out-of-band/output.txt b/acceptance/bundle/resources/clusters/deleted-out-of-band/output.txt index 0b1b7dc9667..e26fb5bc547 100644 --- a/acceptance/bundle/resources/clusters/deleted-out-of-band/output.txt +++ b/acceptance/bundle/resources/clusters/deleted-out-of-band/output.txt @@ -1,14 +1,4 @@ -=== deploy: the cluster is removed from config - ->>> [CLI] bundle deploy --auto-approve -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Files: 3 uploaded, 0 deleted -Resources: 0 created, 0 changed, 0 deleted, 0 unchanged - ->>> print_state.py -[] - === destroy >>> [CLI] bundle destroy --auto-approve @@ -16,6 +6,44 @@ All files and directories at the following location will be deleted: /Workspace/ Destroy: 0 deleted +>>> print_requests.py --get --sort //clusters //libraries +{ + "method": "GET", + "path": "/api/2.0/libraries/cluster-status", + "q": { + "cluster_id": "1126-000000-deleted0" + } +} +{ + "method": "GET", + "path": "/api/2.1/clusters/get", + "q": { + "cluster_id": "1126-000000-deleted0" + } +} + +=== deploy: the cluster is removed from config + +>>> [CLI] bundle deploy --auto-approve +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Files: 2 uploaded, 0 deleted +Resources: 0 created, 0 changed, 0 deleted, 0 unchanged + >>> print_state.py +[] ->>> print_requests.py //clusters/permanent-delete +>>> print_requests.py --get --sort //clusters //libraries +{ + "method": "GET", + "path": "/api/2.0/libraries/cluster-status", + "q": { + "cluster_id": "1126-000000-deleted0" + } +} +{ + "method": "GET", + "path": "/api/2.1/clusters/get", + "q": { + "cluster_id": "1126-000000-deleted0" + } +} diff --git a/acceptance/bundle/resources/clusters/deleted-out-of-band/script b/acceptance/bundle/resources/clusters/deleted-out-of-band/script index af6f9cf8c1f..ac9b81883e1 100644 --- a/acceptance/bundle/resources/clusters/deleted-out-of-band/script +++ b/acceptance/bundle/resources/clusters/deleted-out-of-band/script @@ -4,12 +4,18 @@ seed_state() { mkdir -p .databricks/bundle/default cp state.json .databricks/bundle/default/resources.json - $CLI workspace mkdirs /Workspace/Users/$CURRENT_USER_NAME/.bundle/test-bundle/default + # MSYS_NO_PATHCONV=1 keeps Git Bash on Windows from rewriting the workspace path. + MSYS_NO_PATHCONV=1 $CLI workspace mkdirs /Workspace/Users/$CURRENT_USER_NAME/.bundle/test-bundle/default } +# Destroy runs first: a deploy pushes a newer state that the destroy would pull instead. +title "destroy" +seed_state +trace $CLI bundle destroy --auto-approve +trace print_requests.py --get --sort //clusters //libraries + title "deploy: the cluster is removed from config" seed_state -cp databricks.yml databricks.yml.orig update_file.py databricks.yml " clusters: foo: cluster_name: foo @@ -20,10 +26,4 @@ update_file.py databricks.yml " clusters: " trace $CLI bundle deploy --auto-approve trace print_state.py | jq -c ".state | keys" - -title "destroy" -mv databricks.yml.orig databricks.yml -seed_state -trace $CLI bundle destroy --auto-approve -trace print_state.py | jq -c ".state | keys" -trace print_requests.py //clusters/permanent-delete +trace print_requests.py --get --sort //clusters //libraries diff --git a/acceptance/bundle/resources/clusters/deleted-out-of-band/test.toml b/acceptance/bundle/resources/clusters/deleted-out-of-band/test.toml index 578bacbb3f3..2985bf358f2 100644 --- a/acceptance/bundle/resources/clusters/deleted-out-of-band/test.toml +++ b/acceptance/bundle/resources/clusters/deleted-out-of-band/test.toml @@ -1,6 +1,6 @@ Cloud = false RecordRequests = true -Ignore = [".databricks/", "databricks.yml.orig"] +Ignore = [".databricks/"] [[Server]] Pattern = "GET /api/2.1/clusters/get" diff --git a/bundle/direct/dresources/cluster.go b/bundle/direct/dresources/cluster.go index 79282e9b440..dd68f9a4ae2 100644 --- a/bundle/direct/dresources/cluster.go +++ b/bundle/direct/dresources/cluster.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "net/http" - "regexp" "strings" "sync" "time" @@ -155,17 +154,22 @@ func (r *ResourceCluster) DoRead(ctx context.Context, id string) (*ClusterRemote var libraries []compute.Library // The cluster GET and the library-status GET are independent, so run them concurrently. - // The cluster GET error takes precedence: for a deleted cluster both endpoints fail with - // 400 INVALID_PARAMETER_VALUE, but the SDK maps only the cluster GET one to - // ErrResourceDoesNotExist, so returning whichever error came first would make a missing - // cluster look like a read failure at random. + // The cluster GET error takes precedence: it is the one the SDK maps to not-found for a + // deleted cluster. A library-status error that came first would make a missing cluster look + // like a read failure whenever readLibraries cannot recognize it. + librariesCtx, cancelLibraries := context.WithCancel(ctx) + defer cancelLibraries() var detailsErr, librariesErr error var wg sync.WaitGroup wg.Go(func() { details, detailsErr = r.client.Clusters.GetByClusterId(ctx, id) + if detailsErr != nil { + // The library status is not needed once the cluster GET failed. + cancelLibraries() + } }) wg.Go(func() { - libraries, librariesErr = r.readLibraries(ctx, id) + libraries, librariesErr = r.readLibraries(librariesCtx, id) }) wg.Wait() if detailsErr != nil { @@ -205,6 +209,10 @@ func (r *ResourceCluster) DoRead(ctx context.Context, id string) (*ClusterRemote // https://docs.databricks.com/api/workspace/libraries/clusterstatus func (r *ResourceCluster) readLibraries(ctx context.Context, id string) ([]compute.Library, error) { statuses, err := r.client.Libraries.ClusterStatusByClusterId(ctx, id) + if isClusterDoesNotExist(err, id) { + // The cluster was deleted after (or while) the cluster GET read it. + return nil, fmt.Errorf("%w: %w", apierr.ErrResourceDoesNotExist, err) + } if err != nil { return nil, err } @@ -379,22 +387,20 @@ func (r *ResourceCluster) DoResize(ctx context.Context, id string, config *Clust func (r *ResourceCluster) DoDelete(ctx context.Context, id string, _ *ClusterState) error { err := r.client.Clusters.PermanentDeleteByClusterId(ctx, id) - if isClusterDoesNotExist(err) { + if isClusterDoesNotExist(err, id) { // The backend reports a missing cluster as 400 INVALID_PARAMETER_VALUE, not 404. return fmt.Errorf("%w: %w", apierr.ErrResourceDoesNotExist, err) } return err } -// clusterDoesNotExistMessage matches the backend message for a missing cluster; the SDK applies -// the same match to the cluster GET only. -var clusterDoesNotExistMessage = regexp.MustCompile(`Cluster .* does not exist`) - -func isClusterDoesNotExist(err error) bool { +// isClusterDoesNotExist reports whether err is the backend's answer for a missing cluster id. The +// SDK maps the same answer to ErrResourceDoesNotExist for the cluster GET only. +func isClusterDoesNotExist(err error, id string) bool { apiErr, ok := errors.AsType[*apierr.APIError](err) return ok && apiErr.StatusCode == http.StatusBadRequest && apiErr.ErrorCode == "INVALID_PARAMETER_VALUE" && - clusterDoesNotExistMessage.MatchString(apiErr.Message) + apiErr.Message == "Cluster "+id+" does not exist" } func (r *ResourceCluster) OverrideChangeDesc(ctx context.Context, p *structpath.PathNode, change *ChangeDesc, remoteState *ClusterRemote) error { diff --git a/bundle/direct/dresources/cluster_test.go b/bundle/direct/dresources/cluster_test.go index 20790d16209..2720765a58c 100644 --- a/bundle/direct/dresources/cluster_test.go +++ b/bundle/direct/dresources/cluster_test.go @@ -1,6 +1,8 @@ package dresources import ( + "context" + "net/http" "testing" "time" @@ -103,3 +105,58 @@ func TestClusterDoDeleteMissingCluster(t *testing.T) { require.Error(t, err) assert.True(t, apierr.IsMissing(err), "expected a not-found error, got %v", err) } + +func TestClusterDoDeleteOtherInvalidParameterError(t *testing.T) { + server := testserver.New(t) + server.Handle("POST", "/api/2.1/clusters/permanent-delete", func(req testserver.Request) any { + return testserver.Response{ + StatusCode: http.StatusBadRequest, + Body: map[string]string{ + "error_code": "INVALID_PARAMETER_VALUE", + "message": "Cluster policy 1126-000000-abcdefgh does not exist", + }, + } + }) + client, err := databricks.NewWorkspaceClient(&databricks.Config{Host: server.URL, Token: "testtoken"}) + require.NoError(t, err) + r := (&ResourceCluster{}).New(client).(*ResourceCluster) + + err = r.DoDelete(t.Context(), "1126-000000-abcdefgh", nil) + require.Error(t, err) + assert.False(t, apierr.IsMissing(err), "expected an error that is not not-found, got %v", err) +} + +func TestClusterDoReadCancelsLibrariesWhenClusterIsMissing(t *testing.T) { + server := testserver.New(t) + server.Handle("GET", "/api/2.0/libraries/cluster-status", func(req testserver.Request) any { + // Answers only once the client gives up on the request. + <-req.Context.Done() + return testserver.Response{StatusCode: http.StatusServiceUnavailable} + }) + testserver.AddDefaultHandlers(server) + client, err := databricks.NewWorkspaceClient(&databricks.Config{Host: server.URL, Token: "testtoken"}) + require.NoError(t, err) + r := (&ResourceCluster{}).New(client).(*ResourceCluster) + + ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second) + defer cancel() + _, err = r.DoRead(ctx, "1126-000000-abcdefgh") + assert.True(t, apierr.IsMissing(err), "expected a not-found error, got %v", err) + assert.NoError(t, ctx.Err(), "DoRead waited for the library status after the cluster GET failed") +} + +func TestClusterDoReadClusterDeletedBetweenReads(t *testing.T) { + server := testserver.New(t) + server.Handle("GET", "/api/2.1/clusters/get", func(req testserver.Request) any { + return compute.ClusterDetails{ClusterId: req.URL.Query().Get("cluster_id"), State: compute.StateRunning} + }) + // The fake has no such cluster, so the library status answers with the missing-cluster 400. + testserver.AddDefaultHandlers(server) + client, err := databricks.NewWorkspaceClient(&databricks.Config{Host: server.URL, Token: "testtoken"}) + require.NoError(t, err) + r := (&ResourceCluster{}).New(client).(*ResourceCluster) + + _, err = r.DoRead(t.Context(), "1126-000000-abcdefgh") + require.Error(t, err) + assert.True(t, apierr.IsMissing(err), "expected a not-found error, got %v", err) +} From db54596f6806c429b7d30091cbd49b970917643d Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Thu, 26 Nov 2026 15:53:04 +0000 Subject: [PATCH 5/7] Add PR link to the changelog entry cloud: TestAccept/bundle/invariant/delete_idempotent TestAccept/bundle/invariant/destroy_idempotent Co-authored-by: Isaac --- .nextchanges/bundles/{cluster-missing-400.md => 8068.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .nextchanges/bundles/{cluster-missing-400.md => 8068.md} (57%) diff --git a/.nextchanges/bundles/cluster-missing-400.md b/.nextchanges/bundles/8068.md similarity index 57% rename from .nextchanges/bundles/cluster-missing-400.md rename to .nextchanges/bundles/8068.md index d2c6693ef88..430c7a5b542 100644 --- a/.nextchanges/bundles/cluster-missing-400.md +++ b/.nextchanges/bundles/8068.md @@ -1 +1 @@ -* Fix `bundle deploy` and `bundle destroy` with the direct engine sometimes failing with "Cluster ... does not exist" when a cluster in the state was already deleted. +* Fix `bundle deploy` and `bundle destroy` with the direct engine sometimes failing with "Cluster ... does not exist" when a cluster in the state was already deleted. ([#8068](https://github.com/databricks/cli/pull/8068)) From 203530bf3932ae0cd814eb754e575d51c4967e14 Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Thu, 26 Nov 2026 18:08:31 +0000 Subject: [PATCH 6/7] Drop the message matcher; rely on the DoRead precedence and deleteConfirmedGone Address review: AGENTS.md rules out branching on error message text, and with the cluster GET error taking precedence the re-read in deleteConfirmedGone already confirms an already-deleted cluster. Narrow the testserver comment, keep drained requests in LOG files, drop the unit test that duplicated the acceptance test. cloud: TestAccept/bundle/invariant/delete_idempotent TestAccept/bundle/invariant/destroy_idempotent Co-authored-by: Isaac --- .../deleted-out-of-band-plan/output.txt | 5 +- .../clusters/deleted-out-of-band-plan/script | 6 +- bundle/direct/dresources/cluster.go | 28 ++------ bundle/direct/dresources/cluster_test.go | 69 ------------------- libs/testserver/clusters.go | 4 +- 5 files changed, 13 insertions(+), 99 deletions(-) diff --git a/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/output.txt b/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/output.txt index 4b8b7942c36..5c98d2c47c6 100644 --- a/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/output.txt +++ b/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/output.txt @@ -10,7 +10,7 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... Created clusters.foo -Files: 0 uploaded, 0 deleted +Files: 2 uploaded, 0 deleted Resources: 1 created, 0 changed, 0 deleted, 0 unchanged >>> print_requests.py //clusters @@ -32,8 +32,9 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged >>> [CLI] bundle deploy --plan plan.json --auto-approve Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Warn: destroying resources.clusters.foo: Treating resources.clusters.foo id=[FOO_ID_2] as already deleted despite delete error: Cluster [FOO_ID_2] does not exist Deleted clusters.foo -Files: 2 uploaded, 0 deleted +Files: 3 uploaded, 0 deleted Resources: 0 created, 0 changed, 1 deleted, 0 unchanged >>> print_state.py diff --git a/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/script b/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/script index 20766e4c2b0..63f729e1571 100644 --- a/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/script +++ b/acceptance/bundle/resources/clusters/deleted-out-of-band-plan/script @@ -2,11 +2,11 @@ # library-status and permanent-delete for it with 400 INVALID_PARAMETER_VALUE "does not exist". trace $CLI bundle deploy cluster_id=$(read_id.py foo) -print_requests.py > /dev/null +print_requests.py > LOG.requests_deploy title "deploy: the cluster is still in config, so it is created again" $CLI clusters permanent-delete $cluster_id -print_requests.py > /dev/null +print_requests.py > LOG.requests_oob_delete trace $CLI bundle deploy trace print_requests.py //clusters @@ -21,7 +21,7 @@ update_file.py databricks.yml " clusters: " trace $CLI bundle plan -o json > plan.json $CLI clusters permanent-delete $(read_id.py foo) -print_requests.py > /dev/null +print_requests.py > LOG.requests_plan trace $CLI bundle deploy --plan plan.json --auto-approve trace print_state.py | jq -c ".state | keys" trace print_requests.py //clusters diff --git a/bundle/direct/dresources/cluster.go b/bundle/direct/dresources/cluster.go index dd68f9a4ae2..d3d97ee5f59 100644 --- a/bundle/direct/dresources/cluster.go +++ b/bundle/direct/dresources/cluster.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "net/http" "strings" "sync" "time" @@ -154,9 +153,10 @@ func (r *ResourceCluster) DoRead(ctx context.Context, id string) (*ClusterRemote var libraries []compute.Library // The cluster GET and the library-status GET are independent, so run them concurrently. - // The cluster GET error takes precedence: it is the one the SDK maps to not-found for a - // deleted cluster. A library-status error that came first would make a missing cluster look - // like a read failure whenever readLibraries cannot recognize it. + // The cluster GET error takes precedence: for a deleted cluster both endpoints fail with + // 400 INVALID_PARAMETER_VALUE, but the SDK maps only the cluster GET one to + // ErrResourceDoesNotExist, so a library-status error that came first would make a missing + // cluster look like a read failure. librariesCtx, cancelLibraries := context.WithCancel(ctx) defer cancelLibraries() var detailsErr, librariesErr error @@ -209,10 +209,6 @@ func (r *ResourceCluster) DoRead(ctx context.Context, id string) (*ClusterRemote // https://docs.databricks.com/api/workspace/libraries/clusterstatus func (r *ResourceCluster) readLibraries(ctx context.Context, id string) ([]compute.Library, error) { statuses, err := r.client.Libraries.ClusterStatusByClusterId(ctx, id) - if isClusterDoesNotExist(err, id) { - // The cluster was deleted after (or while) the cluster GET read it. - return nil, fmt.Errorf("%w: %w", apierr.ErrResourceDoesNotExist, err) - } if err != nil { return nil, err } @@ -386,21 +382,7 @@ func (r *ResourceCluster) DoResize(ctx context.Context, id string, config *Clust } func (r *ResourceCluster) DoDelete(ctx context.Context, id string, _ *ClusterState) error { - err := r.client.Clusters.PermanentDeleteByClusterId(ctx, id) - if isClusterDoesNotExist(err, id) { - // The backend reports a missing cluster as 400 INVALID_PARAMETER_VALUE, not 404. - return fmt.Errorf("%w: %w", apierr.ErrResourceDoesNotExist, err) - } - return err -} - -// isClusterDoesNotExist reports whether err is the backend's answer for a missing cluster id. The -// SDK maps the same answer to ErrResourceDoesNotExist for the cluster GET only. -func isClusterDoesNotExist(err error, id string) bool { - apiErr, ok := errors.AsType[*apierr.APIError](err) - return ok && apiErr.StatusCode == http.StatusBadRequest && - apiErr.ErrorCode == "INVALID_PARAMETER_VALUE" && - apiErr.Message == "Cluster "+id+" does not exist" + return r.client.Clusters.PermanentDeleteByClusterId(ctx, id) } func (r *ResourceCluster) OverrideChangeDesc(ctx context.Context, p *structpath.PathNode, change *ChangeDesc, remoteState *ClusterRemote) error { diff --git a/bundle/direct/dresources/cluster_test.go b/bundle/direct/dresources/cluster_test.go index 2720765a58c..8ec5d07e773 100644 --- a/bundle/direct/dresources/cluster_test.go +++ b/bundle/direct/dresources/cluster_test.go @@ -73,59 +73,6 @@ func TestClusterOverrideChangeDescLibraries(t *testing.T) { } } -// The fake workspace answers library-status and permanent-delete for a missing cluster with the -// cloud's 400 INVALID_PARAMETER_VALUE, which the SDK does not map to not-found. The cluster GET -// (which the SDK does map) is delayed so the library-status error arrives first. -func newMissingClusterResource(t *testing.T) *ResourceCluster { - server := testserver.New(t) - server.Handle("GET", "/api/2.1/clusters/get", func(req testserver.Request) any { - time.Sleep(100 * time.Millisecond) - return req.Workspace.ClustersGet(req, req.URL.Query().Get("cluster_id")) - }) - testserver.AddDefaultHandlers(server) - - client, err := databricks.NewWorkspaceClient(&databricks.Config{ - Host: server.URL, - Token: "testtoken", - }) - require.NoError(t, err) - return (&ResourceCluster{}).New(client).(*ResourceCluster) -} - -func TestClusterDoReadMissingCluster(t *testing.T) { - r := newMissingClusterResource(t) - _, err := r.DoRead(t.Context(), "1126-000000-abcdefgh") - require.Error(t, err) - assert.True(t, apierr.IsMissing(err), "expected a not-found error, got %v", err) -} - -func TestClusterDoDeleteMissingCluster(t *testing.T) { - r := newMissingClusterResource(t) - err := r.DoDelete(t.Context(), "1126-000000-abcdefgh", nil) - require.Error(t, err) - assert.True(t, apierr.IsMissing(err), "expected a not-found error, got %v", err) -} - -func TestClusterDoDeleteOtherInvalidParameterError(t *testing.T) { - server := testserver.New(t) - server.Handle("POST", "/api/2.1/clusters/permanent-delete", func(req testserver.Request) any { - return testserver.Response{ - StatusCode: http.StatusBadRequest, - Body: map[string]string{ - "error_code": "INVALID_PARAMETER_VALUE", - "message": "Cluster policy 1126-000000-abcdefgh does not exist", - }, - } - }) - client, err := databricks.NewWorkspaceClient(&databricks.Config{Host: server.URL, Token: "testtoken"}) - require.NoError(t, err) - r := (&ResourceCluster{}).New(client).(*ResourceCluster) - - err = r.DoDelete(t.Context(), "1126-000000-abcdefgh", nil) - require.Error(t, err) - assert.False(t, apierr.IsMissing(err), "expected an error that is not not-found, got %v", err) -} - func TestClusterDoReadCancelsLibrariesWhenClusterIsMissing(t *testing.T) { server := testserver.New(t) server.Handle("GET", "/api/2.0/libraries/cluster-status", func(req testserver.Request) any { @@ -144,19 +91,3 @@ func TestClusterDoReadCancelsLibrariesWhenClusterIsMissing(t *testing.T) { assert.True(t, apierr.IsMissing(err), "expected a not-found error, got %v", err) assert.NoError(t, ctx.Err(), "DoRead waited for the library status after the cluster GET failed") } - -func TestClusterDoReadClusterDeletedBetweenReads(t *testing.T) { - server := testserver.New(t) - server.Handle("GET", "/api/2.1/clusters/get", func(req testserver.Request) any { - return compute.ClusterDetails{ClusterId: req.URL.Query().Get("cluster_id"), State: compute.StateRunning} - }) - // The fake has no such cluster, so the library status answers with the missing-cluster 400. - testserver.AddDefaultHandlers(server) - client, err := databricks.NewWorkspaceClient(&databricks.Config{Host: server.URL, Token: "testtoken"}) - require.NoError(t, err) - r := (&ResourceCluster{}).New(client).(*ResourceCluster) - - _, err = r.DoRead(t.Context(), "1126-000000-abcdefgh") - require.Error(t, err) - assert.True(t, apierr.IsMissing(err), "expected a not-found error, got %v", err) -} diff --git a/libs/testserver/clusters.go b/libs/testserver/clusters.go index 7e7952386c8..e30454860d4 100644 --- a/libs/testserver/clusters.go +++ b/libs/testserver/clusters.go @@ -284,8 +284,8 @@ func (s *FakeWorkspace) ClustersPermanentDelete(req Request) any { return Response{} } -// clusterDoesNotExist is how the cloud answers cluster and library-status requests for a -// missing cluster: 400 INVALID_PARAMETER_VALUE rather than 404. +// clusterDoesNotExist is how the cloud answers clusters/get, clusters/permanent-delete and +// libraries/cluster-status for a missing cluster: 400 INVALID_PARAMETER_VALUE rather than 404. func clusterDoesNotExist(clusterId string) Response { return Response{ StatusCode: http.StatusBadRequest, From a519305759dacdc62bcb3b451bef9153c6b3469f Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Thu, 26 Nov 2026 18:27:10 +0000 Subject: [PATCH 7/7] acc: narrow the deleted-out-of-band comment and show the state after destroy cloud: TestAccept/bundle/invariant/delete_idempotent TestAccept/bundle/invariant/destroy_idempotent Co-authored-by: Isaac --- .../resources/clusters/deleted-out-of-band/output.txt | 2 ++ .../bundle/resources/clusters/deleted-out-of-band/script | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/acceptance/bundle/resources/clusters/deleted-out-of-band/output.txt b/acceptance/bundle/resources/clusters/deleted-out-of-band/output.txt index e26fb5bc547..18105db73e0 100644 --- a/acceptance/bundle/resources/clusters/deleted-out-of-band/output.txt +++ b/acceptance/bundle/resources/clusters/deleted-out-of-band/output.txt @@ -6,6 +6,8 @@ All files and directories at the following location will be deleted: /Workspace/ Destroy: 0 deleted +>>> print_state.py + >>> print_requests.py --get --sort //clusters //libraries { "method": "GET", diff --git a/acceptance/bundle/resources/clusters/deleted-out-of-band/script b/acceptance/bundle/resources/clusters/deleted-out-of-band/script index ac9b81883e1..9c1b59b3ade 100644 --- a/acceptance/bundle/resources/clusters/deleted-out-of-band/script +++ b/acceptance/bundle/resources/clusters/deleted-out-of-band/script @@ -1,6 +1,6 @@ -# The state points at a cluster that was deleted out of band. The backend answers every -# cluster endpoint for it with 400 INVALID_PARAMETER_VALUE "does not exist"; the stub in -# test.toml delays the cluster GET so the library-status GET answers first. +# The state points at a cluster that was deleted out of band. The backend answers clusters/get +# and libraries/cluster-status for it with 400 INVALID_PARAMETER_VALUE "does not exist"; the +# stub in test.toml delays the cluster GET so the library-status GET answers first. seed_state() { mkdir -p .databricks/bundle/default cp state.json .databricks/bundle/default/resources.json @@ -12,6 +12,7 @@ seed_state() { title "destroy" seed_state trace $CLI bundle destroy --auto-approve +trace print_state.py | jq -c ".state | keys" trace print_requests.py --get --sort //clusters //libraries title "deploy: the cluster is removed from config"