Skip to content

Commit

Permalink
Testing: map binary names to HCN types.
Browse files Browse the repository at this point in the history
Signed-off-by: Nashwan Azhari <nazhari@cloudbasesolutions.com>
  • Loading branch information
aznashwan committed Nov 13, 2023
1 parent c12cbb8 commit 541d414
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 26 deletions.
9 changes: 5 additions & 4 deletions plugins/nat/nat_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ import (
"testing"

"github.com/Microsoft/hcsshim/hcn"
"github.com/Microsoft/windows-container-networking/cni"
util "github.com/Microsoft/windows-container-networking/test/utilities"
)

var testDualStack bool
var imageToUse string

func CreateNatTestNetwork() *hcn.HostComputeNetwork {
func CreateNatTestNetwork(t *testing.T) *hcn.HostComputeNetwork {
ipams := util.GetDefaultIpams()
return util.CreateTestNetwork("natNet", "Nat", ipams, false)
return util.CreateTestNetwork(t, "natNet", cni.NatPluginName, ipams, false)
}

func TestNatCmdAdd(t *testing.T) {
// t.Skip("Nat test is disabled for now.")
testDualStack = (os.Getenv("TestDualStack") == "1")
imageToUse = os.Getenv("ImageToUse")
testNetwork := CreateNatTestNetwork()
pt := util.MakeTestStruct(t, testNetwork, "nat", false, false, "", testDualStack, imageToUse)
testNetwork := CreateNatTestNetwork(t)
pt := util.MakeTestStruct(t, testNetwork, false, false, "", testDualStack, imageToUse)
pt.RunAll(t)
}
9 changes: 5 additions & 4 deletions plugins/sdnbridge/sdnbridge_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/Microsoft/hcsshim/hcn"
"github.com/Microsoft/windows-container-networking/cni"
util "github.com/Microsoft/windows-container-networking/test/utilities"

"os"
Expand All @@ -12,20 +13,20 @@ import (
var testDualStack bool
var imageToUse string

func CreateBridgeTestNetwork() *hcn.HostComputeNetwork {
func CreateBridgeTestNetwork(t *testing.T) *hcn.HostComputeNetwork {
ipams := util.GetDefaultIpams()
if testDualStack {
ipams = append(ipams, util.GetDefaultIpv6Ipams()...)
}
return util.CreateTestNetwork("bridgeNet", "L2Bridge", ipams, true)
return util.CreateTestNetwork(t, "bridgeNet", cni.SdnBridgePluginName, ipams, true)
}

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

"github.com/Microsoft/hcsshim/hcn"
"github.com/Microsoft/windows-container-networking/cni"
util "github.com/Microsoft/windows-container-networking/test/utilities"
)

Expand All @@ -28,17 +29,17 @@ func GetVsidPol() []json.RawMessage {
return []json.RawMessage{vsidPolRaw}
}

func CreateOverlayTestNetwork() *hcn.HostComputeNetwork {
func CreateOverlayTestNetwork(t *testing.T) *hcn.HostComputeNetwork {
ipams := util.GetDefaultIpams()
ipams[0].Subnets[0].Policies = GetVsidPol()
return util.CreateTestNetwork("overlayNet", "Overlay", ipams, true)
return util.CreateTestNetwork(t, "overlayNet", cni.SdnOverlayPluginName, ipams, true)
}

func TestOverlayCmdAdd(t *testing.T) {
// t.Skip("Overlay test is disabled for now.")
testDualStack = (os.Getenv("TestDualStack") == "1")
imageToUse = os.Getenv("ImageToUse")
testNetwork := CreateOverlayTestNetwork()
pt := util.MakeTestStruct(t, testNetwork, "Overlay", true, false, "", testDualStack, imageToUse)
testNetwork := CreateOverlayTestNetwork(t)
pt := util.MakeTestStruct(t, testNetwork, true, false, "", testDualStack, imageToUse)
pt.RunAll(t)
}
61 changes: 47 additions & 14 deletions test/utilities/connectivity_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,32 +88,52 @@ func CreateNetConfIpam(cidr string) cni.IpamConfig {
return testIpam
}

func CreateNetworkConf(cniVersion string, name string, pluginType string,
dns *cniTypes.DNS, addArgs []cni.KVP, gatewayPrefix string) *cni.NetworkConfig {
func CreateNetworkConf(t *testing.T, cniVersion string, name string, pluginType hcn.NetworkType,
dns *cniTypes.DNS, addArgs []cni.KVP, gatewayPrefix string) (*cni.NetworkConfig, error) {

mappedType, err := cni.MapCniTypeToHcnType(pluginType)
if err != nil {
return nil, err
}

if pluginType != mappedType {
t.Logf("WARN: supplied network plugin type %q was mapped to HCN network type %q", pluginType, mappedType)
}

netConf := cni.NetworkConfig{
CniVersion: cniVersion,
Name: name,
Ipam: CreateNetConfIpam(gatewayPrefix),
Type: pluginType,
Type: mappedType,
DNS: *dns,
AdditionalArgs: addArgs,
}
return &netConf
return &netConf, nil
}

func CreateDualStackNetworkConf(
t *testing.T,
cniVersion string,
name string,
pluginType string,
pluginType hcn.NetworkType,
dns *cniTypes.DNS,
addArgs []cni.KVP,
gatewayPrefixv4 string,
gatewayPrefixv6 string) *cni.NetworkConfig {
gatewayPrefixv6 string) (*cni.NetworkConfig, error) {

mappedType, err := cni.MapCniTypeToHcnType(pluginType)
if err != nil {
return nil, err
}

if pluginType != mappedType {
t.Logf("WARN: supplied network plugin type %q was mapped to HCN network type %q", pluginType, mappedType)
}

netConf := cni.NetworkConfig{
CniVersion: cniVersion,
Name: name,
Type: pluginType,
Type: mappedType,
DNS: *dns,
AdditionalArgs: addArgs,
}
Expand All @@ -139,7 +159,7 @@ func CreateDualStackNetworkConf(

netConf.AdditionalRoutes = append(netConf.AdditionalRoutes, testRoute)

return &netConf
return &netConf, nil
}

func GetDefaultIpams() []hcn.Ipam {
Expand Down Expand Up @@ -289,14 +309,24 @@ func CreateGatewayEp(t *testing.T, networkId string, ipAddress string, ipv6Adres
return nil
}

func CreateTestNetwork(name string, netType string, ipams []hcn.Ipam, tryGetNetAdapter bool) *hcn.HostComputeNetwork {
func CreateTestNetwork(t *testing.T, name string, netType string, ipams []hcn.Ipam, tryGetNetAdapter bool) *hcn.HostComputeNetwork {
hcnNetType := hcn.NetworkType(netType)
mappedType, err := cni.MapCniTypeToHcnType(hcnNetType)
if err != nil {
t.Errorf("Failed to map testing network type %q to HCN network type: %v", netType, err)
}

if mappedType != hcnNetType {
t.Logf("WARN: testing network type %q was mapped to HCN network type %q", netType, mappedType)
}

network := &hcn.HostComputeNetwork{
SchemaVersion: hcn.SchemaVersion{
Major: 2,
Minor: 0,
},
Name: name,
Type: hcn.NetworkType(netType),
Type: mappedType,
Ipams: ipams,
}

Expand All @@ -312,7 +342,6 @@ func CreateTestNetwork(name string, netType string, ipams []hcn.Ipam, tryGetNetA
func MakeTestStruct(
t *testing.T,
testNetwork *hcn.HostComputeNetwork,
pluginType string,
epPols bool,
needGW bool,
cid string,
Expand Down Expand Up @@ -352,11 +381,15 @@ func MakeTestStruct(
var netConf *cni.NetworkConfig

if !testDualStack {
netConf = CreateNetworkConf(defaultCniVersion, testNetwork.Name, pluginType, dns, addArgs, netConfPrefix)
if netConf, err = CreateNetworkConf(t, defaultCniVersion, testNetwork.Name, testNetwork.Type, dns, addArgs, netConfPrefix); err != nil {
t.Errorf("Failed to create testing network config: %v", err)
return nil
}
} else {

netConfPrefixv6 := "fd00::101/64"
netConf = CreateDualStackNetworkConf(defaultCniVersion, testNetwork.Name, pluginType, dns, addArgs, netConfPrefix, netConfPrefixv6)
if netConf, err = CreateDualStackNetworkConf(t, defaultCniVersion, testNetwork.Name, testNetwork.Type, dns, addArgs, netConfPrefix, netConfPrefixv6); err != nil {
return nil
}

}
netJson, _ := json.Marshal(netConf)
Expand Down

0 comments on commit 541d414

Please sign in to comment.