|
9 | 9 | "github.com/databricks/databricks-sdk-go" |
10 | 10 | "github.com/databricks/databricks-sdk-go/retries" |
11 | 11 | "github.com/databricks/databricks-sdk-go/service/compute" |
12 | | - "github.com/databricks/databricks-sdk-go/service/iam" |
13 | 12 | "github.com/stretchr/testify/assert" |
14 | 13 | "github.com/stretchr/testify/require" |
15 | 14 | ) |
@@ -89,146 +88,3 @@ func TestAccAwsInstanceProfiles(t *testing.T) { |
89 | 88 | require.NoError(t, err) |
90 | 89 | assert.True(t, len(all) >= 1) |
91 | 90 | } |
92 | | - |
93 | | -func TestAccClustersApiIntegration(t *testing.T) { |
94 | | - ctx, w := workspaceTest(t) |
95 | | - |
96 | | - clusterName := RandomName("sdk-go-cluster-") |
97 | | - |
98 | | - // Select the latest LTS version without Photon |
99 | | - latest, err := w.Clusters.SelectSparkVersion(ctx, compute.SparkVersionRequest{ |
100 | | - Latest: true, |
101 | | - LongTermSupport: true, |
102 | | - }) |
103 | | - require.NoError(t, err) |
104 | | - |
105 | | - // Create cluster and wait for it to start properly |
106 | | - clstr, err := w.Clusters.CreateAndWait(ctx, compute.CreateCluster{ |
107 | | - ClusterName: clusterName, |
108 | | - SparkVersion: latest, |
109 | | - InstancePoolId: GetEnvOrSkipTest(t, "TEST_INSTANCE_POOL_ID"), |
110 | | - AutoterminationMinutes: 15, |
111 | | - NumWorkers: 1, |
112 | | - }) |
113 | | - require.NoError(t, err) |
114 | | - |
115 | | - t.Cleanup(func() { |
116 | | - // Permanently delete the cluster |
117 | | - err := w.Clusters.PermanentDeleteByClusterId(ctx, clstr.ClusterId) |
118 | | - require.NoError(t, err) |
119 | | - }) |
120 | | - |
121 | | - byId, err := w.Clusters.GetByClusterId(ctx, clstr.ClusterId) |
122 | | - require.NoError(t, err) |
123 | | - assert.Equal(t, clusterName, byId.ClusterName) |
124 | | - assert.Equal(t, compute.StateRunning, byId.State) |
125 | | - |
126 | | - // Pin the cluster in the list |
127 | | - err = w.Clusters.PinByClusterId(ctx, clstr.ClusterId) |
128 | | - require.NoError(t, err) |
129 | | - |
130 | | - // Unpin the cluster |
131 | | - err = w.Clusters.UnpinByClusterId(ctx, clstr.ClusterId) |
132 | | - require.NoError(t, err) |
133 | | - |
134 | | - // Edit the cluster: change auto-termination and number of workers |
135 | | - _, err = w.Clusters.EditAndWait(ctx, compute.EditCluster{ |
136 | | - ClusterId: clstr.ClusterId, |
137 | | - SparkVersion: latest, |
138 | | - ClusterName: clusterName, |
139 | | - InstancePoolId: GetEnvOrSkipTest(t, "TEST_INSTANCE_POOL_ID"), |
140 | | - |
141 | | - // change auto-termination and number of workers |
142 | | - AutoterminationMinutes: 10, |
143 | | - NumWorkers: 2, |
144 | | - }) |
145 | | - require.NoError(t, err) |
146 | | - |
147 | | - // Assert edit changes are reflected in the cluster |
148 | | - byId, err = w.Clusters.GetByClusterId(ctx, clstr.ClusterId) |
149 | | - require.NoError(t, err) |
150 | | - assert.Equal(t, 10, byId.AutoterminationMinutes) |
151 | | - assert.Equal(t, 2, byId.NumWorkers) |
152 | | - |
153 | | - // Test getting the cluster by name |
154 | | - byName, err := w.Clusters.GetByClusterName(ctx, byId.ClusterName) |
155 | | - require.NoError(t, err) |
156 | | - assert.Equal(t, byId.ClusterId, byName.ClusterId) |
157 | | - |
158 | | - // Terminate the cluster |
159 | | - _, err = w.Clusters.DeleteByClusterIdAndWait(ctx, clstr.ClusterId) |
160 | | - require.NoError(t, err) |
161 | | - |
162 | | - // Assert that the cluster we've just deleted has Terminated state |
163 | | - byId, err = w.Clusters.GetByClusterId(ctx, clstr.ClusterId) |
164 | | - require.NoError(t, err) |
165 | | - assert.Equal(t, byId.State, compute.StateTerminated) |
166 | | - |
167 | | - // Start cluster and wait until it's running again |
168 | | - _, err = w.Clusters.StartByClusterIdAndWait(ctx, clstr.ClusterId) |
169 | | - require.NoError(t, err) |
170 | | - |
171 | | - // Resize the cluster back to 1 worker and wait till completion |
172 | | - byId, err = w.Clusters.ResizeAndWait(ctx, compute.ResizeCluster{ |
173 | | - ClusterId: clstr.ClusterId, |
174 | | - NumWorkers: 1, |
175 | | - }) |
176 | | - require.NoError(t, err) |
177 | | - assert.Equal(t, 1, byId.NumWorkers) |
178 | | - |
179 | | - // Restart the cluster and wait for it to run again |
180 | | - _, err = w.Clusters.RestartAndWait(ctx, compute.RestartCluster{ |
181 | | - ClusterId: clstr.ClusterId, |
182 | | - }) |
183 | | - require.NoError(t, err) |
184 | | - |
185 | | - // Get events for the cluster and assert its non empty |
186 | | - events, err := w.Clusters.EventsAll(ctx, compute.GetEvents{ |
187 | | - ClusterId: clstr.ClusterId, |
188 | | - }) |
189 | | - require.NoError(t, err) |
190 | | - assert.True(t, len(events) > 0) |
191 | | - |
192 | | - // List clusters in workspace |
193 | | - all, err := w.Clusters.ListAll(ctx, compute.ListClustersRequest{}) |
194 | | - require.NoError(t, err) |
195 | | - foundCluster := false |
196 | | - for _, info := range all { |
197 | | - if info.ClusterName == clusterName { |
198 | | - foundCluster = true |
199 | | - } |
200 | | - } |
201 | | - assert.True(t, foundCluster) |
202 | | - |
203 | | - // Get cluster by name and assert it still exists |
204 | | - ClusterDetails, err := w.Clusters.GetByClusterName(ctx, clusterName) |
205 | | - require.NoError(t, err) |
206 | | - assert.Equal(t, ClusterDetails.ClusterName, clusterName) |
207 | | - |
208 | | - otherOwner, err := w.Users.Create(ctx, iam.User{ |
209 | | - UserName: RandomEmail(), |
210 | | - }) |
211 | | - require.NoError(t, err) |
212 | | - defer w.Users.DeleteById(ctx, otherOwner.Id) |
213 | | - |
214 | | - // terminate the cluster |
215 | | - _, err = w.Clusters.DeleteByClusterIdAndWait(ctx, clstr.ClusterId) |
216 | | - require.NoError(t, err) |
217 | | - |
218 | | - // cluster must be terminated to change the owner |
219 | | - err = w.Clusters.ChangeOwner(ctx, compute.ChangeClusterOwner{ |
220 | | - ClusterId: clstr.ClusterId, |
221 | | - OwnerUsername: otherOwner.UserName, |
222 | | - }) |
223 | | - require.NoError(t, err) |
224 | | - |
225 | | - nodes, err := w.Clusters.ListNodeTypes(ctx) |
226 | | - require.NoError(t, err) |
227 | | - assert.True(t, len(nodes.NodeTypes) > 1) |
228 | | - |
229 | | - if w.Config.IsAws() { |
230 | | - zones, err := w.Clusters.ListZones(ctx) |
231 | | - require.NoError(t, err) |
232 | | - assert.True(t, len(zones.Zones) > 1) |
233 | | - } |
234 | | -} |
0 commit comments