Skip to content

test(v2v-helper): un-skip TestLiveReplicateDisks via VMOperations refactor#1947

Open
valentin-pf9 wants to merge 2 commits into
platform9:mainfrom
valentin-pf9:feature/test-livereplicatedisks-fix
Open

test(v2v-helper): un-skip TestLiveReplicateDisks via VMOperations refactor#1947
valentin-pf9 wants to merge 2 commits into
platform9:mainfrom
valentin-pf9:feature/test-livereplicatedisks-fix

Conversation

@valentin-pf9

@valentin-pf9 valentin-pf9 commented May 15, 2026

Copy link
Copy Markdown

Summary

Restores TestLiveReplicateDisks to running. The test was skipped in #1945 with a TODO because vmops.GetVMObj().PowerState(ctx) panicked with a nil-pointer dereference — the mock returned an empty *object.VirtualMachine whose property collector was unset. Three call sites in migrate.go's LiveReplicateDisks (lines ~745, ~853, ~953, all in the post-power-off verification block added in #1927/#1932) hit the panic path.

The fix

Surfaces GetVmPowerState() on the VMOperations interface. The implementation already existed on *VMOps at vmops.go:130 — it just wasn't declared on the interface. main.go:187 already calls it on the concrete type, so this is purely an interface surface expansion plus call-site swap.

The mock becomes trivially stubbable:

mockVMOps.EXPECT().GetVmPowerState().Return(types.VirtualMachinePowerStatePoweredOff, nil).AnyTimes()

Changes

  • v2v-helper/vm/vmops.go — add GetVmPowerState() (types.VirtualMachinePowerState, error) to the VMOperations interface.
  • v2v-helper/vm/vmops_mock.go — hand-added mock pair matching the existing pattern.
  • v2v-helper/migrate/migrate.go — replace 3 vmops.GetVMObj().PowerState(ctx) call sites with vmops.GetVmPowerState(). Uses the internal vmops.ctx, same as main.go:187.
  • v2v-helper/migrate/migrate_test.go — remove the t.Skip() from fix(v2v-helper): repair broken build on main #1945, add the GetVmPowerState expectation to the test setup.

Test plan

make test-v2v-helper:

ok  github.com/platform9/vjailbreak/v2v-helper/migrate    24.055s
ok  github.com/platform9/vjailbreak/v2v-helper/nbd
ok  github.com/platform9/vjailbreak/v2v-helper/pkg/xml
ok  github.com/platform9/vjailbreak/v2v-helper/vcenter
ok  github.com/platform9/vjailbreak/v2v-helper/vm         2.069s

--- PASS: TestLiveReplicateDisks (23.02s) — no skip, no fail.

Note on stacking

This PR branches on top of #1945 (build fix). Until that merges, this PR's diff will show #1945's changes too. Should rebase cleanly onto main once #1945 lands — happy to do that as soon as it merges.


Open in Devin Review

The v2v-helper package fails to build on main after recent merges (platform9#1927,
platform9#1932). This commit restores 'make test-v2v-helper' to passing:

- openstackops_mock.go: add espDiskIndex int parameter to CreateVM mock
  to match the interface signature in openstackops.go (PR platform9#1932 added
  the parameter to the interface but did not regenerate the mock).
- migrate_test.go: add 11th gomock.Any() to the three EXPECT().CreateVM
  call sites for the same reason.
- main.go: replace %s with %v throughout the logMigrationParams format
  string. PR platform9#1927 introduced bool fields (DisconnectSourceNetwork,
  FallbackToDHCP, etc.) but kept the existing %s verbs, which go vet
  rejects.
- migrate_test.go: skip TestLiveReplicateDisks. The test panics at
  vmops.GetVMObj().PowerState() because the post-poweroff verification
  block added in platform9#1927/platform9#1932 wasn't covered when the test was written.
  This is a separate concern from the build fix; will track in a
  follow-up issue.
- deploy/installer.yaml + deploy/00crds.yaml: regenerated via the
  pre-commit 'make build-installer' hook.
…actor

PR platform9#1945 skipped TestLiveReplicateDisks because vmops.GetVMObj().PowerState(ctx)
panicked with a nil pointer dereference — the mock returned an empty
*object.VirtualMachine whose property collector was unset. Three call sites in
migrate.go's LiveReplicateDisks (lines ~745, ~853, ~953) exercised this path
after the post-poweroff verification block landed in platform9#1927/platform9#1932.

Refactor to expose GetVmPowerState on the VMOperations interface (the impl
already existed on *VMOps at vmops.go:130, just wasn't declared on the
interface — main.go:187 already called it on the concrete type). The mock
becomes trivially stubbable:

  mockVMOps.EXPECT().GetVmPowerState().Return(types.VirtualMachinePowerStatePoweredOff, nil).AnyTimes()

Changes:
- v2v-helper/vm/vmops.go: add GetVmPowerState to VMOperations interface.
- v2v-helper/vm/vmops_mock.go: add mock pair for GetVmPowerState.
- v2v-helper/migrate/migrate.go: replace 3 vmops.GetVMObj().PowerState(ctx)
  call sites with vmops.GetVmPowerState() (uses the internal vmops.ctx, same
  pattern as main.go:187).
- v2v-helper/migrate/migrate_test.go: remove t.Skip() added in platform9#1945, add
  the GetVmPowerState EXPECT to the test setup.

Test plan: 'make test-v2v-helper' — TestLiveReplicateDisks now passes
(--- PASS: TestLiveReplicateDisks (23.02s)), no FAIL anywhere.

Stacks on top of platform9#1945 (build fix); should rebase cleanly once that merges.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

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.

1 participant