← Back to Pull requests

test/libvirt: clean up resources on DeleteVPC and resolve provisioner TODOs #3493

Open
unknown opened this pull request with 369 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 25, 2026 11:06 UTC
Author

Summary

Cleans up resource handling and a few leftover TODOs in the libvirt E2E test provisioner. The whole change is in one file: src/cloud-api-adaptor/test/provisioner/libvirt/provision_common.go. Nothing outside the test provisioner is touched.

What changed

1. DeleteVPC now removes the volumes CreateVPC made (was a no-op returning nil)

  • New field LibvirtProvisioner.createdVolumes. CreateVPC appends a volume to it only when it actually creates that volume; volumes that already existed are never recorded.

  • DeleteVPC returns immediately if the list is empty (no pool lookup), otherwise deletes the listed volumes from the storage pool.

  • A volume that is already gone (ERR_NO_STORAGE_VOL) counts as cleaned up. Any other lookup or delete failure is returned (joined with errors.Join), and those volumes stay in createdVolumes so a later call can retry.

  • Removes the DeleteVPC TODO.

  • Scope: tracking is in memory, so it covers the in-process e2e flow (same provisioner calls CreateVPC then DeleteVPC). A separate provisioner-cli -action=deprovision run builds a new provisioner and does not know what an earlier -action=provision created. Persisting that across runs is left for a follow-up; the limitation is documented in the DeleteVPC doc comment.
  • 2. libvirt handle leaks fixed in CreateVPC and UploadPodvm

  • Network, StoragePool, StorageVol and Stream handles are now freed with Free() on every return path (previously several were never freed).

  • UploadPodvm reads the image into memory once (previously re-read from disk for each volume) and uses its length for the upload, so the separate os.Stat is gone.

  • The per-volume upload moves into a new uploadToVolume helper that frees the volume and stream with defer and aborts the stream if Upload or SendAll fails (previously the stream was left open on error).
  • 3. SSH key secret created with the Kubernetes client instead of kubectl

  • createSSHKeySecret no longer shells out to kubectl create secret; it builds the corev1.Secret and applies it through the e2e-framework client. Removes the TODO rewrite this to use go's k8s framework and the kubectl runtime dependency for this step.

  • New upsertSecret helper: creates the secret, or updates the data if it already exists. The old command failed on re-runs; this one is idempotent. The log message changes from "Created" to "Applied" accordingly.

  • cfg.Client() is obtained once and reused for namespace creation too.
  • 4. Stale TODO removed in NewLibvirtProvisioner

  • network and storage default to "default" and are only overridden by non-empty properties, so they can never be empty. The // TODO: Check network and storage are not nil? is deleted; no extra validation was needed.
  • Testing


  • gofmt, go build -tags libvirt ./test/... and go vet -tags libvirt are clean.
  • ---

    fixes: #3492
    Assisted-by: IBM Bob

    Diff: 369 lines (+276 / -93) across 4 files Reviewer: stevenhorsman Review duration: 8845m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.43) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 369 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.354
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #3493"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.8% (MEDIUM) · Higher = larger blast radius
    42.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.8% · Safe to merge
    22.8%