|
10 | 10 | import uuid
|
11 | 11 |
|
12 | 12 | import colorama
|
| 13 | +import jinja2 |
13 | 14 | import pytest
|
14 | 15 |
|
15 | 16 | import sky
|
|
31 | 32 | # id.
|
32 | 33 | test_id = str(uuid.uuid4())[-2:]
|
33 | 34 |
|
| 35 | +storage_setup_commands = [ |
| 36 | + 'touch ~/tmpfile', 'mkdir -p ~/tmp-workdir', |
| 37 | + 'touch ~/tmp-workdir/tmp\ file', 'touch ~/tmp-workdir/foo', |
| 38 | + 'ln -f -s ~/tmp-workdir/ ~/tmp-workdir/circle-link' |
| 39 | +] |
| 40 | + |
34 | 41 |
|
35 | 42 | class Test(NamedTuple):
|
36 | 43 | name: str
|
@@ -327,23 +334,51 @@ def test_env_check():
|
327 | 334 | # ---------- file_mounts ----------
|
328 | 335 | def test_file_mounts():
|
329 | 336 | name = _get_cluster_name()
|
| 337 | + test_commands = [ |
| 338 | + *storage_setup_commands, |
| 339 | + f'sky launch -y -c {name} examples/using_file_mounts.yaml', |
| 340 | + f'sky logs {name} 1 --status', # Ensure the job succeeded. |
| 341 | + ] |
330 | 342 | test = Test(
|
331 | 343 | 'using_file_mounts',
|
332 |
| - [ |
333 |
| - 'touch ~/tmpfile', |
334 |
| - 'mkdir -p ~/tmp-workdir', |
335 |
| - 'touch ~/tmp-workdir/tmp\ file', |
336 |
| - 'touch ~/tmp-workdir/foo', |
337 |
| - 'ln -f -s ~/tmp-workdir/ ~/tmp-workdir/circle-link', |
338 |
| - f'sky launch -y -c {name} examples/using_file_mounts.yaml', |
339 |
| - f'sky logs {name} 1 --status', # Ensure the job succeeded. |
340 |
| - ], |
| 344 | + test_commands, |
341 | 345 | f'sky down -y {name}',
|
342 | 346 | timeout=20 * 60, # 20 mins
|
343 | 347 | )
|
344 | 348 | run_one_test(test)
|
345 | 349 |
|
346 | 350 |
|
| 351 | +# ---------- storage ---------- |
| 352 | +def test_storage_mounts(): |
| 353 | + name = _get_cluster_name() |
| 354 | + storage_name = f'sky-test-{int(time.time())}' |
| 355 | + template_str = pathlib.Path( |
| 356 | + 'tests/test_yamls/test_storage_mounting.yaml').read_text() |
| 357 | + template = jinja2.Template(template_str) |
| 358 | + content = template.render(storage_name=storage_name) |
| 359 | + with tempfile.NamedTemporaryFile(suffix='.yaml', mode='w') as f: |
| 360 | + f.write(content) |
| 361 | + f.flush() |
| 362 | + file_path = f.name |
| 363 | + test_commands = [ |
| 364 | + *storage_setup_commands, |
| 365 | + f'sky launch -y -c {name}-aws --cloud aws {file_path}', |
| 366 | + f'sky logs {name}-aws 1 --status', # Ensure job succeeded. |
| 367 | + f'aws s3 ls {storage_name}/hello.txt', |
| 368 | + f'sky storage delete {storage_name}', # Prepare for next cloud |
| 369 | + f'sky launch -y -c {name}-gcp --cloud gcp {file_path}', |
| 370 | + f'sky logs {name}-gcp 1 --status', # Ensure job succeeded. |
| 371 | + f'gsutil ls gs://{storage_name}/hello.txt', |
| 372 | + ] |
| 373 | + test = Test( |
| 374 | + 'storage_mounts', |
| 375 | + test_commands, |
| 376 | + f'sky down -y {name}-aws {name}-gcp; sky storage delete {storage_name}', |
| 377 | + timeout=20 * 60, # 20 mins |
| 378 | + ) |
| 379 | + run_one_test(test) |
| 380 | + |
| 381 | + |
347 | 382 | # ---------- CLI logs ----------
|
348 | 383 | def test_logs():
|
349 | 384 | name = _get_cluster_name()
|
@@ -921,7 +956,7 @@ def test_spot_cancellation():
|
921 | 956 | '--output text) && printf "$s" && echo; [[ -z "$s" ]] || [[ "$s" = "terminated" ]] || [[ "$s" = "shutting-down" ]]'
|
922 | 957 | ),
|
923 | 958 | # Test cancelling the spot cluster during spot job being setup.
|
924 |
| - f'sky spot launch --cloud aws --region {region} -n {name}-2 tests/test_yamls/long_setup.yaml -y -d', |
| 959 | + f'sky spot launch --cloud aws --region {region} -n {name}-2 tests/test_yamls/test_long_setup.yaml -y -d', |
925 | 960 | 'sleep 300',
|
926 | 961 | f'sky spot cancel -y -n {name}-2',
|
927 | 962 | 'sleep 5',
|
@@ -974,6 +1009,7 @@ def test_spot_storage():
|
974 | 1009 | test = Test(
|
975 | 1010 | 'managed-spot-storage',
|
976 | 1011 | [
|
| 1012 | + *storage_setup_commands, |
977 | 1013 | f'sky spot launch -n {name} {file_path} -y',
|
978 | 1014 | 'sleep 60', # Wait the spot queue to be updated
|
979 | 1015 | f'sky spot queue | grep {name} | grep SUCCEEDED',
|
|
0 commit comments