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

ifupdown2: Modify implementation of nowait option

Ticket: None
Reviewed By: CCR-4058
Testing Done: ifup'd interface with both dhcp-wait: "no" and dhcp-wait: "yes"
and not specified at all.

A previous patch implemented the nowait option for DHCP. This patch changes the
name of the option to "dhcp-wait" and makes the default, if nothing is specified
in the policy files, to be "yes", which means dhclient will be called without
the "-nw" option, causing it to wait for up to a minute for a response from the
DHCP server before continuing.

The format of the JSON in the policy file for this option was also changed so
that it conforms to the other ifupdown2 policy options. This format is now:

{
    "dhcp": {
        "defaults": { "dhcp-wait": "no" }
    }
}

Also, the documented argument values are "yes" and "no". Any other values, will
be interpreted as "yes".

A subsequent patch in cl-basefiles will be made to include this fragment in
/var/lib/ifupdown2/policy.d/dhcp.json so that Cumulus Linux will default to
not waiting for DHCP to complete.
This commit is contained in:
Scott Emery
2016-02-03 16:38:18 -08:00
parent 28102a01e2
commit a0a8d7e094
3 changed files with 27 additions and 22 deletions

View File

@@ -31,10 +31,9 @@ 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" ]
dhcp_wait = policymanager.policymanager_api.get_attr_default(
module_name=self.__class__.__name__, attr='dhcp-wait')
wait = not str(dhcp_wait).lower() == "no"
if ifaceobj.addr_family == 'inet':
# First release any existing dhclient processes
try:
@@ -42,7 +41,7 @@ class dhcp(moduleBase):
self.dhclientcmd.stop(ifaceobj.name)
except:
pass
self.dhclientcmd.start(ifaceobj.name, nowait=nowait)
self.dhclientcmd.start(ifaceobj.name, wait=wait)
elif ifaceobj.addr_family == 'inet6':
accept_ra = ifaceobj.get_attr_value_first('accept_ra')
if accept_ra:
@@ -58,7 +57,7 @@ class dhcp(moduleBase):
self.dhclientcmd.stop6(ifaceobj.name)
except:
pass
self.dhclientcmd.start6(ifaceobj.name, nowait=nowait)
self.dhclientcmd.start6(ifaceobj.name, wait=wait)
except Exception, e:
self.log_error(str(e))

View File

@@ -106,25 +106,25 @@ class policymanager():
# looks for user specified value
val = self.user_policy_array[module_name]['iface_defaults'][ifname][attr]
return val
except:
except (TypeError, KeyError, IndexError):
pass
try:
# failing that, there may be a user default for all intefaces
val = self.user_policy_array[module_name]['defaults'][attr]
return val
except:
except (TypeError, KeyError, IndexError):
pass
try:
# failing that, look for system setting for the interface
val = self.system_policy_array[module_name]['iface_defaults'][ifname][attr]
return val
except:
except (TypeError, KeyError, IndexError):
pass
try:
# failing that, look for system setting for all interfaces
val = self.system_policy_array[module_name]['defaults'][attr]
return val
except:
except (TypeError, KeyError, IndexError):
pass
# could not find any system or user default so return Non
@@ -135,7 +135,7 @@ class policymanager():
get_attr_default: Addon modules must use one of two types of access methods to
the default configs. In this method, we expect the default to be in
[module][attr]
[module]['defaults'][attr]
We first check the user_policy_array and return that value. But if
the user did not specify an override, we use the system_policy_array.
@@ -143,14 +143,20 @@ class policymanager():
if (not attr or not module_name):
return None
# users can specify defaults to override the systemwide settings
# look for user specific interface attribute iface_defaults first
# look for user specific attribute defaults first
val = None
if self.user_policy_array.get(module_name):
val = self.user_policy_array[module_name].get(attr)
if not val:
if self.system_policy_array.get(module_name):
val = self.system_policy_array[module_name].get(attr)
try:
# looks for user specified value
val = self.user_policy_array[module_name]['defaults'][attr]
return val
except (TypeError, KeyError, IndexError):
pass
try:
# failing that, look for system setting
val = self.system_policy_array[module_name]['defaults'][attr]
return val
except (TypeError, KeyError, IndexError):
pass
return val

View File

@@ -42,7 +42,7 @@ class dhclient(utilsBase):
'%s' %ifacename]
self.subprocess_check_call(cmd)
def start(self, ifacename, nowait=False):
def start(self, ifacename, wait=True):
if os.path.exists('/sbin/dhclient3'):
cmd = ['/sbin/dhclient3', '-pf',
'/run/dhclient.%s.pid' %ifacename,
@@ -52,7 +52,7 @@ class dhclient(utilsBase):
cmd = ['/sbin/dhclient', '-pf', '/run/dhclient.%s.pid' %ifacename,
'-lf', '/var/lib/dhcp/dhclient.%s.leases' %ifacename,
'%s' %ifacename]
if nowait:
if not wait:
cmd.append('-nw')
self.subprocess_check_call(cmd)
@@ -69,12 +69,12 @@ class dhclient(utilsBase):
'%s' %ifacename]
self.subprocess_check_call(cmd)
def start6(self, ifacename, nowait=False):
def start6(self, ifacename, wait=True):
cmd = ['dhclient', '-6', '-pf',
'/run/dhclient6.%s.pid' %ifacename, '-lf',
'/var/lib/dhcp/dhclient.%s.leases ' %ifacename,
'%s' %ifacename]
if nowait:
if not wait:
cmd.append('-nw')
self.subprocess_check_call(cmd)