4
4
package network
5
5
6
6
import (
7
+ "context"
7
8
"net"
8
9
"testing"
9
10
@@ -12,9 +13,18 @@ import (
12
13
"github.com/Azure/azure-container-networking/netlink"
13
14
"github.com/Azure/azure-container-networking/network/networkutils"
14
15
"github.com/Azure/azure-container-networking/platform"
16
+ "github.com/pkg/errors"
15
17
"github.com/stretchr/testify/require"
18
+ "k8s.io/kubernetes/pkg/kubelet"
16
19
)
17
20
21
+ // mockDHCPFail is a mock DHCP client that always returns an error
22
+ type mockDHCPFail struct {}
23
+
24
+ func (m * mockDHCPFail ) DiscoverRequest (context.Context , net.HardwareAddr , string ) error {
25
+ return errors .New ("mock DHCP discover request failed" )
26
+ }
27
+
18
28
func TestSecondaryAddEndpoints (t * testing.T ) {
19
29
nl := netlink .NewMockNetlink (false , "" )
20
30
plc := platform .NewMockExecClient (false )
@@ -363,6 +373,33 @@ func TestSecondaryConfigureContainerInterfacesAndRoutes(t *testing.T) {
363
373
wantErr : true ,
364
374
wantErrMsg : "SecondaryEndpointClient Error: routes expected for eth1" ,
365
375
},
376
+ {
377
+ name : "Configure Interface and routes DHCP discover fail" ,
378
+ client : & SecondaryEndpointClient {
379
+ netlink : netlink .NewMockNetlink (false , "" ),
380
+ plClient : platform .NewMockExecClient (false ),
381
+ netUtilsClient : networkutils .NewNetworkUtils (nl , plc ),
382
+ netioshim : netio .NewMockNetIO (false , 0 ),
383
+ dhcpClient : & mockDHCPFail {},
384
+ ep : & endpoint {SecondaryInterfaces : map [string ]* InterfaceInfo {"eth1" : {Name : "eth1" }}},
385
+ },
386
+ epInfo : & EndpointInfo {
387
+ IfName : "eth1" ,
388
+ IPAddresses : []net.IPNet {
389
+ {
390
+ IP : net .ParseIP ("192.168.0.4" ),
391
+ Mask : net .CIDRMask (subnetv4Mask , ipv4Bits ),
392
+ },
393
+ },
394
+ Routes : []RouteInfo {
395
+ {
396
+ Dst : net.IPNet {IP : net .ParseIP ("192.168.0.4" ), Mask : net .CIDRMask (ipv4FullMask , ipv4Bits )},
397
+ },
398
+ },
399
+ },
400
+ wantErr : true ,
401
+ wantErrMsg : kubelet .NetworkNotReadyErrorMsg ,
402
+ },
366
403
}
367
404
368
405
for _ , tt := range tests {
0 commit comments