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

netstat: Update VMI interface status report unit tests #6951

Merged

Conversation

EdDev
Copy link
Member

@EdDev EdDev commented Dec 15, 2021

What this PR does / why we need it:

The existing unit tests which cover the VMI interface status report is missing some realistic overall scenarios about the existing data available.

This change unifies and tries to place some rules on what is the expected data provided to the report processing.

The current netstat unit tests have been updated to reflect the
following expected behavior:

  • When regular interfaces are added, this is the expected state/input:

    • VMI spec interfaces and networks should be in sync with 1:1 relation.
    • Domain spec is expect to reflect the VMI spec, i.e. having the same
      interfaces.
    • The filesystem cache should reflect the same interfaces as the VMI
      spec.
    • The volatile cache is optional, reflecting the same interface.
    • The Guest Agent data is optional.
  • When SR-IOV interfaces are added, this is the expected state/input:

    • VMI spec interfaces and networks should be in sync with 1:1 relation.
    • The Guest Agent data is optional.
      Notes: Caches do not exist and the domain spec interfaces do not
      include the SR-IOV interfaces. These are under the hostdevice section.

Miscellaneous scenarios are also covered to reflect what happens when such cases occur. However, these are not expected to occur in a normal system operation. Future production changes may treat these scenarios explicitly to avoid undefined and nontrivial behavior.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:
Depends on #6926
Only the last 6 commits are to be reviewed as part of this PR.

Release note:

NONE

@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. size/XXL labels Dec 15, 2021
@EdDev
Copy link
Member Author

EdDev commented Dec 15, 2021

/uncc rmohr vladikr

@EdDev
Copy link
Member Author

EdDev commented Dec 15, 2021

@EdDev
Copy link
Member Author

EdDev commented Dec 15, 2021

/sig network

@EdDev
Copy link
Member Author

EdDev commented Dec 16, 2021

change: Added misc test scenarios

@EdDev EdDev force-pushed the refactor-network-update-status-utests branch from f5bed9b to 1c5e61f Compare December 23, 2021 09:25
@EdDev
Copy link
Member Author

EdDev commented Dec 23, 2021

change: Rebase

@@ -278,6 +278,59 @@ var _ = Describe("netstat", func() {
newVMIStatusIface(networkName, nil, ifaceMAC, guestIfaceName),
}), "the SR-IOV interface should be reported in the status, associated to the network")
})

Context("misc scenario", func() {
Copy link
Contributor

@oshoval oshoval Dec 26, 2021

Choose a reason for hiding this comment

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

maybe worth to add in the Context that this is unrealistic scenarios ?
(misc word is too general, and usually we read the code and not going to the commit message / PR desc which does elaborate it in this case)

It is important to people won't think those are the expected flows
while we develop or even during review, it can cause noise if misunderstood

there are some tests here that should not happen at all (unless there is hot plug), so i am not sure it is good to include them, for example has interface in VMI spec but not in domain spec IIUC (i do understand the motivation and saw the PR desc)

Copy link
Member Author

Choose a reason for hiding this comment

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

Unrealistic to whom?
These are indeed edge cases which are the result of the unit API. We can argue that these scenarios have not been expected to occur, at least by their users. However, the unit does allow them to exist, just because the API supports them. Therefore, they should be covered to express what will happen in these cases.

Although we expect not to see these scenarios, they may occur due to bugs or changes to the callers of this unit. In the context of this unit, it has no knowledge on how it is called or by who, and it should not care.

Now that these scenarios are exposed here, a decision may be made to disallow them (e.g. raise an error) or change the output result. But this is not in the scope of this change.

Finally, regarding the name: I consider these miscellaneous scenarios and I did not find any better name for this goup of tests. I do not think they fit to the word "unrealistic" because that is in the context of a caller, not the unit itself.

Copy link
Contributor

@oshoval oshoval left a comment

Choose a reason for hiding this comment

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

first pass

Comment on lines +349 to +475
if !(vmiIface.Name == vmiNetwork.Name && vmiIface.Name == domainIface.Alias.GetName()) {
panic("network name must be the same")
}
Copy link
Contributor

@oshoval oshoval Dec 26, 2021

Choose a reason for hiding this comment

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

why not simply ExpectWithOffset ?
(appears at least twice in the PR)
i understand that it is not runtime but more 'config' phase, but we aren't using panic usually,
and Expect will do the same result

Copy link
Member Author

Choose a reason for hiding this comment

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

To differentiate between the code-under-test failing and the test writer placing an unsupported config in place.

newVMIStatusIface(primaryNetworkName, []string{newGaIPv4, newGaIPv6}, origMAC, ""),
}), "the pod IP/s should be reported in the status")
})

It("should add a new interface based on the domain spec", func() {
It("should report SR-IOV interface when no guest-agent is active", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please consider adding a test with 2 interfaces (without guest agent)

  1. Non SR-IOV
  2. SR-IOV

Because the behavior would be different, as the main loop of UpdateStatus would override the interfaces added by the snippet
https://github.com/kubevirt/kubevirt/pull/6951/files#diff-c2b23c7cf6d14c6f6a9e12f1a63d6c8004ead588e9d4d6a369aeea15701ca086R79

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@kubevirt-bot kubevirt-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 28, 2021
@EdDev EdDev force-pushed the refactor-network-update-status-utests branch from 1c5e61f to 9fc55e8 Compare December 30, 2021 13:00
@kubevirt-bot kubevirt-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 30, 2021
@EdDev
Copy link
Member Author

EdDev commented Dec 30, 2021

change: Rebase

@EdDev EdDev force-pushed the refactor-network-update-status-utests branch from 9fc55e8 to 05b3465 Compare December 30, 2021 13:43
@EdDev
Copy link
Member Author

EdDev commented Dec 30, 2021

Change: Answered review: Added a SR-IOV test to show what happens when it is accompanied with a "regular" interface.

@kubevirt-bot kubevirt-bot removed lgtm Indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jan 9, 2022
@EdDev
Copy link
Member Author

EdDev commented Jan 9, 2022

change: Rebase
The reabse required the inclusion of infoSource to the unit tests.

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Jan 9, 2022
@@ -244,37 +244,6 @@ var _ = Describe("netstat", func() {
}), "the pod IP/s should be reported in the status")
})

