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
20 changes: 6 additions & 14 deletions acto/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from acto.serialization import ActoEncoder, ContextEncoder
from acto.snapshot import Snapshot
from acto.utils import delete_operator_pod, process_crd
from acto.utils.image_helper import ImageHelper
from acto.utils.preprocess import get_existing_images
from acto.utils.thread_logger import get_thread_logger, set_thread_logger_prefix
from ssa.analysis import analyze
Expand Down Expand Up @@ -290,13 +291,15 @@
constraints: Optional[list[XorCondition]] = None,
) -> None:
self.context = context
self.workdir = workdir
self.base_workdir = workdir
self.cluster = cluster
self.images_archive = os.path.join(workdir, "images.tar")
self.images_archive = ImageHelper.prepare_image_archive(
self.context["preload_images"],
)
self.worker_id = worker_id
self.sequence_base = sequence_base # trial number to start with
self.context_name = cluster.get_context_name(

Check warning on line 302 in acto/engine.py

View workflow job for this annotation

GitHub Actions / coverage-report

Missing coverage

Missing coverage on lines 294-302
f"acto-{acto_namespace}-cluster-{worker_id}"
)
self.kubeconfig = os.path.join(
Expand Down Expand Up @@ -880,7 +883,6 @@
self.crd_name = operator_config.crd_name
self.crd_version = operator_config.crd_version
self.workdir_path = workdir_path
self.images_archive = os.path.join(workdir_path, "images.tar")
self.num_workers = num_workers
self.dryrun = dryrun
self.is_reproduce = is_reproduce
Expand Down Expand Up @@ -1132,24 +1134,14 @@
logger = get_thread_logger(with_prefix=True)

# Build an archive to be preloaded
if len(self.context["preload_images"]) > 0:
logger.info("Creating preload images archive")
print_event("Preparing required images...")
# first make sure images are present locally
for image in self.context["preload_images"]:
subprocess.run(
[self.tool, "pull", image],
stdout=subprocess.DEVNULL,
check=True,
)
subprocess.run(
[self.tool, "image", "save", "-o", self.images_archive]
+ list(self.context["preload_images"]),
stdout=subprocess.DEVNULL,
check=True,
ImageHelper.prepare_image_archive(
self.context["preload_images"],
)

start_time = time.time()

Check warning on line 1144 in acto/engine.py

View workflow job for this annotation

GitHub Actions / coverage-report

Missing coverage

Missing coverage on lines 1137-1144

errors: list[OracleResults] = []
runners: list[TrialRunner] = []
Expand Down
23 changes: 10 additions & 13 deletions acto/post_process/post_diff_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import os
import queue
import re
import subprocess
import sys
import threading
import time
Expand Down Expand Up @@ -43,6 +42,7 @@
from acto.snapshot import Snapshot
from acto.trial import Step
from acto.utils import add_acto_label, error_handler, get_thread_logger
from acto.utils.image_helper import ImageHelper


class DiffTestResult(pydantic.BaseModel):
Expand Down Expand Up @@ -383,8 +383,10 @@
self._kubeconfig = os.path.join(
os.path.expanduser("~"), ".kube", self._context_name
)
self._generation = 0
self._images_archive = os.path.join(workdir, "images.tar")
self._images_archive = ImageHelper.prepare_image_archive(

Check warning on line 387 in acto/post_process/post_diff_test.py

View workflow job for this annotation

GitHub Actions / coverage-report

Missing coverage

Missing coverage on lines 386-387
self._context["preload_images"],
)

def run_cr(self, cr, trial, gen):
"""Run a CR and return the snapshot"""
Expand Down Expand Up @@ -452,10 +454,12 @@
self._context_name = cluster.get_context_name(
f"acto-{acto_namespace}-cluster-{worker_id}"
)
self._kubeconfig = os.path.join(
os.path.expanduser("~"), ".kube", self._context_name
)
self._images_archive = os.path.join(workdir, "images.tar")
self._images_archive = ImageHelper.prepare_image_archive(

Check warning on line 460 in acto/post_process/post_diff_test.py

View workflow job for this annotation

GitHub Actions / coverage-report

Missing coverage

Missing coverage on lines 457-460
self._context["preload_images"],
)

def run(self):
"""Run the deploy runner"""
Expand Down Expand Up @@ -699,21 +703,14 @@
num_nodes=self.config.num_nodes,
version=self.config.kubernetes_version,
)
deploy = Deploy(self.config.deploy)
# Build an archive to be preloaded
images_archive = os.path.join(workdir, "images.tar")
if len(self.context["preload_images"]) > 0:
# first make sure images are present locally
for image in self.context["preload_images"]:
subprocess.run(["docker", "pull", image], check=True)
subprocess.run(
["docker", "image", "save", "-o", images_archive]
+ list(self.context["preload_images"]),
check=True,
)
ImageHelper.prepare_image_archive(
self.context["preload_images"],
)

workqueue: multiprocessing.Queue = multiprocessing.Queue()
for unique_input_group in self.unique_inputs.values():

Check warning on line 713 in acto/post_process/post_diff_test.py

View workflow job for this annotation

GitHub Actions / coverage-report

Missing coverage

Missing coverage on lines 706-713
workqueue.put(unique_input_group)

runners: list[DeployRunner] = []
Expand Down
14 changes: 4 additions & 10 deletions acto/post_process/simple_crash_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import os
import queue
import re
import subprocess
import sys
import threading
import time
Expand All @@ -32,6 +31,7 @@
from acto.serialization import ActoEncoder
from acto.trial import Step
from acto.utils.error_handler import handle_excepthook, thread_excepthook
from acto.utils.image_helper import ImageHelper


def get_crash_config_map(
Expand Down Expand Up @@ -269,21 +269,15 @@
num_nodes=self.config.num_nodes,
version=self.config.kubernetes_version,
)
deploy = Deploy(self.config.deploy)

# Build an archive to be preloaded
images_archive = os.path.join(workdir, "images.tar")
if len(self.context["preload_images"]) > 0:
# first make sure images are present locally
for image in self.context["preload_images"]:
subprocess.run(["docker", "pull", image])
subprocess.run(
["docker", "image", "save", "-o", images_archive]
+ list(self.context["preload_images"])
)
ImageHelper.prepare_image_archive(
self._context["preload_images"],
)

################## Operation sequence crash test ######################
num_ops = 0

Check warning on line 280 in acto/post_process/simple_crash_test.py

View workflow job for this annotation

GitHub Actions / coverage-report

Missing coverage

Missing coverage on lines 272-280
workqueue = multiprocessing.Queue()
for trial_name, trial in self._trial_to_steps.items():
new_steps = {}
Expand Down
51 changes: 51 additions & 0 deletions acto/utils/image_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os
import subprocess

from filelock import FileLock


class ImageHelper:
"""Helper class for managing Docker images, including pulling and archiving them."""

image_archive_prefix = os.path.join(os.getcwd(), ".acto_images")
image_tool = os.getenv("IMAGE_TOOL", "docker")

@staticmethod
def prepare_image_archive(images: list[str]) -> str:
"""
Prepare an archive of images for testing.

Args:
images (list[str]): List of image file paths to include in the archive.

Returns:
str: Path to the created archive.
"""

digest = hash("".join(sorted(images)))

archive_name = f"{digest}.tar"
archive_path = os.path.join(
ImageHelper.image_archive_prefix, archive_name
)

lock = FileLock(f"{archive_path}.lock")
with lock:
if os.path.exists(archive_path):
return archive_path

for image in images:
subprocess.run(
[ImageHelper.image_tool, "pull", image],
stdout=subprocess.DEVNULL,
check=True,
)
os.makedirs(ImageHelper.image_archive_prefix, exist_ok=True)
subprocess.run(
[ImageHelper.image_tool, "image", "save", "-o", archive_path]
+ list(images),
stdout=subprocess.DEVNULL,
check=True,
)

return archive_path

Check warning on line 51 in acto/utils/image_helper.py

View workflow job for this annotation

GitHub Actions / coverage-report

Missing coverage

Missing coverage on lines 25-51
Loading