1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00

ifupdown2: Add nowait attribute for dhcp addon

Ticket: None
Reviewed By: CCR-4058
Testing Done: ifup'd interface with both nowait=0 and nowait=1 and not specified
at all.

The Mellanox platform, as well as some others probably, has two management
interfaces: eth0 and eth1. The customer may plug a cable into either one of
these interfaces, and very rarely both of them. If only one cable is plugged in
and we don't know which one, then /etc/network/interfaces must be configured
by default to automatically bring up both interfaces using DHCP. But when an
interface does not have link, it stalls the boot process for 60 seconds while
dhclient times out.

This patch changes the default dhclient behavior to not wait for DHCP to
complete, by using the "-nw" option when calling dhclient. This means that
dhclient will immediately return and DHCP will complete in the background.

A module attribute has been added for the DHCP addon called "nowait", which
defaults to 1. If this attribute is set to 0, then dhclient will revert to its
previous behavior and delay up to a minute while DHCP completes. This attribute
can be specified in a policy file, e.g. /etc/network/ifupdown2/policy.d/dhcp.json,
with contents such as:

{
  "dhcp" :
  {
    "nowait" : 0
  }
}
This commit is contained in:
Scott Emery
2016-02-01 16:42:14 -08:00
parent ec205cb3f8
commit 6d359159c3
2 changed files with 16 additions and 6 deletions

View File

@@ -8,6 +8,7 @@ try:
from ipaddr import IPNetwork
from sets import Set
from ifupdown.iface import *
import ifupdown.policymanager as policymanager
from ifupdownaddons.modulebase import moduleBase
from ifupdownaddons.dhclient import dhclient
from ifupdownaddons.iproute2 import iproute2
@@ -30,6 +31,10 @@ class dhcp(moduleBase):
ifaceobj.name)
return
try:
nowait = policymanager.policymanager_api.get_attr_default(
module_name='dhcp', attr='nowait')
nowait = not str(nowait).lower() in [ "false", "f", "no", "n", "o",
"off", "disabled", "0", "0.0" ]
if ifaceobj.addr_family == 'inet':
# First release any existing dhclient processes
try:
@@ -37,7 +42,7 @@ class dhcp(moduleBase):
self.dhclientcmd.stop(ifaceobj.name)
except:
pass
self.dhclientcmd.start(ifaceobj.name)
self.dhclientcmd.start(ifaceobj.name, nowait=nowait)
elif ifaceobj.addr_family == 'inet6':
accept_ra = ifaceobj.get_attr_value_first('accept_ra')
if accept_ra:
@@ -53,7 +58,7 @@ class dhcp(moduleBase):
self.dhclientcmd.stop6(ifaceobj.name)
except:
pass
self.dhclientcmd.start6(ifaceobj.name)
self.dhclientcmd.start6(ifaceobj.name, nowait=nowait)
except Exception, e:
self.log_error(str(e))