Skip to content

Add volume snapshot test with vm part#2531

Open
asc5543 wants to merge 2 commits intoharvester:mainfrom
asc5543:dev-472
Open

Add volume snapshot test with vm part#2531
asc5543 wants to merge 2 commits intoharvester:mainfrom
asc5543:dev-472

Conversation

@asc5543
Copy link
Copy Markdown
Contributor

@asc5543 asc5543 commented Mar 24, 2026

Which issue(s) this PR fixes:

Issue #472

What this PR does / why we need it:

Add volume snapshot test with vm part.

Additional documentation or context

Test Pass in v1.8.0-rc5 in the lastest changes
image

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an e2e integration test covering volume snapshots in the context of a VM workflow (write data → snapshot volume → restore to new volume → boot new VM from restored volume → verify data), addressing Issue #472’s request for snapshot support coverage.

Changes:

  • Updated the ubuntu_vm fixture to inject an SSH public key via cloud-init so tests can SSH into the VM.
  • Added a VM+volume snapshot/restore test (test_snapshot_of_volume_on_vm) under TestVolumeWithVM.
  • Introduced a helper (vm_shell_do) to SSH into a VM via a host jumphost and run actions/assertions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@asc5543 asc5543 removed the request for review from a team March 24, 2026 08:15
@asc5543 asc5543 marked this pull request as draft March 24, 2026 08:16
@asc5543 asc5543 force-pushed the dev-472 branch 4 times, most recently from 12ef35e to 1b9b624 Compare March 25, 2026 07:14
@asc5543 asc5543 marked this pull request as ready for review March 25, 2026 07:15
@asc5543 asc5543 requested a review from a team March 25, 2026 07:16
Copy link
Copy Markdown
Member

@lanfon72 lanfon72 left a comment

Choose a reason for hiding this comment

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

and it looks we should refactor the class class TestVolumeWithVM.
3 test cases: pause_vm, stop_vm and delete_vm are duplicated in test_3_vm_functions, it looks like we are not testing additional volumes on those test cases.

and remaining test cases: test_delete_volume_on_existing_vm and test_delete_volume_on_deleted_vm should be moved to test_3_vm_functions as well.
Maybe we can move them into class TestVMWithVolumes in test_3_vm_functions or test_3_vm?

@albinsun the class was added by you, could you work on this?

# source
assert ubuntu_image["id"] == annotations['harvesterhci.io/imageId'], (code, data)

def test_snapshot_of_volume_on_vm(self, api_client, ubuntu_vm, ubuntu_image,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this test case should move to test_4_vm_snapshot as it hardly depends on VM. (then we won't need to re-implement the vm_shell_do again.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pause_vm, stop_vm and delete_vm are functions for test cases test_delete_volume_on_existing_vm and test_delete_volume_on_deleted_vm.
These 2 test cases focuses on volume deletion which used by a VM, so I put them in this test_1_volumes suite.

As volume and VM frequently work together, so it's easy to have overlaped scenarios.
I'm ok to refactor it once we have clear guideline for how to classify volume related test case into test_1_volumes, test_3_vm_functions or test_3_vm.

Copy link
Copy Markdown
Contributor Author

@asc5543 asc5543 Mar 26, 2026

Choose a reason for hiding this comment

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

The test cases under TestVMWithVolumes focus on volume not vm, so I prefer to remain those test cases in test_1_volumes.
For vm_shell_do, maybe we can move it under VirtualMachineManager?

Copy link
Copy Markdown
Member

@lanfon72 lanfon72 Mar 26, 2026

Choose a reason for hiding this comment

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

@albinsun @asc5543, we did described how to determine the test case in https://github.com/harvester/tests/blob/main/harvester_e2e_tests/integrations/README.md, as you mentioned, those test cases are hardly depend on VM, so they should be VM related test case.

It means, if VM's basic functionality is not working (for example, not able to be running status), those test cases' result will be affected.

pause_vm, stop_vm and delete_vm are functions for test cases

but the delete_vm not be used, and pause_vm/stop_vm could be used in the class only, consider we would moved to test_3_vm, we can use existing fixture vmchecker.wait_status_stopped to reduce the maintain effort. (we don't have fixture for pause status, maybe it good to have one?)

For vm_shell_do, maybe we can move it under VirtualMachineManager?

I didn't get the point, do you mean move to _apiclient`'s manager? could you explain more about you thought?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@albinsun @asc5543, we did described how to determine the test case in https://github.com/harvester/tests/blob/main/harvester_e2e_tests/integrations/README.md, as you mentioned, those test cases are hardly depend on VM, so they should be VM related test case.
It means, if VM's basic functionality is not working (for example, not able to be running status), those test cases' result will be affected.

I see, I'm okay to refactor it to test_4_vm_snapshot with the definition on https://github.com/harvester/tests/blob/main/harvester_e2e_tests/integrations/README.md

I didn't get the point, do you mean move to _apiclient`'s manager? could you explain more about you thought?

Yes, move to the VirtualMachineManager, which will be called as api_client.vms
Such as implement a function in VirtualMachineManager like

class VirtualMachineManager(BaseManager):
    ...
    def shell_do(self, name, namespace, ...):
         # Do what vm_shell_do
    ...

And in integration test cases, we can just call

api_client.vms.vm_shell_do(vm_name, api_client,
                         host_shell, vm_shell,
                         ubuntu_image['ssh_user'], ssh_keypair,
                         action, wait_timeout)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess it might not be a good idea.
Managers reflect to our UI's pages (hosts, images, volumes, vms, cluster network...etc)
and models align to backend api's data model, the vm_shell_do more like the human behavior, if we move it to managers, which means related fixtures would also need to be placed in.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved test_snapshot_of_volume_on_vm from test_1_volumes to test_4_vm_snapshot

@asc5543 asc5543 force-pushed the dev-472 branch 2 times, most recently from 0741580 to fc3891c Compare April 7, 2026 01:29
@asc5543 asc5543 marked this pull request as draft April 7, 2026 01:31
@asc5543 asc5543 force-pushed the dev-472 branch 5 times, most recently from 6f79bdc to b4811be Compare April 8, 2026 03:24
@asc5543 asc5543 marked this pull request as ready for review April 8, 2026 03:27
@asc5543 asc5543 force-pushed the dev-472 branch 2 times, most recently from 1a7313d to 2e21315 Compare April 9, 2026 03:10
Signed-off-by: asc5543 <asc5543@gmail.com>
@asc5543 asc5543 marked this pull request as draft April 9, 2026 03:27
@asc5543 asc5543 marked this pull request as ready for review April 9, 2026 03:38
@asc5543 asc5543 requested a review from irishgordo April 9, 2026 03:45
Signed-off-by: asc5543 <asc5543@gmail.com>
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.

5 participants