Skip to content

feat(mpi): install Open MPI with apt-get on Ubuntu AMIs (#1487) - #1492

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/1487-mpi-apt-ubuntu
Nov 2, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/1487-mpi-apt-ubuntu

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1487

Based on main, not stacked on #1489. Both PRs touch pkg/userdata/mpi.go and mpi_sandbox_test.go, so whichever merges second needs a rebase. The overlapping hunks are distinct: #1489 changes the readiness gate and the marker, this PR the install, mpi.sh and the instance ID.

Design

  • Install (pkg/userdata/mpi.go): the package manager is detected with command -v.
    • yum is tried first, so AL2 and AL2023 (dnf's yum alias) are byte-for-byte the same command.
    • Otherwise apt-get, which installs openmpi-bin (mpirun and orted; it pulls in openssh-client) and libopenmpi-dev (mpicc and headers, like openmpi-devel) with --no-install-recommends. That is about 100 packages instead of 143, and drops gfortran. Ubuntu ships Open MPI 4.1.2 on 22.04 and 4.1.6 on 24.04; both are in fix(mpi): pass --allow-run-as-root so --mpi-command starts as root on Open MPI 4.0.1 (AL2) #1482's root matrix.
    • Lock retry: apt-get update and the install are retried together, up to 10 times 15 s apart. I measured in ubuntu:24.04 that apt-get update under a held lists lock exits 100 immediately, with or without -o DPkg::Lock::Timeout, which waits only for the dpkg lock. On first boot, apt-daily or cloud-init can hold the lists lock. After 10 tries the script exits 1 and fix(mpi): build the hostfile without jq; fail closed on any MPI setup failure (#1483) #1485's trap records mpi-bootstrap.
    • Neither manager: the script prints spawn: no yum or apt-get to install Open MPI; use an image with it and --skip-mpi-install and exits 1, which is recorded.
  • Refusing at launch is not possible, so this relies on fix(mpi): build the hostfile without jq; fail closed on any MPI setup failure (#1483) #1485's fail-closed. Before launch spawn knows only TargetOS (windows/linux, from DescribeImages' Platform), and Windows already refuses --mpi. Ubuntu, Debian, SUSE and Alpine all report Platform as empty or Linux/UNIX. The SSH username (spawn:local-username) is decided on the instance by the bootstrap. A distro the install can't handle now fails closed within about 2 minutes, with that message, on every member.
  • mpi.sh on Ubuntu: nothing needed. mpirun and orted are in /usr/bin and libmpi is in the default library path (checked in the container). The /usr/lib64/openmpi entries don't exist there, which is harmless.
    • Also fixed, under Security: LD_LIBRARY_PATH=/usr/lib64/openmpi/lib:$LD_LIBRARY_PATH ended in an empty entry (the current directory) whenever the variable was unset, in every login shell on every MPI member, AL included. It is now ${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}.
  • Instance ID (needed for Ubuntu to assemble at all): the MPI fragment fell back to ec2-metadata, and the bootstrap gets INSTANCE_ID only from it. Ubuntu has no ec2-metadata: it is absent from Canonical's 22.04 and 24.04 cloud-image manifests. So on Ubuntu, rank 0 would write an empty key owner file, and pkg/mpicohort reads rank 0's public key only once that file names the instance (ami create: an image of an MPI rank-0 instance carries the cohort's root SSH key, which a child cohort reuses #1338), so assembly could never complete. The fragment now reads the ID from IMDSv2 with curl (already a base tool) when INSTANCE_ID is empty. The bootstrap's own empty INSTANCE_ID is filed as bootstrap: INSTANCE_ID is empty on Ubuntu (no ec2-metadata), so every tag read and the --command once-marker use an empty ID #1490, since fixing it changes the published bootstrap body.
  • EFA: the distribution's Open MPI wins, on Ubuntu as on AL today. The install runs before efa_installer.sh, mpi.sh prepends /usr/lib64/openmpi/bin, and nothing puts /opt/amazon/openmpi/bin on the script's PATH. The installer's profile.d snippet is read by login shells only. On Ubuntu that resolves mpirun to /usr/bin/mpirun.
  • Published bootstrap body: unchanged.

Gates (pkg/userdata/mpi_apt_test.go, mpi_tools_test.go)

  • TestMPIInstallsOpenMPIWithApt: rank 0 of a 3-member cohort with no mpirun and only apt-get. Expect exactly an update then one install with -y openmpi-bin libopenmpi-dev, no yum, the correct hostfile, and a completed record. Runs in the host sandbox and in an ubuntu:24.04 container (Ubuntu's bash 5.2, mawk, grep, coreutils; skips without docker or the image).
  • TestMPIAptRetriesABusyLock: apt-get update fails twice (counted), so expect 3 updates, 1 install, and success. TestMPIAptGivesUpAndFailsClosed: expect exactly 10 updates, then exit 1 with an mpi-bootstrap record and no mpirun.
  • TestMPINoPackageManagerFailsClosed: expect a recorded failure and a message naming --skip-mpi-install.
  • TestMPIKeyOwnerIsTheInstanceWithoutEC2Metadata: INSTANCE_ID unset and a stub IMDS, so the key owner file must name the instance.
  • TestMPIProfileAddsNoEmptyLibraryPathEntry: source the rendered mpi.sh with LD_LIBRARY_PATH unset; expect no empty entry.
  • Tool inventory (TestMPIUserDataToolsExistOnEveryBase), extended to Ubuntu:
    • The base set now claims AL2023, AL2 and Ubuntu 22.04/24.04, each tool checked against Canonical's manifests.
    • yum and ec2-metadata are no longer base tools. yum and apt-get are mpiPackageManagers, allowed only inside if command -v <same tool>; the AST is checked across the whole config matrix. TestMPIPackageManagerGuardScanSeesABareYum proves the scan sees the pre-MPI: add an apt install path for Ubuntu AMIs (today --mpi on Ubuntu can never work) #1487 bare yum.

Watched failing against compiling reverts (template-only, go vet clean)

  1. Drop the apt-get branch: both TestMPIInstallsOpenMPIWithApt runs (sandbox and ubuntu container) fail with rank 0 exited 1 on an apt-based member, and the retry and give-up tests fail.
  2. Single apt-get update + install, no retry: rank 0 exited 100 although apt's lock was free on the third try, and apt-get update ran 1 times, want the bound of 10.
  3. Restore ec2-metadata: key owner = "\n", want the instance's own ID from IMDS, and the tool gate reports runs "ec2-metadata", which is not a base tool of every supported MPI base.
  4. The pre-MPI: add an apt install path for Ubuntu AMIs (today --mpi on Ubuntu can never work) #1487 bare yum install: the tool gate reports runs "yum" outside 'if command -v yum', and the apt tests fail with exit 127 (the live Ubuntu failure).
  5. Old LD_LIBRARY_PATH line: mpi.sh sets LD_LIBRARY_PATH="/usr/lib64/openmpi/lib:", which has an empty entry.

Real install, outside the test suite

In ubuntu:24.04 as root, with network, I ran the rendered rank-0 script against the real apt-get and real Open MPI 4.1.6, with a 1-host hostfile and 2 slots. The install succeeded and mpirun resolved to /usr/bin/mpirun. Through the rank wrapper with --allow-run-as-root it printed rank-0 and rank-1, the script exited 0, and it wrote {"status": "completed", "exit_code": 0, "source": "mpi"}.

Sizes

MPI user data with the #1486 live shape (--mpi-command, ready gate): 8487 → 9277 raw, 3765 → 4051 gzip (+286). With --efa: 3961 → 4242 gzip.

Checks

make check (from /private/tmp), make lint (0 issues, 10 modules) and semgrep scan --config=auto --error . (0 findings) all pass. The AL2 container tests pass too: bash 4.2, still on the yum path.

Live check before merge (branch-built CLI)

@scttfrdmn scttfrdmn added this to the v0.155.0 milestone Nov 2, 2026
@codecov

codecov Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Live-verified on EC2 (2026-11-02) with a CLI built from a local merge of #1489 (e4132a9c) and #1492 (ff9a9639), in account 942542972736, us-east-1, on c7g.medium:

Base Open MPI Clusters Result
AL2 4.0.1 3× 2-node + 1× 3-node PASS: all completed/mpi, 0 No such file
AL2023 4.1.2 1× 2-node PASS
Ubuntu 24.04 4.1.6 (/usr/bin/mpirun) 1× 2-node PASS: apt 6+9 s, 0 lock retries; key-owner holds the instance ID
Ubuntu 22.04 4.1.2 1× 2-node PASS: apt 7 s, 0 retries

The 3-node AL2 run caught #1486 live. Rank 0's SSH probe of rank 2 was accepted at 04:58:46, but rank 2's mpi-rank and marker are stamped 04:58:47.476. The old SSH-only gate would have started mpirun about 1 s early. The new gate logged all peers ready after 5s, and mpirun started after the last marker. Every marker holds the cohort ID, and its mtime equals its mpi-rank mtime.

Ubuntu confirmed #1490, which is wider than filed: there's no ec2-metadata and no aws CLI. Evidence is on #1490.

Cost was about $0.05 for 24 instances. The leak check is clean, and I confirmed it independently.

The MPI user data installed Open MPI only with yum, so --mpi on an
Ubuntu --ami without --skip-mpi-install died at 'yum: command not found'.

- Detect the package manager with command -v: yum first (AL unchanged),
  then apt-get (openmpi-bin libopenmpi-dev, --no-install-recommends),
  retrying update+install up to 10x because DPkg::Lock::Timeout does not
  cover the apt lists lock; neither: fail closed naming --skip-mpi-install.
- Read the instance ID from IMDSv2 when INSTANCE_ID is empty: Ubuntu has
  no ec2-metadata, so the key owner was empty and mpicohort never
  released rank 0's key.
- mpi.sh: no empty LD_LIBRARY_PATH entry (cwd) when it was unset.
- Tool inventory covers Ubuntu; package managers must be guarded.

Fixes #1487
@scttfrdmn
scttfrdmn force-pushed the feat/1487-mpi-apt-ubuntu branch from ff9a963 to e646a0a Compare November 2, 2026 05:36
@scttfrdmn
scttfrdmn merged commit 0ba21db into main Nov 2, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the feat/1487-mpi-apt-ubuntu branch November 2, 2026 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MPI: add an apt install path for Ubuntu AMIs (today --mpi on Ubuntu can never work)

1 participant