|  | 
| 23 | 23 | """ | 
| 24 | 24 | 
 | 
| 25 | 25 | import inspect | 
|  | 26 | +import json | 
| 26 | 27 | import os | 
| 27 | 28 | import re | 
| 28 | 29 | import shutil | 
| @@ -66,6 +67,14 @@ def pytest_addoption(parser): | 
| 66 | 67 |         help="use firecracker/jailer binaries from this directory instead of compiling from source", | 
| 67 | 68 |     ) | 
| 68 | 69 | 
 | 
|  | 70 | +    parser.addoption( | 
|  | 71 | +        "--custom-cpu-template", | 
|  | 72 | +        action="store", | 
|  | 73 | +        help="Path to custom CPU template to be applied unless overwritten by a test", | 
|  | 74 | +        default=None, | 
|  | 75 | +        type=Path, | 
|  | 76 | +    ) | 
|  | 77 | + | 
| 69 | 78 | 
 | 
| 70 | 79 | def pytest_report_header(): | 
| 71 | 80 |     """Pytest hook to print relevant metadata in the logs""" | 
| @@ -275,9 +284,22 @@ def microvm_factory(request, record_property, results_dir): | 
| 275 | 284 |         fc_binary_path, jailer_binary_path = build_tools.get_firecracker_binaries() | 
| 276 | 285 |     record_property("firecracker_bin", str(fc_binary_path)) | 
| 277 | 286 | 
 | 
|  | 287 | +    # If `--custom-cpu-template` option is provided, the given CPU template will | 
|  | 288 | +    # be applied afterwards unless overwritten. | 
|  | 289 | +    custom_cpu_template_path = request.config.getoption("--custom-cpu-template") | 
|  | 290 | +    custom_cpu_template = ( | 
|  | 291 | +        { | 
|  | 292 | +            "name": custom_cpu_template_path.stem, | 
|  | 293 | +            "template": json.loads(custom_cpu_template_path.read_text("utf-8")), | 
|  | 294 | +        } | 
|  | 295 | +        if custom_cpu_template_path | 
|  | 296 | +        else None | 
|  | 297 | +    ) | 
| 278 | 298 |     # We could override the chroot base like so | 
| 279 | 299 |     # jailer_kwargs={"chroot_base": "/srv/jailo"} | 
| 280 |  | -    uvm_factory = MicroVMFactory(fc_binary_path, jailer_binary_path) | 
|  | 300 | +    uvm_factory = MicroVMFactory( | 
|  | 301 | +        fc_binary_path, jailer_binary_path, custom_cpu_template=custom_cpu_template | 
|  | 302 | +    ) | 
| 281 | 303 |     yield uvm_factory | 
| 282 | 304 | 
 | 
| 283 | 305 |     # if the test failed, save important files from the root of the uVM into `test_results` for troubleshooting | 
|  | 
0 commit comments