It("should add a new interface based on the domain spec", func() {
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand the commit message. Why such option is not supported? What if there is no GA at all?

Copy link
Member Author

Choose a reason for hiding this comment

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

The VMI spec is not updated with any interfaces, so having only the domain defined but not the vmi spec is odd.

Later on in the PR, I re-introduces this case in a more direct manner. see here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to express it better in the commit message.

Copy link
Member

@AlonaKaplan AlonaKaplan left a comment

Choose a reason for hiding this comment

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

Great work!

ifaceFSCacheFactory *interfaceCacheFactoryStatusStub

// There are two types of caches used: virt-launcher/pod filesystem & virt-handler in-memory (volatile).
// volatileCache flag marks is the setup should also populate the volatile cache when a network interface is added.
Copy link
Member

Choose a reason for hiding this comment

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

"marks that the setup"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

}), "the SR-IOV interface should be reported in the status, associated to the network")
})

It("should not report SR-IOV interface when guest-agent is inactive and a regular interface exists", func() {
Copy link
Member

Choose a reason for hiding this comment

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

This sounds like a bug. The appearance of the sriov interface shouldn't be effected by another interface existence.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, SR-IOV reporting is buggy.
On one hand, it is reported sometimes even if there is no "proof" of it being there. On the other hand, it is not reported if at least one non-SRIOV interface is there.

None of these are correct, both represent a bug: When the guest has no guest-agent, SR-IOV interfaces are not reported correctly (either not at all, or based on false data).

But al least now we express this clearly through the tests.

I opened #7050 to track this.
Ref it also in the commit message.

Copy link
Member

Choose a reason for hiding this comment

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

Can you please add the ref to #7050 to the code as well? So the next developer that will see those tests won't think it is "by design" behaviour.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I'll add it to the tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

In the current implementation, the domain spec is directly affected by
the VMI spec (in the network interfaces scope).
The scenario were the domain is configured with interfaces that do not
appear in the VMI spec is no supported (or expected).

Therefore, the test that checks such a scenario (in an implicit manner)
is removed.

Signed-off-by: Edward Haas <edwardh@redhat.com>
Tests should represent real scenarios which are to be expected.
Undefined scenario have their own place, but those need to be explicit
and show what may happen in such cases as exceptions.

The current netstat unit tests have been updated to reflect the
following expected behavior:
- When regular interfaces are added, this is the expected state/input:
  - VMI spec interfaces and networks should be in sync with 1:1 relation.
  - Domain spec is expect to reflect the VMI spec, i.e. having the same
    interfaces.
  - The filesystem cache should reflect the same interfaces as the VMI
    spec.
  - The volatile cache is optional, reflecting the same interface.
  - The Guest Agent data is optional.

- When SR-IOV interfaces are added, this is the expected state/input:
  - VMI spec interfaces and networks should be in sync with 1:1 relation.
  - The Guest Agent data is optional.
  Notes: Caches do not exist and the domain spec interfaces do not
  include the SR-IOV interfaces. These are under the hostdevice section.

Signed-off-by: Edward Haas <edwardh@redhat.com>
@EdDev EdDev force-pushed the refactor-network-update-status-utests branch from 3920609 to 5e8f178 Compare January 9, 2022 14:54
@kubevirt-bot kubevirt-bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 9, 2022
@EdDev
Copy link
Member Author

EdDev commented Jan 9, 2022

change: Answered review feedback.

When an SR-IOV interface is present in the VMI spec and the guest is not
running the guest-agent, the interface is appearing in the status
section with just the network name and no other data.

On the other hand, if another non SR-IOV interface exists, the result
changes and the SR-IOV interface will not appear in the report at all.

The behavior observed is tracked through:
kubevirt#7050

Signed-off-by: Edward Haas <edwardh@redhat.com>
The unit tests included in this change represent undefined behavior.
These scenarios are explicitly represented through dedicated tests to
show the expected result if such a case occurs.

Future changes may suggest to change this output and replace it with
something that fits better (e.g. do not show the interface entry).

Signed-off-by: Edward Haas <edwardh@redhat.com>
The volatile cache needs to be populated based on the non-volatile
cache.

Signed-off-by: Edward Haas <edwardh@redhat.com>
@EdDev EdDev force-pushed the refactor-network-update-status-utests branch from 5e8f178 to 0c5b65d Compare January 10, 2022 07:06
@AlonaKaplan
Copy link
Member

/approve

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AlonaKaplan

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 Jan 10, 2022
@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Jan 10, 2022
@EdDev
Copy link
Member Author

EdDev commented Jan 10, 2022

/retest

2 similar comments
@EdDev
Copy link
Member Author

EdDev commented Jan 10, 2022

/retest

@EdDev
Copy link
Member Author

EdDev commented Jan 10, 2022

/retest

@kubevirt-commenter-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs.
Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@EdDev
Copy link
Member Author

EdDev commented Jan 11, 2022

/retest

@kubevirt-bot kubevirt-bot merged commit e18d164 into kubevirt:main Jan 11, 2022
@EdDev EdDev deleted the refactor-network-update-status-utests branch January 11, 2022 09:07
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. sig/network size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants