net, vm import: clone source VM before migration#4007
net, vm import: clone source VM before migration#4007servolkov wants to merge 1 commit intoRedHatQE:mainfrom
Conversation
For the sake of scalability (different OCP versions can be tested in parallel) the source VM should be cloned before migration to OCP, using same VM for migration is not safe. Signed-off-by: Sergei Volkov <sevolkov@redhat.com>
📝 WalkthroughWalkthroughThis PR enhances the provider migration test infrastructure by introducing VM cloning and deletion capabilities. A unique SOURCE_VM_NAME constant is added, and the test setup is refactored to clone VMs from templates instead of directly powering them on, with corresponding cleanup logic and error handling. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Report bugs in Issues Welcome! 🎉This pull request will be automatically processed with the following features: 🔄 Automatic Actions
📋 Available CommandsPR Status Management
Review & Approval
Testing & Validation
Container Operations
Cherry-pick Operations
Label Management
✅ Merge RequirementsThis PR will be automatically approved when the following conditions are met:
📊 Review ProcessApprovers and ReviewersApprovers:
Reviewers:
Available Labels
💡 Tips
For more information, please refer to the project documentation or contact the maintainers. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/network/provider_migration/libprovider.py`:
- Around line 69-90: Add Google-style docstrings to the public methods clone_vm
and delete_vm: for clone_vm (method name clone_vm) document parameters
(template_name, clone_name, power_on), the return type (vim.VirtualMachine),
side effects (creates a VM from template, may power it on), and exceptions
raised on failure; for delete_vm (method name delete_vm) document parameters
(vm_name), return type (None), side effects (may power off the VM before
deletion, deletes the VM), and exceptions logged/raised on failure; ensure the
docstrings follow Google style sections (Args, Returns, Raises) and sit directly
above each method definition.
- Around line 82-90: The try/except in the VM deletion flow (around
vm.Destroy_Task(), WaitForTask and power_off_vm) currently uses a bare "except
Exception" which hides root causes; change it to catch only the expected vSphere
errors (e.g., vmodl.MethodFault, vim.fault.InvalidState, vim.fault.NotFound or
the specific exception types raised by WaitForTask/power_off_vm) and any
IO/errors you expect, log the error with context via LOGGER.error, then re-raise
a new, descriptive exception using "raise RuntimeError(f\"Failed to delete VM
'{vm_name}': ...\") from e" (or a more specific custom exception) so the
original traceback is preserved; keep the existing logging messages for success
paths and ensure power_off_vm and WaitForTask calls remain inside the try block.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
tests/network/provider_migration/conftest.pytests/network/provider_migration/libprovider.py
|
/verified |
Test execution plan request detailsCRITICAL: You MUST post an inline review comment on the first changed line of the first file. As an expert software testing engineer, analyze all modified files in this PR and create a targeted test execution plan. Analysis Requirements:
Your deliverable: Test Execution Plan
Guidelines:
Hardware-Related Checks (SR-IOV, GPU, DPDK): When PR modifies fixtures for hardware-specific resources:
CRITICAL WORKFLOW COMPLETION RULES: When responding to this test execution plan request, you MUST follow these rules EXACTLY:
ABSOLUTE PROHIBITIONS (violating these creates empty/meaningless reviews):
Remember: The pull request review is visible to users. Additional comments are redundant noise. CRITICAL: Before setting "Run smoke tests: True", you MUST use shell scripts to: |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 1821 🏁 Script executed: Length of output: 2181 🏁 Script executed: Length of output: 270 🏁 Script executed: Length of output: 1735 🧠 Learnings used |
| CUDN_LABEL: Final[dict] = {"cudn": "mtv"} | ||
| CUDN_SUBNET_IPV4: Final[str] = "192.168.100.0/24" | ||
| MTV_RESOURCE_TIMEOUT_SEC: Final[int] = 30 | ||
| SOURCE_VM_NAME: Final[str] = f"cnv-vm-for-mtv-import-{uuid.uuid4().hex[:8]}" |
There was a problem hiding this comment.
Have you encountered any problems with the name? It's not too long?
| template_vm = self.get_vm_by_name(name=template_name) | ||
| clone_spec = vim.vm.CloneSpec(location=vim.vm.RelocateSpec(), powerOn=False) | ||
| task = template_vm.Clone(name=clone_name, folder=template_vm.parent, spec=clone_spec) | ||
| WaitForTask(task=task, maxWaitTime=600) |
There was a problem hiding this comment.
Cloning a VM could take ~10 minutes?
| self.power_off_vm(vm_name=vm_name) | ||
| WaitForTask(task=vm.Destroy_Task(), maxWaitTime=120) | ||
| LOGGER.info(f"Successfully deleted VM '{vm_name}'") | ||
| except Exception: |
There was a problem hiding this comment.
Can you specify the exception here?
Now we have a prepared source provider VM, which we power on, transfer, and power off after the transfer.
For the sake of scalability (different OCP versions can be tested in parallel) the source VM should be cloned before migration to OCP, using same VM for migration is not safe.
jira-ticket: https://issues.redhat.com/browse/CNV-75261
Summary by CodeRabbit
Tests
Chores