|  | 
| 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 | @pytest.hookimpl(wrapper=True, tryfirst=True) | 
| 71 | 80 | def pytest_runtest_makereport(item, call):  # pylint:disable=unused-argument | 
| @@ -270,9 +279,22 @@ def microvm_factory(request, record_property, results_dir): | 
| 270 | 279 |         fc_binary_path, jailer_binary_path = build_tools.get_firecracker_binaries() | 
| 271 | 280 |     record_property("firecracker_bin", str(fc_binary_path)) | 
| 272 | 281 | 
 | 
|  | 282 | +    # If `--custom-cpu-template` option is provided, the given CPU template will | 
|  | 283 | +    # be applied afterwards unless overwritten. | 
|  | 284 | +    custom_cpu_template_path = request.config.getoption("--custom-cpu-template") | 
|  | 285 | +    custom_cpu_template = ( | 
|  | 286 | +        { | 
|  | 287 | +            "name": custom_cpu_template_path.stem, | 
|  | 288 | +            "template": json.loads(custom_cpu_template_path.read_text("utf-8")), | 
|  | 289 | +        } | 
|  | 290 | +        if custom_cpu_template_path | 
|  | 291 | +        else None | 
|  | 292 | +    ) | 
| 273 | 293 |     # We could override the chroot base like so | 
| 274 | 294 |     # jailer_kwargs={"chroot_base": "/srv/jailo"} | 
| 275 |  | -    uvm_factory = MicroVMFactory(fc_binary_path, jailer_binary_path) | 
|  | 295 | +    uvm_factory = MicroVMFactory( | 
|  | 296 | +        fc_binary_path, jailer_binary_path, custom_cpu_template=custom_cpu_template | 
|  | 297 | +    ) | 
| 276 | 298 |     yield uvm_factory | 
| 277 | 299 | 
 | 
| 278 | 300 |     # if the test failed, save important files from the root of the uVM into `test_results` for troubleshooting | 
|  | 
0 commit comments