Skip to content

Commit 7319df6

Browse files
committed
qwer
1 parent a7ed088 commit 7319df6

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tests/containers/base_image_test.py

+59
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,65 @@ def test_pip_install_cowsay_runs(self, image: str):
189189
finally:
190190
docker_utils.NotebookContainer(container).stop(timeout=0)
191191

192+
# There are two ways how the image is being updated
193+
# 1. A change to the image is being done (e.g. package update, Dockerfile update etc.). In this case, we need to check the size of the build image that contains these updates.
194+
# 2. A change is done to the params.env file where we update manifest references to a new image. In this case we shall check that the updated reference matches our size constraints
195+
size_treshold: int = 100 # in MBs
196+
percent_treshold: int = 10
197+
def test_image_size_change(self, image: str):
198+
"""Checks the image size didn't change extensively - treshold is 10% or XXX MB."""
199+
200+
# Map of image label names with expected size in MBs.
201+
expected_image_name_size_map = {
202+
"odh-notebook-base-centos-stream9-python-3.11": 1,
203+
"odh-notebook-base-ubi9-python-3.11": 1,
204+
"odh-notebook-cuda-c9s-python-3.11": 1,
205+
"odh-notebook-cuda-ubi9-python-3.11": 9070, # TODO
206+
"odh-notebook-jupyter-datascience-ubi9-python-3.11": 2845,
207+
"odh-notebook-jupyter-minimal-ubi9-python-3.11": 1472, # gpu 9070; rocm 26667 ???
208+
"odh-notebook-jupyter-pytorch-ubi9-python-3.11": 15444,
209+
"odh-notebook-cuda-jupyter-tensorflow-ubi9-python-3.11": 15218,
210+
"odh-notebook-jupyter-trustyai-ubi9-python-3.11": 8613,
211+
"odh-notebook-jupyter-rocm-pytorch-ubi9-python-3.11": 33001,
212+
"odh-notebook-jupyter-rocm-tensorflow-ubi9-python-3.11": 30241,
213+
"odh-notebook-rstudio-server-c9s-python-3.11": 13201, # 3221 ??
214+
"odh-notebook-runtime-datascience-ubi9-python-3.11": 2518,
215+
"odh-notebook-runtime-minimal-ubi9-python-3.11": 1362,
216+
"odh-notebook-runtime-pytorch-ubi9-python-3.11": 7487,
217+
"odh-notebook-cuda-runtime-tensorflow-ubi9-python-3.11": 14572,
218+
"odh-notebook-runtime-rocm-pytorch-ubi9-python-3.11": 32682,
219+
"odh-notebook-rocm-runtime-tensorflow-ubi9-python-3.11": 29805,
220+
"odh-notebook-code-server-ubi9-python-3.11": 2598,
221+
"odh-notebook-rocm-python-3.11": 26667, # TODO
222+
}
223+
224+
import docker
225+
client = testcontainers.core.container.DockerClient()
226+
try:
227+
image_metadata = client.client.images.get(image)
228+
except docker.errors.ImageNotFound:
229+
image_metadata = client.client.images.pull(image)
230+
assert isinstance(image_metadata, docker.models.images.Image)
231+
232+
actual_img_size = image_metadata.attrs["Size"]
233+
actual_img_size = round(actual_img_size / 1024 / 1024)
234+
logging.info(f"The size of the image is {actual_img_size} MBs.")
235+
logging.debug(f"The image metadata: {image_metadata}")
236+
237+
img_label_name = image_metadata.labels["name"]
238+
if img_label_name in expected_image_name_size_map:
239+
expected_img_size = expected_image_name_size_map[img_label_name]
240+
logging.debug(f"Expected size of the '{img_label_name}' image is {expected_img_size} MBs.")
241+
else:
242+
pytest.fail(f"Image name label '{img_label_name}' is not in the expected image size map {expected_image_name_size_map}")
243+
244+
# Check the size change constraints now
245+
# 1. Percentual size change
246+
percent_change = actual_img_size / expected_img_size * 100 - 100
247+
assert percent_change < self.percent_treshold, f"Image size of '{img_label_name}' changed by {percent_change}% (expected: {expected_img_size} MB; actual: {actual_img_size} MB; treshold: {self.percent_treshold}%)."
248+
# 2. Absolute size change
249+
size_difference = actual_img_size - expected_img_size
250+
assert size_difference < self.size_treshold, f"Image size of '{img_label_name}' changed by {size_difference} MB (expected: {expected_img_size} MB; actual: {actual_img_size} MB; treshold: {self.size_treshold} MB)."
192251

193252
def encode_python_function_execution_command_interpreter(python: str, function: Callable[..., Any], *args: list[Any]) -> list[str]:
194253
"""Returns a cli command that will run the given Python function encoded inline.

0 commit comments

Comments
 (0)