Repository navigation
feat: support running system-tests locally instead of via Farm - #10253
Conversation
…89d85fa0818479c81c1025049a7ff ic-build: sha256:4bd0bda360187ee57fb9923c788a61c51675b8c4d430695892e65b57333d5795 ic-dev: sha256:c6da125dd03ebc4b55cf357e6ecb528e5a9154ce38ce1b877d81ca4cb9c0c5c9
|
New container images with tag: |
…12d9b1189a814656d579c04095e25 ic-build: sha256:151d1ebf531a9d83baeb566a0ac5dcc91983aee94cf01b76c2b88722dada037f ic-dev: sha256:a4ad94ed89fc266191fb01e168332f2d73c808cf110eb71f0b7a956b895e4c58
|
New container images with tag: |
…4690bb71e96a05635f67ab9ed912b ic-build: sha256:dcb838604bc2a7643b677965d1b59e1e7b1e9830106b528219a47ac754731d6e ic-dev: sha256:e4969a5a299c7505c4934edf718dc3c9d78518ce8dce9f57b70588478241ffb5
|
New container images with tag: |
…12d9b1189a814656d579c04095e25 ic-build: sha256:a9d38170c5bb83a91d916d0aa6d70270f675e2f8f3dea09a1dad8fdfcc08c9d5 ic-dev: sha256:5f4557cc25d33aaf034f0053f5f33e89d9681cf8eb1af9b91616e61e51d9a514
|
New container images with tag: |
…d6f7027f841e00ceb8cf4ba516ffc ic-build: sha256:978aa74fecbbba51f2cc9cc7a17954a64343d1b9a3e7fc2bbebbf19da102fd74 ic-dev: sha256:44cd547319418a8f0b717b1cb8fa88f6e23bf0edd624f0e71cec68f2255f893c
|
New container images with tag: |
The LocalBackend Drop impl never ran: the backend is held by a process-wide static REGISTRY, which Rust never drops at exit, so the strong count never reaches zero. Had it run, it would have wrongly killed libvirtd in the setup subprocess, which must outlive setup so test/teardown subprocesses can connect to its socket. Remove it along with the libvirtd/pid_path fields it was the sole reader of. Instead stop libvirtd explicitly at the end of delete_group via its pid-file: SIGTERM, wait briefly for a graceful exit, then escalate to a PID-reuse-guarded SIGKILL if it overruns the grace period. kill_all_descendants stays as the final safety net but now finds nothing left to kill. Verified with //rs/tests/idx:basic_health_test_local.
… tests The _local (libvirt/QEMU) backend creates per-VM TAPs via 'ip tuntap add', which opens /dev/net/tun. Docker exposes it as 0600 root:root (the namespace.so daemon forces this regardless of host perms or --device/bind-mount), so the unprivileged container user gets 'open: Permission denied'. CAP_NET_ADMIN does not bypass this DAC check on the device node. Open up the perms in init.sh, the same way it already does for /dev/fuse and /dev/kvm. Also add ci/container/init.sh to get-image-tag.sh inputs: it is baked into the image as the ENTRYPOINT but was excluded from the tag hash, so changes to it would not produce a new image.
…ac895bdd550cac7bacb9dad553bae ic-build: sha256:0ed93dc568f53cce56042a86b31f98cd1bbb9cd3ea8e649532c366494b9c160a ic-dev: sha256:72798a5bed36f7174d2a318efe1996ed44d598c37f8cf3c909e6dec53cb73812
|
New container images with tag: |
The local (libvirt/QEMU) system-test backend opens VM disks with cache='none'
(O_DIRECT), which refuses a writable raw image whose byte size is not a multiple
of the host block size ("Image size is not a multiple of request alignment").
The universal-VM / GuestOS config images are sized as 2*du + 1MiB and so are not
block aligned.
Pad each extra (config) disk up to a 4 KiB multiple in the local backend's
attach_disk_images -- the single choke point covering every source -- and also
round the size up at each builder so the artifacts are aligned at the source:
- rs/tests/driver/assets/create-universal-vm-config-image.sh
- rs/tests/system_tests.bzl (uvm_config_image _size genrule)
- rs/ic_os/config/tool/src/hostos/guestos_bootstrap_image.rs
Boot disks are left untouched: they are already block aligned and may carry a
GPT backup header at the last sector that padding would displace.
|
✅ No security or compliance issues detected. Reviewed everything up to 09d3336. Security OverviewDetected Code ChangesThe diff is too large to display a summary of code changes. |
What?
Provide a "local" variant for each system-test which deploys testnets inside the local bazel sandbox (without
sudoand withoutrequires-network) instead of using the external, proprietary and VPN-only Farm web-service which deploys testnets to DFINITY's DCs.To run a system-test locally suffix its name with
_localfor example:The
_localsystem-tests currently don't run as part of thebazel-test-alljob since they reserve a high number of CPUs from bazel causing them to spend most of their time acquiring resources from the single 64-CPU GitHub runner. In total it takes over 3 hours to run them which is obviously too long for PRs. The plan is to run all tests on a Bazel Remote Execution cluster such that they parallelise over many 64-CPU machines. This is WIP. For the moment we just run the single//rs/tests/idx:basic_health_test_localinbazel-test-allas a smoke-test such that thelocal_backendcode gets exercised. (See BuildBuddy). The remaining jobs will temporarily run in thelocal-system-testsjob of the nightlyschedule-dailyworkflow.Why?
Status?
166 non farm-only tests are passing with the local backed!
63 tests are configured as farm-only because they're considered too big to fit on the local backend. We could decide to overload runners a bit (like we do with Farm hosts) so that we can run more big tests on the local backend.
13 tests still need to be supported on the local backend.
How?
Architecture
Currently a system-test using the
Farmbackend works like visualised in the following diagram:flowchart TD subgraph k8s_cluster["zh1-idx1"] subgraph runner["github-runner / devenv"] subgraph devc["dev-container"] subgraph bazel["bazel test //rs/tests/..."] subgraph sandbox["linux-sandbox (×N parallel)"] subgraph driver["ic-system-test-driver"] end end end end end bazel_cache["artifacts.zh1-idx1.dfinity.network"] end subgraph aws["AWS"] farm["farm.dfinity.systems"] end subgraph hosts["Farm hosts (dfinity.network)"] subgraph fr1["fr1"] subgraph fr1dll01["fr1-dll01"] libvirtd Q["qemu-system-x86_64 (×N)"] end fr1dll02["fr1-dll02"] end subgraph zh1["zh1"] zh1b["zh1-dll02"] zh1a["zh1-dll01"] end subgraph dm1["dm1"] dm1b["dm1-dll02"] dm1a["dm1-dll01"] end end driver -->|"POST /group/{group-name}/vm/{vm-name}"| farm farm -->|"virsh --connect qemu+ssh://fr1-dll01.fr1.dfinity.network define ..."| fr1dll01 fr1dll01 -->|GET /cas/hash_of_image|bazel_cache Q -->|GET /cas/hash_of_image|bazel_cacheSo the test will make an HTTP requests to the DFINITY-VPN-only Farm web-service in AWS to create a VM. Farm will then pick a suitable host to deploy the VM to and instruct the host to download the image from the remote bazel cache. Farm will then call
virshwhich connects over SSH to thelibvirtdrunning on the host to create the VM.For some tests the IC node running in the VM will do an upgrade and will download another image from the remote bazel cache. It's actually a bit more involved since there's an additional caching layer in front of the bazel cache called the
dc_http_proxywhich is left out of this diagram for simplicity.This PR introduces an additional
Localbackend which moves thelibvirtdrunning on a Farm host to run locally under the test itself. Since images are now locally available they don't need to be downloaded anymore from the bazel cache. IC nodes running in the VM will still need to download images from a web-server during upgrades. For that reason the test runs an internalserve_files_taskweb-server serving the local images:flowchart TD subgraph k8s_cluster["zh1-idx1 / Namespace.so"] subgraph runner["github-runner / devenv"] subgraph devc["dev-container"] subgraph bazel["bazel test //rs/tests/..."] subgraph sandbox["linux-sandbox (×N parallel)"] subgraph driver["ic-system-test-driver"] libvirtd dnsmasq Q["qemu-system-x86_64 (×N)"] serve_files_task end end end end end end classDef green stroke:#008a0e,color:#008a0e,fill:#fff; class libvirtd,dnsmasq,Q,serve_files_task green; Q -->|GET /hash_of_image|serve_files_taskNetworking
Motivation
The Farm backend provisions VMs on a multi-tenant cluster with managed DNS, TLS, and system-mode libvirt networking. The local backend (
local_backend.rs) reproduces just enough of that on a single developer/CI host fully unprivileged — nosudo, no root-ownedlibvirtd, no system-mode libvirt networks.libvirtdruns as the current user in session mode (qemu:///session) and QEMU opens pre-created, user-owned TAPs directly.The only privileged primitive is a narrow capability launcher,
ic-net-admin, asetcap'd copy ofcapshgranting exactlycap_net_admin,cap_net_raw,cap_net_bind_service(never root). It raises those caps into the ambient set andexecs a short shell script, so theip/dnsmasqcommands it runs inherit them across theexec. Everything else is unprivileged.Topology (per test group)
flowchart LR subgraph Host drv["ic-system-test-driver<br/>(sources from mgmt addr)"] lo["lo (all /128)<br/>:1::1 mgmt · :2::1 logs · :3::1 files"] fs["serve_files_task<br/>files:8080"] dq["dnsmasq<br/>RA + DHCPv4 + default route"] br["Linux bridge vbr-xxxx<br/>fd00:AABB:CCDD::1/64 · 10.X.Y.1/24"] drv --- lo fs --- lo dq --- br lo -. "route src override, metric 256" .- br end br === tap1["tap-aaaa"] === vm1["VM A<br/>enp1s0: SLAAC /64<br/>enp2s0: DHCPv4"] br === tap2["tap-bbbb"] === vm2["VM B<br/>enp1s0: SLAAC /64"]1. Per-group Linux bridge and deterministic addressing
Each test group gets its own Linux bridge (
vbr-<hash>, kept within the 15-charIFNAMSIZlimit), created and torn down via the capability launcher increate_group/delete_group. All addresses are derived from a SHA-256 of the group name, so concurrently-running groups get distinct bridges, prefixes, and subnets with no central allocator:/64fd00:AABB:CCDD::/64(ULA)fd00:AABB:CCDD::1/64(the host is the guests' default router via RA, §2)fd00:AABB:CCDD:1::1lofd00:AABB:CCDD:2::1lofd00:AABB:CCDD:3::1lo/2410.X.Y.0/24(RFC 1918)2. SLAAC + Router Advertisements via dnsmasq
The IC GuestOS does not statically configure its global IPv6 address — it brings up link-local only, then derives its deterministic global address via SLAAC from a Router Advertisement:
global = group /64 prefix + EUI-64 of the deterministic MAC. Because the MAC is itself a hash of(group, vm), the driver can compute each VM's IPv6 up front.A minimal per-group
dnsmasq(run through the launcher) supplies this instart_ra_daemon:--dhcp-range=<prefix>,ra-onlyadvertises the on-link, autonomous prefix so guests SLAAC (no stateful IPv6 leases).--ra-param=<bridge>,10,1800sets a non-zero router lifetime, installing the bridge (i.e. the host) as the guests' default router.--dhcp-range=10.X.Y.2,…,254serves stateful DHCPv4 for the optional second NIC.--port=0disables DNS. We might later enable name serving to simulate DNS in tests.3. Per-VM TAP devices
In
start_vm, each VM's TAP (tap-<hash>) is created via the launcher, taggeduser <current-user>so the unprivileged QEMU can open it, and enslaved to the group bridge. The libvirt domain XML references it withmanaged='no'(guestos_vm_template.xml) so libvirt uses the existing device rather than trying to create one (which would need root). MACs and the IPv6 are deterministic, so addressing survives re-runs and reboots.4. Off-
/64management address (the firewall-testing trick)This is the subtlest part. The GuestOS firewall has a built-in accept for the node's own
/64. If the driver reached nodes from an address inside that prefix, the registry-derived deny rules under test would be shadowed and never exercised. So the driver sources host→node traffic from a second/64— the management addressfd00:AABB:CCDD:1::1assigned tolo— which lies outside every node/64but still inside thefd00::/8range the GuestOS bootstrap whitelists.Making this work requires two things set up in
create_group:ip -6 route replace <prefix>/64 dev <bridge> proto kernel metric 256 src <mgmt>, which rewrites the kernel route thataddr addauto-creates so host-originated traffic is sourced from the management address rather than the on-bridge gateway.No IP forwarding or NAT is involved — the management address is on
lo, so traffic to it terminates on the host and is delivered locally.Why three off-
/64addresses, not one? The GuestOS firewall also caps the number of simultaneous connections per source address (max_simultaneous_connections_per_ip_address). The management address is therefore kept exclusively for the test's own host→node traffic: the driver's long-lived auxiliary connections — the per-node journald streams (fd00:AABB:CCDD:2::1; see the Logging section below) and the file server (fd00:AABB:CCDD:3::1, §6) — each bind to their own siblingloaddress so they don't consume a slot in the management address' budget. This matters forfirewall_max_connections_test, which deliberately saturates that budget from the management address and would otherwise race the journald stream for the last connection slot.5. Optional IPv4 second NIC
VMs that request IPv4 get a second TAP on the same bridge (the guest's
enp2s0), pinned to PCIe bus 2 in the domain XML for deterministic interface naming (bus 1 →enp1s0primary, bus 2 →enp2s0). It obtains an address purely via DHCPv4; since the driver always reaches VMs over IPv6, this subnet needs no routing or NAT.6. Per-group file server
There is no external network, so ICOS images that nodes fetch over HTTP (e.g. GuestOS/HostOS update images for upgrade tests) are served by a small web server spawned from the driver (
serve_files_task.rs), listening on the group's dedicated file-server addressfd00:AABB:CCDD:3::1(onlo; see §1 and §4) at fixed portFILE_SERVER_PORT = 8080. Serving from an off-/64address mirrors production, where the web server hosting GuestOS/HostOS images is not on the IC nodes'/64; nodes still reach it via their RA-installed default route (§2), and their download replies are accepted by the firewall's statefulestablished,relatedrule. The port can be fixed because each group has its own (per-group-unique) file-server address, so there's no cross-group contention.7. Isolation and teardown
Per-group hashing plus per-group network namespaces keep concurrent groups from colliding. Teardown in
delete_groupstops the RA daemon, destroys all of the group's domains (releasing their TAPs), deletes every TAP still enslaved to the bridge, removes the bridge, and removes the management, log-streaming and file-server addresses fromlo.What has no local equivalent: managed playnet DNS, TLS issuance, and multi-tenant scheduling — these log a warning and return dummy values.
Logging
Since VMs running via the local system-test backend don't have access to the external network their journald logs can't be streamed to DFINITY's ElasticSearch cluster. Logs of their consoles are also local and not available via Farm's console feature.
However we need access to both to effectively debug tests. For this reason both journald and console logs of each VM are streamed to the the test log which will look like:
Process Management
The main test process is turned into a child-subreaper (think systemd) such that all daemons like
libvirtd,dnsmasq,virtlogdand theqemu-system-x86_64per VM get reparented to the main test process. This allows the main process to kill any remaining childs at finalisation. If we didn't do this these daemons would become children of bazel's child-subreaper (process-wrapper/linux-sandbox) causing the test to never finish since these daemons would keep on running.The process tree of a
bazel test //rs/tests/idx:basic_health_test_localinvocation will look like: