From 7199f32ac5e28231c816a598153dc7221ad5bd60 Mon Sep 17 00:00:00 2001 From: ZePing Guo Date: Tue, 17 Dec 2024 16:35:25 +0800 Subject: [PATCH 1/6] verify azure spot instance --- tests/smoke_tests/test_cluster_job.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/smoke_tests/test_cluster_job.py b/tests/smoke_tests/test_cluster_job.py index 0255884ae30..6e8056fccde 100644 --- a/tests/smoke_tests/test_cluster_job.py +++ b/tests/smoke_tests/test_cluster_job.py @@ -1299,6 +1299,32 @@ 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\" | 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.""" From 09caf934397fe28d38073ba3b963267f418df1d1 Mon Sep 17 00:00:00 2001 From: ZePing Guo Date: Tue, 17 Dec 2024 16:36:34 +0800 Subject: [PATCH 2/6] string style --- tests/smoke_tests/test_cluster_job.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/smoke_tests/test_cluster_job.py b/tests/smoke_tests/test_cluster_job.py index 6e8056fccde..42bc9c9c345 100644 --- a/tests/smoke_tests/test_cluster_job.py +++ b/tests/smoke_tests/test_cluster_job.py @@ -1310,15 +1310,14 @@ def test_azure_spot_instance_verification(): 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\" | grep -qw 'Spot' && exit 0 || exit 1" + 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" | grep -qw "Spot" && exit 0 || exit 1' ], f'sky down -y {name}', ) From b5bd4d821cb9616385c41493b9f5399b820e4db8 Mon Sep 17 00:00:00 2001 From: ZePing Guo Date: Tue, 17 Dec 2024 16:37:45 +0800 Subject: [PATCH 3/6] echo --- tests/smoke_tests/test_cluster_job.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/smoke_tests/test_cluster_job.py b/tests/smoke_tests/test_cluster_job.py index 42bc9c9c345..659b5147cd8 100644 --- a/tests/smoke_tests/test_cluster_job.py +++ b/tests/smoke_tests/test_cluster_job.py @@ -1317,6 +1317,7 @@ def test_azure_spot_instance_verification(): '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}', From a6706e49b57548276bf141b72cab461c8e3fb249 Mon Sep 17 00:00:00 2001 From: ZePing Guo Date: Tue, 17 Dec 2024 16:45:25 +0800 Subject: [PATCH 4/6] echo vm detail --- tests/smoke_tests/test_cluster_job.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/smoke_tests/test_cluster_job.py b/tests/smoke_tests/test_cluster_job.py index 659b5147cd8..935912c76a2 100644 --- a/tests/smoke_tests/test_cluster_job.py +++ b/tests/smoke_tests/test_cluster_job.py @@ -1310,7 +1310,8 @@ def test_azure_spot_instance_verification(): test = smoke_tests_utils.Test( 'azure-spot-verification', [ - f'TARGET_VM_NAME=\'{name}\'; ' + 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}\'); ' From b1a93ab71c65e9d16df36e1bbce1267498a90c4c Mon Sep 17 00:00:00 2001 From: ZePing Guo Date: Tue, 17 Dec 2024 17:14:38 +0800 Subject: [PATCH 5/6] bug fix --- tests/smoke_tests/test_cluster_job.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/smoke_tests/test_cluster_job.py b/tests/smoke_tests/test_cluster_job.py index 935912c76a2..1e3b9edfede 100644 --- a/tests/smoke_tests/test_cluster_job.py +++ b/tests/smoke_tests/test_cluster_job.py @@ -1311,17 +1311,18 @@ def test_azure_spot_instance_verification(): '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); ' + 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); ' + '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}', + #f'sky down -y {name}', ) smoke_tests_utils.run_one_test(test) From f98b8571158fcb9d3d7d47a6abab4661783aabc0 Mon Sep 17 00:00:00 2001 From: ZePing Guo Date: Wed, 18 Dec 2024 11:48:57 +0800 Subject: [PATCH 6/6] remove comment --- tests/smoke_tests/test_cluster_job.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/smoke_tests/test_cluster_job.py b/tests/smoke_tests/test_cluster_job.py index 1e3b9edfede..18b82c649e7 100644 --- a/tests/smoke_tests/test_cluster_job.py +++ b/tests/smoke_tests/test_cluster_job.py @@ -1322,7 +1322,7 @@ def test_azure_spot_instance_verification(): 'echo "VM Details:"; echo "$VM_DETAILS"; ' 'echo "$VM_DETAILS" | grep -qw "Spot" && exit 0 || exit 1' ], - #f'sky down -y {name}', + f'sky down -y {name}', ) smoke_tests_utils.run_one_test(test)