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

Lock file integration test #318

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

zeeke
Copy link
Member

@zeeke zeeke commented Jan 16, 2025

Integration tests for

This PR is not part of #313 because it depends on

which I prefer to keep aside from #313 review.

zeeke added 5 commits January 15, 2025 17:06
Having a test suite that covers the code from an out-of-process perspective helps
in testing specific scenarios, e.g. when the concurrency of multiple program instances
occurs. Also, using test doubles instead of real SR-IOV capable NICs makes tests fast
and portable, in a way that can be run at every commit.

Add a test suite that invokes a system-mocked version of the sriov CNI binary, in which
the `/sys` filesystem content is defined at code, and the network interfaces are of type dummy.

Add `test-integration` make target to invoke the test suite.

Signed-off-by: Andrea Panattoni <[email protected]>
When running on heavy a load, sriov-cni might be invoked multiple times
by the kubelet or the container runtime. In these situations, it might happen
that a `cmdAdd` or a `cmdDel` run on the same device that is still handled by
a `cmdDel` instance (e.g. when the IPAM plugin takes a long time to finish).

This commit adds a Lock mechanism around the `/var/lib/cni/sriov/<PCI>` address,
to avoid two or more instances handling the same the device.
The lock is based on `flock` [1] using the `O_CLOEXEC` flag, which  garantees that the lock
is released when the process finishes.

[1] https://linux.die.net/man/2/flock

Signed-off-by: Andrea Panattoni <[email protected]>
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Println(err)
return

Check warning

Code scanning / CodeQL

Writable file handle closed without error handling Warning test

File handle may be writable as a result of data flow from a
call to OpenFile
and closing it may result in data loss upon failure, which is not handled explicitly.
@coveralls
Copy link

coveralls commented Jan 16, 2025

Pull Request Test Coverage Report for Build 12809721778

Details

  • 7 of 425 (1.65%) changed or added relevant lines in 8 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-4.6%) to 36.821%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/sriov/sriov.go 0 1 0.0%
pkg/config/config.go 7 9 77.78%
cmd/sriov/main.go 0 3 0.0%
pkg/utils/netlink_manager.go 0 3 0.0%
pkg/utils/pci_allocator.go 0 26 0.0%
test/integration/sriov-mocked.go 0 30 0.0%
pkg/utils/testing.go 0 115 0.0%
pkg/cnicommands/cni.go 0 238 0.0%
Files with Coverage Reduction New Missed Lines %
cmd/sriov/main.go 1 0.0%
Totals Coverage Status
Change from base Build 12743187155: -4.6%
Covered Lines: 563
Relevant Lines: 1529

💛 - Coveralls

Depends on:
 - k8snetworkplumbingwg#313

Signed-off-by: Andrea Panattoni <[email protected]>
@zeeke zeeke force-pushed the us/lock-file-integration-test branch from 80f1d8d to 9932e03 Compare January 16, 2025 13:16
@zeeke zeeke changed the title Us/lock file integration test Lock file integration test Jan 16, 2025
@zeeke
Copy link
Member Author

zeeke commented Jan 16, 2025

/hold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants