mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
Move LINK_MASTER/LINK_SLAVE to a new field link_type (purna hit some
issues with having it in flags) + add check for bond slave being already up Ticket: CM-4408 Reviewed By: Testing Done: some bond sanity test (cherry picked from commit 346b62a41fbf4521008cd8a9b0fa227e75a5d994)
This commit is contained in:
@@ -105,7 +105,7 @@ class ifenslave(moduleBase):
|
|||||||
|
|
||||||
# Also save a copy for future use
|
# Also save a copy for future use
|
||||||
ifaceobj.priv_data = list(slave_list)
|
ifaceobj.priv_data = list(slave_list)
|
||||||
ifaceobj.flags |= iface.LINK_MASTER
|
ifaceobj.link_type = ifaceLinkType.LINK_MASTER
|
||||||
return slave_list
|
return slave_list
|
||||||
|
|
||||||
def get_dependent_ifacenames_running(self, ifaceobj):
|
def get_dependent_ifacenames_running(self, ifaceobj):
|
||||||
@@ -145,6 +145,7 @@ class ifenslave(moduleBase):
|
|||||||
|
|
||||||
def _apply_master_settings(self, ifaceobj):
|
def _apply_master_settings(self, ifaceobj):
|
||||||
have_attrs_to_set = 0
|
have_attrs_to_set = 0
|
||||||
|
linkup = False
|
||||||
ifenslavecmd_attrmap = OrderedDict([('bond-mode' , 'mode'),
|
ifenslavecmd_attrmap = OrderedDict([('bond-mode' , 'mode'),
|
||||||
('bond-miimon' , 'miimon'),
|
('bond-miimon' , 'miimon'),
|
||||||
('bond-use-carrier', 'use_carrier'),
|
('bond-use-carrier', 'use_carrier'),
|
||||||
@@ -157,10 +158,7 @@ class ifenslave(moduleBase):
|
|||||||
('bond-ad-sys-priority' , 'ad_sys_priority'),
|
('bond-ad-sys-priority' , 'ad_sys_priority'),
|
||||||
('bond-lacp-fallback-allow', 'lacp_fallback_allow'),
|
('bond-lacp-fallback-allow', 'lacp_fallback_allow'),
|
||||||
('bond-lacp-fallback-period', 'lacp_fallback_period')])
|
('bond-lacp-fallback-period', 'lacp_fallback_period')])
|
||||||
linkstatus = self.ipcmd.link_get_status(ifaceobj.name)
|
linkup = self.ipcmd.is_link_up(ifaceobj.name)
|
||||||
if not linkstatus:
|
|
||||||
# assume link status is 'UP'
|
|
||||||
linkstatus = 'UP'
|
|
||||||
try:
|
try:
|
||||||
# order of attributes set matters for bond, so
|
# order of attributes set matters for bond, so
|
||||||
# construct the list sequentially
|
# construct the list sequentially
|
||||||
@@ -173,11 +171,11 @@ class ifenslave(moduleBase):
|
|||||||
return
|
return
|
||||||
have_attrs_to_set = 1
|
have_attrs_to_set = 1
|
||||||
self.ifenslavecmd.set_attrs(ifaceobj.name, attrstoset,
|
self.ifenslavecmd.set_attrs(ifaceobj.name, attrstoset,
|
||||||
self.ipcmd.link_down if linkstatus == 'UP' else None)
|
self.ipcmd.link_down if linkup else None)
|
||||||
except:
|
except:
|
||||||
raise
|
raise
|
||||||
finally:
|
finally:
|
||||||
if have_attrs_to_set and linkstatus == 'UP':
|
if have_attrs_to_set and linkup:
|
||||||
self.ipcmd.link_up(ifaceobj.name)
|
self.ipcmd.link_up(ifaceobj.name)
|
||||||
|
|
||||||
def _add_slaves(self, ifaceobj):
|
def _add_slaves(self, ifaceobj):
|
||||||
@@ -201,6 +199,8 @@ class ifenslave(moduleBase):
|
|||||||
self.log_warn('%s: skipping slave %s, does not exist'
|
self.log_warn('%s: skipping slave %s, does not exist'
|
||||||
%(ifaceobj.name, slave))
|
%(ifaceobj.name, slave))
|
||||||
continue
|
continue
|
||||||
|
if self.ipcmd.is_link_up(slave):
|
||||||
|
rtnetlink_api.rtnl_api.link_set(slave, "down")
|
||||||
self.ipcmd.link_set(slave, 'master', ifaceobj.name)
|
self.ipcmd.link_set(slave, 'master', ifaceobj.name)
|
||||||
rtnetlink_api.rtnl_api.link_set(slave, "up")
|
rtnetlink_api.rtnl_api.link_set(slave, "up")
|
||||||
|
|
||||||
|
8
debian/python-ifupdown2.postinst
vendored
8
debian/python-ifupdown2.postinst
vendored
@@ -50,10 +50,10 @@ case "$1" in
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ -e /sbin/ifup ] || ln -s /sbin/ifupdown /sbin/ifup
|
[ -e /sbin/ifup ] || ln -sf /sbin/ifupdown /sbin/ifup
|
||||||
[ -e /sbin/ifdown ] || ln -s /sbin/ifupdown /sbin/ifdown
|
[ -e /sbin/ifdown ] || ln -sf /sbin/ifupdown /sbin/ifdown
|
||||||
[ -e /sbin/ifquery ] || ln -s /sbin/ifupdown /sbin/ifquery
|
[ -e /sbin/ifquery ] || ln -sf /sbin/ifupdown /sbin/ifquery
|
||||||
[ -e /sbin/ifreload ] || ln -s /sbin/ifupdown /sbin/ifreload
|
[ -e /sbin/ifreload ] || ln -sf /sbin/ifupdown /sbin/ifreload
|
||||||
|
|
||||||
(cd /usr/share/man/man8/ && ln -sf /usr/share/man/man8/ifup.8.gz ifdown.8.gz)
|
(cd /usr/share/man/man8/ && ln -sf /usr/share/man/man8/ifup.8.gz ifdown.8.gz)
|
||||||
|
|
||||||
|
@@ -22,6 +22,11 @@ class ifaceType():
|
|||||||
IFACE = 0x1
|
IFACE = 0x1
|
||||||
BRIDGE_VLAN = 0x2
|
BRIDGE_VLAN = 0x2
|
||||||
|
|
||||||
|
class ifaceLinkType():
|
||||||
|
UNKNOWN = 0x0
|
||||||
|
LINK_SLAVE = 0x1
|
||||||
|
LINK_MASTER = 0x2
|
||||||
|
|
||||||
class ifaceStatus():
|
class ifaceStatus():
|
||||||
"""Enumerates iface status """
|
"""Enumerates iface status """
|
||||||
|
|
||||||
@@ -181,8 +186,6 @@ class iface():
|
|||||||
HAS_SIBLINGS = 0x2
|
HAS_SIBLINGS = 0x2
|
||||||
IFACERANGE_ENTRY = 0x3
|
IFACERANGE_ENTRY = 0x3
|
||||||
IFACERANGE_START = 0x4
|
IFACERANGE_START = 0x4
|
||||||
LINK_MASTER = 0x5
|
|
||||||
LINK_SLAVE = 0x6
|
|
||||||
|
|
||||||
version = '0.1'
|
version = '0.1'
|
||||||
|
|
||||||
@@ -218,6 +221,7 @@ class iface():
|
|||||||
"""interface type"""
|
"""interface type"""
|
||||||
self.priv_data = None
|
self.priv_data = None
|
||||||
self.realname = None
|
self.realname = None
|
||||||
|
self.link_type = ifaceLinkType.UNKNOWN
|
||||||
|
|
||||||
def _set_attrs_from_dict(self, attrdict):
|
def _set_attrs_from_dict(self, attrdict):
|
||||||
self.auto = attrdict.get('auto', False)
|
self.auto = attrdict.get('auto', False)
|
||||||
@@ -401,6 +405,7 @@ class iface():
|
|||||||
del odict['raw_config']
|
del odict['raw_config']
|
||||||
del odict['linkstate']
|
del odict['linkstate']
|
||||||
del odict['env']
|
del odict['env']
|
||||||
|
del odict['link_type']
|
||||||
return odict
|
return odict
|
||||||
|
|
||||||
def __setstate__(self, dict):
|
def __setstate__(self, dict):
|
||||||
@@ -417,6 +422,7 @@ class iface():
|
|||||||
self.priv_flags = 0
|
self.priv_flags = 0
|
||||||
self.raw_config = []
|
self.raw_config = []
|
||||||
self.flags |= self._PICKLED
|
self.flags |= self._PICKLED
|
||||||
|
self.link_type = ifaceLinkType.UNKNOWN
|
||||||
|
|
||||||
def dump_raw(self, logger):
|
def dump_raw(self, logger):
|
||||||
indent = ' '
|
indent = ' '
|
||||||
|
@@ -112,7 +112,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
# by its link master interface, then dont set the link state.
|
# by its link master interface, then dont set the link state.
|
||||||
# But do allow user to change state of the link if the interface
|
# But do allow user to change state of the link if the interface
|
||||||
# is already with its link master (hence the master check).
|
# is already with its link master (hence the master check).
|
||||||
if ((ifaceobj.flags & iface.LINK_SLAVE) and
|
if ((ifaceobj.link_type == ifaceLinkType.LINK_SLAVE) and
|
||||||
not os.path.exists('/sys/class/net/%s/master' %ifaceobj.name)):
|
not os.path.exists('/sys/class/net/%s/master' %ifaceobj.name)):
|
||||||
return
|
return
|
||||||
if self.link_exists(ifaceobj.name):
|
if self.link_exists(ifaceobj.name):
|
||||||
@@ -123,7 +123,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
# by its link master interface, then dont set the link state.
|
# by its link master interface, then dont set the link state.
|
||||||
# But do allow user to change state of the link if the interface
|
# But do allow user to change state of the link if the interface
|
||||||
# is already with its link master (hence the master check).
|
# is already with its link master (hence the master check).
|
||||||
if ((ifaceobj.flags & iface.LINK_SLAVE) and
|
if ((ifaceobj.link_type == ifaceLinkType.LINK_SLAVE) and
|
||||||
not os.path.exists('/sys/class/net/%s/master' %ifaceobj.name)):
|
not os.path.exists('/sys/class/net/%s/master' %ifaceobj.name)):
|
||||||
return
|
return
|
||||||
if self.link_exists(ifaceobj.name):
|
if self.link_exists(ifaceobj.name):
|
||||||
@@ -357,14 +357,14 @@ class ifupdownMain(ifupdownBase):
|
|||||||
del_list.append(d)
|
del_list.append(d)
|
||||||
if ni:
|
if ni:
|
||||||
ni.add_to_upperifaces(upperifaceobj.name)
|
ni.add_to_upperifaces(upperifaceobj.name)
|
||||||
if (upperifaceobj.flags & iface.LINK_MASTER):
|
if upperifaceobj.link_type == ifaceLinkType.LINK_MASTER:
|
||||||
ni.flags |= iface.LINK_SLAVE
|
ni.link_type = ifaceLinkType.LINK_SLAVE
|
||||||
else:
|
else:
|
||||||
for di in dilist:
|
for di in dilist:
|
||||||
di.inc_refcnt()
|
di.inc_refcnt()
|
||||||
di.add_to_upperifaces(upperifaceobj.name)
|
di.add_to_upperifaces(upperifaceobj.name)
|
||||||
if (upperifaceobj.flags & iface.LINK_MASTER):
|
if upperifaceobj.flags == ifaceLinkType.LINK_MASTER:
|
||||||
di.flags |= iface.LINK_SLAVE
|
di.link_type = ifaceLinkType.LINK_SLAVE
|
||||||
|
|
||||||
for d in del_list:
|
for d in del_list:
|
||||||
dlist.remove(d)
|
dlist.remove(d)
|
||||||
|
@@ -673,3 +673,15 @@ class iproute2(utilsBase):
|
|||||||
|
|
||||||
def is_bridge(self, bridge):
|
def is_bridge(self, bridge):
|
||||||
return os.path.exists('/sys/class/net/%s/bridge' %bridge)
|
return os.path.exists('/sys/class/net/%s/bridge' %bridge)
|
||||||
|
|
||||||
|
def is_link_up(self, ifacename):
|
||||||
|
ret = False
|
||||||
|
try:
|
||||||
|
flags = self.read_file_oneline('/sys/class/net/%s/flags' %ifacename)
|
||||||
|
iflags = int(flags, 16)
|
||||||
|
if (iflags & 0x0001):
|
||||||
|
ret = True
|
||||||
|
except:
|
||||||
|
ret = False
|
||||||
|
pass
|
||||||
|
return ret
|
||||||
|
Reference in New Issue
Block a user