-
Notifications
You must be signed in to change notification settings - Fork 54
/
test_instance_admin.py
754 lines (623 loc) · 25.6 KB
/
test_instance_admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
# Copyright 2011 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from google.cloud.bigtable import enums
from google.cloud.bigtable.table import ClusterState
from . import _helpers
def _create_app_profile_helper(
app_profile_id,
instance,
routing_policy_type,
description=None,
cluster_id=None,
allow_transactional_writes=None,
ignore_warnings=None,
):
app_profile = instance.app_profile(
app_profile_id=app_profile_id,
routing_policy_type=routing_policy_type,
description=description,
cluster_id=cluster_id,
allow_transactional_writes=allow_transactional_writes,
)
assert app_profile.allow_transactional_writes == allow_transactional_writes
app_profile.create(ignore_warnings=ignore_warnings)
# Load a different app_profile objec form the server and
# verrify that it is the same
alt_app_profile = instance.app_profile(app_profile_id)
alt_app_profile.reload()
app_profile.app_profile_id == alt_app_profile.app_profile_id
app_profile.routing_policy_type == routing_policy_type
alt_app_profile.routing_policy_type == routing_policy_type
app_profile.description == alt_app_profile.description
assert not app_profile.allow_transactional_writes
assert not alt_app_profile.allow_transactional_writes
return app_profile
def _list_app_profiles_helper(instance, expected_app_profile_ids):
app_profiles = instance.list_app_profiles()
found = [app_prof.app_profile_id for app_prof in app_profiles]
for expected in expected_app_profile_ids:
assert expected in found
def _modify_app_profile_helper(
app_profile_id,
instance,
routing_policy_type,
description=None,
cluster_id=None,
allow_transactional_writes=None,
ignore_warnings=None,
):
app_profile = instance.app_profile(
app_profile_id=app_profile_id,
routing_policy_type=routing_policy_type,
description=description,
cluster_id=cluster_id,
allow_transactional_writes=allow_transactional_writes,
)
operation = app_profile.update(ignore_warnings=ignore_warnings)
operation.result(timeout=60)
alt_profile = instance.app_profile(app_profile_id)
alt_profile.reload()
assert alt_profile.description == description
assert alt_profile.routing_policy_type == routing_policy_type
assert alt_profile.cluster_id == cluster_id
assert alt_profile.allow_transactional_writes == allow_transactional_writes
def _delete_app_profile_helper(app_profile):
assert app_profile.exists()
app_profile.delete(ignore_warnings=True)
assert not app_profile.exists()
def test_client_list_instances(
admin_client, admin_instance_populated, skip_on_emulator
):
instances, failed_locations = admin_client.list_instances()
assert failed_locations == []
found = set([instance.name for instance in instances])
assert admin_instance_populated.name in found
def test_instance_exists_hit(admin_instance_populated, skip_on_emulator):
# Emulator does not support instance admin operations (create / delete).
# It allows connecting with *any* project / instance name.
# See: https://cloud.google.com/bigtable/docs/emulator
assert admin_instance_populated.exists()
def test_instance_exists_miss(admin_client, skip_on_emulator):
alt_instance = admin_client.instance("nonesuch-instance")
assert not alt_instance.exists()
def test_instance_reload(
admin_client, admin_instance_id, admin_instance_populated, skip_on_emulator
):
# Use same arguments as 'admin_instance_populated'
# so we can use reload() on a fresh instance.
alt_instance = admin_client.instance(admin_instance_id)
# Make sure metadata unset before reloading.
alt_instance.display_name = None
alt_instance.reload()
assert alt_instance.display_name == admin_instance_populated.display_name
assert alt_instance.labels == admin_instance_populated.labels
assert alt_instance.type_ == enums.Instance.Type.PRODUCTION
def test_instance_create_prod(
admin_client,
unique_suffix,
location_id,
instance_labels,
instances_to_delete,
skip_on_emulator,
):
from google.cloud.bigtable import enums
alt_instance_id = f"ndef{unique_suffix}"
instance = admin_client.instance(alt_instance_id, labels=instance_labels)
alt_cluster_id = f"{alt_instance_id}-cluster"
serve_nodes = 1
cluster = instance.cluster(
alt_cluster_id, location_id=location_id, serve_nodes=serve_nodes,
)
operation = instance.create(clusters=[cluster])
instances_to_delete.append(instance)
operation.result(timeout=60) # Ensure the operation completes.
assert instance.type_ is None
# Create a new instance instance and make sure it is the same.
instance_alt = admin_client.instance(alt_instance_id)
instance_alt.reload()
assert instance == instance_alt
assert instance.display_name == instance_alt.display_name
assert instance_alt.type_ == enums.Instance.Type.PRODUCTION
def test_instance_create_development(
admin_client,
unique_suffix,
location_id,
instance_labels,
instances_to_delete,
skip_on_emulator,
):
alt_instance_id = f"new{unique_suffix}"
instance = admin_client.instance(
alt_instance_id,
instance_type=enums.Instance.Type.DEVELOPMENT,
labels=instance_labels,
)
alt_cluster_id = f"{alt_instance_id}-cluster"
cluster = instance.cluster(alt_cluster_id, location_id=location_id)
operation = instance.create(clusters=[cluster])
instances_to_delete.append(instance)
operation.result(timeout=60) # Ensure the operation completes.
# Create a new instance instance and make sure it is the same.
instance_alt = admin_client.instance(alt_instance_id)
instance_alt.reload()
assert instance == instance_alt
assert instance.display_name == instance_alt.display_name
assert instance.type_ == instance_alt.type_
assert instance_alt.labels == instance_labels
assert instance_alt.state == enums.Instance.State.READY
def test_instance_create_w_two_clusters(
admin_client,
unique_suffix,
admin_instance_populated,
admin_cluster,
location_id,
instance_labels,
instances_to_delete,
skip_on_emulator,
):
alt_instance_id = f"dif{unique_suffix}"
instance = admin_client.instance(
alt_instance_id,
instance_type=enums.Instance.Type.PRODUCTION,
labels=instance_labels,
)
serve_nodes = 1
alt_cluster_id_1 = f"{alt_instance_id}-c1"
cluster_1 = instance.cluster(
alt_cluster_id_1,
location_id=location_id,
serve_nodes=serve_nodes,
default_storage_type=enums.StorageType.HDD,
)
alt_cluster_id_2 = f"{alt_instance_id}-c2"
location_id_2 = "us-central1-f"
cluster_2 = instance.cluster(
alt_cluster_id_2,
location_id=location_id_2,
serve_nodes=serve_nodes,
default_storage_type=enums.StorageType.HDD,
)
operation = instance.create(clusters=[cluster_1, cluster_2])
instances_to_delete.append(instance)
operation.result(timeout=120) # Ensure the operation completes.
# Create a new instance instance and make sure it is the same.
instance_alt = admin_client.instance(alt_instance_id)
instance_alt.reload()
assert instance == instance_alt
assert instance.display_name == instance_alt.display_name
assert instance.type_ == instance_alt.type_
clusters, failed_locations = instance_alt.list_clusters()
assert failed_locations == []
alt_cluster_1, alt_cluster_2 = sorted(clusters, key=lambda x: x.name)
assert cluster_1.location_id == alt_cluster_1.location_id
assert alt_cluster_1.state == enums.Cluster.State.READY
assert cluster_1.serve_nodes == alt_cluster_1.serve_nodes
assert cluster_1.default_storage_type == alt_cluster_1.default_storage_type
assert cluster_2.location_id == alt_cluster_2.location_id
assert alt_cluster_2.state == enums.Cluster.State.READY
assert cluster_2.serve_nodes == alt_cluster_2.serve_nodes
assert cluster_2.default_storage_type == alt_cluster_2.default_storage_type
# Test list clusters in project via 'client.list_clusters'
clusters, failed_locations = admin_client.list_clusters()
assert not failed_locations
found = set([cluster.name for cluster in clusters])
expected = {alt_cluster_1.name, alt_cluster_2.name, admin_cluster.name}
assert expected.issubset(found)
temp_table_id = "test-get-cluster-states"
temp_table = instance.table(temp_table_id)
_helpers.retry_grpc_unavailable(temp_table.create)()
EncryptionType = enums.EncryptionInfo.EncryptionType
encryption_info = temp_table.get_encryption_info()
assert (
encryption_info[alt_cluster_id_1][0].encryption_type
== EncryptionType.GOOGLE_DEFAULT_ENCRYPTION
)
assert (
encryption_info[alt_cluster_id_2][0].encryption_type
== EncryptionType.GOOGLE_DEFAULT_ENCRYPTION
)
c_states = temp_table.get_cluster_states()
cluster_ids = set(c_states.keys())
assert cluster_ids == {alt_cluster_id_1, alt_cluster_id_2}
ReplicationState = enums.Table.ReplicationState
expected_results = [
ClusterState(ReplicationState.STATE_NOT_KNOWN),
ClusterState(ReplicationState.INITIALIZING),
ClusterState(ReplicationState.PLANNED_MAINTENANCE),
ClusterState(ReplicationState.UNPLANNED_MAINTENANCE),
ClusterState(ReplicationState.READY),
]
for clusterstate in c_states.values():
assert clusterstate in expected_results
# Test create app profile with multi_cluster_routing policy
app_profiles_to_delete = []
description = "routing policy-multy"
app_profile_id_1 = "app_profile_id_1"
routing = enums.RoutingPolicyType.ANY
app_profile_1 = _create_app_profile_helper(
app_profile_id_1,
instance,
routing_policy_type=routing,
description=description,
ignore_warnings=True,
)
app_profiles_to_delete.append(app_profile_1)
# Test list app profiles
_list_app_profiles_helper(instance, [app_profile_id_1])
# Test modify app profile app_profile_id_1
# routing policy to single cluster policy,
# cluster -> alt_cluster_id_1,
# allow_transactional_writes -> disallowed
# modify description
description = "to routing policy-single"
routing = enums.RoutingPolicyType.SINGLE
_modify_app_profile_helper(
app_profile_id_1,
instance,
routing_policy_type=routing,
description=description,
cluster_id=alt_cluster_id_1,
allow_transactional_writes=False,
)
# Test modify app profile app_profile_id_1
# cluster -> alt_cluster_id_2,
# allow_transactional_writes -> allowed
_modify_app_profile_helper(
app_profile_id_1,
instance,
routing_policy_type=routing,
description=description,
cluster_id=alt_cluster_id_2,
allow_transactional_writes=True,
ignore_warnings=True,
)
# Test create app profile with single cluster routing policy
description = "routing policy-single"
app_profile_id_2 = "app_profile_id_2"
routing = enums.RoutingPolicyType.SINGLE
app_profile_2 = _create_app_profile_helper(
app_profile_id_2,
instance,
routing_policy_type=routing,
description=description,
cluster_id=alt_cluster_id_2,
allow_transactional_writes=False,
)
app_profiles_to_delete.append(app_profile_2)
# Test list app profiles
_list_app_profiles_helper(instance, [app_profile_id_1, app_profile_id_2])
# Test modify app profile app_profile_id_2 to
# allow transactional writes
# Note: no need to set ``ignore_warnings`` to True
# since we are not restrictings anything with this modification.
_modify_app_profile_helper(
app_profile_id_2,
instance,
routing_policy_type=routing,
description=description,
cluster_id=alt_cluster_id_2,
allow_transactional_writes=True,
)
# Test modify app profile app_profile_id_2 routing policy
# to multi_cluster_routing policy
# modify description
description = "to routing policy-multy"
routing = enums.RoutingPolicyType.ANY
_modify_app_profile_helper(
app_profile_id_2,
instance,
routing_policy_type=routing,
description=description,
allow_transactional_writes=False,
ignore_warnings=True,
)
# Test delete app profiles
for app_profile in app_profiles_to_delete:
_delete_app_profile_helper(app_profile)
def test_instance_create_w_two_clusters_cmek(
admin_client,
unique_suffix,
admin_instance_populated,
admin_cluster,
location_id,
instance_labels,
instances_to_delete,
with_kms_key_name,
skip_on_emulator,
):
alt_instance_id = f"dif-cmek{unique_suffix}"
instance = admin_client.instance(
alt_instance_id,
instance_type=enums.Instance.Type.PRODUCTION,
labels=instance_labels,
)
serve_nodes = 1
alt_cluster_id_1 = f"{alt_instance_id}-c1"
cluster_1 = instance.cluster(
alt_cluster_id_1,
location_id=location_id,
serve_nodes=serve_nodes,
default_storage_type=enums.StorageType.HDD,
kms_key_name=with_kms_key_name,
)
alt_cluster_id_2 = f"{alt_instance_id}-c2"
location_id_2 = "us-central1-f"
cluster_2 = instance.cluster(
alt_cluster_id_2,
location_id=location_id_2,
serve_nodes=serve_nodes,
default_storage_type=enums.StorageType.HDD,
kms_key_name=with_kms_key_name,
)
operation = instance.create(clusters=[cluster_1, cluster_2])
instances_to_delete.append(instance)
operation.result(timeout=120) # Ensure the operation completes.
# Create a new instance instance and make sure it is the same.
instance_alt = admin_client.instance(alt_instance_id)
instance_alt.reload()
assert instance == instance_alt
assert instance.display_name == instance_alt.display_name
assert instance.type_ == instance_alt.type_
clusters, failed_locations = instance_alt.list_clusters()
assert failed_locations == []
alt_cluster_1, alt_cluster_2 = sorted(clusters, key=lambda x: x.name)
assert cluster_1.location_id == alt_cluster_1.location_id
assert alt_cluster_1.state == enums.Cluster.State.READY
assert cluster_1.serve_nodes == alt_cluster_1.serve_nodes
assert cluster_1.default_storage_type == alt_cluster_1.default_storage_type
assert cluster_2.location_id == alt_cluster_2.location_id
assert alt_cluster_2.state == enums.Cluster.State.READY
assert cluster_2.serve_nodes == alt_cluster_2.serve_nodes
assert cluster_2.default_storage_type == alt_cluster_2.default_storage_type
# Test list clusters in project via 'client.list_clusters'
clusters, failed_locations = admin_client.list_clusters()
assert not failed_locations
found = set([cluster.name for cluster in clusters])
expected = {alt_cluster_1.name, alt_cluster_2.name, admin_cluster.name}
assert expected.issubset(found)
temp_table_id = "test-get-cluster-states"
temp_table = instance.table(temp_table_id)
temp_table.create()
EncryptionType = enums.EncryptionInfo.EncryptionType
encryption_info = temp_table.get_encryption_info()
assert (
encryption_info[alt_cluster_id_1][0].encryption_type
== EncryptionType.CUSTOMER_MANAGED_ENCRYPTION
)
assert (
encryption_info[alt_cluster_id_2][0].encryption_type
== EncryptionType.CUSTOMER_MANAGED_ENCRYPTION
)
def test_instance_update_display_name_and_labels(
admin_client,
admin_instance_id,
admin_instance_populated,
label_key,
instance_labels,
skip_on_emulator,
):
old_display_name = admin_instance_populated.display_name
new_display_name = "Foo Bar Baz"
new_labels = {label_key: _helpers.label_stamp()}
admin_instance_populated.display_name = new_display_name
admin_instance_populated.labels = new_labels
operation = admin_instance_populated.update()
operation.result(timeout=60) # ensure the operation completes.
# Create a new instance instance and reload it.
instance_alt = admin_client.instance(admin_instance_id, labels={})
assert instance_alt.display_name == old_display_name
assert instance_alt.labels == {}
instance_alt.reload()
assert instance_alt.display_name == new_display_name
assert instance_alt.labels == new_labels
# Make sure to put the instance back the way it was for the
# other test cases.
admin_instance_populated.display_name = old_display_name
admin_instance_populated.labels = instance_labels
operation = admin_instance_populated.update()
operation.result(timeout=60) # ensure the operation completes.
def test_instance_update_w_type(
admin_client,
unique_suffix,
admin_instance_populated,
location_id,
instance_labels,
instances_to_delete,
skip_on_emulator,
):
alt_instance_id = f"ndif{unique_suffix}"
instance = admin_client.instance(
alt_instance_id,
instance_type=enums.Instance.Type.DEVELOPMENT,
labels=instance_labels,
)
alt_cluster_id = f"{alt_instance_id}-cluster"
cluster = instance.cluster(alt_cluster_id, location_id=location_id,)
operation = instance.create(clusters=[cluster])
instances_to_delete.append(instance)
operation.result(timeout=60) # Ensure the operation completes.
instance.display_name = None
instance.type_ = enums.Instance.Type.PRODUCTION
operation = instance.update()
operation.result(timeout=60) # ensure the operation completes.
# Create a new instance instance and reload it.
instance_alt = admin_client.instance(alt_instance_id)
assert instance_alt.type_ is None
instance_alt.reload()
assert instance_alt.type_ == enums.Instance.Type.PRODUCTION
def test_cluster_exists_hit(admin_cluster, skip_on_emulator):
assert admin_cluster.exists()
def test_cluster_exists_miss(admin_instance_populated, skip_on_emulator):
alt_cluster = admin_instance_populated.cluster("nonesuch-cluster")
assert not alt_cluster.exists()
def test_cluster_create(
admin_instance_populated, admin_instance_id, skip_on_emulator,
):
alt_cluster_id = f"{admin_instance_id}-c2"
alt_location_id = "us-central1-f"
serve_nodes = 2
cluster_2 = admin_instance_populated.cluster(
alt_cluster_id,
location_id=alt_location_id,
serve_nodes=serve_nodes,
default_storage_type=(enums.StorageType.SSD),
)
operation = cluster_2.create()
operation.result(timeout=60) # Ensure the operation completes.
# Create a new object instance, reload and make sure it is the same.
alt_cluster = admin_instance_populated.cluster(alt_cluster_id)
alt_cluster.reload()
assert cluster_2 == alt_cluster
assert cluster_2.location_id == alt_cluster.location_id
assert alt_cluster.state == enums.Cluster.State.READY
assert cluster_2.serve_nodes == alt_cluster.serve_nodes
assert cluster_2.default_storage_type == alt_cluster.default_storage_type
# Delete the newly created cluster and confirm
assert cluster_2.exists()
cluster_2.delete()
assert not cluster_2.exists()
def test_cluster_create_w_autoscaling(
admin_instance_populated, admin_instance_id, skip_on_emulator,
):
alt_cluster_id = f"{admin_instance_id}-c2"
alt_location_id = "us-central1-f"
min_serve_nodes = 1
max_serve_nodes = 8
cpu_utilization_percent = 20
cluster_2 = admin_instance_populated.cluster(
alt_cluster_id,
location_id=alt_location_id,
min_serve_nodes=min_serve_nodes,
max_serve_nodes=max_serve_nodes,
cpu_utilization_percent=cpu_utilization_percent,
default_storage_type=(enums.StorageType.SSD),
)
operation = cluster_2.create()
operation.result(timeout=60) # Ensure the operation completes.
# Create a new object instance, reload and make sure it is the same.
alt_cluster = admin_instance_populated.cluster(alt_cluster_id)
alt_cluster.reload()
assert cluster_2 == alt_cluster
assert cluster_2.location_id == alt_cluster.location_id
assert alt_cluster.state == enums.Cluster.State.READY
assert cluster_2.min_serve_nodes == alt_cluster.min_serve_nodes
assert cluster_2.max_serve_nodes == alt_cluster.max_serve_nodes
assert cluster_2.cpu_utilization_percent == alt_cluster.cpu_utilization_percent
assert cluster_2.default_storage_type == alt_cluster.default_storage_type
# Delete the newly created cluster and confirm
assert cluster_2.exists()
cluster_2.delete()
assert not cluster_2.exists()
def test_cluster_update(
admin_instance_populated,
admin_cluster_id,
admin_cluster,
serve_nodes,
skip_on_emulator,
):
new_serve_nodes = 4
admin_cluster.serve_nodes = new_serve_nodes
operation = admin_cluster.update()
operation.result(timeout=60) # Ensure the operation completes.
# Create a new cluster instance and reload it.
alt_cluster = admin_instance_populated.cluster(admin_cluster_id)
alt_cluster.reload()
assert alt_cluster.serve_nodes == new_serve_nodes
# Put the cluster back the way it was for the other test cases.
admin_cluster.serve_nodes = serve_nodes
operation = admin_cluster.update()
operation.result(timeout=60) # Ensure the operation completes.
def test_cluster_update_w_autoscaling(
admin_instance_populated,
admin_cluster_id,
admin_cluster_with_autoscaling,
min_serve_nodes,
max_serve_nodes,
cpu_utilization_percent,
skip_on_emulator,
):
new_min_serve_nodes = min_serve_nodes + 1
new_max_serve_nodes = max_serve_nodes + 1
new_cpu_utilization_percent = cpu_utilization_percent + 10
admin_cluster_with_autoscaling.min_serve_nodes = new_min_serve_nodes
admin_cluster_with_autoscaling.max_serve_nodes = new_max_serve_nodes
admin_cluster_with_autoscaling.cpu_utilization_percent = new_cpu_utilization_percent
operation = admin_cluster_with_autoscaling.update()
operation.result(timeout=60) # Ensure the operation completes.
# Create a new cluster instance and reload it.
alt_cluster = admin_instance_populated.cluster(admin_cluster_id)
alt_cluster.reload()
assert alt_cluster.min_serve_nodes == new_min_serve_nodes
assert alt_cluster.max_serve_nodes == new_max_serve_nodes
assert alt_cluster.cpu_utilization_percent == new_cpu_utilization_percent
# Put the cluster back the way it was for the other test cases.
admin_cluster_with_autoscaling.min_serve_nodes = min_serve_nodes
admin_cluster_with_autoscaling.max_serve_nodes = max_serve_nodes
admin_cluster_with_autoscaling.cpu_utilization_percent = cpu_utilization_percent
operation = admin_cluster_with_autoscaling.update()
operation.result(timeout=60) # Ensure the operation completes.
def test_cluster_update_w_autoscaling_partial(
admin_instance_populated,
admin_cluster_id,
admin_cluster_with_autoscaling,
min_serve_nodes,
max_serve_nodes,
cpu_utilization_percent,
skip_on_emulator,
):
new_min_serve_nodes = min_serve_nodes + 1
admin_cluster_with_autoscaling.min_serve_nodes = new_min_serve_nodes
operation = admin_cluster_with_autoscaling.update()
operation.result(timeout=60) # Ensure the operation completes.
# Create a new cluster instance and reload it.
alt_cluster = admin_instance_populated.cluster(admin_cluster_id)
alt_cluster.reload()
# assert that only the min_serve_nodes was changed
assert alt_cluster.min_serve_nodes == new_min_serve_nodes
assert alt_cluster.max_serve_nodes == max_serve_nodes
assert alt_cluster.cpu_utilization_percent == cpu_utilization_percent
# Put the cluster back the way it was for the other test cases.
admin_cluster_with_autoscaling.min_serve_nodes = min_serve_nodes
admin_cluster_with_autoscaling.max_serve_nodes = max_serve_nodes
admin_cluster_with_autoscaling.cpu_utilization_percent = cpu_utilization_percent
operation = admin_cluster_with_autoscaling.update()
operation.result(timeout=60) # Ensure the operation completes.
def test_cluster_disable_autoscaling(
admin_instance_populated,
admin_cluster_id,
admin_cluster_with_autoscaling,
serve_nodes,
min_serve_nodes,
max_serve_nodes,
cpu_utilization_percent,
skip_on_emulator,
):
operation = admin_cluster_with_autoscaling.disable_autoscaling(
serve_nodes=serve_nodes
)
operation.result(timeout=60) # Ensure the operation completes.
# Create a new cluster instance and reload it.
alt_cluster = admin_instance_populated.cluster(admin_cluster_id)
alt_cluster.reload()
assert alt_cluster.min_serve_nodes == 0
assert alt_cluster.max_serve_nodes == 0
assert alt_cluster.cpu_utilization_percent == 0
assert alt_cluster.serve_nodes == serve_nodes
# Put the cluster back the way it was for the other test cases.
admin_cluster_with_autoscaling.min_serve_nodes = min_serve_nodes
admin_cluster_with_autoscaling.max_serve_nodes = max_serve_nodes
admin_cluster_with_autoscaling.cpu_utilization_percent = cpu_utilization_percent
admin_cluster_with_autoscaling.serve_nodes = 0
operation = admin_cluster_with_autoscaling.update()
operation.result(timeout=60) # Ensure the operation completes.