-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Core] Relax cluster name restriction and process cloud cluster name (#…
…3130) * [core] change regex to allow for uppercase, periods, and underscores for cluster name * [core] process cluster name when making it for the cloud * [core] add tests for make cluster name on cloud * [core] format * [core] add quotations to logged local cluster name * [core] move quotation marks inside parentheses * [core] update param name from local_cluster_name to display name for naming consistency * [core] update docstr * [core] simplify replace and lowercase * [core] use logger.debug * [core] remove unused exception and rename hash var * [core] move check cluster name method to common_utils * [core] update docstr for check cluster name method * [core] fix verb * [core] update docstr and debug for make cluster name on cloud method * [core] update docstr and include dot and underscore for regex --------- Co-authored-by: David Tran <[email protected]>
- Loading branch information
Showing
6 changed files
with
105 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from sky import exceptions | ||
from sky.utils import common_utils | ||
|
||
MOCKED_USER_HASH = 'ab12cd34' | ||
|
||
|
||
class TestCheckClusterNameIsValid: | ||
|
||
def test_check(self): | ||
common_utils.check_cluster_name_is_valid("lora") | ||
|
||
def test_check_with_hyphen(self): | ||
common_utils.check_cluster_name_is_valid("seed-1") | ||
|
||
def test_check_with_characters_to_transform(self): | ||
common_utils.check_cluster_name_is_valid("Cuda_11.8") | ||
|
||
def test_check_when_starts_with_number(self): | ||
with pytest.raises(exceptions.InvalidClusterNameError): | ||
common_utils.check_cluster_name_is_valid("11.8cuda") | ||
|
||
def test_check_with_invalid_characters(self): | ||
with pytest.raises(exceptions.InvalidClusterNameError): | ||
common_utils.check_cluster_name_is_valid("lor@") | ||
|
||
def test_check_when_none(self): | ||
common_utils.check_cluster_name_is_valid(None) | ||
|
||
|
||
class TestMakeClusterNameOnCloud: | ||
|
||
@patch('sky.utils.common_utils.get_user_hash') | ||
def test_make(self, mock_get_user_hash): | ||
mock_get_user_hash.return_value = MOCKED_USER_HASH | ||
assert "lora-ab12" == common_utils.make_cluster_name_on_cloud("lora") | ||
|
||
@patch('sky.utils.common_utils.get_user_hash') | ||
def test_make_with_hyphen(self, mock_get_user_hash): | ||
mock_get_user_hash.return_value = MOCKED_USER_HASH | ||
assert "seed-1-ab12" == common_utils.make_cluster_name_on_cloud( | ||
"seed-1") | ||
|
||
@patch('sky.utils.common_utils.get_user_hash') | ||
def test_make_with_characters_to_transform(self, mock_get_user_hash): | ||
mock_get_user_hash.return_value = MOCKED_USER_HASH | ||
assert "cuda-11-8-ab12" == common_utils.make_cluster_name_on_cloud( | ||
"Cuda_11.8") |