dhcp: add -resendmax option to limit lease acquisition time for testcases

The default lease acquisition timeout of 62 seconds is way too long when
running multiple testcases, overrunning the `go test` timeout of 10m. Let
testcases specify a shorter timeout.

Signed-off-by: Dan Williams <dcbw@redhat.com>
This commit is contained in:
Dan Williams
2021-02-12 14:38:20 -06:00
parent 4ddc8ba460
commit dd3f6064f6
3 changed files with 18 additions and 12 deletions

View File

@@ -43,13 +43,15 @@ type DHCP struct {
leases map[string]*DHCPLease
hostNetnsPrefix string
clientTimeout time.Duration
clientResendMax time.Duration
broadcast bool
}
func newDHCP(clientTimeout time.Duration) *DHCP {
func newDHCP(clientTimeout, clientResendMax time.Duration) *DHCP {
return &DHCP{
leases: make(map[string]*DHCPLease),
clientTimeout: clientTimeout,
leases: make(map[string]*DHCPLease),
clientTimeout: clientTimeout,
clientResendMax: clientResendMax,
}
}
@@ -67,7 +69,7 @@ func (d *DHCP) Allocate(args *skel.CmdArgs, result *current.Result) error {
clientID := generateClientID(args.ContainerID, conf.Name, args.IfName)
hostNetns := d.hostNetnsPrefix + args.Netns
l, err := AcquireLease(clientID, hostNetns, args.IfName, d.clientTimeout, d.broadcast)
l, err := AcquireLease(clientID, hostNetns, args.IfName, d.clientTimeout, d.clientResendMax, d.broadcast)
if err != nil {
return err
}
@@ -161,7 +163,7 @@ func getListener(socketPath string) (net.Listener, error) {
func runDaemon(
pidfilePath, hostPrefix, socketPath string,
dhcpClientTimeout time.Duration, broadcast bool,
dhcpClientTimeout time.Duration, resendMax time.Duration, broadcast bool,
) error {
// since other goroutines (on separate threads) will change namespaces,
// ensure the RPC server does not get scheduled onto those
@@ -182,7 +184,7 @@ func runDaemon(
return fmt.Errorf("Error getting listener: %v", err)
}
dhcp := newDHCP(dhcpClientTimeout)
dhcp := newDHCP(dhcpClientTimeout, resendMax)
dhcp.hostNetnsPrefix = hostPrefix
dhcp.broadcast = broadcast
rpc.Register(dhcp)