tests/virtual-machine: Fix skipped dry-run test#602
tests/virtual-machine: Fix skipped dry-run test#602RamLavi wants to merge 1 commit intok8snetworkplumbingwg:mainfrom
Conversation
The pending dry-run test relied on cross-VM duplicate MAC blocking that no longer exists. Replace it with a straightforward check that dry-run create allocates a MAC without persisting the VM. Assisted-by: Claude Upus 4.6 <noreply@anthropic.com> Signed-off-by: Ram Lavi <ralavi@redhat.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue with a skipped dry-run test for virtual machine creation. The original test's underlying assumption about MAC address blocking was no longer valid. The updated implementation provides a more direct and relevant test to confirm that dry-run VM creation operations successfully assign a MAC address to the VM object, ensuring the dry-run functionality behaves as expected without actual resource persistence. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Code Review
This pull request fixes a skipped dry-run test by replacing it with a simpler, correct implementation. The new test verifies that a MAC address is allocated during a dry-run Create operation.
My review includes a suggestion to enhance the test by also verifying that the VirtualMachine object is not persisted to the cluster, which would make the test for the dry-run behavior more complete.
| It("should allocate a MAC address", Label(MACAllocationLabel), func() { | ||
| vm := CreateVMObject(TestNamespace, []kubevirtv1.Interface{newInterface("br", "")}, []kubevirtv1.Network{newNetwork("br")}) | ||
| createOptions := &client.CreateOptions{} | ||
| client.DryRunAll.ApplyToCreate(createOptions) | ||
|
|
||
| err = testClient.CRClient.Create(context.TODO(), vm) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
| Expect(net.ParseMAC(vm.Spec.Template.Spec.Domain.Devices.Interfaces[0].MacAddress)).ToNot(BeEmpty(), | ||
| "Should successfully parse mac address") | ||
| macAddress = vm.Spec.Template.Spec.Domain.Devices.Interfaces[0].MacAddress | ||
| }) | ||
|
|
||
| // TODO Add dry-run functionality in kubevirt/client-go's VirtualMachine().Create(context.TODO(), ) | ||
| PIt("should not allocate the Mac assigned in the dryRun request into the pool", func() { | ||
| By("creating a vm with the same mac to make sure the dryRun assigned mac is not occupied on the macpool") | ||
| var err error | ||
| vmDryRunOverlap := CreateVMObject(TestNamespace, | ||
| []kubevirtv1.Interface{newInterface("brDryRunOverlap", macAddress)}, | ||
| []kubevirtv1.Network{newNetwork("brDryRunOverlap")}) | ||
| err = testClient.CRClient.Create(context.TODO(), vmDryRunOverlap) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| actualMac, err := net.ParseMAC(vmDryRunOverlap.Spec.Template.Spec.Domain.Devices.Interfaces[0].MacAddress) | ||
| Expect(err).ToNot(HaveOccurred(), "Should succeed parsing vmDryRunOverlap mac") | ||
| Expect(testClient.CRClient.Create(context.TODO(), vm, client.DryRunAll)).To(Succeed()) | ||
|
|
||
| Expect(actualMac.String()).To(Equal(macAddress), "Should successfully parse mac address") | ||
| _, err := net.ParseMAC(vm.Spec.Template.Spec.Domain.Devices.Interfaces[0].MacAddress) | ||
| Expect(err).ToNot(HaveOccurred(), "dry run should return a valid MAC address") | ||
| }) |
There was a problem hiding this comment.
This test correctly verifies that a MAC address is allocated during a dry-run operation. To make the test more comprehensive and fully align with the goal of verifying dry-run behavior, it would be beneficial to also assert that the VirtualMachine object is not actually persisted in the cluster.
You can achieve this by attempting to Get the VM after the dry-run Create call and expecting a NotFound error.
It("should allocate a MAC address without persisting the VM", Label(MACAllocationLabel), func() {
vm := CreateVMObject(TestNamespace, []kubevirtv1.Interface{newInterface("br", "")}, []kubevirtv1.Network{newNetwork("br")})
Expect(testClient.CRClient.Create(context.TODO(), vm, client.DryRunAll)).To(Succeed())
_, err := net.ParseMAC(vm.Spec.Template.Spec.Domain.Devices.Interfaces[0].MacAddress)
Expect(err).ToNot(HaveOccurred(), "dry run should return a valid MAC address")
By("verifying the vm does not exist")
fetchedVM := &kubevirtv1.VirtualMachine{}
err = testClient.CRClient.Get(context.TODO(), client.ObjectKey{Namespace: vm.Namespace, Name: vm.Name}, fetchedVM)
Expect(apierrors.IsNotFound(err)).To(BeTrue(), "dry-run vm should not be persisted")
})There was a problem hiding this comment.
But are we not asserintg k8s behavior ? I mean, it's not kubemacpool webhook's job to set (or not, in case of dry-run) the VM on atcd - then why should kubemacpool check that??
What this PR does / why we need it:
The pending dry-run test relied on cross-VM duplicate MAC blocking that no longer exists.
This PR replaces it with a straightforward check that dry-run create allocates a MAC without persisting the VM.
Special notes for your reviewer:
Release note: