-
-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathtest_provisioning.py
More file actions
165 lines (155 loc) · 6.03 KB
/
test_provisioning.py
File metadata and controls
165 lines (155 loc) · 6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import pytest
from dstack._internal import settings
from dstack._internal.core.models.backends.base import BackendType
from dstack._internal.core.models.instances import InstanceType
from dstack._internal.core.models.runs import JobProvisioningData
from dstack._internal.server.services.backends.provisioning import (
resolve_provisioning_image,
)
from dstack._internal.server.testing.common import get_job_provisioning_data
class TestResolveProvisioningImageName:
@staticmethod
def _create_job_provisioning_data_with_instance_type(
backend: BackendType,
instance_type: str,
) -> JobProvisioningData:
job_provisioning_data = get_job_provisioning_data(backend=backend)
job_provisioning_data.instance_type = InstanceType(
name=instance_type,
resources=job_provisioning_data.instance_type.resources,
)
return job_provisioning_data
@staticmethod
def _call_resolve_provisioning_image(
image_name: str,
backend: BackendType,
instance_type: str,
) -> str:
job_provisioning_data = (
TestResolveProvisioningImageName._create_job_provisioning_data_with_instance_type(
backend,
instance_type,
)
)
image_name, _ = resolve_provisioning_image(image_name, None, job_provisioning_data)
return image_name
@pytest.mark.parametrize(
("suffix", "instance_type"),
[
("-base", "p6-b200.48xlarge"),
("-devel", "p5.48xlarge"),
],
)
def test_patch_aws_efa_instance_with_suffix(self, suffix: str, instance_type: str) -> None:
image_name = (
f"{settings.DSTACK_BASE_IMAGE}:{settings.DSTACK_BASE_IMAGE_VERSION}{suffix}"
f"-ubuntu{settings.DSTACK_BASE_IMAGE_UBUNTU_VERSION}"
)
result = self._call_resolve_provisioning_image(
image_name,
BackendType.AWS,
instance_type,
)
expected = (
f"{settings.DSTACK_BASE_IMAGE}:{settings.DSTACK_BASE_IMAGE_VERSION}"
f"-devel-efa-ubuntu{settings.DSTACK_BASE_IMAGE_UBUNTU_VERSION}"
)
assert result == expected
@pytest.mark.parametrize("suffix", ["-base", "-devel"])
@pytest.mark.parametrize(
"instance_type",
[
"p5.48xlarge",
"p5e.48xlarge",
"p4d.24xlarge",
"p4de.24xlarge",
"g6.8xlarge",
"g6e.8xlarge",
"g7e.8xlarge",
],
)
def test_patch_all_efa_instance_types(self, instance_type: str, suffix: str) -> None:
image_name = (
f"{settings.DSTACK_BASE_IMAGE}:{settings.DSTACK_BASE_IMAGE_VERSION}{suffix}"
f"-ubuntu{settings.DSTACK_BASE_IMAGE_UBUNTU_VERSION}"
)
result = self._call_resolve_provisioning_image(
image_name,
BackendType.AWS,
instance_type,
)
expected = (
f"{settings.DSTACK_BASE_IMAGE}:{settings.DSTACK_BASE_IMAGE_VERSION}"
f"-devel-efa-ubuntu{settings.DSTACK_BASE_IMAGE_UBUNTU_VERSION}"
)
assert result == expected
@pytest.mark.parametrize("suffix", ["-base", "-devel"])
@pytest.mark.parametrize(
"backend",
[BackendType.GCP, BackendType.AZURE, BackendType.LAMBDA, BackendType.LOCAL],
)
@pytest.mark.parametrize(
"instance_type",
["standard-4", "p5.xlarge", "p6.2xlarge", "g6.xlarge"],
)
def test_no_patch_non_aws_backends(
self,
backend: BackendType,
suffix: str,
instance_type: str,
) -> None:
image_name = (
f"{settings.DSTACK_BASE_IMAGE}:{settings.DSTACK_BASE_IMAGE_VERSION}{suffix}"
f"-ubuntu{settings.DSTACK_BASE_IMAGE_UBUNTU_VERSION}"
)
result = self._call_resolve_provisioning_image(image_name, backend, instance_type)
assert result == image_name
@pytest.mark.parametrize("suffix", ["-base", "-devel"])
@pytest.mark.parametrize(
"instance_type",
["t3.micro", "m5.large", "c5.xlarge", "r5.2xlarge", "m6i.large", "g6.xlarge"],
)
def test_no_patch_non_efa_aws_instances(self, instance_type: str, suffix: str) -> None:
image_name = f"{settings.DSTACK_BASE_IMAGE}:{settings.DSTACK_BASE_IMAGE_VERSION}{suffix}"
result = self._call_resolve_provisioning_image(
image_name,
BackendType.AWS,
instance_type,
)
assert result == image_name
@pytest.mark.parametrize(
"instance_type",
["p5.xlarge", "p6.2xlarge", "t3.micro", "m5.large"],
)
@pytest.mark.parametrize(
"image_name",
[
"ubuntu:20.04",
"nvidia/cuda:11.8-runtime-ubuntu20.04",
"python:3.9-slim",
"custom/image:latest",
f"{settings.DSTACK_BASE_IMAGE}:{settings.DSTACK_BASE_IMAGE_VERSION}-custom",
f"{settings.DSTACK_BASE_IMAGE}:{settings.DSTACK_BASE_IMAGE_VERSION}-devel-efa",
f"{settings.DSTACK_BASE_IMAGE}:{settings.DSTACK_BASE_IMAGE_VERSION}",
],
)
def test_no_patch_other_images(self, instance_type: str, image_name: str) -> None:
result = self._call_resolve_provisioning_image(
image_name,
BackendType.AWS,
instance_type,
)
assert result == image_name
@pytest.mark.parametrize("suffix", ["-base", "-devel"])
def test_patch_aws_efa_image_with_registry_prefix(self, suffix: str) -> None:
registry = "registry.example"
image_name = (
f"{registry}/{settings.DSTACK_BASE_IMAGE}:{settings.DSTACK_BASE_IMAGE_VERSION}{suffix}"
f"-ubuntu{settings.DSTACK_BASE_IMAGE_UBUNTU_VERSION}"
)
result = self._call_resolve_provisioning_image(image_name, BackendType.AWS, "p5.48xlarge")
expected = (
f"{registry}/{settings.DSTACK_BASE_IMAGE}:{settings.DSTACK_BASE_IMAGE_VERSION}"
f"-devel-efa-ubuntu{settings.DSTACK_BASE_IMAGE_UBUNTU_VERSION}"
)
assert result == expected