Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.2] VMI controller - move unit tests to fake client (VirtualMachineInstanceInterface) #11863

Merged

Conversation

fossedihelm
Copy link
Contributor

What this PR does

This is a manual cherry-pick of #11751

Release note

NONE

Signed-off-by: fossedihelm <ffossemo@redhat.com>
(cherry picked from commit 54034ae)
Signed-off-by: fossedihelm <ffossemo@redhat.com>

(cherry picked from commit 88d0e48)
Signed-off-by: fossedihelm <ffossemo@redhat.com>
Signed-off-by: fossedihelm <ffossemo@redhat.com>
(cherry picked from commit 669d5f9)
Add the virtclientset to be used when vmi client
is interrogated.

Signed-off-by: fossedihelm <ffossemo@redhat.com>
(cherry picked from commit e3e8373)
Register resources to the fakeclient during their
addition to the informers. In this way wa can interact
directly with the fakeclient that will store the
changes that will be applied to the resources.

Created `addPod`, `addDataVolumePVC`, `addDataVolume`
convenience functions. These will be used in subsequent
commits.

Signed-off-by: fossedihelm <ffossemo@redhat.com>
(cherry picked from commit c3022aa)
Created `addPod`, `addDataVolumePVC`, `addDataVolume`
convenience functions allow us to register the resoruces
to the fakeclient. Let's use them instead of specific
informer additions.

This allows us to remove some fake prepend reactor, since
the resources are correctly registered (or not), in the client.

Also, the podFeeder and dataVolumeFeeder have been removed
since they art not used anymore.

Signed-off-by: fossedihelm <ffossemo@redhat.com>
(cherry picked from commit 383c1bc)
The mockinterfaces need to be instructed to what
expect before the controller execution, while using
the fakeclient allow us to check resources after the
controller execution.

Convert the `shouldExpect` functions, which prepare the
mockinterface to `expect` ones, which check the fakeclient.

In particular:
- shouldExpectMatchingPodCreation -> expectMatchingPodCreation
- shouldExpectPodCreation -> expectPodExists
- shouldExpectPodDeletion -> expectPodDoesNotExist
- dropped shouldExpectMultiplePodDeletions
- shouldExpectHotplugPod -> expectHotplugPod

N.B. shouldExpectPodDeletion was also moved under a
specific `DescribeTable` which requires it.
This will be address in the future.

Signed-off-by: fossedihelm <ffossemo@redhat.com>
(cherry picked from commit 8b4e43b)
The mockinterfaces need to be instructed to what
expect before the controller execution, while using
the fakeclient allow us to check resources after the
controller execution.

Convert the `shouldExpect` functions, which prepare the
mockinterface to `expect` ones, which check the fakeclient.

In particular:
- shouldExpectVirtualMachineSchedulingState -> expectVMISchedulingState
- shouldExpectVirtualMachineScheduledState -> expectVMIScheduledState
- shouldExpectVirtualMachineFailedState -> expectVMIFailedState
- shouldExpectVirtualMachineDataVolumesReadyCondition -> expectVMIDataVolumeReadyCondition
- added expectVMIWithMatcherConditions generic function
- added expectVMIBeInPhase generic function
- added expectVMITimestamp generic function
- dropped shouldExpectVirtualMachineDataVolumesReadyConditionWithMessage
  since it was used only once and replaced using generic expectVMIWithMatcherConditions

Signed-off-by: fossedihelm <ffossemo@redhat.com>
(cherry picked from commit 179b6da)
There are two tests that want to check the
existence(or not) of specific network annotations
on the pod.

Currently, those tests are not checking correctly
the annotations, since they are looking at the
`pod` variable that is defined under the test scope itself.

What we want to check is that the `updatedPod` (IOW: in the
fakeclient) has the correct annotations.

Signed-off-by: fossedihelm <ffossemo@redhat.com>

(cherry picked from commit e573666)
Signed-off-by: fossedihelm <ffossemo@redhat.com>
`NewPendingVirtualMachine` function returns a vmi in
pending status. This vmi is used in the tests and it
is registered in the fakeclient and the informers.

Both activePods and volumeStatus are defined as `json:<name,omitempty>`.
This means that the in real clusters it is not possible that
there will be a Pod with empty activePods (because the marshall will
convert it to nil). However, currently, we are storing a vmi with
empty (non-nil) activepods in the vmi informer.
Since the pod in the vmi informer is used by the vmi controller
to build the patch operations, the empty map causes a failure in the
`test` patch operation in the test `should add active pods to status if VMI is in running state`.

In other words, the resource stored in the vmi fakeclient is different to
what we put in the vmi informer because in the fakeclient there is
a nil value, while in the vmi informer an empty map.

The empty map will result in this patch operation:
`{ "op": "test", "path": "/status/activePods", "value": {} }`
that fails because it should be:
`{ "op": "test", "path": "/status/activePods", "value": null }`

This is a clear example of how the fakeclient help us to create
tests closer to reality, which results in an increasing of
stability.

Even if no failures was observed around the VolumeStatus,
the same logic can be applied, so here we are going to
align its behavior too.

Signed-off-by: fossedihelm <ffossemo@redhat.com>
(cherry picked from commit dabac9f)
With `Actions()` fakeclient function we can check
how many actions has been performed.
This is useful when we want to check that nothing
is happened.

Signed-off-by: fossedihelm <ffossemo@redhat.com>
(cherry picked from commit a912feb)
There are two tests that checks the vmi phase and volumestatus.

Regarding the phase, currently, those tests are not performing
the right check, since they are looking at the
`vmi` variable that is defined under the test scope itself.

What we want to check is that the `updatedVmi` (IOW: in the
fakeclient) has the correct phase.

Regarding the volumestatus, we can switch checking the
updated vmi from the fakeclient instead of expexting the
right patch operation.

Signed-off-by: fossedihelm <ffossemo@redhat.com>
(cherry picked from commit e66a79e)
It is not used anymore.

Signed-off-by: fossedihelm <ffossemo@redhat.com>
(cherry picked from commit ad6e016)
Both invtsc and hyperv tests expect a pod creation
when topoloty hints is going to be set, but actually
this pod creation does not occur (it can occur in the
subsequent reconcile cycle).

Remove also `runController` function since it does not
add anything.

Signed-off-by: fossedihelm <ffossemo@redhat.com>
(cherry picked from commit 6645dcd)
@kubevirt-bot kubevirt-bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels May 8, 2024
@acardace
Copy link
Member

acardace commented May 9, 2024

/approve

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: acardace

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

The pull request process is described here

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

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 9, 2024
@fossedihelm
Copy link
Contributor Author

/retest-required

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label May 15, 2024
@kubevirt-bot
Copy link
Contributor

kubevirt-bot commented May 15, 2024

@fossedihelm: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubevirt-e2e-kind-1.27-vgpu f69a971 link false /test pull-kubevirt-e2e-kind-1.27-vgpu-1.2
pull-kubevirt-goveralls f69a971 link false /test pull-kubevirt-goveralls-1.2

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@kubevirt-bot kubevirt-bot merged commit 34ec316 into kubevirt:release-1.2 May 15, 2024
32 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants