2021-09-20 22:04:35 +03:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2021-10-16 00:28:37 +03:00
|
|
|
"github.com/Azure/azure-container-networking/netlink"
|
2021-09-20 22:04:35 +03:00
|
|
|
"github.com/Azure/azure-container-networking/ovsctl"
|
2021-10-16 00:28:37 +03:00
|
|
|
"github.com/Azure/azure-container-networking/platform"
|
2021-09-20 22:04:35 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
bridgeName = "testbridge"
|
|
|
|
hostIntf = "testintf"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
os.Exit(m.Run())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddRoutes(t *testing.T) {
|
|
|
|
ovsctlClient := ovsctl.NewMockOvsctl(false, "", "")
|
2021-10-16 00:28:37 +03:00
|
|
|
ovsClient := NewOVSClient(bridgeName, hostIntf, ovsctlClient,
|
|
|
|
netlink.NewMockNetlink(false, ""), platform.NewMockExecClient(false))
|
2021-09-20 22:04:35 +03:00
|
|
|
|
|
|
|
if err := ovsClient.AddRoutes(nil, ""); err != nil {
|
|
|
|
t.Errorf("Add routes failed")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeleteBridge(t *testing.T) {
|
|
|
|
ovsctlClient := ovsctl.NewMockOvsctl(false, "", "")
|
|
|
|
|
2021-10-16 00:28:37 +03:00
|
|
|
ovsClient := NewOVSClient(bridgeName, hostIntf, ovsctlClient,
|
|
|
|
netlink.NewMockNetlink(false, ""), platform.NewMockExecClient(false))
|
2021-09-20 22:04:35 +03:00
|
|
|
if err := ovsClient.DeleteBridge(); err != nil {
|
|
|
|
t.Errorf("Error deleting the OVS bridge: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddL2Rules(t *testing.T) {
|
|
|
|
ovsctlClient := ovsctl.NewMockOvsctl(false, "", "")
|
|
|
|
extIf := externalInterface{
|
|
|
|
Name: hostIntf,
|
|
|
|
MacAddress: []byte("2C:54:91:88:C9:E3"),
|
|
|
|
}
|
|
|
|
|
2021-10-16 00:28:37 +03:00
|
|
|
ovsClient := NewOVSClient(bridgeName, hostIntf, ovsctlClient,
|
|
|
|
netlink.NewMockNetlink(false, ""), platform.NewMockExecClient(false))
|
2021-09-20 22:04:35 +03:00
|
|
|
if err := ovsClient.AddL2Rules(&extIf); err != nil {
|
|
|
|
t.Errorf("Unable to add L2 rules: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeleteL2Rules(t *testing.T) {
|
|
|
|
ovsctlClient := ovsctl.NewMockOvsctl(false, "", "")
|
|
|
|
extIf := externalInterface{
|
|
|
|
Name: hostIntf,
|
|
|
|
MacAddress: []byte("2C:54:91:88:C9:E3"),
|
|
|
|
}
|
|
|
|
|
2021-10-16 00:28:37 +03:00
|
|
|
ovsClient := NewOVSClient(bridgeName, hostIntf, ovsctlClient,
|
|
|
|
netlink.NewMockNetlink(false, ""), platform.NewMockExecClient(false))
|
2021-09-20 22:04:35 +03:00
|
|
|
ovsClient.DeleteL2Rules(&extIf)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetBridgeMasterToHostInterface(t *testing.T) {
|
|
|
|
ovsctlClient := ovsctl.NewMockOvsctl(false, "", "")
|
|
|
|
|
2021-10-16 00:28:37 +03:00
|
|
|
ovsClient := NewOVSClient(bridgeName, hostIntf, ovsctlClient,
|
|
|
|
netlink.NewMockNetlink(false, ""), platform.NewMockExecClient(false))
|
2021-09-20 22:04:35 +03:00
|
|
|
if err := ovsClient.SetBridgeMasterToHostInterface(); err != nil {
|
|
|
|
t.Errorf("Unable to set bridge master to host intf: %v", err)
|
|
|
|
}
|
|
|
|
}
|