Skip to content

tests/virtual-machine: Fix skipped dry-run test#602

Open
RamLavi wants to merge 1 commit intok8snetworkplumbingwg:mainfrom
RamLavi:unskip_dry-run
Open

tests/virtual-machine: Fix skipped dry-run test#602
RamLavi wants to merge 1 commit intok8snetworkplumbingwg:mainfrom
RamLavi:unskip_dry-run

Conversation

@RamLavi
Copy link
Member

@RamLavi RamLavi commented Mar 16, 2026

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:

NONE

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>
@gemini-code-assist
Copy link

Summary of Changes

Hello, 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

  • Dry-run test fix: Replaced a previously skipped dry-run test that relied on a deprecated cross-VM duplicate MAC blocking mechanism.
  • MAC address allocation verification: Introduced a new test to verify that a dry-run virtual machine creation correctly allocates a MAC address to the VM object without persisting the virtual machine.
Changelog
  • tests/virtual_machines_test.go
    • Removed a skipped test case that checked for MAC address allocation in a dry-run scenario.
    • Added a new test case to directly verify that a valid MAC address is allocated to a VM object during a dry-run create operation.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@kubevirt-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign phoracek for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +85 to 91
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")
})

Choose a reason for hiding this comment

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

medium

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")
				})

Copy link
Member Author

Choose a reason for hiding this comment

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

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??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants