Skip to content

eBPF-based security platform

testing: have vm-clean remove VMs and stack-down the stack

John Fastabend15ac73fe9ff8
diff --git a/.agents/skills/testing/SKILL.md b/.agents/skills/testing/SKILL.md
index 8f188e92..858394a4 100644
--- a/.agents/skills/testing/SKILL.md
+++ b/.agents/skills/testing/SKILL.md
@@ -220,5 +220,7 @@ initrd verified; `shirudo-runtime status` shows an initialized target,
and `. /etc/shirudo-test-vm.env` sets the environment a family run
gives the target tests.
The checkout is mounted read-only at `/workspace/shirudo`. Without
-`VM_NAME`, `vm-clean` removes all of `build/test-vm/`, the bundles and
-the cached runtime image included, so always name the VM.
+`VM_NAME`, `vm-clean` stops every VM and removes the state and logs of
+them all, and leaves the bundles, the cache and the local stack; name
+the VM to remove only its state. `make stack-down` removes the local
+stack with its data and CA.
diff --git a/Documentation/contribute/testing/testing.rst b/Documentation/contribute/testing/testing.rst
index aa3eb556..edf4b38f 100644
--- a/Documentation/contribute/testing/testing.rst
+++ b/Documentation/contribute/testing/testing.rst
@@ -555,11 +555,11 @@ Boot an interactive VM
# make -C testing vm-stop VM_NAME=<name>
# make -C testing vm-clean VM_NAME=<name>
-.. warning::
-
- Without ``VM_NAME``, ``vm-clean`` removes the whole
- ``build/test-vm/`` directory, the bundles and the cached runtime
- image included. Name the VM to remove only its state.
+ Without ``VM_NAME``, ``vm-clean`` stops every VM and removes the state
+ and logs of them all, ``build/test-vm/vms/`` and
+ ``build/test-vm/logs/``. The bundles, the cached kernels and runtime
+ image, and the local stack stay; ``make -C testing clean`` removes the
+ bundles, and ``make stack-down`` the stack.
.. list-table::
:header-rows: 1
@@ -746,7 +746,8 @@ own ``enroll.json``.
Without the checker, ``make telemetry`` starts the telemetry stack alone and says so. A
stack started before the checker was built keeps its collector: run
-``make stack-down`` before ``make telemetry`` to add the backend.
+``make stack-down``, which also removes the stack's data, before
+``make telemetry`` to add the backend.
``make vm`` prepares a stable CA even when neither service is running.
After initialization, it activates the signed ``config-local-stack``
@@ -764,8 +765,11 @@ collector JSON is ``out/otlp.json`` there. Server private keys live outside
the checkout in a directory under ``/tmp`` named for the checkout's hash.
Normal and sudo invocations use the same trust material. The guest
receives only the public CA. ``make stack-down`` removes the service
-containers and network while retaining the data and CA for the next start.
-It does not stop the VM; use ``make vm-stop`` for that.
+containers and network, then ``build/test-vm/stack/`` and the private
+keys: the registry's and ClickHouse's data, the collector JSON and the
+CA. The next ``make stack-up`` starts empty, with a new CA, which a VM
+booted before does not trust: boot the VMs again after it. It does not
+stop the VMs; use ``make vm-stop`` for that.
``make -C testing vm`` uses the same defaults. Set ``LOCAL_STACK=0`` to
boot a VM without the local-stack configuration and use the explicit
diff --git a/testing/vm/run.sh b/testing/vm/run.sh
index 4774aafa..4f3660d8 100755
--- a/testing/vm/run.sh
+++ b/testing/vm/run.sh
@@ -978,9 +978,11 @@ clean_state()
log "removed VM state and logs: $VM_NAME_REQUEST"
return 0
fi
+ # The bundles, the cache and the local stack stay: rebuilding them is
+ # slow, and make -C testing clean and make stack-down remove them.
stop_all_state
- rm -rf -- "$VM_ROOT"
- log "removed VM state and logs: $VM_ROOT"
+ rm -rf -- "$VMS_DIR" "$LOGS_DIR" "$VM_ROOT/enroll.json"
+ log "removed the state and logs of every VM under $VM_ROOT"
}
save_failure_logs()
diff --git a/testing/vm/stack.sh b/testing/vm/stack.sh
index fef28113..73fd6e7d 100755
--- a/testing/vm/stack.sh
+++ b/testing/vm/stack.sh
@@ -50,7 +50,22 @@ telemetry)
printf '%s\n' 'no backend: make quote-check, make stack-down, then make telemetry' >&2
fi
;;
-down) stack_down ;;
+down)
+ case "$W/:$TLS_DIR/" in
+ //:* | *://) echo 'refusing to remove a stack at /' >&2; exit 1 ;;
+ esac
+ stack_down
+ # What the containers wrote is theirs, not ours to remove: a
+ # container removes it, and then the stack's directory goes.
+ if [ -d "$W" ]; then
+ docker run --rm -v "$W:/stack" --entrypoint sh "$CLICKHOUSE_IMAGE" \
+ -c 'rm -rf /stack/clickhouse /stack/registry /stack/out' ||
+ { echo "cannot remove the data under $W" >&2; exit 1; }
+ fi
+ rm -rf -- "$W" "$TLS_DIR"
+ rmdir -- "$(dirname "$TLS_DIR")" 2>/dev/null || :
+ printf 'removed the stack, its data and its CA: %s\n' "$W"
+ ;;
enroll)
# Shown before they run, so that a demo shows what each step is: the
# keys the builder made, then the builds the VMs boot.