Files
spinifex/scripts/install-node_test.sh
Bryn Mailer 4a4442b7bb feat: OCI Block Volumes as an EBS provider (ocibsd) (#1683)
* feat: add the SnapshotCopy capability and send the volume type to the EBS provider

CopySnapshot is now optional behaviour. A provider that leaves SnapshotCopy
false refuses it as unsupported_capability, the conformance suite runs its
copy cases only when it is advertised, and AWS CopySnapshot answers
UnsupportedOperation on the refusal. viperblockd, qemunbd and the memory
reference set advertise it.

AWS CreateVolume and the root volume create send the volume type in
CreateVolumeRequest.Parameters, which the existing providers ignore.

* feat: add an OCI block storage client and its fake

BlockClient covers what an EBS provider on OCI block volumes needs: volume
create, get, list by tag, update and delete; iSCSI attach, get, list and
detach; and incremental backup create, get, list by tag and delete. Creates
carry an opc-retry-token, and attachments are never shareable.

BlockFake models the behaviours the provider has to handle: the 50 GB
floor, retry tokens, replies lost after the call took effect, the 409s on
deleting a volume or a backup while a backup is in progress, backups that
stay CREATING until a test settles them, attachment state transitions and
the 32 iSCSI attachments per instance.

* feat: add the ocibsd EBS provider over OCI block volumes

* test: publish at the latest version in the EBS conformance suite

Lifecycle publishes use the latest contract version. Per-version publish
cases require a provider whose latest export is a block device to refuse a
caller below the descriptor version, and ocibsd now refuses such a publish
before attaching. The ocibsd suite runs over NATS against the fakes.

* feat: write imported and SQS store images to block exports

The image import and the SQS store volume publish at the latest contract
version, since a block export has no version 1 form, and write through a
shared imagewrite.Writer. It dispatches on the export's kind: an nbd export
goes to the NBD writer, and a block export is written to its device path with
qemu-img convert -n, refusing an image larger than the export. The SQS
preparer's writer takes the published export and is supplied by the daemon.

* feat: add the iscsiadm initiator and the ocibsd stale-session logout on start

The real Initiator runs iscsiadm through an injectable command runner, writes every node record with manual startup and a 120 s replacement timeout before logging in, and waits for the by-path device. Provider.Start reads the compartment's volumes, then logs out only sessions to this cluster's OCI volumes that OCI no longer attaches to this node; PublishVolume is refused until it has run.

* feat: add the ocibsd service role, its config and the spx admin init flags

runtime/roles/ocibsd reads the node's OCI instance, refuses a node outside the cluster's availability domain, starts the provider and serves it with this node's per-node subjects; the cluster tag is derived from the cluster CA. service.New and spx service gain an ocibsd arm. [nodes.<name>.ebs.oci] carries compartment_id, availability_domain and the credential keys, validated with the external pool's OCI auth rules and required to agree across nodes. spx admin init gains --ebs-provider, --oci-compartment-id and --oci-availability-domain, and formation carries the choice to every joining node.

* feat: generate the ocibsd cluster ID at init and carry it to joining nodes

spx admin init with --ebs-provider ocibsd generates a random 128-bit cluster ID once, writes it as [nodes.<name>.ebs.oci] cluster_id, keeps an existing one across a --force re-init, and formation carries it to every joining node with the provider choice. Any other provider writes no cluster ID and renders the same spinifex.toml as before. ocibsd tags every OCI resource with it in place of a value derived from the cluster CA, which would change if the CA were reissued, and refuses to start without it; config validation refuses nodes that carry different IDs.

* feat: ship the ocibsd unit, daemon device drop-in and udev rule in the tarball

build/ocibsd holds spinifex-ocibsd.service, which runs spx service ocibsd start as root with no capabilities once NATS is up, a spinifex-daemon.service drop-in allowing block-sd so QEMU opens the iSCSI disk, and a udev rule giving group spinifex read-write on disks whose by-path names an OCI attachment IQN. The release image and dev-install.sh package the directory as ocibsd/, which setup.sh never installs; the install role copies it onto ocibsd nodes only. uninstall-spx.sh removes the drop-in, which its unit globs miss.

* fix: leave the ebs object out of a viperblock cluster's formation payload

formation.NetworkConfig carries the EBS provider as a nil pointer with omitempty, set only when the provider is not viperblockd, so a viperblock cluster's payload is the same JSON as before the provider choice existed. A joining node that receives no ebs object writes the default provider; one that receives ocibsd still gets the provider, OCI fields and cluster_id.

* fix: refuse to start viperblock on a node configured for another EBS provider

spx service viperblock start exits with an error when the node's [ebs] provider resolves to anything but viperblockd, so a viperblock unit reinstalled over its mask on an ocibsd or qemunbd node does not answer the provider subjects; an unset provider still resolves to viperblockd and passes. ocibsd start shares the same check.

* test: run the ocibsd conformance suite live against OCI

The live test runs the unmodified EBS provider conformance suite, in process
and over NATS, against the real SDK block client and one OCI instance, with
iscsiadm and the device check run on the instance over SSH. It also checks
that OCI's GB is 2^30 bytes on the attached device, and that a volume
recreated under a deleted volume's ID is never answered with the deleted one.
It skips unless SPINIFEX_OCIBSD_LIVE is set; the README lists its inputs.

* test: keep the live ocibsd NATS server serving through the suite's teardown

t.Context is cancelled before cleanups run, so the suite's teardown, sent over NATS, reached the provider with a cancelled context and left every volume, backup and attachment behind.

* fix: list each OCI volume and backup once

In a live run OCI's ListVolumeBackups returned one new backup twice as it
left REQUEST_RECEIVED, and ocibsd refused the snapshot read because two
backups appeared to carry its snapshot ID. The SDK client's ListVolumes and
ListVolumeBackups now keep the first entry for each OCID.

* fix: give a pending snapshot five minutes to settle in conformance

An OCI backup takes 40-49 s, past the 30 s ceiling. The poll now backs off from 10 ms to 2 s so fast providers still settle at once and a slow backend is not read in a tight loop.

* feat: pass an EBS provider and its OCI placement through install-node.sh

install-node.sh takes --ebs-provider, --oci-compartment-id and --oci-availability-domain and adds them to spx admin init. The values are joined into a remote sh -c, so each is checked against the characters an OCID or availability domain can hold.

* feat: cover the ocibsd EBS provider in the OCI cloud-vendor nightly

Adds the vm-single-ocibsd and vm-multi-ocibsd topologies. They build nodes with the Block Volume Management plugin disabled, grant the node principal manage volume-family and use instances, install the ocibsd units, and init with --ebs-provider ocibsd and the state's compartment and availability domain.

An ebs provider gate checks the units and masks on every node, boots from an AMI imported onto OCI, and drives stop and start, attach and detach, snapshot and restore with a guest-written marker, a cross-node start on multi-node, and a terminate that leaves no tagged OCI volume or backup.

Each run records the cluster_id init generated, and e2e-oci.sh deletes every volume and backup tagged with it after the destroy and in --sweep-only, failing the run if any remain.

* feat: select the EBS provider at init by existing config, SPINIFEX_EBS_PROVIDER or OCI detection

spx admin init loses --ebs-provider, --oci-compartment-id and --oci-availability-domain. It resolves the provider once: the one an existing node config resolves to, an omitted provider counting as viperblockd; then SPINIFEX_EBS_PROVIDER; then detection, which picks ocibsd when the OCI instance metadata service answers within one second with a shape that is not BM.*, and viperblockd otherwise. Init prints the provider and where it came from.

For ocibsd the compartment and availability domain come from the metadata and auth defaults to instance_principal, with an existing config's [nodes.<name>.ebs.oci] values winning; the cluster ID is generated once as before. Before any config is written, init makes the read ocibsd makes at start with the node's credential and stops, naming the manage volume-family and use instances statements, when it is refused. spx admin join takes the provider from formation and checks its own credential the same way.

When the provider is ocibsd, init and join install the unit, udev rule and daemon drop-in staged under /usr/local/share/spinifex/ocibsd, mask spinifex-viperblock.service by a link to /dev/null, enable spinifex-ocibsd.service, and reload systemd and udev. A viperblock node is untouched.

* feat: install the iSCSI initiator and stage the ocibsd files from setup.sh on an OCI VM

When the OCI instance metadata service answers within a second with a shape that is not bare metal, the check spx admin init detects ocibsd by, setup.sh installs open-iscsi (apt) or iscsi-initiator-utils (dnf), enables iscsid.socket, and stages the tarball's ocibsd/ under /usr/local/share/spinifex/ocibsd for init or join to install.

On a node whose existing config already names ocibsd, the new ocibsd stage also reinstalls the unit, daemon drop-in and udev rule from the new stage, masks the viperblock unit install_systemd has just rewritten, and reloads systemd and udev. Any other node gets none of them.

* feat: carry SPINIFEX_EBS_PROVIDER to init in place of install-node.sh's EBS flags

install-node.sh drops --ebs-provider, --oci-compartment-id and --oci-availability-domain, which spx admin init no longer takes. A SPINIFEX_EBS_PROVIDER in its environment is passed to init on the first host through env, after sudo, and joining nodes take the provider from formation. The value is joined into a remote sh -c, so anything but lower-case letters is refused.

* feat: let the OCI nightly's ocibsd topologies rely on init's detection

The ocibsd topologies set no EBS provider and check that init detected it on
the OCI VM, with the placement the state reports; the other topologies set
SPINIFEX_EBS_PROVIDER=viperblockd. The ocibsd unit install and the post-init
auth write are gone; an API-key run installs the credential and seeds each
node's config before init.

* fix: leave a masked unit masked during the systemd reconcile

* chore: fix lint findings on the ocibsd branch

* fix: return the volume parameter encoding error instead of panicking

* docs: specify the snapshot copy capability and the version-2 block export

* docs: describe EBS on OCI Block Volumes for operators

* fix: give volume publish its own request budget

A publish on a remote block backend waits for the attachment and the
device it yields, which can take minutes, so the 30s request floor turned
a slow but successful attach into an ambiguous mount failure. Publish now
gets PublishTimeout (5m) on the NATS client, and ocibsd bounds a whole
publish 30s short of it so it answers retry-later before the client gives up.

* fix: grant OCI volume rights only to ocibsd deployments

The node policy and the API-key policy statements granted manage
volume-family and use instances to every deployment, although only
ocibsd touches OCI volumes. They now follow ebs_provider, and
setup-identity.sh takes --ebs-provider so the shared policy can carry
them; validate-topology.sh passes the topology's provider.

* fix: keep a timed-out publish classified as unavailable

* refactor: map OCI conflicts to sentinels through ociError

* refactor: find volumes and backups through one tagged lookup

* refactor: page OCI list calls through one listAll helper

* refactor: drop the EBS fields applyNetworkConfig set before the node's EBS choice

* refactor: share one exported EBS schema version check

* refactor: check a capacity range through CapacityRange.Valid

* refactor: sort listed IDs with slices.Sorted

* refactor: refuse a volume held by another instance in one heldElsewhere check

* refactor: wait for OCI work and the iSCSI device through one poll loop

* refactor: name the OCI auth selections once in bootstrap/config

* refactor: check a masked unit through systemd.IsMasked

* refactor: replace unreachable negative-size guards with gosec notes

* test: build ocibsd test nodes through one newNode helper

* refactor: share the OCI fakes' staged failures and the OCI IQN prefix

* test: build the test block client through NewBlockClientWithProvider

* test: read the live run's exit status through the initiator's exitCode

* test: table the OCI not-found and limit classification cases

* test: read the OCI retry token header by its canonical name

* fix: parse the nightly's node table and cluster_id as spx now writes them

spx get nodes draws its columns with box characters, so the Ready count
split on '|' never found a node. A multi-node leader's config lists the
other nodes without EBS tables, so read the cluster_id only from tables
that carry one.

* fix: resume the nightly's formation only from a config init wrote

An ocibsd API-key run seeds spinifex.toml with the credential before init,
so a non-empty file no longer shows that formation ran, and a checkpoint
left by an earlier run skipped init on fresh nodes.

* fix: check the provider only on node tables and capture iSCSI state when the EBS gate fails

* fix: refuse an ocibsd logout that leaves the session open and test logout under the unit sandbox on gate failure

* fix: give spinifex-ocibsd CAP_SYS_ADMIN so iscsiadm sees and logs out its sessions

* fix: expand an ocibsd volume only at the ETag it read and keep gate diagnostics read-only

* fix: keep the guest's gate reports when the EBS gate times out waiting on the console

* test: read the data marker back after a reattach in the ocibsd gate

* test: never overwrite a gate disk whose first block could not be read

* test: report why the ocibsd gate guest could not read a disk

* test: do the ocibsd gate guest's direct I/O with an aligned buffer

* test: tear down the ocibsd gate's volumes in the order Spinifex accepts

* fix: retry install-node's first SSH reach of a host

* Revert "fix: retry install-node's first SSH reach of a host"

This reverts commit 5adf4130e4.

* test: forget stale host keys for reused OCI addresses before formation

* test: show why a workbook image import failed and how EKS endpoints resolve

* test: hold the OCI install until apt has stayed idle

* test: stop the Oracle Cloud Agent's hung apt update before installing

* test: install OCI nodes from the Australian Ubuntu mirror with retries

* test: keep whole-run node journals and dump EKS worker consoles on a failed join

* test: read the host DNS drop-in as root and list EKS nodes by endpoint IP

* test: let OCI nodes' apt fall back through a list of Ubuntu mirrors
2026-11-13 15:35:00 +10:00

53 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Tests remote_join_cmd and init_env from install-node.sh: the join token reaches spx only on
# stdin, so sudo's log never holds it; other values arrive as plain arguments even when they
# hold shell syntax; and a SPINIFEX_EBS_PROVIDER that is not a provider name is refused.
# preflight runs this with sh
[ -n "${BASH_VERSION:-}" ] || exec bash "$0" "$@"
set -euo pipefail
here="$(cd "$(dirname "$0")" && pwd)"
work="$(mktemp -d)"
trap 'rm -rf "$work"' EXIT
mkdir "$work/bin"
cd "$work"
cat > "$work/bin/sudo" <<'SH'
#!/bin/sh
echo "$*" >> "$FAKE_SUDO_LOG"
exec "$@"
SH
cat > "$work/bin/spx" <<'SH'
#!/bin/sh
for a in "$@"; do printf '<%s>' "$a"; done > "$FAKE_SPX_ARGV"
SH
chmod +x "$work/bin/sudo" "$work/bin/spx"
export FAKE_SUDO_LOG="$work/sudo.log" FAKE_SPX_ARGV="$work/spx.argv" PATH="$work/bin:$PATH"
eval "$(sed -n '/^remote_join_cmd()/,/^}/p' "$here/install-node.sh")"
fails=0
check() { if [ "$2" = "$3" ]; then echo "ok $1"; else echo "FAIL $1: want '$3' got '$2'"; fails=$((fails + 1)); fi; }
TOKEN=spx_join_FAKETOKEN-abc_1
cmd="$(remote_join_cmd node2 10.0.0.2 203.0.113.2 '10.0.0.1:4432;touch PWNED' us-east-1 'az $(touch PWNED2)')"
bash -c "$cmd" <<<"$TOKEN"
check "the token is not in the command" "$(printf '%s' "$cmd" | grep -c FAKETOKEN || true)" 0
check "the token is not in sudo's log" "$(grep -c FAKETOKEN "$FAKE_SUDO_LOG" || true)" 0
check "spx got the token" "$(grep -o '<--token><[^>]*>' "$FAKE_SPX_ARGV")" "<--token><$TOKEN>"
check "spx got the other values as given" "$(cat "$FAKE_SPX_ARGV")" "<admin><join><--force><--node><node2><--bind><10.0.0.2><--cluster-bind><10.0.0.2><--advertise><203.0.113.2><--host><10.0.0.1:4432;touch PWNED><--token><$TOKEN><--region><us-east-1><--az><az \$(touch PWNED2)>"
check "no value was run as a command" "$(find "$work" -maxdepth 1 -name 'PWNED*' | wc -l | tr -d ' ')" 0
# init_env: its value is joined into a remote sh -c unquoted, so anything beyond
# a provider name's characters is refused, not passed on.
eval "$(sed -n '/^init_env()/,/^}/p' "$here/install-node.sh")"
check "no provider sets nothing" "$(init_env "")" ""
check "a provider is carried to init" "$(init_env viperblockd)" "env SPINIFEX_EBS_PROVIDER=viperblockd "
check "a provider with shell syntax is refused" \
"$(init_env 'ocibsd;touch PWNED3' >/dev/null 2>&1 && echo accepted || echo refused)" refused
check "a provider with a space is refused" \
"$(init_env 'ocibsd $(touch PWNED4)' >/dev/null 2>&1 && echo accepted || echo refused)" refused
check "no refused value was run as a command" "$(find "$work" -maxdepth 1 -name 'PWNED*' | wc -l | tr -d ' ')" 0
[ "$fails" -eq 0 ]