forked from skypilot-org/skypilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_cluster_job.py
1926 lines (1773 loc) · 89.1 KB
/
test_cluster_job.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
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Smoke tests for SkyPilot for sky launched cluster and cluster job
# Default options are set in pyproject.toml
# Example usage:
# Run all tests except for AWS and Lambda Cloud
# > pytest tests/smoke_tests/test_cluster_job.py
#
# Terminate failed clusters after test finishes
# > pytest tests/smoke_tests/test_cluster_job.py --terminate-on-failure
#
# Re-run last failed tests
# > pytest --lf
#
# Run one of the smoke tests
# > pytest tests/smoke_tests/test_cluster_job.py::test_job_queue
#
# Only run test for AWS + generic tests
# > pytest tests/smoke_tests/test_cluster_job.py --aws
#
# Change cloud for generic tests to aws
# > pytest tests/smoke_tests/test_cluster_job.py --generic-cloud aws
import pathlib
import re
import tempfile
import textwrap
from typing import Dict
import jinja2
import pytest
from smoke_tests import smoke_tests_utils
import sky
from sky import AWS
from sky import Azure
from sky import GCP
from sky.skylet import constants
from sky.utils import common_utils
from sky.utils import resources_utils
# ---------- Job Queue. ----------
@pytest.mark.no_vast # Vast has low availability of T4 GPUs
@pytest.mark.no_fluidstack # FluidStack DC has low availability of T4 GPUs
@pytest.mark.no_lambda_cloud # Lambda Cloud does not have T4 gpus
@pytest.mark.no_ibm # IBM Cloud does not have T4 gpus. run test_ibm_job_queue instead
@pytest.mark.no_scp # SCP does not have T4 gpus. Run test_scp_job_queue instead
@pytest.mark.no_paperspace # Paperspace does not have T4 gpus.
@pytest.mark.no_oci # OCI does not have T4 gpus
@pytest.mark.no_nebius # Nebius does not support T4 GPUs
@pytest.mark.resource_heavy
@pytest.mark.parametrize('accelerator', [{'do': 'H100'}])
def test_job_queue(generic_cloud: str, accelerator: Dict[str, str]):
accelerator = accelerator.get(generic_cloud, 'T4')
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'job_queue',
[
f'sky launch -y -c {name} --cloud {generic_cloud} {smoke_tests_utils.LOW_RESOURCE_ARG} --gpus {accelerator} examples/job_queue/cluster.yaml',
f'sky exec {name} -n {name}-1 -d --gpus {accelerator}:0.5 examples/job_queue/job.yaml',
f'sky exec {name} -n {name}-2 -d --gpus {accelerator}:0.5 examples/job_queue/job.yaml',
f'sky exec {name} -n {name}-3 -d --gpus {accelerator}:0.5 examples/job_queue/job.yaml',
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep {name}-1 | grep RUNNING',
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep {name}-2 | grep RUNNING',
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep {name}-3 | grep PENDING',
f'sky cancel -y {name} 2',
'sleep 5',
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep {name}-3 | grep RUNNING',
f'sky cancel -y {name} 3',
f'sky exec {name} --gpus {accelerator}:0.2 "[[ \$SKYPILOT_NUM_GPUS_PER_NODE -eq 1 ]] || exit 1"',
f'sky exec {name} --gpus {accelerator}:1 "[[ \$SKYPILOT_NUM_GPUS_PER_NODE -eq 1 ]] || exit 1"',
f'sky logs {name} 4 --status',
f'sky logs {name} 5 --status',
],
f'sky down -y {name}',
)
smoke_tests_utils.run_one_test(test)
# ---------- Job Queue with Docker. ----------
@pytest.mark.no_fluidstack # FluidStack does not support docker for now
@pytest.mark.no_lambda_cloud # Doesn't support Lambda Cloud for now
@pytest.mark.no_ibm # Doesn't support IBM Cloud for now
@pytest.mark.no_vast # Vast has low availability of T4 GPUs
@pytest.mark.no_paperspace # Paperspace doesn't have T4 GPUs
@pytest.mark.no_scp # Doesn't support SCP for now
@pytest.mark.no_oci # Doesn't support OCI for now
@pytest.mark.no_kubernetes # Doesn't support Kubernetes for now
@pytest.mark.no_nebius # Nebius does not support Docker
@pytest.mark.parametrize('accelerator', [{'do': 'H100'}])
@pytest.mark.parametrize(
'image_id',
[
'docker:nvidia/cuda:11.8.0-devel-ubuntu18.04',
'docker:ubuntu:18.04',
# Test latest image with python 3.11 installed by default.
'docker:continuumio/miniconda3:24.1.2-0',
# Test python>=3.12 where SkyPilot should automatically create a separate
# conda env for runtime with python 3.10.
'docker:continuumio/miniconda3:latest',
# Axolotl image is a good example custom image that has its conda path
# set in PATH with dockerfile and uses python>=3.12. It could test:
# 1. we handle the env var set in dockerfile correctly
# 2. python>=3.12 works with SkyPilot runtime.
'docker:winglian/axolotl:main-latest'
])
def test_job_queue_with_docker(generic_cloud: str, image_id: str,
accelerator: Dict[str, str]):
accelerator = accelerator.get(generic_cloud, 'T4')
name = smoke_tests_utils.get_cluster_name() + image_id[len('docker:'):][:4]
total_timeout_minutes = 40 if generic_cloud == 'azure' else 15
time_to_sleep = 300 if generic_cloud == 'azure' else 200
test = smoke_tests_utils.Test(
'job_queue_with_docker',
[
f'sky launch -y -c {name} --cloud {generic_cloud} {smoke_tests_utils.LOW_RESOURCE_ARG} --gpus {accelerator} --image-id {image_id} examples/job_queue/cluster_docker.yaml',
f'sky exec {name} -n {name}-1 -d --gpus {accelerator}:0.5 --image-id {image_id} --env TIME_TO_SLEEP={time_to_sleep*2} examples/job_queue/job_docker.yaml',
f'sky exec {name} -n {name}-2 -d --gpus {accelerator}:0.5 --image-id {image_id} --env TIME_TO_SLEEP={time_to_sleep} examples/job_queue/job_docker.yaml',
f'sky exec {name} -n {name}-3 -d --gpus {accelerator}:0.5 --image-id {image_id} --env TIME_TO_SLEEP={time_to_sleep} examples/job_queue/job_docker.yaml',
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep {name}-1 | grep RUNNING',
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep {name}-2 | grep RUNNING',
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep {name}-3 | grep PENDING',
f'sky cancel -y {name} 2',
'sleep 5',
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep {name}-3 | grep RUNNING',
f'sky cancel -y {name} 3',
# Make sure the GPU is still visible to the container.
f'sky exec {name} --image-id {image_id} nvidia-smi | grep -i "{accelerator}"',
f'sky logs {name} 4 --status',
f'sky stop -y {name}',
# Make sure the job status preserve after stop and start the
# cluster. This is also a test for the docker container to be
# preserved after stop and start.
f'sky start -y {name}',
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep {name}-1 | grep FAILED',
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep {name}-2 | grep CANCELLED',
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep {name}-3 | grep CANCELLED',
f'sky exec {name} --gpus {accelerator}:0.2 "[[ \$SKYPILOT_NUM_GPUS_PER_NODE -eq 1 ]] || exit 1"',
f'sky exec {name} --gpus {accelerator}:1 "[[ \$SKYPILOT_NUM_GPUS_PER_NODE -eq 1 ]] || exit 1"',
f'sky logs {name} 5 --status',
f'sky logs {name} 6 --status',
# Make sure it is still visible after an stop & start cycle.
f'sky exec {name} --image-id {image_id} nvidia-smi | grep "Tesla T4"',
f'sky logs {name} 7 --status'
],
f'sky down -y {name}',
timeout=total_timeout_minutes * 60,
)
smoke_tests_utils.run_one_test(test)
@pytest.mark.lambda_cloud
def test_lambda_job_queue():
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'lambda_job_queue',
[
f'sky launch -y -c {name} {smoke_tests_utils.LAMBDA_TYPE} examples/job_queue/cluster.yaml',
f'sky exec {name} -n {name}-1 --gpus A10:0.5 -d examples/job_queue/job.yaml',
f'sky exec {name} -n {name}-2 --gpus A10:0.5 -d examples/job_queue/job.yaml',
f'sky exec {name} -n {name}-3 --gpus A10:0.5 -d examples/job_queue/job.yaml',
f'sky queue {name} | grep {name}-1 | grep RUNNING',
f'sky queue {name} | grep {name}-2 | grep RUNNING',
f'sky queue {name} | grep {name}-3 | grep PENDING',
f'sky cancel -y {name} 2',
'sleep 5',
f'sky queue {name} | grep {name}-3 | grep RUNNING',
f'sky cancel -y {name} 3',
],
f'sky down -y {name}',
)
smoke_tests_utils.run_one_test(test)
@pytest.mark.ibm
def test_ibm_job_queue():
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'ibm_job_queue',
[
f'sky launch -y -c {name} --cloud ibm --gpus v100',
f'sky exec {name} -n {name}-1 --cloud ibm -d examples/job_queue/job_ibm.yaml',
f'sky exec {name} -n {name}-2 --cloud ibm -d examples/job_queue/job_ibm.yaml',
f'sky exec {name} -n {name}-3 --cloud ibm -d examples/job_queue/job_ibm.yaml',
f'sky queue {name} | grep {name}-1 | grep RUNNING',
f'sky queue {name} | grep {name}-2 | grep RUNNING',
f'sky queue {name} | grep {name}-3 | grep PENDING',
f'sky cancel -y {name} 2',
'sleep 5',
f'sky queue {name} | grep {name}-3 | grep RUNNING',
f'sky cancel -y {name} 3',
],
f'sky down -y {name}',
)
smoke_tests_utils.run_one_test(test)
@pytest.mark.scp
def test_scp_job_queue():
name = smoke_tests_utils.get_cluster_name()
num_of_gpu_launch = 1
num_of_gpu_exec = 0.5
test = smoke_tests_utils.Test(
'SCP_job_queue',
[
f'sky launch -y -c {name} {smoke_tests_utils.SCP_TYPE} {smoke_tests_utils.SCP_GPU_V100}:{num_of_gpu_launch} examples/job_queue/cluster.yaml',
f'sky exec {name} -n {name}-1 {smoke_tests_utils.SCP_GPU_V100}:{num_of_gpu_exec} -d examples/job_queue/job.yaml',
f'sky exec {name} -n {name}-2 {smoke_tests_utils.SCP_GPU_V100}:{num_of_gpu_exec} -d examples/job_queue/job.yaml',
f'sky exec {name} -n {name}-3 {smoke_tests_utils.SCP_GPU_V100}:{num_of_gpu_exec} -d examples/job_queue/job.yaml',
f'sky queue {name} | grep {name}-1 | grep RUNNING',
f'sky queue {name} | grep {name}-2 | grep RUNNING',
f'sky queue {name} | grep {name}-3 | grep PENDING',
f'sky cancel -y {name} 2',
'sleep 5',
f'sky queue {name} | grep {name}-3 | grep RUNNING',
f'sky cancel -y {name} 3',
],
f'sky down -y {name}',
)
smoke_tests_utils.run_one_test(test)
@pytest.mark.no_vast # Vast has low availability of T4 GPUs
@pytest.mark.no_fluidstack # FluidStack DC has low availability of T4 GPUs
@pytest.mark.no_lambda_cloud # Lambda Cloud does not have T4 gpus
@pytest.mark.no_ibm # IBM Cloud does not have T4 gpus. run test_ibm_job_queue_multinode instead
@pytest.mark.no_paperspace # Paperspace does not have T4 gpus.
@pytest.mark.no_scp # SCP does not support num_nodes > 1 yet
@pytest.mark.no_oci # OCI Cloud does not have T4 gpus.
@pytest.mark.no_vast # Vast does not support num_nodes > 1 yet
@pytest.mark.no_kubernetes # Kubernetes not support num_nodes > 1 yet
@pytest.mark.no_nebius # Nebius does not have T4 gpus.
@pytest.mark.parametrize('accelerator', [{'do': 'H100'}])
def test_job_queue_multinode(generic_cloud: str, accelerator: Dict[str, str]):
accelerator = accelerator.get(generic_cloud, 'T4')
name = smoke_tests_utils.get_cluster_name()
total_timeout_minutes = 30 if generic_cloud == 'azure' else 15
test = smoke_tests_utils.Test(
'job_queue_multinode',
[
f'sky launch -y -c {name} --cloud {generic_cloud} {smoke_tests_utils.LOW_RESOURCE_ARG} --gpus {accelerator} examples/job_queue/cluster_multinode.yaml',
f'sky exec {name} -n {name}-1 -d --gpus {accelerator}:0.5 examples/job_queue/job_multinode.yaml',
f'sky exec {name} -n {name}-2 -d --gpus {accelerator}:0.5 examples/job_queue/job_multinode.yaml',
f'sky launch -c {name} -n {name}-3 -d --gpus {accelerator}:0.5 examples/job_queue/job_multinode.yaml',
f's=$(sky queue {name}) && echo "$s" && (echo "$s" | grep {name}-1 | grep RUNNING)',
f's=$(sky queue {name}) && echo "$s" && (echo "$s" | grep {name}-2 | grep RUNNING)',
f's=$(sky queue {name}) && echo "$s" && (echo "$s" | grep {name}-3 | grep PENDING)',
'sleep 90',
f'sky cancel -y {name} 1',
'sleep 5',
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep {name}-3 | grep SETTING_UP',
f'sky cancel -y {name} 1 2 3',
f'sky launch -c {name} -n {name}-4 -d --gpus {accelerator} examples/job_queue/job_multinode.yaml',
# Test the job status is correctly set to SETTING_UP, during the setup is running,
# and the job can be cancelled during the setup.
'sleep 5',
f's=$(sky queue {name}) && echo "$s" && (echo "$s" | grep {name}-4 | grep SETTING_UP)',
f'sky cancel -y {name} 4',
f's=$(sky queue {name}) && echo "$s" && (echo "$s" | grep {name}-4 | grep CANCELLED)',
f'sky exec {name} --gpus {accelerator}:0.2 "[[ \$SKYPILOT_NUM_GPUS_PER_NODE -eq 1 ]] || exit 1"',
f'sky exec {name} --gpus {accelerator}:0.2 --num-nodes 2 "[[ \$SKYPILOT_NUM_GPUS_PER_NODE -eq 1 ]] || exit 1"',
f'sky exec {name} --gpus {accelerator}:1 --num-nodes 2 "[[ \$SKYPILOT_NUM_GPUS_PER_NODE -eq 1 ]] || exit 1"',
f'sky logs {name} 5 --status',
f'sky logs {name} 6 --status',
f'sky logs {name} 7 --status',
],
f'sky down -y {name}',
timeout=total_timeout_minutes * 60,
)
smoke_tests_utils.run_one_test(test)
@pytest.mark.no_fluidstack # No FluidStack VM has 8 CPUs
@pytest.mark.no_lambda_cloud # No Lambda Cloud VM has 8 CPUs
@pytest.mark.no_vast # Vast doesn't guarantee exactly 8 CPUs, only at least.
@pytest.mark.resource_heavy
def test_large_job_queue(generic_cloud: str):
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'large_job_queue',
[
f'sky launch -y -c {name} --cpus 8 --cloud {generic_cloud}',
f'for i in `seq 1 75`; do sky exec {name} -n {name}-$i -d "echo $i; sleep 100000000"; done',
f'sky cancel -y {name} 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16',
'sleep 90',
# Each job takes 0.5 CPU and the default VM has 8 CPUs, so there should be 8 / 0.5 = 16 jobs running.
# The first 16 jobs are canceled, so there should be 75 - 32 = 43 jobs PENDING.
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep -v grep | grep PENDING | wc -l | grep 43',
# Make sure the jobs are scheduled in FIFO order
*[
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep {name}-{i} | grep CANCELLED'
for i in range(1, 17)
],
*[
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep {name}-{i} | grep RUNNING'
for i in range(17, 33)
],
*[
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep {name}-{i} | grep PENDING'
for i in range(33, 75)
],
f'sky cancel -y {name} 33 35 37 39 17 18 19',
*[
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep {name}-{i} | grep CANCELLED'
for i in range(33, 40, 2)
],
'sleep 10',
*[
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep {name}-{i} | grep RUNNING'
for i in [34, 36, 38]
],
],
f'sky down -y {name}',
timeout=25 * 60,
)
smoke_tests_utils.run_one_test(test)
@pytest.mark.no_fluidstack # No FluidStack VM has 8 CPUs
@pytest.mark.no_lambda_cloud # No Lambda Cloud VM has 8 CPUs
@pytest.mark.no_vast # No Vast Cloud VM has 8 CPUs
@pytest.mark.resource_heavy
def test_fast_large_job_queue(generic_cloud: str):
# This is to test the jobs can be scheduled quickly when there are many jobs in the queue.
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'fast_large_job_queue',
[
f'sky launch -y -c {name} --cpus 8 --cloud {generic_cloud}',
f'for i in `seq 1 32`; do sky exec {name} -n {name}-$i -d "echo $i"; done',
'sleep 60',
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep -v grep | grep SUCCEEDED | wc -l | grep 32',
],
f'sky down -y {name}',
timeout=20 * 60,
)
smoke_tests_utils.run_one_test(test)
@pytest.mark.ibm
def test_ibm_job_queue_multinode():
name = smoke_tests_utils.get_cluster_name()
task_file = 'examples/job_queue/job_multinode_ibm.yaml'
test = smoke_tests_utils.Test(
'ibm_job_queue_multinode',
[
f'sky launch -y -c {name} --cloud ibm --gpus v100 --num-nodes 2',
f'sky exec {name} -n {name}-1 -d {task_file}',
f'sky exec {name} -n {name}-2 -d {task_file}',
f'sky launch -y -c {name} -n {name}-3 -d {task_file}',
f's=$(sky queue {name}) && printf "$s" && (echo "$s" | grep {name}-1 | grep RUNNING)',
f's=$(sky queue {name}) && printf "$s" && (echo "$s" | grep {name}-2 | grep RUNNING)',
f's=$(sky queue {name}) && printf "$s" && (echo "$s" | grep {name}-3 | grep SETTING_UP)',
'sleep 90',
f's=$(sky queue {name}) && printf "$s" && (echo "$s" | grep {name}-3 | grep PENDING)',
f'sky cancel -y {name} 1',
'sleep 5',
f'sky queue {name} | grep {name}-3 | grep RUNNING',
f'sky cancel -y {name} 1 2 3',
f'sky launch -c {name} -n {name}-4 -d {task_file}',
# Test the job status is correctly set to SETTING_UP, during the setup is running,
# and the job can be cancelled during the setup.
f's=$(sky queue {name}) && printf "$s" && (echo "$s" | grep {name}-4 | grep SETTING_UP)',
f'sky cancel -y {name} 4',
f's=$(sky queue {name}) && printf "$s" && (echo "$s" | grep {name}-4 | grep CANCELLED)',
f'sky exec {name} --gpus v100:0.2 "[[ \$SKYPILOT_NUM_GPUS_PER_NODE -eq 1 ]] || exit 1"',
f'sky exec {name} --gpus v100:0.2 --num-nodes 2 "[[ \$SKYPILOT_NUM_GPUS_PER_NODE -eq 1 ]] || exit 1"',
f'sky exec {name} --gpus v100:1 --num-nodes 2 "[[ \$SKYPILOT_NUM_GPUS_PER_NODE -eq 1 ]] || exit 1"',
f'sky logs {name} 5 --status',
f'sky logs {name} 6 --status',
f'sky logs {name} 7 --status',
],
f'sky down -y {name}',
timeout=20 * 60, # 20 mins
)
smoke_tests_utils.run_one_test(test)
# ---------- Docker with preinstalled package. ----------
@pytest.mark.no_fluidstack # Doesn't support Fluidstack for now
@pytest.mark.no_lambda_cloud # Doesn't support Lambda Cloud for now
@pytest.mark.no_ibm # Doesn't support IBM Cloud for now
@pytest.mark.no_scp # Doesn't support SCP for now
@pytest.mark.no_oci # Doesn't support OCI for now
@pytest.mark.no_kubernetes # Doesn't support Kubernetes for now
@pytest.mark.no_nebius # Nebius does not support Docker
# TODO(zhwu): we should fix this for kubernetes
def test_docker_preinstalled_package(generic_cloud: str):
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'docker_with_preinstalled_package',
[
f'sky launch -y -c {name} --cloud {generic_cloud} {smoke_tests_utils.LOW_RESOURCE_ARG} --image-id docker:nginx',
f'sky exec {name} "nginx -V"',
f'sky logs {name} 1 --status',
f'sky exec {name} whoami | grep root',
],
f'sky down -y {name}',
)
smoke_tests_utils.run_one_test(test)
# ---------- Submitting multiple tasks to the same cluster. ----------
@pytest.mark.no_vast # Vast has low availability of T4 GPUs
@pytest.mark.no_fluidstack # FluidStack DC has low availability of T4 GPUs
@pytest.mark.no_lambda_cloud # Lambda Cloud does not have T4 gpus
@pytest.mark.no_paperspace # Paperspace does not have T4 gpus
@pytest.mark.no_ibm # IBM Cloud does not have T4 gpus
@pytest.mark.no_scp # SCP does not support num_nodes > 1 yet
@pytest.mark.no_oci # OCI Cloud does not have T4 gpus
@pytest.mark.no_do # DO does not have T4 gpus
@pytest.mark.no_nebius # Nebius does not have T4 gpus
@pytest.mark.resource_heavy
def test_multi_echo(generic_cloud: str):
name = smoke_tests_utils.get_cluster_name()
use_spot = True
# EKS does not support spot instances
if generic_cloud == 'kubernetes':
use_spot = not smoke_tests_utils.is_eks_cluster()
test = smoke_tests_utils.Test(
'multi_echo',
[
f'python examples/multi_echo.py {name} {generic_cloud} {int(use_spot)}',
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep "FAILED" && exit 1 || true',
'sleep 10',
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep "FAILED" && exit 1 || true',
'sleep 30',
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep "FAILED" && exit 1 || true',
'sleep 30',
# Make sure that our job scheduler is fast enough to have at least
# 15 RUNNING jobs in parallel.
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep "RUNNING" | wc -l | awk \'{{if ($1 < 15) exit 1}}\'',
'sleep 30',
f's=$(sky queue {name}); echo "$s"; echo; echo; echo "$s" | grep "FAILED" && exit 1 || true',
# This is to make sure we can finish job 32 before the test timeout.
f'until sky logs {name} 32 --status; do echo "Waiting for job 32 to finish..."; sleep 1; done',
] +
# Ensure jobs succeeded.
[
smoke_tests_utils.
get_cmd_wait_until_job_status_contains_matching_job_id(
cluster_name=name,
job_id=i + 1,
job_status=[sky.JobStatus.SUCCEEDED],
timeout=120) for i in range(32)
] + [
# ssh record will only be created on cli command like sky status on client side.
f'sky status {name}',
# Ensure monitor/autoscaler didn't crash on the 'assert not
# unfulfilled' error. If process not found, grep->ssh returns 1.
f'ssh {name} \'ps aux | grep "[/]"monitor.py\''
],
f'sky down -y {name}',
timeout=20 * 60,
)
smoke_tests_utils.run_one_test(test)
# ---------- Task: 1 node training. ----------
@pytest.mark.no_vast # Vast has low availability of T4 GPUs
@pytest.mark.no_fluidstack # Fluidstack does not have T4 gpus for now
@pytest.mark.no_lambda_cloud # Lambda Cloud does not have V100 gpus
@pytest.mark.no_ibm # IBM cloud currently doesn't provide public image with CUDA
@pytest.mark.no_scp # SCP does not have V100 (16GB) GPUs. Run test_scp_huggingface instead.
@pytest.mark.no_nebius # Nebius does not have T4 gpus for now
@pytest.mark.resource_heavy
@pytest.mark.parametrize('accelerator', [{'do': 'H100'}])
def test_huggingface(generic_cloud: str, accelerator: Dict[str, str]):
accelerator = accelerator.get(generic_cloud, 'T4')
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'huggingface_glue_imdb_app',
[
f'sky launch -y -c {name} --cloud {generic_cloud} {smoke_tests_utils.LOW_RESOURCE_ARG} --gpus {accelerator} examples/huggingface_glue_imdb_app.yaml',
f'sky logs {name} 1 --status', # Ensure the job succeeded.
f'sky exec {name} --gpus {accelerator} examples/huggingface_glue_imdb_app.yaml',
f'sky logs {name} 2 --status', # Ensure the job succeeded.
],
f'sky down -y {name}',
)
smoke_tests_utils.run_one_test(test)
@pytest.mark.lambda_cloud
def test_lambda_huggingface(generic_cloud: str):
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'lambda_huggingface_glue_imdb_app',
[
f'sky launch -y -c {name} {smoke_tests_utils.LAMBDA_TYPE} {smoke_tests_utils.LOW_RESOURCE_ARG} examples/huggingface_glue_imdb_app.yaml',
f'sky logs {name} 1 --status', # Ensure the job succeeded.
f'sky exec {name} {smoke_tests_utils.LAMBDA_TYPE} examples/huggingface_glue_imdb_app.yaml',
f'sky logs {name} 2 --status', # Ensure the job succeeded.
],
f'sky down -y {name}',
)
smoke_tests_utils.run_one_test(test)
@pytest.mark.scp
def test_scp_huggingface(generic_cloud: str):
name = smoke_tests_utils.get_cluster_name()
num_of_gpu_launch = 1
test = smoke_tests_utils.Test(
'SCP_huggingface_glue_imdb_app',
[
f'sky launch -y -c {name} {smoke_tests_utils.SCP_TYPE} {smoke_tests_utils.SCP_GPU_V100}:{num_of_gpu_launch} examples/huggingface_glue_imdb_app.yaml',
f'sky logs {name} 1 --status', # Ensure the job succeeded.
f'sky exec {name} {smoke_tests_utils.SCP_TYPE} {smoke_tests_utils.SCP_GPU_V100}:{num_of_gpu_launch} examples/huggingface_glue_imdb_app.yaml',
f'sky logs {name} 2 --status', # Ensure the job succeeded.
],
f'sky down -y {name}',
)
smoke_tests_utils.run_one_test(test)
# ---------- Inferentia. ----------
@pytest.mark.aws
def test_inferentia():
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'test_inferentia',
[
f'sky launch -y -c {name} -t inf2.xlarge -- echo hi',
f'sky exec {name} --gpus Inferentia2:1 echo hi',
f'sky logs {name} 1 --status', # Ensure the job succeeded.
f'sky logs {name} 2 --status', # Ensure the job succeeded.
],
f'sky down -y {name}',
)
smoke_tests_utils.run_one_test(test)
# ---------- TPU. ----------
@pytest.mark.gcp
@pytest.mark.tpu
def test_tpu():
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'tpu_app',
[
f'sky launch -y -c {name} examples/tpu/tpu_app.yaml',
f'sky logs {name} 1', # Ensure the job finished.
f'sky logs {name} 1 --status', # Ensure the job succeeded.
f'sky launch -y -c {name} examples/tpu/tpu_app.yaml | grep "TPU .* already exists"', # Ensure sky launch won't create another TPU.
],
f'sky down -y {name}',
timeout=30 * 60, # can take >20 mins
)
smoke_tests_utils.run_one_test(test)
# ---------- TPU VM. ----------
@pytest.mark.gcp
@pytest.mark.tpu
def test_tpu_vm():
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'tpu_vm_app',
[
f'sky launch -y -c {name} examples/tpu/tpuvm_mnist.yaml',
f'sky logs {name} 1', # Ensure the job finished.
f'sky logs {name} 1 --status', # Ensure the job succeeded.
f'sky stop -y {name}',
f's=$(sky status {name} --refresh); echo "$s"; echo; echo; echo "$s" | grep {name} | grep STOPPED', # Ensure the cluster is STOPPED.
# Use retry: guard against transient errors observed for
# just-stopped TPU VMs (#962).
f'sky start --retry-until-up -y {name}',
f'sky exec {name} examples/tpu/tpuvm_mnist.yaml',
f'sky logs {name} 2 --status', # Ensure the job succeeded.
f'sky stop -y {name}',
],
f'sky down -y {name}',
timeout=30 * 60, # can take 30 mins
)
smoke_tests_utils.run_one_test(test)
# ---------- TPU VM Pod. ----------
@pytest.mark.gcp
@pytest.mark.tpu
def test_tpu_vm_pod():
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'tpu_pod',
[
f'sky launch -y -c {name} examples/tpu/tpuvm_mnist.yaml --gpus tpu-v2-32 --use-spot --zone europe-west4-a',
f'sky logs {name} 1', # Ensure the job finished.
f'sky logs {name} 1 --status', # Ensure the job succeeded.
],
f'sky down -y {name}',
timeout=30 * 60, # can take 30 mins
)
smoke_tests_utils.run_one_test(test)
# ---------- TPU Pod Slice on GKE. ----------
@pytest.mark.kubernetes
@pytest.mark.skip
def test_tpu_pod_slice_gke():
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'tpu_pod_slice_gke',
[
f'sky launch -y -c {name} examples/tpu/tpuvm_mnist.yaml --cloud kubernetes --gpus tpu-v5-lite-podslice',
f'sky logs {name} 1', # Ensure the job finished.
f'sky logs {name} 1 --status', # Ensure the job succeeded.
f'sky exec {name} "conda activate flax; python -c \'import jax; print(jax.devices()[0].platform);\' | grep tpu || exit 1;"', # Ensure TPU is reachable.
f'sky logs {name} 2 --status'
],
f'sky down -y {name}',
timeout=30 * 60, # can take 30 mins
)
smoke_tests_utils.run_one_test(test)
# ---------- Simple apps. ----------
@pytest.mark.no_vast # Vast does not support num_nodes > 1 yet
@pytest.mark.no_scp # SCP does not support num_nodes > 1 yet
def test_multi_hostname(generic_cloud: str):
name = smoke_tests_utils.get_cluster_name()
total_timeout_minutes = 25 if generic_cloud == 'azure' else 15
test = smoke_tests_utils.Test(
'multi_hostname',
[
f'sky launch -y -c {name} --cloud {generic_cloud} {smoke_tests_utils.LOW_RESOURCE_ARG} examples/multi_hostname.yaml',
f'sky logs {name} 1 --status', # Ensure the job succeeded.
f'sky logs {name} 1 | grep "My hostname:" | wc -l | grep 2', # Ensure there are 2 hosts.
f'sky exec {name} examples/multi_hostname.yaml',
f'sky logs {name} 2 --status', # Ensure the job succeeded.
],
f'sky down -y {name}',
timeout=smoke_tests_utils.get_timeout(generic_cloud,
total_timeout_minutes * 60),
)
smoke_tests_utils.run_one_test(test)
@pytest.mark.no_vast # Vast does not support num_nodes > 1 yet
@pytest.mark.no_scp # SCP does not support num_nodes > 1 yet
def test_multi_node_failure(generic_cloud: str):
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'multi_node_failure',
[
f'sky launch -y -c {name} --cloud {generic_cloud} {smoke_tests_utils.LOW_RESOURCE_ARG} tests/test_yamls/failed_worker_setup.yaml || [ $? -eq 100 ]',
f'sky logs {name} 1 --status | grep FAILED_SETUP', # Ensure the job setup failed.
f'sky exec {name} tests/test_yamls/failed_worker_run.yaml || [ $? -eq 100 ]',
f'sky logs {name} 2 --status | grep FAILED', # Ensure the job failed.
f'sky logs {name} 2 | grep "My hostname:" | wc -l | grep 2', # Ensure there 2 of the hosts printed their hostname.
],
f'sky down -y {name}',
)
smoke_tests_utils.run_one_test(test)
# ---------- Web apps with custom ports on GCP. ----------
@pytest.mark.gcp
def test_gcp_http_server_with_custom_ports():
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'gcp_http_server_with_custom_ports',
[
f'sky launch -y -d -c {name} --cloud gcp {smoke_tests_utils.LOW_RESOURCE_ARG} examples/http_server_with_custom_ports/task.yaml',
f'until SKYPILOT_DEBUG=0 sky status --endpoint 33828 {name}; do sleep 10; done',
# Retry a few times to avoid flakiness in ports being open.
f'ip=$(SKYPILOT_DEBUG=0 sky status --endpoint 33828 {name}); success=false; for i in $(seq 1 5); do if curl $ip | grep "<h1>This is a demo HTML page.</h1>"; then success=true; break; fi; sleep 10; done; if [ "$success" = false ]; then exit 1; fi',
],
f'sky down -y {name}',
)
smoke_tests_utils.run_one_test(test)
# ---------- Web apps with custom ports on AWS. ----------
@pytest.mark.aws
def test_aws_http_server_with_custom_ports():
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'aws_http_server_with_custom_ports',
[
f'sky launch -y -d -c {name} --cloud aws {smoke_tests_utils.LOW_RESOURCE_ARG} examples/http_server_with_custom_ports/task.yaml',
f'until SKYPILOT_DEBUG=0 sky status --endpoint 33828 {name}; do sleep 10; done',
# Retry a few times to avoid flakiness in ports being open.
f'ip=$(SKYPILOT_DEBUG=0 sky status --endpoint 33828 {name}); success=false; for i in $(seq 1 5); do if curl $ip | grep "<h1>This is a demo HTML page.</h1>"; then success=true; break; fi; sleep 10; done; if [ "$success" = false ]; then exit 1; fi'
],
f'sky down -y {name}',
)
smoke_tests_utils.run_one_test(test)
# ---------- Web apps with custom ports on Azure. ----------
@pytest.mark.azure
def test_azure_http_server_with_custom_ports():
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'azure_http_server_with_custom_ports',
[
f'sky launch -y -d -c {name} --cloud azure {smoke_tests_utils.LOW_RESOURCE_ARG} examples/http_server_with_custom_ports/task.yaml',
f'until SKYPILOT_DEBUG=0 sky status --endpoint 33828 {name}; do sleep 10; done',
# Retry a few times to avoid flakiness in ports being open.
f'ip=$(SKYPILOT_DEBUG=0 sky status --endpoint 33828 {name}); success=false; for i in $(seq 1 5); do if curl $ip | grep "<h1>This is a demo HTML page.</h1>"; then success=true; break; fi; sleep 10; done; if [ "$success" = false ]; then exit 1; fi'
],
f'sky down -y {name}',
)
smoke_tests_utils.run_one_test(test)
# ---------- Web apps with custom ports on Kubernetes. ----------
@pytest.mark.kubernetes
@pytest.mark.resource_heavy
def test_kubernetes_http_server_with_custom_ports():
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'kubernetes_http_server_with_custom_ports',
[
f'sky launch -y -d -c {name} --cloud kubernetes examples/http_server_with_custom_ports/task.yaml',
f'until SKYPILOT_DEBUG=0 sky status --endpoint 33828 {name}; do sleep 10; done',
# Retry a few times to avoid flakiness in ports being open.
f'ip=$(SKYPILOT_DEBUG=0 sky status --endpoint 33828 {name}); success=false; for i in $(seq 1 100); do if curl $ip | grep "<h1>This is a demo HTML page.</h1>"; then success=true; break; fi; sleep 5; done; if [ "$success" = false ]; then exit 1; fi'
],
f'sky down -y {name}',
)
smoke_tests_utils.run_one_test(test)
# ---------- Web apps with custom ports on Paperspace. ----------
@pytest.mark.paperspace
def test_paperspace_http_server_with_custom_ports():
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'paperspace_http_server_with_custom_ports',
[
f'sky launch -y -d -c {name} --cloud paperspace examples/http_server_with_custom_ports/task.yaml',
f'until SKYPILOT_DEBUG=0 sky status --endpoint 33828 {name}; do sleep 10; done',
# Retry a few times to avoid flakiness in ports being open.
f'ip=$(SKYPILOT_DEBUG=0 sky status --endpoint 33828 {name}); success=false; for i in $(seq 1 5); do if curl $ip | grep "<h1>This is a demo HTML page.</h1>"; then success=true; break; fi; sleep 10; done; if [ "$success" = false ]; then exit 1; fi',
],
f'sky down -y {name}',
)
smoke_tests_utils.run_one_test(test)
# ---------- Web apps with custom ports on RunPod. ----------
@pytest.mark.runpod
def test_runpod_http_server_with_custom_ports():
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'runpod_http_server_with_custom_ports',
[
f'sky launch -y -d -c {name} --cloud runpod examples/http_server_with_custom_ports/task.yaml',
f'until SKYPILOT_DEBUG=0 sky status --endpoint 33828 {name}; do sleep 10; done',
# Retry a few times to avoid flakiness in ports being open.
f'ip=$(SKYPILOT_DEBUG=0 sky status --endpoint 33828 {name}); success=false; for i in $(seq 1 5); do if curl $ip | grep "<h1>This is a demo HTML page.</h1>"; then success=true; break; fi; sleep 10; done; if [ "$success" = false ]; then exit 1; fi',
],
f'sky down -y {name}',
)
smoke_tests_utils.run_one_test(test)
# ---------- Web apps with custom ports on SCP. ----------
@pytest.mark.scp
def test_scp_http_server_with_custom_ports():
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'scp_http_server_with_custom_ports',
[
f'sky launch -y -d -c {name} --cloud scp examples/http_server_with_custom_ports/task.yaml',
f'until SKYPILOT_DEBUG=0 sky status --endpoint 33828 {name}; do sleep 10; done',
# Retry a few times to avoid flakiness in ports being open.
f'ip=$(SKYPILOT_DEBUG=0 sky status --endpoint 33828 {name}); success=false; for i in $(seq 1 5); do if curl $ip | grep "<h1>This is a demo HTML page.</h1>"; then success=true; break; fi; sleep 10; done; if [ "$success" = false ]; then exit 1; fi'
],
f'sky down -y {name}',
)
smoke_tests_utils.run_one_test(test)
# ---------- Labels from task on AWS (instance_tags) ----------
@pytest.mark.aws
def test_task_labels_aws():
name = smoke_tests_utils.get_cluster_name()
template_str = pathlib.Path(
'tests/test_yamls/test_labels.yaml.j2').read_text()
template = jinja2.Template(template_str)
content = template.render(cloud='aws', region='us-east-1')
with tempfile.NamedTemporaryFile(suffix='.yaml', mode='w') as f:
f.write(content)
f.flush()
file_path = f.name
test = smoke_tests_utils.Test(
'task_labels_aws',
[
smoke_tests_utils.launch_cluster_for_cloud_cmd('aws', name),
f'sky launch -y -c {name} {smoke_tests_utils.LOW_RESOURCE_ARG} {file_path}',
# Verify with aws cli that the tags are set.
smoke_tests_utils.run_cloud_cmd_on_cluster(
name, 'aws ec2 describe-instances '
'--query "Reservations[*].Instances[*].InstanceId" '
'--filters "Name=instance-state-name,Values=running" '
f'--filters "Name=tag:skypilot-cluster-name,Values={name}*" '
'--filters "Name=tag:inlinelabel1,Values=inlinevalue1" '
'--filters "Name=tag:inlinelabel2,Values=inlinevalue2" '
'--region us-east-1 --output text'),
],
f'sky down -y {name} && {smoke_tests_utils.down_cluster_for_cloud_cmd(name)}',
)
smoke_tests_utils.run_one_test(test)
# ---------- Labels from task on GCP (labels) ----------
@pytest.mark.gcp
def test_task_labels_gcp():
name = smoke_tests_utils.get_cluster_name()
template_str = pathlib.Path(
'tests/test_yamls/test_labels.yaml.j2').read_text()
template = jinja2.Template(template_str)
content = template.render(cloud='gcp')
with tempfile.NamedTemporaryFile(suffix='.yaml', mode='w') as f:
f.write(content)
f.flush()
file_path = f.name
test = smoke_tests_utils.Test(
'task_labels_gcp',
[
smoke_tests_utils.launch_cluster_for_cloud_cmd('gcp', name),
f'sky launch -y -c {name} {smoke_tests_utils.LOW_RESOURCE_ARG} {file_path}',
# Verify with gcloud cli that the tags are set
smoke_tests_utils.run_cloud_cmd_on_cluster(
name,
cmd=
(f'gcloud compute instances list --filter="name~\'^{name}\' AND '
'labels.inlinelabel1=\'inlinevalue1\' AND '
'labels.inlinelabel2=\'inlinevalue2\'" '
'--format="value(name)" | grep .')),
],
f'sky down -y {name} && {smoke_tests_utils.down_cluster_for_cloud_cmd(name)}',
)
smoke_tests_utils.run_one_test(test)
# ---------- Labels from task on Kubernetes (labels) ----------
@pytest.mark.kubernetes
def test_task_labels_kubernetes():
name = smoke_tests_utils.get_cluster_name()
template_str = pathlib.Path(
'tests/test_yamls/test_labels.yaml.j2').read_text()
template = jinja2.Template(template_str)
content = template.render(cloud='kubernetes')
with tempfile.NamedTemporaryFile(suffix='.yaml', mode='w') as f:
f.write(content)
f.flush()
file_path = f.name
test = smoke_tests_utils.Test(
'task_labels_kubernetes',
[
smoke_tests_utils.launch_cluster_for_cloud_cmd(
'kubernetes', name),
f'sky launch -y -c {name} {smoke_tests_utils.LOW_RESOURCE_ARG} {file_path}',
# Verify with kubectl that the labels are set.
smoke_tests_utils.run_cloud_cmd_on_cluster(
name, 'kubectl get pods '
'--selector inlinelabel1=inlinevalue1 '
'--selector inlinelabel2=inlinevalue2 '
'-o jsonpath=\'{.items[*].metadata.name}\' | '
f'grep \'^{name}\'')
],
f'sky down -y {name} && '
f'{smoke_tests_utils.down_cluster_for_cloud_cmd(name)}',
)
smoke_tests_utils.run_one_test(test)
# ---------- Pod Annotations on Kubernetes ----------
@pytest.mark.kubernetes
def test_add_pod_annotations_for_autodown_with_launch():
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'add_pod_annotations_for_autodown_with_launch',
[
smoke_tests_utils.launch_cluster_for_cloud_cmd('kubernetes', name),
# Launch Kubernetes cluster with two nodes, each being head node and worker node.
# Autodown is set.
f'sky launch -y -c {name} -i 10 --down --num-nodes 2 --cpus=1 --cloud kubernetes',
# Get names of the pods containing cluster name.
smoke_tests_utils.run_cloud_cmd_on_cluster(
name,
f'pod_1=$(kubectl get pods -o name | grep {name} | sed -n 1p) && '
# Describe the first pod and check for annotations.
'pod_tag=$(kubectl describe $pod_1); echo "$pod_tag"; echo "$pod_tag" | grep -q skypilot.co/autodown && '
'pod_tag=$(kubectl describe $pod_1); echo "$pod_tag"; echo "$pod_tag" | grep -q skypilot.co/idle_minutes_to_autostop'
),
# Get names of the pods containing cluster name.
smoke_tests_utils.run_cloud_cmd_on_cluster(
name,
f'pod_2=$(kubectl get pods -o name | grep {name} | sed -n 2p) && '
# Describe the second pod and check for annotations.
'pod_tag=$(kubectl describe $pod_2); echo "$pod_tag"; echo "$pod_tag" | grep -q skypilot.co/autodown && '
'pod_tag=$(kubectl describe $pod_2); echo "$pod_tag"; echo "$pod_tag" | grep -q skypilot.co/idle_minutes_to_autostop'
),
],
f'sky down -y {name} && '
f'{smoke_tests_utils.down_cluster_for_cloud_cmd(name)}',
)
smoke_tests_utils.run_one_test(test)
@pytest.mark.kubernetes
def test_add_and_remove_pod_annotations_with_autostop():
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'add_and_remove_pod_annotations_with_autostop',
[
smoke_tests_utils.launch_cluster_for_cloud_cmd('kubernetes', name),
# Launch Kubernetes cluster with two nodes, each being head node and worker node.
f'sky launch -y -c {name} --num-nodes 2 --cpus=1 --cloud kubernetes',
# Set autodown on the cluster with 'autostop' command.
f'sky autostop -y {name} -i 20 --down',
# Get names of the pods containing cluster name.
smoke_tests_utils.run_cloud_cmd_on_cluster(
name,
f'pod_1=$(kubectl get pods -o name | grep {name} | sed -n 1p) && '
# Describe the first pod and check for annotations.
'pod_tag=$(kubectl describe $pod_1); echo "$pod_tag"; echo "$pod_tag" | grep -q skypilot.co/autodown && '
'pod_tag=$(kubectl describe $pod_1); echo "$pod_tag"; echo "$pod_tag" | grep -q skypilot.co/idle_minutes_to_autostop',
),
# Describe the second pod and check for annotations.
smoke_tests_utils.run_cloud_cmd_on_cluster(
name,
f'pod_2=$(kubectl get pods -o name | grep {name} | sed -n 2p) && '
'pod_tag=$(kubectl describe $pod_2); echo "$pod_tag"; echo "$pod_tag" | grep -q skypilot.co/autodown && '
'pod_tag=$(kubectl describe $pod_2); echo "$pod_tag"; echo "$pod_tag" | grep -q skypilot.co/idle_minutes_to_autostop'
),
# Cancel the set autodown to remove the annotations from the pods.
f'sky autostop -y {name} --cancel',
# Describe the first pod and check if annotations are removed.
smoke_tests_utils.run_cloud_cmd_on_cluster(
name,
f'pod_1=$(kubectl get pods -o name | grep {name} | sed -n 1p) && '
'pod_tag=$(kubectl describe $pod_1); echo "$pod_tag"; ! echo "$pod_tag" | grep -q skypilot.co/autodown && '
'pod_tag=$(kubectl describe $pod_1); echo "$pod_tag"; ! echo "$pod_tag" | grep -q skypilot.co/idle_minutes_to_autostop',
),
# Describe the second pod and check if annotations are removed.
smoke_tests_utils.run_cloud_cmd_on_cluster(
name,
f'pod_2=$(kubectl get pods -o name | grep {name} | sed -n 2p) && '
'pod_tag=$(kubectl describe $pod_2); echo "$pod_tag"; ! echo "$pod_tag" | grep -q skypilot.co/autodown && '
'pod_tag=$(kubectl describe $pod_2); echo "$pod_tag"; ! echo "$pod_tag" | grep -q skypilot.co/idle_minutes_to_autostop',
),
],
f'sky down -y {name} && '
f'{smoke_tests_utils.down_cluster_for_cloud_cmd(name)}',
)
smoke_tests_utils.run_one_test(test)
# ---------- Container logs from task on Kubernetes ----------
@pytest.mark.resource_heavy
@pytest.mark.kubernetes
def test_container_logs_multinode_kubernetes():
name = smoke_tests_utils.get_cluster_name()
task_yaml = 'tests/test_yamls/test_k8s_logs.yaml'
head_logs = (
'all_pods=$(kubectl get pods); echo "$all_pods"; '
f'echo "$all_pods" | grep {name} | '
# Exclude the cloud cmd execution pod.
'grep -v "cloud-cmd" | '
'grep head | '
" awk '{print $1}' | xargs -I {} kubectl logs {}")
worker_logs = ('all_pods=$(kubectl get pods); echo "$all_pods"; '
f'echo "$all_pods" | grep {name} | grep worker | '
" awk '{print $1}' | xargs -I {} kubectl logs {}")
with tempfile.NamedTemporaryFile(suffix='.yaml', mode='w') as f:
test = smoke_tests_utils.Test(
'container_logs_multinode_kubernetes',
[
smoke_tests_utils.launch_cluster_for_cloud_cmd(
'kubernetes', name),
f'sky launch -y -c {name} {task_yaml} --num-nodes 2',
smoke_tests_utils.run_cloud_cmd_on_cluster(
name,
f'{head_logs} | wc -l | grep 9',
),
smoke_tests_utils.run_cloud_cmd_on_cluster(
name,
f'{worker_logs} | wc -l | grep 9',
),
],
f'sky down -y {name} && '
f'{smoke_tests_utils.down_cluster_for_cloud_cmd(name)}',
)
smoke_tests_utils.run_one_test(test)
@pytest.mark.kubernetes
def test_container_logs_two_jobs_kubernetes():
name = smoke_tests_utils.get_cluster_name()
task_yaml = 'tests/test_yamls/test_k8s_logs.yaml'
pod_logs = (
'all_pods=$(kubectl get pods); echo "$all_pods"; '
f'echo "$all_pods" | grep {name} | '
# Exclude the cloud cmd execution pod.