Skip to content

evetest: recover from transient Proxmox failures in the broker - #7195

Draft
milan-zededa wants to merge 4 commits into
lf-edge:masterfrom
milan-zededa:evetest-proxmox-retries
Draft

milan-zededa wants to merge 4 commits into
lf-edge:masterfrom
milan-zededa:evetest-proxmox-retries

Conversation

@milan-zededa

@milan-zededa milan-zededa commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

Make the Proxmox provider of the evetest broker recover from transient
Proxmox failures that made whole test suites fail in the nightly runs. One
commit per problem:

  1. Clear a device left over by a failed teardown on setup. When
    TeardownDevice fails, the provider keeps the device in its map so that
    the teardown can be retried, but the broker forgets it. A client session
    reuses its SDN device name, so every later test of the suite failed with
    device "sdn-<client>" already exists, even when PVE had deleted the VM
    seconds after the teardown gave up. A device whose teardown failed is now
    marked, and SetupDevice finishes its teardown first. A device that was
    never torn down is still rejected, so that a broker bug which sets up a
    live device again fails instead of destroying its VM. Seen e.g. in the 16.0-stable nightly
    45103341150,
    where 8 tests of TestDeviceConnectivitySuite in a row failed this way.
  2. Split the deadline of a Proxmox call among its retries.
    retryProxmoxCall ran all attempts on the caller's context, so a first
    attempt that hung until the deadline left no time for the retries it
    announced (Attempt 1/3: ... (will retry) was never followed by a
    second attempt). Each attempt now gets an equal share of the time left,
    and fewer attempts are made when that share would drop below 30 seconds.
    The per-device teardown budget is raised from one to three minutes,
    as deleting a VM on a loaded host was seen to take just over a minute.
    This is what left the devices behind in (1).
  3. Retry a failed VM create. Creates failed transiently on a loaded
    host, failing the test, while the next setup seconds later went through.
    Both the create call (500 got no worker upid - start worker failed,
    500 user name not set, e.g. in the master nightly
    45075176035,
    TestKubeRegistrationSuite) and the create task that PVE runs afterwards
    failed: in the 17.0-stable nightly
    45092013678
    (TestStorageSuite, TestUpgradeSuite) creates timed out on the storage
    lock, which PVE holds for the whole import of a disk:
    cannot import from 'local:import/...' - can't lock file '/var/lock/pve-manager/pve-storage-<id>' - got timeout.
    The VMID allocation, the create and the wait for its task are now
    retried, with a fresh VMID, after the failed VM is removed. A failure of
    the wait itself, e.g. a client-side timeout, is not retried, as PVE may
    still be creating the VM.
    The removal of a failed VM does not run under the VMID lock, which would
    block all other creates meanwhile. As a VMID that is not locked can be
    allocated again (and PVE removes the VM of a failed create task itself),
    a VM is stopped or deleted by its VMID, also in teardown and in the
    sweep, only after checking under the VMID lock that no other device holds
    that VMID. Only issuing the call runs under the lock, not the wait for
    its task.
  4. Sweep orphaned resources periodically. The VMs, VNets and import
    volumes that no device owns, e.g. a VM whose failed create could not be
    removed, were only removed when the broker started, which with
    auto-upgrade may be days later. So was a device whose teardown failed for
    good once its session ended. The startup sweep now also runs every 30
    minutes, and spares what devices own, set up or being set up:
    • it first finishes the failed teardowns from (1);
    • it lists the VMs while holding the mutex that every VM create holds
      while it allocates the VMID and records it in its pending device;
    • it removes only the VNets the provider does not track, holding the
      mutex under which VNets are created and tracked;
    • it spares the import volumes of the devices. The volume names now
      start with the number of the setup, unique to each device, so the
      sweep tells the volumes of each device apart exactly, and a setup
      never uploads a volume with the name of one the sweep is removing.

How to test and validate this PR

  • Unit tests in evetest/broker/provider cover each change with a fake PVE
    API: a leftover device whose VM is gone is cleared, and kept when its VM
    cannot be removed; a device that was never torn down is not removed by a
    setup of its name; a failed create call is retried with a new VMID; the
    deadline is split among the attempts, and a timed-out attempt is retried;
    a create task that PVE completed as failed is retried, and a failed wait
    for it is not; a VM whose VMID another device holds is never removed; the orphan sweep finishes the failed teardowns and removes
    only the VMs, VNets and import volumes that no device owns.
  • make -C evetest checks and the nightly evetest runs: the failure
    signatures listed above should no longer fail suites.

Changelog notes

None (evetest only).

PR Backports

  • 17.0-stable: To be backported.
  • 16.0-stable: To be backported.
  • 14.5-stable: To be backported.
  • 13.4-stable: To be backported.

