From f778ee09af15ecbf2d1b22b089076e7c6c379f5d Mon Sep 17 00:00:00 2001 From: Junjie Wu Date: Wed, 25 Oct 2023 08:35:42 -0700 Subject: [PATCH] [antlir2][vm] rework pre-configured VMs Summary: Originally I expected more sharing of various type of VMs, but after migrating all tests, that need apparently doesn't exist. For just handful pre-built VMs, we can provide the targets in the main defs.bzl directly. Later more artifacts can be moved over there too. Test Plan: CI. No real change other than renaming a target. Reviewed By: aijayadams Differential Revision: D50617859 fbshipit-source-id: 409525ee87961dc3ae0dfd8089ae9fb88bf8bac2 --- antlir/antlir2/antlir2_vm/BUCK | 24 +------------------ antlir/antlir2/antlir2_vm/bzl/defs.bzl | 12 ++++++++++ .../antlir2/antlir2_vm/bzl/preconfigured.bzl | 17 ------------- antlir/antlir2/antlir2_vm/tests/BUCK | 19 ++++++++------- .../antlir2/docs/docs/internals/vm-tests.md | 9 ++++--- 5 files changed, 28 insertions(+), 53 deletions(-) delete mode 100644 antlir/antlir2/antlir2_vm/bzl/preconfigured.bzl diff --git a/antlir/antlir2/antlir2_vm/BUCK b/antlir/antlir2/antlir2_vm/BUCK index 21cefe0a76..5e0a823f16 100644 --- a/antlir/antlir2/antlir2_vm/BUCK +++ b/antlir/antlir2/antlir2_vm/BUCK @@ -68,17 +68,7 @@ vm.host( ) vm.host( - name = "disk-boot-5.19", - compatible_with = ["ovr_config//cpu:x86_64"], - disks = [simple_disk.get_boot_disk( - arch = "x86_64", - interface = "virtio-blk", - uname = "5.19", - )], -) - -vm.host( - name = "default-nondisk-boot", + name = "default-initrd-boot", compatible_with = ["ovr_config//cpu:x86_64"], disks = [simple_disk.default_control_disk], initrd = initrd.default, @@ -86,18 +76,6 @@ vm.host( visibility = ["PUBLIC"], ) -vm.host( - name = "nondisk-boot-5.19", - compatible_with = ["ovr_config//cpu:x86_64"], - disks = [simple_disk.get_control_disk( - arch = "x86_64", - interface = "virtio-blk", - uname = "5.19", - )], - initrd = initrd.get("x86_64", "5.19"), - kernel = metalos_kernel.get("x86_64", "5.19").vmlinuz, -) - vm.host( name = "default-nvme-disk-boot", compatible_with = ["ovr_config//cpu:x86_64"], diff --git a/antlir/antlir2/antlir2_vm/bzl/defs.bzl b/antlir/antlir2/antlir2_vm/bzl/defs.bzl index 949a4de6ac..efa46f9db1 100644 --- a/antlir/antlir2/antlir2_vm/bzl/defs.bzl +++ b/antlir/antlir2/antlir2_vm/bzl/defs.bzl @@ -207,4 +207,16 @@ vm = struct( rust_test = vm_rust_test, sh_test = vm_sh_test, run_command = vm_run_command, + + # Various pre-built targets useful for building VM or writing tests + artifacts = struct( + # Pre-built VMs for `vm_host` of tests + default_vms = struct( + # initrd_boot is recommended for faster boot performance + initrd_boot = "//antlir/antlir2/antlir2_vm:default-initrd-boot", + # disk boots are recommended for more real boot sequence + disk_boot = "//antlir/antlir2/antlir2_vm:default-disk-boot", + nvme_disk_boot = "//antlir/antlir2/antlir2_vm:default-nvme-disk-boot", + ), + ), ) diff --git a/antlir/antlir2/antlir2_vm/bzl/preconfigured.bzl b/antlir/antlir2/antlir2_vm/bzl/preconfigured.bzl deleted file mode 100644 index 3ec71e81ab..0000000000 --- a/antlir/antlir2/antlir2_vm/bzl/preconfigured.bzl +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright (c) Meta Platforms, Inc. and affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Lists pre-configured VM targets that any test can refer to based on their needs. -# Refer to actual target for their detailed configuration. -PRECONFIGURED_VM = { - "disk-boot": "//antlir/antlir2/antlir2_vm:default-disk-boot", - "nondisk-boot": "//antlir/antlir2/antlir2_vm:default-nondisk-boot", - "nvme-disk-boot": "//antlir/antlir2/antlir2_vm:default-nvme-disk-boot", -} - -def get_vm(name: str = "nondisk-boot") -> str: - if name not in PRECONFIGURED_VM: - fail("{} not listed in pre-configured VMs".format(name)) - return PRECONFIGURED_VM[name] diff --git a/antlir/antlir2/antlir2_vm/tests/BUCK b/antlir/antlir2/antlir2_vm/tests/BUCK index 209f0f9f07..813f457871 100644 --- a/antlir/antlir2/antlir2_vm/tests/BUCK +++ b/antlir/antlir2/antlir2_vm/tests/BUCK @@ -1,5 +1,4 @@ load("//antlir/antlir2/antlir2_vm/bzl:defs.bzl", "vm") -load("//antlir/antlir2/antlir2_vm/bzl:preconfigured.bzl", "PRECONFIGURED_VM", "get_vm") load("//antlir/bzl:build_defs.bzl", "rust_binary") load("//metalos/vm/disks:simple.bzl", "simple_disk") @@ -12,7 +11,7 @@ vm.cpp_test( "ENV_ARTIFACT": "$(exe :sidecar)", }, run_as_bundle = True, - vm_host = get_vm(), + vm_host = vm.artifacts.default_vms.initrd_boot, ) vm.python_test( @@ -23,7 +22,7 @@ vm.python_test( "ENV_ARTIFACT": "$(exe :sidecar)", }, run_as_bundle = True, - vm_host = get_vm(), + vm_host = vm.artifacts.default_vms.initrd_boot, ) vm.rust_test( @@ -36,7 +35,7 @@ vm.rust_test( "ENV_ARTIFACT": "$(exe :sidecar)", }, run_as_bundle = True, - vm_host = get_vm(), + vm_host = vm.artifacts.default_vms.initrd_boot, ) vm.sh_test( @@ -46,7 +45,7 @@ vm.sh_test( "ENV_ARTIFACT": "$(exe :sidecar)", }, test = "test.sh", - vm_host = get_vm(), + vm_host = vm.artifacts.default_vms.initrd_boot, ) # Verify all pre-configured VMs @@ -62,7 +61,11 @@ vm.sh_test( }, vm_host = target, ) - for name, target in PRECONFIGURED_VM.items() + for name, target in { + "disk-boot": vm.artifacts.default_vms.disk_boot, + "initrd-boot": vm.artifacts.default_vms.initrd_boot, + "nvme-disk-boot": vm.artifacts.default_vms.nvme_disk_boot, + }.items() ] # Test for sidecar @@ -121,11 +124,11 @@ vm.rust_test( vm.run_command( name = "run-command", command = "uname -r", - vm_host = get_vm(), + vm_host = vm.artifacts.default_vms.initrd_boot, ) vm.run_command( name = "run-command-with-location", command = "bash -c 'echo $(location :sidecar)'", - vm_host = get_vm(), + vm_host = vm.artifacts.default_vms.initrd_boot, ) diff --git a/antlir/antlir2/docs/docs/internals/vm-tests.md b/antlir/antlir2/docs/docs/internals/vm-tests.md index dde944a157..ecd74c0553 100644 --- a/antlir/antlir2/docs/docs/internals/vm-tests.md +++ b/antlir/antlir2/docs/docs/internals/vm-tests.md @@ -186,7 +186,6 @@ For example, the example test target looks like this. ``` load("//antlir/antlir2/antlir2_vm/bzl:defs.bzl", "vm") -load("//antlir/antlir2/antlir2_vm/bzl:preconfigured.bzl", "get_vm") vm.rust_test( name = "rust-test", @@ -196,7 +195,7 @@ vm.rust_test( env = { "ANTLIR2_TEST": "1", }, - vm_host = get_vm(), # vm specific + vm_host = vm.artifacts.default_vms.initrd_boot, # vm specific ) ``` @@ -209,9 +208,9 @@ optional `env` will be passed through into the VM, so your test will have access to them. The `vm_host` field specifies the VM host target to execute the test in. -`get_vm()` is a function provided by `antlir2/antlir2_vm/bzl:preconfigured.bzl` -for you to select from a list of pre-configured VMs, if you can find one that -satisfies your need. +`vm.artifacts.default_vms` provides several pre-configured VMs that can be +directly used by VM test. If none of them meet your need, you would need to +build a custom VM. ### Build a custom VM for your test (optional)