Skip to content

Commit

Permalink
Add tests for Azure spot instance (#4475)
Browse files Browse the repository at this point in the history
* verify azure spot instance

* string style

* echo

* echo vm detail

* bug fix

* remove comment
  • Loading branch information
zpoint authored Dec 19, 2024
1 parent ce1cb83 commit c19e94e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/smoke_tests/test_cluster_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,34 @@ def test_use_spot(generic_cloud: str):
smoke_tests_utils.run_one_test(test)


@pytest.mark.azure
def test_azure_spot_instance_verification():
"""Test Azure spot instance provisioning with explicit verification.
This test verifies that when --use-spot is specified for Azure:
1. The cluster launches successfully
2. The instances are actually provisioned as spot instances
"""
name = smoke_tests_utils.get_cluster_name()
test = smoke_tests_utils.Test(
'azure-spot-verification',
[
f'sky launch -c {name} --cloud azure tests/test_yamls/minimal.yaml --use-spot -y',
f'sky logs {name} 1 --status', f'TARGET_VM_NAME="{name}"; '
'VM_INFO=$(az vm list --query "[?contains(name, \'$TARGET_VM_NAME\')].{Name:name, ResourceGroup:resourceGroup}" -o tsv); '
'[[ -z "$VM_INFO" ]] && exit 1; '
'FULL_VM_NAME=$(echo "$VM_INFO" | awk \'{print $1}\'); '
'RESOURCE_GROUP=$(echo "$VM_INFO" | awk \'{print $2}\'); '
'VM_DETAILS=$(az vm list --resource-group "$RESOURCE_GROUP" '
'--query "[?name==\'$FULL_VM_NAME\'].{Name:name, Location:location, Priority:priority}" -o table); '
'[[ -z "$VM_DETAILS" ]] && exit 1; '
'echo "VM Details:"; echo "$VM_DETAILS"; '
'echo "$VM_DETAILS" | grep -qw "Spot" && exit 0 || exit 1'
],
f'sky down -y {name}',
)
smoke_tests_utils.run_one_test(test)


@pytest.mark.gcp
def test_stop_gcp_spot():
"""Test GCP spot can be stopped, autostopped, restarted."""
Expand Down

0 comments on commit c19e94e

Please sign in to comment.