-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
Showing
7 changed files
with
425 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Integration tests | ||
|
||
This folder contains tests and related tools to run integration test suite. These tests leverages a mocked version of the cni, which runs with a | ||
fake, programmed version of the `/sys` filesystem and a mocked version of `NetlinkLib`. Both are implemented in `pkg/utils/testing.go`. | ||
|
||
The following diagram describes the interactions between the component. | ||
|
||
```mermaid | ||
graph TD | ||
subgraph "pkg/utils/testing.go" | ||
CreateTmpSysFs | ||
MockNetlinkLib | ||
end | ||
sriovmocked["test/integration/sriov-mocked.go"] | ||
subgraph "sriov CNI" | ||
sriov["cmd/sriov/main.go"] | ||
cnicommands_pkg["CmdAdd | CmdDel"] | ||
sriov --- cnicommands_pkg | ||
end | ||
sriovmocked --- cnicommands_pkg | ||
sriovmocked -.setup.- CreateTmpSysFs | ||
sriovmocked -.setup.- MockNetlinkLib | ||
subgraph "System"graph TD | ||
subgraph "Go files" | ||
sriovmocked["test/integration/<b>sriov-mocked.go</b>"] | ||
sriov["cmd/sriov/<b>main.go</b>"] | ||
cnicommands_pkg["CmdAdd | CmdDel"] | ||
sriov --- cnicommands_pkg | ||
subgraph "pkg/utils/testing.go" | ||
CreateTmpSysFs | ||
MockNetlinkLib | ||
end | ||
netlinkLib["<small><< lib >></small><br>github.com/vishvananda/netlink"] | ||
end | ||
sriovmocked --- cnicommands_pkg | ||
subgraph "Test Harness" | ||
calls_file[(<small><< file >><br>/tmp/x/< pf_name >.calls)] | ||
PF{{<small><< dummy >></small><br>PF}} | ||
VF1{{<small><< dummy >></small><br>VF1}} | ||
VF2{{<small><< dummy >></small><br>VF2}} | ||
end | ||
test_sriov_cni.sh | ||
test_sriov_cni.sh --> sriovmocked | ||
cnicommands_pkg --> CreateTmpSysFs | ||
cnicommands_pkg --> MockNetlinkLib | ||
MockNetlinkLib -.write.- calls_file | ||
MockNetlinkLib -..- netlinkLib | ||
netlinkLib -..- PF | ||
netlinkLib -..- VF1 | ||
netlinkLib -..- VF2 | ||
test_sriov_cni.sh -.read.- calls_file | ||
test_sriov_cni.sh -.assert.- PF | ||
test_sriov_cni.sh -.assert.- VF1 | ||
test_sriov_cni.sh -.assert.- VF2 | ||
linkStyle default stroke-width:2px | ||
linkStyle 1,2,3,4 stroke:green,stroke-width:4px | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"runtime" | ||
|
||
"github.com/containernetworking/cni/pkg/skel" | ||
"github.com/containernetworking/cni/pkg/version" | ||
"github.com/k8snetworkplumbingwg/sriov-cni/pkg/cnicommands" | ||
"github.com/k8snetworkplumbingwg/sriov-cni/pkg/config" | ||
"github.com/k8snetworkplumbingwg/sriov-cni/pkg/utils" | ||
) | ||
|
||
func init() { | ||
// this ensures that main runs only on main thread (thread group leader). | ||
// since namespace ops (unshare, setns) are done for a single thread, we | ||
// must ensure that the goroutine does not jump from OS thread to thread | ||
runtime.LockOSThread() | ||
} | ||
|
||
func main() { | ||
customCNIDir, ok := os.LookupEnv("DEFAULT_CNI_DIR") | ||
if ok { | ||
config.DefaultCNIDir = customCNIDir | ||
} | ||
|
||
err := utils.CreateTmpSysFs() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
defer func() { | ||
err := utils.RemoveTmpSysFs() | ||
if err != nil { | ||
panic(err) | ||
} | ||
}() | ||
|
||
cancel, err := utils.MockNetlinkLib(config.DefaultCNIDir) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer cancel() | ||
|
||
|
||
cniFuncs := skel.CNIFuncs{ | ||
Add: cnicommands.CmdAdd, | ||
Del: cnicommands.CmdDel, | ||
Check: cnicommands.CmdCheck, | ||
} | ||
skel.PluginMainFuncs(cniFuncs, version.All, "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
if [[ -n "${IPAM_MOCK_SLEEP}" ]]; then | ||
sleep "${IPAM_MOCK_SLEEP}" | ||
fi | ||
|
||
cat << EOF | ||
{ | ||
"cniVersion": "0.3.1", | ||
"interfaces": [{ | ||
"name": "${CNI_IFNAME}" | ||
}], | ||
"ips": [{ | ||
"name": "${CNI_IFNAME}", | ||
"address": "192.0.2.1/24" | ||
}] | ||
} | ||
EOF |
Oops, something went wrong.