Skip to content

Commit

Permalink
Enable Unit Tests (#94)
Browse files Browse the repository at this point in the history
* fix: separate config name from config type to allow creation of multiple networks

* tests: enable nat plugin tests

* allow icmp requests on job runners

* set nano server 2022 for windows server 2022 runner

* enable sdn bridge tests

* update network type to L2Bridge

* fix: restore network plugin setup steps

* enable sdn overlay tests

* limit parallel test execution to 1
  • Loading branch information
iankingori authored Oct 2, 2023
1 parent 3a5374c commit b360521
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 60 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ jobs:
go install ./...
working-directory: src/github.com/Microsoft/windows-container-networking

- name: Enable ICMP V4
shell: pwsh
run: |
netsh advFirewall Firewall add rule name="Enable ICMP Protocal" protocol=icmpv4:8,any dir=in action=allow
- name: Test
env:
ImageToUse: ${{ matrix.os == 'windows-2022' && 'mcr.microsoft.com/windows/nanoserver:ltsc2022' || '' }}
run: |
mingw32-make.exe test
working-directory: src/github.com/Microsoft/windows-container-networking
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CNIFILES = \
GOCMD=go
GOLOCALENV=GO111MODULE=on GOARCH=amd64 GOOS=windows
GOBUILD=$(GOLOCALENV) $(GOCMD) build -v -mod=vendor
GOTEST=$(GOLOCALENV) $(GOCMD) test -v -mod=vendor
GOTEST=$(GOLOCALENV) $(GOCMD) test -v -p 1 -mod=vendor

CNI_NET_DIR = plugins
OUTPUTDIR = out
Expand Down
2 changes: 1 addition & 1 deletion cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (config *NetworkConfig) GetNetworkInfo(podNamespace string) (ninfo *network
ninfo = &network.NetworkInfo{
ID: config.Name,
Name: config.Name,
Type: network.NetworkType(config.Name),
Type: network.NetworkType(config.Type),
Subnets: subnets,
InterfaceName: "",
DNS: dnsSettings,
Expand Down
2 changes: 1 addition & 1 deletion plugins/nat/nat_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func CreateNatTestNetwork() *hcn.HostComputeNetwork {
}

func TestNatCmdAdd(t *testing.T) {
t.Skip("Nat test is disabled for now.")
// t.Skip("Nat test is disabled for now.")
testDualStack = (os.Getenv("TestDualStack") == "1")
imageToUse = os.Getenv("ImageToUse")
testNetwork := CreateNatTestNetwork()
Expand Down
4 changes: 2 additions & 2 deletions plugins/sdnbridge/sdnbridge_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ func CreateBridgeTestNetwork() *hcn.HostComputeNetwork {
}

func TestBridgeCmdAdd(t *testing.T) {
t.Skip("Bridge test is disabled for now.")
// t.Skip("Bridge test is disabled for now.")
testDualStack = (os.Getenv("TestDualStack") == "1")
imageToUse = os.Getenv("ImageToUse")
testNetwork := CreateBridgeTestNetwork()
pt := util.MakeTestStruct(t, testNetwork, "sdnbridge", true, true, "", testDualStack, imageToUse)
pt := util.MakeTestStruct(t, testNetwork, "L2Bridge", true, true, "", testDualStack, imageToUse)
pt.Ipv6Url = os.Getenv("Ipv6UrlToUse")
pt.RunAll(t)
}
4 changes: 2 additions & 2 deletions plugins/sdnoverlay/sdnoverlay_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ func CreateOverlayTestNetwork() *hcn.HostComputeNetwork {
}

func TestOverlayCmdAdd(t *testing.T) {
t.Skip("Overlay test is disabled for now.")
// t.Skip("Overlay test is disabled for now.")
testDualStack = (os.Getenv("TestDualStack") == "1")
imageToUse = os.Getenv("ImageToUse")
testNetwork := CreateOverlayTestNetwork()
pt := util.MakeTestStruct(t, testNetwork, "sdnoverlay", true, false, "", testDualStack, imageToUse)
pt := util.MakeTestStruct(t, testNetwork, "Overlay", true, false, "", testDualStack, imageToUse)
pt.RunAll(t)
}
18 changes: 9 additions & 9 deletions test/container/container_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/Microsoft/go-winio/vhd"
"github.com/Microsoft/hcsshim"
runhcs "github.com/Microsoft/hcsshim/pkg/go-runhcs"
"github.com/Microsoft/hcsshim/test/functional/utilities"
runc "github.com/containerd/go-runc"
"github.com/opencontainers/runtime-tools/generate"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
"io"
"io/ioutil"
"os"
Expand All @@ -21,6 +13,15 @@ import (
"strconv"
"strings"
"testing"

"github.com/Microsoft/go-winio/vhd"
"github.com/Microsoft/hcsshim"
runhcs "github.com/Microsoft/hcsshim/pkg/go-runhcs"
testutilities "github.com/Microsoft/hcsshim/test/functional/utilities"
runc "github.com/containerd/go-runc"
"github.com/opencontainers/runtime-tools/generate"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
)

const (
Expand All @@ -32,7 +33,6 @@ const (

func PingTest(c hcsshim.Container, ip string, ipv6 bool) error {
var pingCommand string

if !ipv6 {
pingCommand = fmt.Sprintf("ping -w 8000 -n 4 %s", ip)
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/utilities/connectivity_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
func getDefaultDns() *cniTypes.DNS {
defaultDns := cniTypes.DNS{
// Nameservers: []string{"8.8.8.8", "11.0.0.10"},
Nameservers: []string{"10.50.10.50"},
Nameservers: []string{"10.50.10.50", "8.8.8.8"},
Search: []string{"svc.cluster.local", "svc.cluster.local"},
}
return &defaultDns
Expand Down
2 changes: 1 addition & 1 deletion test/utilities/container_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/Microsoft/hcsshim"
"github.com/Microsoft/hcsshim/hcn"
"github.com/Microsoft/windows-container-networking/test/container"
contTest "github.com/Microsoft/windows-container-networking/test/container"
)

const (
Expand Down
33 changes: 24 additions & 9 deletions test/utilities/plugin_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/Microsoft/hcsshim/hcn"
"github.com/Microsoft/windows-container-networking/cni"
cniSkel "github.com/containernetworking/cni/pkg/skel"
"net"
"strings"
"testing"

"github.com/Microsoft/hcsshim/hcn"
"github.com/Microsoft/windows-container-networking/cni"
cniSkel "github.com/containernetworking/cni/pkg/skel"
)

type PluginUnitTest struct {
Expand Down Expand Up @@ -178,10 +179,14 @@ func (pt *PluginUnitTest) verifyAddEndpointProperties(t *testing.T, ci *Containe
}

func (pt *PluginUnitTest) verifyAddNamespaceProperties(t *testing.T, ci *ContainerInfo) {
EpNamespace := string(ci.Namespace.Resources[0].Data)
if !strings.Contains(EpNamespace, strings.ToUpper(ci.Endpoint.Id)) {
t.Errorf("Namespace does not contain a reference to endpoint.")
if len(ci.Namespace.Resources) > 0 {
EpNamespace := string(ci.Namespace.Resources[0].Data)
if strings.Contains(EpNamespace, strings.ToUpper(ci.Endpoint.Id)) {
return
}
}

t.Errorf("Namespace does not contain a reference to endpoint.")
}

func (pt *PluginUnitTest) verifyDelNamespaceProperties(t *testing.T, ci *ContainerInfo) {
Expand Down Expand Up @@ -292,9 +297,11 @@ func (pt *PluginUnitTest) RunBasicConnectivityTest(t *testing.T, numContainers i
var err error

if !pt.DualStack {
err = ctList[0].RunContainerConnectivityTest(
t, pt.HostIp.String(), ctx.Endpoint.IpConfigurations[0].IpAddress,
false, "", "", "")
if ctx.Endpoint != nil {
err = ctList[0].RunContainerConnectivityTest(
t, pt.HostIp.String(), ctx.Endpoint.IpConfigurations[0].IpAddress,
false, "", "", "")
}
} else {
var ipv4addr string
var ipv6addr string
Expand Down Expand Up @@ -331,6 +338,14 @@ func (pt *PluginUnitTest) RunBasicConnectivityTest(t *testing.T, numContainers i
}

func (pt *PluginUnitTest) RunAll(t *testing.T) {
if err := pt.Setup(t); err != nil {
t.Errorf("Failed to set up test case for %v: %s", pt.CniCmdArgs, err)
}
defer func() {
if err := pt.Teardown(t); err != nil {
t.Logf("WARN: failed to tear down test case for %v: %s", pt.CniCmdArgs, err)
}
}()
pt.RunUnitTest(t)
pt.RunBasicConnectivityTest(t, 2)
}
70 changes: 37 additions & 33 deletions test/utilities/testing_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"encoding/json"
"errors"
"fmt"
"net"

"github.com/Microsoft/hcsshim/hcn"
"github.com/Microsoft/windows-container-networking/cni"
"github.com/Microsoft/windows-container-networking/common"
"github.com/Microsoft/windows-container-networking/common/core"
cniSkel "github.com/containernetworking/cni/pkg/skel"
"net"
)

const Interface = "Ethernet"
var Interface string

func GetDefaultInterface(getipv6 bool) (*net.Interface, *net.IP, *net.IP, error) {
var foundv4 bool
Expand All @@ -23,41 +24,44 @@ func GetDefaultInterface(getipv6 bool) (*net.Interface, *net.IP, *net.IP, error)

foundInterface := net.Interface{}
ifaces, _ := net.Interfaces()
for _, i := range ifaces {
if i.Name == Interface {
foundInterface = i
foundv4 = false
foundv6 = false

addrs, _ := i.Addrs()
for _, addr := range addrs {
ipTemp, _, _ := net.ParseCIDR(addr.String())
if ipTemp.To4() != nil {

if !foundv4 {
foundIp = &ipTemp
foundv4 = true
}

} else {
if getipv6 &&
!foundv6 &&
!ipTemp.IsLinkLocalUnicast() &&
!ipTemp.IsLoopback() {

foundIpv6 = &ipTemp
foundv6 = true
}
}

if foundv4 && foundv6 {
break
}

if len(ifaces) == 0 {
return nil, nil, nil, fmt.Errorf("failed to find any network interfaces, unable to proceed with tests")
}

i := ifaces[0] // use highest priority network
foundInterface = i
Interface = i.Name
foundv4 = false
foundv6 = false

addrs, _ := i.Addrs()
for _, addr := range addrs {
ipTemp, _, _ := net.ParseCIDR(addr.String())
if ipTemp.To4() != nil {

if !foundv4 {
foundIp = &ipTemp
foundv4 = true
}

} else {
if getipv6 &&
!foundv6 &&
!ipTemp.IsLinkLocalUnicast() &&
!ipTemp.IsLoopback() {

foundIpv6 = &ipTemp
foundv6 = true
}
}

if foundv4 && foundv6 {
break
}
}
if foundIp == nil {
return nil, nil, nil, fmt.Errorf("Failed to find interface %s, unable to proceed with tests", Interface)
return nil, nil, nil, fmt.Errorf("failed to find interface %s, unable to proceed with tests", Interface)
}
return &foundInterface, foundIp, foundIpv6, nil
}
Expand Down

0 comments on commit b360521

Please sign in to comment.