Checklist

  • I've provided a proper description
  • I've added the proper documentation
  • I've tested my PR on amd64 device
  • I've tested my PR on arm64 device
  • I've written the test verification instructions
  • I've set the proper labels to this PR
  • I've checked the boxes above, or I've provided a good reason why I didn't
    check them: this changes only the evetest broker, which is covered by unit
    tests; it was not run against a real Proxmox host yet.

@milan-zededa milan-zededa added stable Should be backported to stable release(s) testing New test or test framework changes labels Nov 23, 2026
@milan-zededa
milan-zededa requested a review from rene November 23, 2026 10:40
@milan-zededa
milan-zededa force-pushed the evetest-proxmox-retries branch 2 times, most recently from dd4cba8 to b85cb71 Compare November 23, 2026 11:15
@milan-zededa

Copy link
Copy Markdown
Contributor Author

@claude

@milan-zededa
milan-zededa marked this pull request as draft November 23, 2026 11:37
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @milan-zededa's task in 4m 13s —— View job


Review complete

I reviewed all three changed files against origin/master, focusing on the five fixes described.

Overall: solid, carefully reasoned change. Lock ordering is consistent (vmCreateMutex is always taken before devMutex, including in the new listVMsAndOwnedIDs, so the sweep can't deadlock with a create), the retry/attemptContext deadline-splitting terminates correctly (attemptsLeft reaches 1 → last==true within proxmoxRetryMaxAttempts), the orphan-sweep invariant ("a listed VM is either already owned or never will be") holds because the listing runs under vmCreateMutex, and the create-call vs. create-task retry/permanent distinction matches the stated intent. Test coverage for each fix is thorough.

One point raised inline (proxmox.go, SetupDevice): the leftover-device path turns a previously loud device already exists error into a silent destroy-and-recreate. Correct for the failed-teardown case, but it now relies wholly on the "name in p.devices is always a leftover" invariant; if that is ever violated it would delete a live device's VM and mask the bug. Non-blocking — see the inline comment for details.

No correctness, security, or concurrency bugs found beyond that note.

Checklist

  • Read the diff and changed files
  • Analyze each of the 5 changes
  • Post inline review comments
  • Summarize

Comment thread evetest/broker/provider/proxmox.go Resolved
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 31.45%. Comparing base (38639b2) to head (fb49c8b).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7195      +/-   ##
==========================================
+ Coverage   31.01%   31.45%   +0.44%     
==========================================
  Files         562      573      +11     
  Lines      101231   102826    +1595     
==========================================
+ Hits        31399    32349     +950     
- Misses      67389    68083     +694     
+ Partials     2443     2394      -49     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@milan-zededa
milan-zededa force-pushed the evetest-proxmox-retries branch 2 times, most recently from a1fff8f to 6f6c40a Compare November 23, 2026 15:15
@milan-zededa

Copy link
Copy Markdown
Contributor Author

@claude Do a fresh new PR review.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @milan-zededa's task in 3m 39s —— View job


Fresh review — PR #7195

Re-reviewed all four changed files from scratch, focusing on the five fixes and their concurrency.

Overall: this holds up well. The reasoning in the doc comments is unusually careful and matches the code. Spot checks that passed:

  • Lock ordering stays one-directional: sdnMutex → sdnApplyMutex (in resolveDeviceNetworks/removeOrphanedVNets → applySDN) and vmCreateMutex → devMutex (in createVM and listVMsAndOwnedIDs) are both consistent, so the periodic sweep can't AB-BA against a create.
  • Deadline splitting (attemptContext) terminates in every branch: an already-passed deadline, a tiny share, or attemptsLeft==1 all fall through to the last==true / WithCancel path, and the retry loop exits on last. No infinite loop.
  • Orphan-sweep invariant ("a listed VM is owned now or never will be") holds because listVMsAndOwnedIDs lists under vmCreateMutex, which every create holds while it allocates the VMID and records it in its pending device. The import-volume spare is sound for the same reason (name reserved in pending before any upload; uploadSeq makes per-setup names unique).
  • dev.vmID is written in createVM under vmCreateMutex and read by the sweep under the same mutex; other readers get dev published through p.devices/p.pending under devMutex after the same-goroutine write — memory-safe.
  • create-call vs. create-task retry/permanent split matches the stated intent: a failed create call retries with a fresh VMID after cleanup; a task PVE completed-as-failed retries, but a failed/timed-out wait is permanent (PVE may still be creating). The guard milan added (teardownFailed gating removeLeftoverDevice) correctly distinguishes a leftover from a live double-setup.

Two non-blocking notes posted inline:

  1. createVM (line ~750) — removeFailedVM runs under vmCreateMutex and goes through retryProxmoxCall (retries + pauses), so a slow cleanup on a loaded host serializes all concurrent creates and stalls the sweep's VM listing. Deliberate correctness trade-off (VMID can't be reserved), but worth being aware of.
  2. removeOrphanedImportVolumes (line ~1586) — nit: the owned-volume check is a string prefix, so one device name being a prefix of another over-spares an orphan volume. Leak-only, harmless in practice.

