Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion network/secondary_endpoint_client_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/Azure/azure-container-networking/platform"
"github.com/pkg/errors"
"go.uber.org/zap"
"k8s.io/kubernetes/pkg/kubelet"
)

var errorSecondaryEndpointClient = errors.New("SecondaryEndpointClient Error")
Expand Down Expand Up @@ -141,7 +142,7 @@ func (client *SecondaryEndpointClient) ConfigureContainerInterfacesAndRoutes(epI
logger.Info("Sending DHCP packet", zap.Any("macAddress", epInfo.MacAddress), zap.String("ifName", epInfo.IfName))
err := client.dhcpClient.DiscoverRequest(ctx, epInfo.MacAddress, epInfo.IfName)
if err != nil {
return errors.Wrapf(err, "failed to issue dhcp discover packet to create mapping in host")
return errors.Wrap(err, kubelet.NetworkNotReadyErrorMsg+" - failed to issue dhcp discover packet to create mapping in host")
}
logger.Info("Finished configuring container interfaces and routes for secondary endpoint client")

Expand Down
37 changes: 37 additions & 0 deletions network/secondary_endpoint_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package network

import (
"context"
"net"
"testing"

Expand All @@ -12,9 +13,18 @@ import (
"github.com/Azure/azure-container-networking/netlink"
"github.com/Azure/azure-container-networking/network/networkutils"
"github.com/Azure/azure-container-networking/platform"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"k8s.io/kubernetes/pkg/kubelet"
)

// mockDHCPFail is a mock DHCP client that always returns an error
type mockDHCPFail struct{}

func (m *mockDHCPFail) DiscoverRequest(context.Context, net.HardwareAddr, string) error {
return errors.New("mock DHCP discover request failed")
}

func TestSecondaryAddEndpoints(t *testing.T) {
nl := netlink.NewMockNetlink(false, "")
plc := platform.NewMockExecClient(false)
Expand Down Expand Up @@ -363,6 +373,33 @@ func TestSecondaryConfigureContainerInterfacesAndRoutes(t *testing.T) {
wantErr: true,
wantErrMsg: "SecondaryEndpointClient Error: routes expected for eth1",
},
{
name: "Configure Interface and routes DHCP discover fail",
client: &SecondaryEndpointClient{
netlink: netlink.NewMockNetlink(false, ""),
plClient: platform.NewMockExecClient(false),
netUtilsClient: networkutils.NewNetworkUtils(nl, plc),
netioshim: netio.NewMockNetIO(false, 0),
dhcpClient: &mockDHCPFail{},
ep: &endpoint{SecondaryInterfaces: map[string]*InterfaceInfo{"eth1": {Name: "eth1"}}},
},
epInfo: &EndpointInfo{
IfName: "eth1",
IPAddresses: []net.IPNet{
{
IP: net.ParseIP("192.168.0.4"),
Mask: net.CIDRMask(subnetv4Mask, ipv4Bits),
},
},
Routes: []RouteInfo{
{
Dst: net.IPNet{IP: net.ParseIP("192.168.0.4"), Mask: net.CIDRMask(ipv4FullMask, ipv4Bits)},
},
},
},
wantErr: true,
wantErrMsg: kubelet.NetworkNotReadyErrorMsg,
},
}

for _, tt := range tests {
Expand Down
Loading