|
10 | 10 | ReplicaGroup, |
11 | 11 | ServiceConfiguration, |
12 | 12 | ) |
| 13 | +from dstack._internal.core.models.profiles import SpotPolicy |
13 | 14 | from dstack._internal.core.models.resources import Range |
14 | 15 | from dstack._internal.core.models.services import OpenAIChatModel |
15 | 16 | from dstack._internal.server.services.docker import ImageConfig |
@@ -118,7 +119,7 @@ def _make_run_spec(replicas, **service_kwargs): |
118 | 119 | @pytest.mark.usefixtures("image_config_mock") |
119 | 120 | class TestPerGroupOverrides: |
120 | 121 | """Verifies that ServiceJobConfigurator picks up per-replica-group |
121 | | - image-source fields (image, docker, python, nvcc, privileged).""" |
| 122 | + image-source fields (image, docker, python, nvcc, privileged, etc).""" |
122 | 123 |
|
123 | 124 | async def test_image_name_uses_group_image(self): |
124 | 125 | run_spec = _make_run_spec( |
@@ -331,3 +332,103 @@ async def test_user_does_not_lookup_for_group_docker(self, monkeypatch: pytest.M |
331 | 332 | configurator = ServiceJobConfigurator(run_spec, replica_group_name="a") |
332 | 333 | await configurator._user() |
333 | 334 | mock_get_image_config.assert_not_called() |
| 335 | + |
| 336 | + async def test_spot_policy_uses_group_value(self): |
| 337 | + run_spec = _make_run_spec( |
| 338 | + replicas=[ |
| 339 | + ReplicaGroup( |
| 340 | + name="a", |
| 341 | + count=Range(min=1, max=1), |
| 342 | + commands=["x"], |
| 343 | + spot_policy=SpotPolicy.SPOT, |
| 344 | + ) |
| 345 | + ], |
| 346 | + ) |
| 347 | + configurator = ServiceJobConfigurator(run_spec, replica_group_name="a") |
| 348 | + assert configurator._spot_policy() == SpotPolicy.SPOT |
| 349 | + |
| 350 | + async def test_spot_policy_defaults_to_ondemand_when_group_unset(self): |
| 351 | + run_spec = _make_run_spec( |
| 352 | + replicas=[ |
| 353 | + ReplicaGroup( |
| 354 | + name="a", |
| 355 | + count=Range(min=1, max=1), |
| 356 | + commands=["x"], |
| 357 | + ) |
| 358 | + ], |
| 359 | + ) |
| 360 | + configurator = ServiceJobConfigurator(run_spec, replica_group_name="a") |
| 361 | + assert configurator._spot_policy() == SpotPolicy.ONDEMAND |
| 362 | + |
| 363 | + async def test_different_groups_different_spot_policies(self): |
| 364 | + run_spec = _make_run_spec( |
| 365 | + replicas=[ |
| 366 | + ReplicaGroup( |
| 367 | + name="spot", |
| 368 | + count=Range(min=1, max=1), |
| 369 | + commands=["x"], |
| 370 | + spot_policy=SpotPolicy.SPOT, |
| 371 | + ), |
| 372 | + ReplicaGroup( |
| 373 | + name="od", |
| 374 | + count=Range(min=1, max=1), |
| 375 | + commands=["y"], |
| 376 | + spot_policy=SpotPolicy.ONDEMAND, |
| 377 | + ), |
| 378 | + ], |
| 379 | + ) |
| 380 | + assert ( |
| 381 | + ServiceJobConfigurator(run_spec, replica_group_name="spot")._spot_policy() |
| 382 | + == SpotPolicy.SPOT |
| 383 | + ) |
| 384 | + assert ( |
| 385 | + ServiceJobConfigurator(run_spec, replica_group_name="od")._spot_policy() |
| 386 | + == SpotPolicy.ONDEMAND |
| 387 | + ) |
| 388 | + |
| 389 | + async def test_reservation_uses_group_value(self): |
| 390 | + run_spec = _make_run_spec( |
| 391 | + replicas=[ |
| 392 | + ReplicaGroup( |
| 393 | + name="a", |
| 394 | + count=Range(min=1, max=1), |
| 395 | + commands=["x"], |
| 396 | + reservation="my-reservation", |
| 397 | + ) |
| 398 | + ], |
| 399 | + ) |
| 400 | + configurator = ServiceJobConfigurator(run_spec, replica_group_name="a") |
| 401 | + assert configurator._reservation() == "my-reservation" |
| 402 | + |
| 403 | + async def test_reservation_defaults_to_none_when_group_unset(self): |
| 404 | + run_spec = _make_run_spec( |
| 405 | + replicas=[ |
| 406 | + ReplicaGroup( |
| 407 | + name="a", |
| 408 | + count=Range(min=1, max=1), |
| 409 | + commands=["x"], |
| 410 | + ) |
| 411 | + ], |
| 412 | + ) |
| 413 | + configurator = ServiceJobConfigurator(run_spec, replica_group_name="a") |
| 414 | + assert configurator._reservation() is None |
| 415 | + |
| 416 | + async def test_different_groups_different_reservations(self): |
| 417 | + run_spec = _make_run_spec( |
| 418 | + replicas=[ |
| 419 | + ReplicaGroup( |
| 420 | + name="a", |
| 421 | + count=Range(min=1, max=1), |
| 422 | + commands=["x"], |
| 423 | + reservation="res-a", |
| 424 | + ), |
| 425 | + ReplicaGroup( |
| 426 | + name="b", |
| 427 | + count=Range(min=1, max=1), |
| 428 | + commands=["y"], |
| 429 | + reservation="res-b", |
| 430 | + ), |
| 431 | + ], |
| 432 | + ) |
| 433 | + assert ServiceJobConfigurator(run_spec, replica_group_name="a")._reservation() == "res-a" |
| 434 | + assert ServiceJobConfigurator(run_spec, replica_group_name="b")._reservation() == "res-b" |
0 commit comments