Skip to content

Commit

Permalink
[antlir2][vm] rework pre-configured VMs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wujj123456 authored and facebook-github-bot committed Oct 25, 2023
1 parent e1d5c5b commit f778ee0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 53 deletions.
24 changes: 1 addition & 23 deletions antlir/antlir2/antlir2_vm/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -68,36 +68,14 @@ 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,
kernel = metalos_kernel.default.vmlinuz,
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"],
Expand Down
12 changes: 12 additions & 0 deletions antlir/antlir2/antlir2_vm/bzl/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
),
)
17 changes: 0 additions & 17 deletions antlir/antlir2/antlir2_vm/bzl/preconfigured.bzl

This file was deleted.

19 changes: 11 additions & 8 deletions antlir/antlir2/antlir2_vm/tests/BUCK
Original file line number Diff line number Diff line change
@@ -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")

Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
)
9 changes: 4 additions & 5 deletions antlir/antlir2/docs/docs/internals/vm-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
)
```

Expand All @@ -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)

Expand Down

0 comments on commit f778ee0

Please sign in to comment.