No correctness, security, or concurrency bugs found. Test coverage for each fix is thorough.

· branch evetest-proxmox-retries

Comment thread evetest/broker/provider/proxmox.go Resolved
Comment thread evetest/broker/provider/proxmox.go Resolved
@milan-zededa
milan-zededa force-pushed the evetest-proxmox-retries branch 2 times, most recently from 2d4e9d1 to a131e95 Compare November 23, 2026 19:02
When TeardownDevice fails, the Proxmox provider keeps the device in its
devices map so that the teardown can be retried. The broker, however,
forgets the device, and as a client session reuses its SDN device name,
every later SetupDevice of the session failed with "device already
exists". This happened in a nightly run where PVE completed the delete
of the SDN VM two seconds after the broker's teardown timed out: the VM
was gone, yet all remaining tests of the suite failed on its stale
entry.

Mark the device whose teardown failed, and let SetupDevice finish that
teardown and continue the setup. A device that was never torn down is
still rejected with "device already exists", so that a broker bug which
sets up a live device again fails the test instead of destroying the
device's VM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Milan Lenco <milan@zededa.com>
retryProxmoxCall ran every attempt on the caller's context. When the
first attempt hung until the deadline, the retries it announced never
ran. In a nightly run the broker's one-minute teardown of an SDN VM
timed out this way while PVE was still deleting the VM, which it
completed two seconds later, and the failed teardown then broke the rest
of the test suite.

Give each attempt its own context, bounded to an equal share of the time
left until the caller's deadline, minus the pauses before the remaining
attempts. An attempt that fails early leaves its time to the next ones,
and the last attempt gets all the time left. When the time left would
give an attempt less than 30 seconds, plan fewer attempts instead: an
attempt cut that short is unlikely to succeed, and may still leave behind
what its call started. Calls without a deadline are unaffected.

