Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/aks-preview/azext_aks_preview/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

from ._consts import ADDONS


logger = get_logger(__name__)


Expand Down Expand Up @@ -215,7 +214,7 @@ def validate_spot_max_price(namespace):
if not isnan(namespace.spot_max_price):
if namespace.priority != "Spot":
raise CLIError("--spot_max_price can only be set when --priority is Spot")
if namespace.spot_max_price * 100000 % 1 != 0:
if namespace.spot_max_price > 0 and not isclose(namespace.spot_max_price * 100000 % 1, 0, rel_tol=1e-06):
raise CLIError("--spot_max_price can only include up to 5 decimal places")
if namespace.spot_max_price <= 0 and not isclose(namespace.spot_max_price, -1.0, rel_tol=1e-06):
raise CLIError(
Expand Down
30 changes: 30 additions & 0 deletions src/aks-preview/azext_aks_preview/tests/latest/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ def __init__(self, max_surge):
self.max_surge = max_surge


class SpotMaxPriceNamespace:
def __init__(self, spot_max_price):
self.priority = "Spot"
self.spot_max_price = spot_max_price


class TestMaxSurge(unittest.TestCase):
def test_valid_cases(self):
valid = ["5", "33%", "1", "100%"]
Expand All @@ -171,6 +177,30 @@ def test_throws_on_negative(self):
self.assertTrue('positive' in str(cm.exception), msg=str(cm.exception))


class TestSpotMaxPrice(unittest.TestCase):
def test_valid_cases(self):
valid = [5, 5.12345, -1.0]
for v in valid:
validators.validate_spot_max_price(SpotMaxPriceNamespace(v))

def test_throws_if_more_than_5(self):
with self.assertRaises(CLIError) as cm:
validators.validate_spot_max_price(SpotMaxPriceNamespace(5.123456))
self.assertTrue('--spot_max_price can only include up to 5 decimal places' in str(cm.exception), msg=str(cm.exception))

def test_throws_if_non_valid_negative(self):
with self.assertRaises(CLIError) as cm:
validators.validate_spot_max_price(SpotMaxPriceNamespace(-2))
self.assertTrue('--spot_max_price can only be any decimal value greater than zero, or -1 which indicates' in str(cm.exception), msg=str(cm.exception))

def test_throws_if_input_max_price_for_regular(self):
ns = SpotMaxPriceNamespace(2)
ns.priority = "Regular"
with self.assertRaises(CLIError) as cm:
validators.validate_spot_max_price(ns)
self.assertTrue('--spot_max_price can only be set when --priority is Spot' in str(cm.exception), msg=str(cm.exception))


class ValidateAddonsNamespace:
def __init__(self, addons):
self.addons = addons
Expand Down