xpk 0.14.0__py3-none-any.whl → 0.14.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- integration/__init__.py +15 -0
- integration/docker_manager_test.py +102 -0
- integration/gcluster_a3mega_test.py +204 -0
- integration/gcluster_a3ultra_test.py +176 -0
- integration/gcluster_a4_test.py +176 -0
- integration/gcluster_test.py +107 -0
- xpk/commands/cluster.py +17 -4
- xpk/commands/cluster_gcluster.py +4 -0
- xpk/commands/cluster_test.py +92 -0
- xpk/commands/common.py +6 -0
- xpk/commands/kind.py +1 -0
- xpk/commands/workload.py +41 -7
- xpk/commands/workload_test.py +81 -0
- xpk/core/blueprint/testing/__init__.py +15 -0
- xpk/core/cluster.py +1 -1
- xpk/core/config.py +1 -1
- xpk/core/kueue_manager.py +62 -22
- xpk/core/kueue_manager_test.py +53 -21
- xpk/core/system_characteristics.py +16 -4
- xpk/core/system_characteristics_test.py +73 -0
- xpk/templates/cluster_preheat.yaml.j2 +31 -0
- xpk/templates/filestore-pv.yaml +17 -0
- xpk/templates/filestore-pvc.yaml +11 -0
- xpk/templates/filestore-sc.yaml +10 -0
- xpk/templates/fuse-pv.yaml +17 -0
- xpk/templates/fuse-pvc.yaml +13 -0
- xpk/templates/kueue_config.yaml.j2 +95 -0
- xpk/templates/kueue_gke_default_topology.yaml.j2 +10 -0
- xpk/templates/kueue_sub_slicing_topology.yaml.j2 +14 -0
- xpk/templates/mtc-cpc.yaml +15 -0
- xpk/templates/volume_bundle.yaml +7 -0
- xpk/utils/templates.py +14 -1
- xpk/utils/topology.py +9 -0
- xpk/utils/topology_test.py +21 -1
- {xpk-0.14.0.dist-info → xpk-0.14.2.dist-info}/METADATA +1 -1
- {xpk-0.14.0.dist-info → xpk-0.14.2.dist-info}/RECORD +40 -19
- xpk-0.14.2.dist-info/top_level.txt +2 -0
- xpk-0.14.0.dist-info/top_level.txt +0 -1
- {xpk-0.14.0.dist-info → xpk-0.14.2.dist-info}/WHEEL +0 -0
- {xpk-0.14.0.dist-info → xpk-0.14.2.dist-info}/entry_points.txt +0 -0
- {xpk-0.14.0.dist-info → xpk-0.14.2.dist-info}/licenses/LICENSE +0 -0
integration/__init__.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright 2024 Google LLC
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
"""
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright 2024 Google LLC
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import docker
|
|
18
|
+
from docker.errors import APIError
|
|
19
|
+
from xpk.core.docker_manager import DockerManager, ctk_build_ref
|
|
20
|
+
import pytest
|
|
21
|
+
import os
|
|
22
|
+
import time
|
|
23
|
+
|
|
24
|
+
test_cfg_path = '/tmp/xpk_gcloud_cfg'
|
|
25
|
+
test_deployment_dir = '/tmp/xpk_deployment'
|
|
26
|
+
test_gcluster_cmd = 'gcluster --version'
|
|
27
|
+
test_ctk_xpk_img = 'gcluster-xpk'
|
|
28
|
+
test_ctk_xpk_container = 'xpk-test-container'
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def remove_img():
|
|
32
|
+
dc = docker.from_env()
|
|
33
|
+
try:
|
|
34
|
+
dc.images.remove(test_ctk_xpk_img, force=True)
|
|
35
|
+
except APIError as _:
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def remove_container():
|
|
40
|
+
dc = docker.from_env()
|
|
41
|
+
try:
|
|
42
|
+
container = dc.containers.get(test_ctk_xpk_container)
|
|
43
|
+
container.remove(force=True)
|
|
44
|
+
except APIError as _:
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def create_tmp_dirs():
|
|
49
|
+
os.mkdir(test_cfg_path)
|
|
50
|
+
os.mkdir(test_deployment_dir)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def remove_tmp_dirs():
|
|
54
|
+
os.removedirs(test_cfg_path)
|
|
55
|
+
os.removedirs(test_deployment_dir)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@pytest.fixture(name='setup_img_name')
|
|
59
|
+
def remove_test_ctk_img():
|
|
60
|
+
create_tmp_dirs()
|
|
61
|
+
remove_container()
|
|
62
|
+
remove_img()
|
|
63
|
+
yield test_ctk_xpk_img
|
|
64
|
+
remove_container()
|
|
65
|
+
remove_img()
|
|
66
|
+
remove_tmp_dirs()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_docker_build_image(setup_img_name):
|
|
70
|
+
dm = DockerManager(
|
|
71
|
+
gcloud_cfg_path=test_cfg_path,
|
|
72
|
+
working_dir=test_deployment_dir,
|
|
73
|
+
img_name=setup_img_name,
|
|
74
|
+
)
|
|
75
|
+
dm.initialize()
|
|
76
|
+
|
|
77
|
+
dc = docker.from_env()
|
|
78
|
+
containers_before = dc.containers.list(all=True)
|
|
79
|
+
dc.images.get(f'{setup_img_name}:{ctk_build_ref}')
|
|
80
|
+
containers_after = dc.containers.list(all=True)
|
|
81
|
+
assert len(containers_before) == len(containers_after)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def test_run_command(setup_img_name):
|
|
85
|
+
|
|
86
|
+
dm = DockerManager(
|
|
87
|
+
gcloud_cfg_path=test_cfg_path,
|
|
88
|
+
working_dir=test_deployment_dir,
|
|
89
|
+
img_name=setup_img_name,
|
|
90
|
+
remove_container=True,
|
|
91
|
+
)
|
|
92
|
+
dc = docker.from_env()
|
|
93
|
+
|
|
94
|
+
containers_before = dc.containers.list(all=True)
|
|
95
|
+
dm.initialize()
|
|
96
|
+
dm.run_command(test_gcluster_cmd)
|
|
97
|
+
|
|
98
|
+
time.sleep(2)
|
|
99
|
+
|
|
100
|
+
containers_after = dc.containers.list(all=True)
|
|
101
|
+
|
|
102
|
+
assert len(containers_after) - len(containers_before) == 0
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright 2024 Google LLC
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from xpk.commands.cluster_gcluster import get_unique_name
|
|
18
|
+
from xpk.core.docker_manager import DockerManager
|
|
19
|
+
from xpk.core.gcluster_manager import GclusterManager
|
|
20
|
+
from xpk.core.blueprint.blueprint_generator import BlueprintGenerator
|
|
21
|
+
import pytest
|
|
22
|
+
import os
|
|
23
|
+
import shutil
|
|
24
|
+
|
|
25
|
+
ctk_gcloud_cfg = os.getenv("GCLOUD_CFG_PATH")
|
|
26
|
+
project_id = os.getenv("PROJECT_ID")
|
|
27
|
+
region = os.getenv("REGION")
|
|
28
|
+
zone = os.getenv("ZONE")
|
|
29
|
+
auth_cidr = os.getenv("AUTH_CIDR")
|
|
30
|
+
cluster_name = os.getenv("A3_MEGA_TEST_CLUSTER_NAME")
|
|
31
|
+
|
|
32
|
+
uploads_dir = "uploads"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@pytest.fixture(name="setup_tests")
|
|
36
|
+
def prepare_test():
|
|
37
|
+
pwd = os.getcwd()
|
|
38
|
+
docker_path = os.path.join(pwd, "xpk_test_docker_dir")
|
|
39
|
+
bp_path = os.path.join(pwd, "xpk_bp_path")
|
|
40
|
+
if not os.path.exists(docker_path):
|
|
41
|
+
os.makedirs(docker_path)
|
|
42
|
+
if not os.path.exists(bp_path):
|
|
43
|
+
os.makedirs(bp_path)
|
|
44
|
+
yield (docker_path, bp_path)
|
|
45
|
+
shutil.rmtree(docker_path)
|
|
46
|
+
shutil.rmtree(bp_path)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@pytest.mark.skip(
|
|
50
|
+
reason=(
|
|
51
|
+
"This test requires A3 capacity, therefore it should not be run on each"
|
|
52
|
+
" build. Please invoke it manually if needed. "
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
def test_deploy_a3_mega_deployment(setup_tests):
|
|
56
|
+
docker_path, bp_path = setup_tests[0], setup_tests[1]
|
|
57
|
+
(
|
|
58
|
+
blueprint_name,
|
|
59
|
+
prefix,
|
|
60
|
+
gcluster_manager,
|
|
61
|
+
staged_bp_path,
|
|
62
|
+
) = create_test_a3_mega_deployment(docker_path, bp_path)
|
|
63
|
+
gcluster_manager.deploy(
|
|
64
|
+
blueprint_path=staged_bp_path,
|
|
65
|
+
deployment_name=blueprint_name,
|
|
66
|
+
prefix=prefix,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
# cleanup part
|
|
70
|
+
gcluster_manager.destroy_deployment(
|
|
71
|
+
deployment_name=blueprint_name, prefix=prefix
|
|
72
|
+
)
|
|
73
|
+
shutil.rmtree(docker_path)
|
|
74
|
+
shutil.rmtree(bp_path)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@pytest.mark.skip(
|
|
78
|
+
reason=(
|
|
79
|
+
"This test requires A3 capacity, therefore it should not be run on each"
|
|
80
|
+
" build. Please invoke it manually if needed. "
|
|
81
|
+
)
|
|
82
|
+
)
|
|
83
|
+
def test_create_a3_mega_deployment_files(setup_tests):
|
|
84
|
+
assert project_id is not None
|
|
85
|
+
assert region is not None
|
|
86
|
+
assert zone is not None
|
|
87
|
+
assert auth_cidr is not None
|
|
88
|
+
assert ctk_gcloud_cfg is not None
|
|
89
|
+
assert cluster_name is not None
|
|
90
|
+
docker_path, bp_path = setup_tests[0], setup_tests[1]
|
|
91
|
+
|
|
92
|
+
blueprint_name = f"{cluster_name}-a3-mega-xpk"
|
|
93
|
+
prefix = "prefix"
|
|
94
|
+
|
|
95
|
+
docker_manager = DockerManager(
|
|
96
|
+
gcloud_cfg_path=ctk_gcloud_cfg, working_dir=docker_path
|
|
97
|
+
)
|
|
98
|
+
docker_manager.initialize()
|
|
99
|
+
|
|
100
|
+
bpm = BlueprintGenerator(storage_path=bp_path)
|
|
101
|
+
a3_mega_blueprint = bpm.generate_a3_mega_blueprint(
|
|
102
|
+
cluster_name=cluster_name,
|
|
103
|
+
blueprint_name=blueprint_name,
|
|
104
|
+
prefix=prefix,
|
|
105
|
+
region=region,
|
|
106
|
+
project_id=project_id,
|
|
107
|
+
auth_cidr=auth_cidr,
|
|
108
|
+
zone=zone,
|
|
109
|
+
system_node_pool_min_node_count=3,
|
|
110
|
+
)
|
|
111
|
+
blueprint_test_path = os.path.join(bp_path, prefix, f"{blueprint_name}.yaml")
|
|
112
|
+
blueprint_deps_test_path = os.path.join(bp_path, prefix, blueprint_name)
|
|
113
|
+
|
|
114
|
+
assert a3_mega_blueprint.blueprint_file == blueprint_test_path
|
|
115
|
+
assert a3_mega_blueprint.blueprint_dependencies == blueprint_deps_test_path
|
|
116
|
+
|
|
117
|
+
assert os.path.isfile(blueprint_test_path)
|
|
118
|
+
assert os.path.isdir(blueprint_deps_test_path)
|
|
119
|
+
assert os.path.isfile(
|
|
120
|
+
os.path.join(blueprint_deps_test_path, "config-map.yaml.tftpl")
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
gcluster_manager = GclusterManager(
|
|
124
|
+
gcluster_command_runner=docker_manager, remote_state_client=None
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
staged_bp_path = gcluster_manager.stage_files(
|
|
128
|
+
blueprint_file=a3_mega_blueprint.blueprint_file,
|
|
129
|
+
blueprint_dependencies=a3_mega_blueprint.blueprint_dependencies,
|
|
130
|
+
prefix=prefix,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
assert staged_bp_path == os.path.join(
|
|
134
|
+
"/out", uploads_dir, prefix, f"{blueprint_name}.yaml"
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
staged_bp_path_local = os.path.join(
|
|
138
|
+
docker_path, uploads_dir, prefix, f"{blueprint_name}.yaml"
|
|
139
|
+
)
|
|
140
|
+
staged_bp_deps_path_local = os.path.join(
|
|
141
|
+
docker_path, uploads_dir, prefix, blueprint_name
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
assert os.path.isfile(staged_bp_path_local)
|
|
145
|
+
assert os.path.isdir(staged_bp_deps_path_local)
|
|
146
|
+
assert os.path.isfile(
|
|
147
|
+
os.path.join(staged_bp_deps_path_local, "config-map.yaml.tftpl")
|
|
148
|
+
)
|
|
149
|
+
assert os.path.isfile(
|
|
150
|
+
os.path.join(
|
|
151
|
+
staged_bp_deps_path_local, "kueue-xpk-configuration.yaml.tftpl"
|
|
152
|
+
)
|
|
153
|
+
)
|
|
154
|
+
unique_name = get_unique_name(project_id, region, zone)
|
|
155
|
+
gcluster_manager.deploy(
|
|
156
|
+
blueprint_path=staged_bp_path, deployment_name=unique_name, dry_run=True
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def create_test_a3_mega_deployment(docker_path: str, bp_path: str):
|
|
161
|
+
assert project_id is not None
|
|
162
|
+
assert region is not None
|
|
163
|
+
assert zone is not None
|
|
164
|
+
assert auth_cidr is not None
|
|
165
|
+
assert ctk_gcloud_cfg is not None
|
|
166
|
+
assert cluster_name is not None
|
|
167
|
+
|
|
168
|
+
blueprint_name = f"{cluster_name}-a3-mega-xpk"
|
|
169
|
+
prefix = "prefix"
|
|
170
|
+
|
|
171
|
+
docker_manager = DockerManager(
|
|
172
|
+
gcloud_cfg_path=ctk_gcloud_cfg, working_dir=docker_path
|
|
173
|
+
)
|
|
174
|
+
docker_manager.initialize()
|
|
175
|
+
|
|
176
|
+
bpm = BlueprintGenerator(storage_path=bp_path)
|
|
177
|
+
a3_mega_blueprint = bpm.generate_a3_mega_blueprint(
|
|
178
|
+
cluster_name=cluster_name,
|
|
179
|
+
blueprint_name=blueprint_name,
|
|
180
|
+
prefix=prefix,
|
|
181
|
+
region=region,
|
|
182
|
+
project_id=project_id,
|
|
183
|
+
auth_cidr=auth_cidr,
|
|
184
|
+
zone=zone,
|
|
185
|
+
system_node_pool_min_node_count=3,
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
gcluster_manager = GclusterManager(
|
|
189
|
+
gcluster_command_runner=docker_manager,
|
|
190
|
+
remote_state_client=None,
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
staged_bp_path = gcluster_manager.stage_files(
|
|
194
|
+
blueprint_file=a3_mega_blueprint.blueprint_file,
|
|
195
|
+
blueprint_dependencies=a3_mega_blueprint.blueprint_dependencies,
|
|
196
|
+
prefix=prefix,
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
return (
|
|
200
|
+
blueprint_name,
|
|
201
|
+
prefix,
|
|
202
|
+
gcluster_manager,
|
|
203
|
+
staged_bp_path,
|
|
204
|
+
)
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright 2024 Google LLC
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import os
|
|
18
|
+
import shutil
|
|
19
|
+
|
|
20
|
+
import pytest
|
|
21
|
+
|
|
22
|
+
from xpk.commands.cluster_gcluster import get_unique_name
|
|
23
|
+
from xpk.core.blueprint.blueprint_generator import BlueprintGenerator
|
|
24
|
+
from xpk.core.capacity import CapacityType
|
|
25
|
+
from xpk.core.docker_manager import DockerManager
|
|
26
|
+
from xpk.core.gcluster_manager import GclusterManager
|
|
27
|
+
|
|
28
|
+
ctk_gcloud_cfg = os.getenv("GCLOUD_CFG_PATH")
|
|
29
|
+
project_id = os.getenv("PROJECT_ID")
|
|
30
|
+
region = os.getenv("REGION")
|
|
31
|
+
zone = os.getenv("ZONE")
|
|
32
|
+
auth_cidr = os.getenv("AUTH_CIDR")
|
|
33
|
+
cluster_name = os.getenv("A3_ULTRA_TEST_CLUSTER_NAME")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@pytest.fixture(name="setup_tests")
|
|
37
|
+
def prepare_test():
|
|
38
|
+
pwd = os.getcwd()
|
|
39
|
+
docker_path = os.path.join(pwd, "xpk_test_docker_dir")
|
|
40
|
+
bp_path = os.path.join(pwd, "xpk_test_bp_dir")
|
|
41
|
+
if not os.path.exists(docker_path):
|
|
42
|
+
os.makedirs(docker_path)
|
|
43
|
+
if not os.path.exists(bp_path):
|
|
44
|
+
os.makedirs(bp_path)
|
|
45
|
+
yield (docker_path, bp_path)
|
|
46
|
+
shutil.rmtree(docker_path)
|
|
47
|
+
shutil.rmtree(bp_path)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@pytest.mark.skip(
|
|
51
|
+
reason=(
|
|
52
|
+
"This test requires A3 capacity, therefore it should not be run on each"
|
|
53
|
+
" build. Please invoke it manually if needed. "
|
|
54
|
+
)
|
|
55
|
+
)
|
|
56
|
+
def test_create_a3_ultra_deployment_files(setup_tests):
|
|
57
|
+
assert project_id is not None
|
|
58
|
+
assert region is not None
|
|
59
|
+
assert zone is not None
|
|
60
|
+
assert auth_cidr is not None
|
|
61
|
+
assert ctk_gcloud_cfg is not None
|
|
62
|
+
assert cluster_name is not None
|
|
63
|
+
docker_path, bp_path = setup_tests[0], setup_tests[1]
|
|
64
|
+
blueprint_name = f"{cluster_name}-a3-ultra-xpk"
|
|
65
|
+
|
|
66
|
+
docker_manager = DockerManager(
|
|
67
|
+
gcloud_cfg_path=ctk_gcloud_cfg, working_dir=docker_path
|
|
68
|
+
)
|
|
69
|
+
docker_manager.initialize()
|
|
70
|
+
prefix = f"{project_id}-{region}".lower()
|
|
71
|
+
bpm = BlueprintGenerator(storage_path=bp_path)
|
|
72
|
+
a3_mega_blueprint = bpm.generate_a3_ultra_blueprint(
|
|
73
|
+
cluster_name=cluster_name,
|
|
74
|
+
blueprint_name=blueprint_name,
|
|
75
|
+
region=region,
|
|
76
|
+
project_id=project_id,
|
|
77
|
+
auth_cidr=auth_cidr,
|
|
78
|
+
zone=zone,
|
|
79
|
+
reservation="foo",
|
|
80
|
+
num_nodes=1,
|
|
81
|
+
system_node_pool_machine_type="e2-standard-16",
|
|
82
|
+
prefix=prefix,
|
|
83
|
+
)
|
|
84
|
+
blueprint_test_path = os.path.join(bp_path, prefix, f"{blueprint_name}.yaml")
|
|
85
|
+
blueprint_deps_test_path = os.path.join(bp_path, blueprint_name)
|
|
86
|
+
assert a3_mega_blueprint.blueprint_file == blueprint_test_path
|
|
87
|
+
assert a3_mega_blueprint.blueprint_dependencies == blueprint_deps_test_path
|
|
88
|
+
|
|
89
|
+
assert os.path.isfile(blueprint_test_path)
|
|
90
|
+
assert os.path.isdir(blueprint_deps_test_path)
|
|
91
|
+
assert os.path.isfile(
|
|
92
|
+
os.path.join(blueprint_deps_test_path, "mlgru-disable.yaml")
|
|
93
|
+
)
|
|
94
|
+
assert os.path.isfile(
|
|
95
|
+
os.path.join(blueprint_deps_test_path, "nccl-installer.yaml")
|
|
96
|
+
)
|
|
97
|
+
gcluster_manager = GclusterManager(
|
|
98
|
+
gcluster_command_runner=docker_manager, remote_state_client=None
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
staged_bp_path = gcluster_manager.stage_files(
|
|
102
|
+
blueprint_file=a3_mega_blueprint.blueprint_file,
|
|
103
|
+
blueprint_dependencies=a3_mega_blueprint.blueprint_dependencies,
|
|
104
|
+
prefix=prefix,
|
|
105
|
+
)
|
|
106
|
+
assert staged_bp_path == os.path.join(
|
|
107
|
+
"/out/uploads", prefix, f"{blueprint_name}.yaml"
|
|
108
|
+
)
|
|
109
|
+
unique_name = get_unique_name(project_id, region, zone)
|
|
110
|
+
gcluster_manager.deploy(
|
|
111
|
+
blueprint_path=staged_bp_path, deployment_name=unique_name, dry_run=True
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@pytest.mark.skip(
|
|
116
|
+
reason=(
|
|
117
|
+
"This test requires A3 capacity, therefore it should not be run on each"
|
|
118
|
+
" build. Please invoke it manually if needed. "
|
|
119
|
+
)
|
|
120
|
+
)
|
|
121
|
+
def test_create_a3_ultra_deployment(setup_tests):
|
|
122
|
+
assert project_id is not None
|
|
123
|
+
assert region is not None
|
|
124
|
+
assert zone is not None
|
|
125
|
+
assert auth_cidr is not None
|
|
126
|
+
assert ctk_gcloud_cfg is not None
|
|
127
|
+
assert cluster_name is not None
|
|
128
|
+
docker_path, bp_path = setup_tests[0], setup_tests[1]
|
|
129
|
+
blueprint_name = f"{cluster_name}-a3-ultra-xpk"
|
|
130
|
+
|
|
131
|
+
docker_manager = DockerManager(
|
|
132
|
+
gcloud_cfg_path=ctk_gcloud_cfg, working_dir=docker_path
|
|
133
|
+
)
|
|
134
|
+
docker_manager.initialize()
|
|
135
|
+
|
|
136
|
+
bpm = BlueprintGenerator(storage_path=bp_path)
|
|
137
|
+
a3_mega_blueprint = bpm.generate_a3_ultra_blueprint(
|
|
138
|
+
cluster_name=cluster_name,
|
|
139
|
+
blueprint_name=blueprint_name,
|
|
140
|
+
region=region,
|
|
141
|
+
project_id=project_id,
|
|
142
|
+
auth_cidr=auth_cidr,
|
|
143
|
+
zone=zone,
|
|
144
|
+
capacity_type=CapacityType.SPOT,
|
|
145
|
+
num_nodes=1,
|
|
146
|
+
system_node_pool_machine_type="e2-standard-16",
|
|
147
|
+
)
|
|
148
|
+
blueprint_test_path = os.path.join(bp_path, f"{blueprint_name}.yaml")
|
|
149
|
+
blueprint_deps_test_path = os.path.join(bp_path, blueprint_name)
|
|
150
|
+
|
|
151
|
+
assert a3_mega_blueprint.blueprint_file == blueprint_test_path
|
|
152
|
+
assert a3_mega_blueprint.blueprint_dependencies == blueprint_deps_test_path
|
|
153
|
+
|
|
154
|
+
assert os.path.isfile(blueprint_test_path)
|
|
155
|
+
assert os.path.isdir(blueprint_deps_test_path)
|
|
156
|
+
assert os.path.isfile(
|
|
157
|
+
os.path.join(blueprint_deps_test_path, "mlgru-disable.yaml")
|
|
158
|
+
)
|
|
159
|
+
assert os.path.isfile(
|
|
160
|
+
os.path.join(blueprint_deps_test_path, "nccl-installer.yaml")
|
|
161
|
+
)
|
|
162
|
+
gcluster_manager = GclusterManager(
|
|
163
|
+
gcluster_command_runner=docker_manager, remote_state_client=None
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
staged_bp_path = gcluster_manager.stage_files(
|
|
167
|
+
blueprint_file=a3_mega_blueprint.blueprint_file,
|
|
168
|
+
blueprint_dependencies=a3_mega_blueprint.blueprint_dependencies,
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
gcluster_manager.deploy(
|
|
172
|
+
blueprint_path=staged_bp_path, deployment_name=blueprint_name
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
# cleanup part
|
|
176
|
+
gcluster_manager.destroy_deployment(deployment_name=blueprint_name)
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright 2024 Google LLC
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import os
|
|
18
|
+
import shutil
|
|
19
|
+
|
|
20
|
+
import pytest
|
|
21
|
+
|
|
22
|
+
from xpk.commands.cluster_gcluster import get_unique_name
|
|
23
|
+
from xpk.core.blueprint.blueprint_generator import BlueprintGenerator
|
|
24
|
+
from xpk.core.capacity import CapacityType
|
|
25
|
+
from xpk.core.docker_manager import DockerManager
|
|
26
|
+
from xpk.core.gcluster_manager import GclusterManager
|
|
27
|
+
|
|
28
|
+
ctk_gcloud_cfg = os.getenv("GCLOUD_CFG_PATH")
|
|
29
|
+
project_id = os.getenv("PROJECT_ID")
|
|
30
|
+
region = os.getenv("REGION")
|
|
31
|
+
zone = os.getenv("ZONE")
|
|
32
|
+
auth_cidr = os.getenv("AUTH_CIDR")
|
|
33
|
+
cluster_name = os.getenv("A4_TEST_CLUSTER_NAME")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@pytest.fixture(name="setup_tests")
|
|
37
|
+
def prepare_test():
|
|
38
|
+
pwd = os.getcwd()
|
|
39
|
+
docker_path = os.path.join(pwd, "xpk_test_docker_dir")
|
|
40
|
+
bp_path = os.path.join(pwd, "xpk_test_bp_dir")
|
|
41
|
+
if not os.path.exists(docker_path):
|
|
42
|
+
os.makedirs(docker_path)
|
|
43
|
+
if not os.path.exists(bp_path):
|
|
44
|
+
os.makedirs(bp_path)
|
|
45
|
+
yield (docker_path, bp_path)
|
|
46
|
+
shutil.rmtree(docker_path)
|
|
47
|
+
shutil.rmtree(bp_path)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@pytest.mark.skip(
|
|
51
|
+
reason=(
|
|
52
|
+
"This test requires A4 capacity, therefore it should not be run on each"
|
|
53
|
+
" build. Please invoke it manually if needed. "
|
|
54
|
+
)
|
|
55
|
+
)
|
|
56
|
+
def test_create_a4_deployment_files(setup_tests):
|
|
57
|
+
assert project_id is not None
|
|
58
|
+
assert region is not None
|
|
59
|
+
assert zone is not None
|
|
60
|
+
assert auth_cidr is not None
|
|
61
|
+
assert ctk_gcloud_cfg is not None
|
|
62
|
+
assert cluster_name is not None
|
|
63
|
+
docker_path, bp_path = setup_tests[0], setup_tests[1]
|
|
64
|
+
blueprint_name = f"{cluster_name}-a4-xpk"
|
|
65
|
+
|
|
66
|
+
docker_manager = DockerManager(
|
|
67
|
+
gcloud_cfg_path=ctk_gcloud_cfg, working_dir=docker_path
|
|
68
|
+
)
|
|
69
|
+
docker_manager.initialize()
|
|
70
|
+
prefix = f"{project_id}-{region}".lower()
|
|
71
|
+
bpm = BlueprintGenerator(storage_path=bp_path)
|
|
72
|
+
a4_blueprint = bpm.generate_a4_blueprint(
|
|
73
|
+
cluster_name=cluster_name,
|
|
74
|
+
blueprint_name=blueprint_name,
|
|
75
|
+
region=region,
|
|
76
|
+
project_id=project_id,
|
|
77
|
+
auth_cidr=auth_cidr,
|
|
78
|
+
zone=zone,
|
|
79
|
+
reservation="foo",
|
|
80
|
+
num_nodes=1,
|
|
81
|
+
system_node_pool_machine_type="e2-standard-16",
|
|
82
|
+
prefix=prefix,
|
|
83
|
+
)
|
|
84
|
+
blueprint_test_path = os.path.join(bp_path, prefix, f"{blueprint_name}.yaml")
|
|
85
|
+
blueprint_deps_test_path = os.path.join(bp_path, blueprint_name)
|
|
86
|
+
assert a4_blueprint.blueprint_file == blueprint_test_path
|
|
87
|
+
assert a4_blueprint.blueprint_dependencies == blueprint_deps_test_path
|
|
88
|
+
|
|
89
|
+
assert os.path.isfile(blueprint_test_path)
|
|
90
|
+
assert os.path.isdir(blueprint_deps_test_path)
|
|
91
|
+
assert os.path.isfile(
|
|
92
|
+
os.path.join(blueprint_deps_test_path, "mlgru-disable.yaml")
|
|
93
|
+
)
|
|
94
|
+
assert os.path.isfile(
|
|
95
|
+
os.path.join(blueprint_deps_test_path, "nccl-installer.yaml")
|
|
96
|
+
)
|
|
97
|
+
gcluster_manager = GclusterManager(
|
|
98
|
+
gcluster_command_runner=docker_manager, remote_state_client=None
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
staged_bp_path = gcluster_manager.stage_files(
|
|
102
|
+
blueprint_file=a4_blueprint.blueprint_file,
|
|
103
|
+
blueprint_dependencies=a4_blueprint.blueprint_dependencies,
|
|
104
|
+
prefix=prefix,
|
|
105
|
+
)
|
|
106
|
+
assert staged_bp_path == os.path.join(
|
|
107
|
+
"/out/uploads", prefix, f"{blueprint_name}.yaml"
|
|
108
|
+
)
|
|
109
|
+
unique_name = get_unique_name(project_id, region, zone)
|
|
110
|
+
gcluster_manager.deploy(
|
|
111
|
+
blueprint_path=staged_bp_path, deployment_name=unique_name, dry_run=True
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@pytest.mark.skip(
|
|
116
|
+
reason=(
|
|
117
|
+
"This test requires A4 capacity, therefore it should not be run on each"
|
|
118
|
+
" build. Please invoke it manually if needed. "
|
|
119
|
+
)
|
|
120
|
+
)
|
|
121
|
+
def test_create_a4_deployment(setup_tests):
|
|
122
|
+
assert project_id is not None
|
|
123
|
+
assert region is not None
|
|
124
|
+
assert zone is not None
|
|
125
|
+
assert auth_cidr is not None
|
|
126
|
+
assert ctk_gcloud_cfg is not None
|
|
127
|
+
assert cluster_name is not None
|
|
128
|
+
docker_path, bp_path = setup_tests[0], setup_tests[1]
|
|
129
|
+
blueprint_name = f"{cluster_name}-a4-xpk"
|
|
130
|
+
|
|
131
|
+
docker_manager = DockerManager(
|
|
132
|
+
gcloud_cfg_path=ctk_gcloud_cfg, working_dir=docker_path
|
|
133
|
+
)
|
|
134
|
+
docker_manager.initialize()
|
|
135
|
+
|
|
136
|
+
bpm = BlueprintGenerator(storage_path=bp_path)
|
|
137
|
+
a4_blueprint = bpm.generate_a4_blueprint(
|
|
138
|
+
cluster_name=cluster_name,
|
|
139
|
+
blueprint_name=blueprint_name,
|
|
140
|
+
region=region,
|
|
141
|
+
project_id=project_id,
|
|
142
|
+
auth_cidr=auth_cidr,
|
|
143
|
+
zone=zone,
|
|
144
|
+
capacity_type=CapacityType.SPOT,
|
|
145
|
+
num_nodes=1,
|
|
146
|
+
system_node_pool_machine_type="e2-standard-16",
|
|
147
|
+
)
|
|
148
|
+
blueprint_test_path = os.path.join(bp_path, f"{blueprint_name}.yaml")
|
|
149
|
+
blueprint_deps_test_path = os.path.join(bp_path, blueprint_name)
|
|
150
|
+
|
|
151
|
+
assert a4_blueprint.blueprint_file == blueprint_test_path
|
|
152
|
+
assert a4_blueprint.blueprint_dependencies == blueprint_deps_test_path
|
|
153
|
+
|
|
154
|
+
assert os.path.isfile(blueprint_test_path)
|
|
155
|
+
assert os.path.isdir(blueprint_deps_test_path)
|
|
156
|
+
assert os.path.isfile(
|
|
157
|
+
os.path.join(blueprint_deps_test_path, "mlgru-disable.yaml")
|
|
158
|
+
)
|
|
159
|
+
assert os.path.isfile(
|
|
160
|
+
os.path.join(blueprint_deps_test_path, "nccl-installer.yaml")
|
|
161
|
+
)
|
|
162
|
+
gcluster_manager = GclusterManager(
|
|
163
|
+
gcluster_command_runner=docker_manager, remote_state_client=None
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
staged_bp_path = gcluster_manager.stage_files(
|
|
167
|
+
blueprint_file=a4_blueprint.blueprint_file,
|
|
168
|
+
blueprint_dependencies=a4_blueprint.blueprint_dependencies,
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
gcluster_manager.deploy(
|
|
172
|
+
blueprint_path=staged_bp_path, deployment_name=blueprint_name
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
# cleanup part
|
|
176
|
+
gcluster_manager.destroy_deployment(deployment_name=blueprint_name)
|