Raise the per-device teardown budget from one to three minutes, so that
the first delete attempt gets about a minute.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Milan Lenco <milan@zededa.com>
A VM create fails transiently on a loaded PVE host, and SetupDevice then
failed the device setup, although a setup on the same host seconds later
went through. Both the create call and the create task that PVE runs
afterwards were seen failing in nightly runs:
- PVE could not start the worker for the create ("got no worker upid -
  start worker failed").
- On a host with a ZFS pool on a single SATA SSD, creates timed out on
  the storage lock, which PVE holds for the whole import of a disk,
  while several VMs were created at once:

    unable to create VM 106 - cannot import from
    'local:import/ev-eve-0bee873a-edge-dev-0.qcow2' - can't lock file
    '/var/lock/pve-manager/pve-storage-farfalle-pve-zfs-pool' - got timeout

Move the VMID allocation, the create and the wait for its task into
createAndWaitVM and retry it, with a fresh VMID on each attempt, after
removing whatever the failed attempt left behind. A failed create task
is a runtime problem on the host, as PVE rejects invalid options already
in the create call, and is retried. An error from buildVMOptions is not
retried, and neither is a failure of the wait itself (e.g. it timed out
client-side), as PVE may still be creating the VM. The API calls of an
attempt are bounded by its share of the deadline, while the wait and the
cleanup run on the deadline of the whole device setup: the import can
take a while, and the cleanup must not run on the context that just
expired. As the VM of a failed create is now always removed right where
the create failed, SetupDevice no longer has to track whether a VM was
created.

The removal runs without the VMID lock, which the create holds only
while it allocates the VMID and creates the VM: the import, the wait and
the retries of the removal could otherwise block all other creates for
minutes. A VMID that is no longer locked can be allocated again, though,
and PVE removes the VM of a failed create task itself, so a removal by
VMID could hit the VM of another device. Every VMID is recorded in its
device before its VM is created, so stop and delete a VM by its VMID, in
teardown and in the startup sweep too, only after checking under the
VMID lock that no other device holds the VMID. Only the lookup, the check
and the call that starts the task run under the lock; the wait for the
task does not, as the VM, and so its VMID, exists until the task
completes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Milan Lenco <milan@zededa.com>
The Proxmox provider removes the VMs, VNets and import volumes that no
device owns only when the broker starts. A VM whose failed create could
not be removed, for example, stayed on the host until the next broker
run, which with auto-upgrade may be days away. So did a device whose
teardown failed for good once its session ended, as only a setup of the
same name would finish that teardown.

Run the startup sweep every 30 minutes too, and make it spare what the
devices own, set up or being set up:
- It first finishes the failed teardowns, reserving each name while
  doing so, so that a concurrent setup of it fails instead of destroying
  the same VM.
- It lists the VMs while holding the VMID lock, which every create holds
  while it allocates the VMID, records it in its pending device and
  creates the VM, and spares the VMIDs of all devices. A VM missing from
  those is owned by no device and never will be, as the VMID of an
  existing VM is never allocated again. The listing is bounded so that a
  hung call cannot block creates for long. Each orphan is then removed
  only if no device holds its VMID by then.
- It removes only the xconnect VNets the provider does not track,
  holding sdnMutex, under which the VNets are created and tracked. The
  tracked ones that no device uses are garbage-collected as after a
  teardown.
- It spares the import volumes of the devices set up or being set up.
  The volume names now start with the number of the setup, unique to
  each device, which a setup records in its pending device before it
  uploads anything. This tells the volumes of each device apart exactly,
  even when one device name is a prefix of another, and a setup never
  uploads a volume of the same name as one the sweep is removing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Milan Lenco <milan@zededa.com>
@milan-zededa
milan-zededa force-pushed the evetest-proxmox-retries branch from a131e95 to fb49c8b Compare November 23, 2026 19:21
@milan-zededa

Copy link
Copy Markdown
Contributor Author

@claude Do a fresh new PR review.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @milan-zededa's task in 2m 19s —— View job


Fresh review — PR #7195

Re-read all four changed files from scratch (diff against origin/master), tracing the five fixes and their concurrency end to end.

Verdict: this holds up. The doc comments are unusually precise and match the code, and every point raised in the two earlier rounds was addressed (the teardownFailed guard, moving removeFailedVM out from under the VMID lock via callOwnedVM, and the exact per-setup uploadSeq volume prefix). I found no new correctness, concurrency, or security issues.

Checks that passed on this read:

  • Lock ordering is one-directional. vmIDMutex → devMutex everywhere it nests (createVM, callOwnedVM/vmIDOwnedByOther, listVMsAndOwnedIDs); sdnMutex and sdnApplyMutex nest separately and are never crossed with the VMID path. The periodic sweep runs its steps sequentially, not nested, so it can't AB-BA against a create. removeFailedVM is always called after vmIDMutex.Unlock(), and callOwnedVM re-acquires it — no re-entrant deadlock.
  • attemptContext / retryProxmoxCall terminate in every branch. attemptsLeft runs proxmoxRetryMaxAttempts → 1; attemptsLeft<=1, a sub-proxmoxMinAttemptTime share, or no deadline all fall to the last==true / WithCancel path, and the loop returns on last. The reserved pauses ((attemptsLeft-1)*proxmoxRetryDelay) are the same ones later consumed by time.After, so the split is self-consistent.
  • create-call vs. create-task split matches intent. A failed create call returns a plain (retryable) error after removeFailedVM; buildVMOptions failure is permanent; createAndWaitVM returns the task-failed error as retryable only when the VM was removed and errors.Is(err, errTaskFailed), and permanent otherwise (wait timeout → PVE may still be creating). On retry a fresh VMID overwrites dev.vmID, so a VM left behind by a failed removeFailedVM stops being "owned" and the sweep reclaims it.
  • Recycled-VMID safety. Once vmIDMutex is released a freed VMID can be reallocated; callOwnedVM + vmIDOwnedByOther re-check ownership under the lock before any stop/delete, so a cleanup (owner dev), teardown, or sweep (owner nil) never touches another device's VM. Every VMID is recorded in p.pending under vmIDMutex before the VM exists, so the check is reliable.
  • Orphan-sweep invariant holds. listVMsAndOwnedIDs lists VMs under vmIDMutex, which every create holds while allocating the VMID and recording it, so a listed VM is owned now or never will be. Import-volume sparing is exact now that uploadPrefix is ev-<seq>- and seq is unique per setup, reserved in pending before any upload. removeOrphanedVNets holds sdnMutex across list-and-check so a concurrent resolveDeviceNetworks can't create a VNet it would then delete.
  • Lifecycle. stopSweep is created in the constructor, closed once via closeOnce, and the loop runs on context.WithoutCancel(ctx) and exits on it — no leak, and Close is idempotent.

No inline comments to add — the two non-blocking notes from the last round were both fixed. Nothing blocking.

  • Read the diff against origin/master
  • Analyze the five fixes and their concurrency
  • Post inline comments for any findings (none)
  • Summarize
    · branch evetest-proxmox-retries

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stable Should be backported to stable release(s) testing New test or test framework changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant