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

ifupdownmain: squash multiple iface stanzas for the same interface by

default

Ticket:
Reviewed By: CCR-4268 (previous review)
Testing Done: Tested ifup/ifdown/ifreload/ifquery of multiple iface stanzas for
same interface

This patch is an extension to previous commit 99ce689411.
The previous commit squashes both external (ifquery) and internal
(ifup/ifdown/ifreload) representation of multiple iface stanzas into
one and it is off by default.

What we really want is internal representation to be squashed by
default. To that effect this patch introduces a new config flag
ifaceobj_squash_internal to only squash internal representation which is
used by ifup/ifdown/ifreload. ifquery forces this flag to off so that
external representations remain unsquashed and user does not see any
difference. This flag is on by default.

User can still get a squashed external representation if he sets
ifaceobj_squash=1 in ifupdown2.conf

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
This commit is contained in:
Roopa Prabhu
2016-03-16 18:38:43 -07:00
parent dad6af7eb7
commit 2ddd65c587

View File

@@ -262,9 +262,18 @@ class ifupdownMain(ifupdownBase):
'state changes will be delayed till the ' +
'masters admin state change.')
# squash iface objects for same interface both internal and
# external representation. It is off by default.
self._ifaceobj_squash = True if self.config.get(
'ifaceobj_squash', '0') == '1' else False
# squash iface objects for same interface internal
# representation only. External representation as seen by ifquery
# will continue to see multiple iface stanzas if it was specified
# that way by the user. It is on by default.
self._ifaceobj_squash_internal = True if self.config.get(
'ifaceobj_squash_internal', '1') == '1' else False
# initialize global config object with config passed by the user
# This makes config available to addon modules
ifupdownConfig.config = self.config
@@ -656,6 +665,23 @@ class ifupdownMain(ifupdownBase):
self._cache_no_repeats[k] = v
return False
def _save_iface_squash(self, ifaceobj):
""" squash ifaceobjects belonging to same iface
into a single object """
if self._check_config_no_repeats(ifaceobj):
return
ifaceobj.priv_flags = ifacePrivFlags()
if not self._link_master_slave:
ifaceobj.link_type = ifaceLinkType.LINK_NA
currentifaceobjlist = self.ifaceobjdict.get(ifaceobj.name)
if not currentifaceobjlist:
self.ifaceobjdict[ifaceobj.name] = [ifaceobj]
return
if ifaceobj.compare(currentifaceobjlist[0]):
self.logger.warn('duplicate interface %s found' %ifaceobj.name)
return
currentifaceobjlist[0].squash(ifaceobj)
def _save_iface(self, ifaceobj):
if self._check_config_no_repeats(ifaceobj):
return
@@ -668,10 +694,6 @@ class ifupdownMain(ifupdownBase):
if not self._ifaceobj_squash:
ifaceobj.flags |= ifaceobj.YOUNGEST_SIBLING
return
if self._ifaceobj_squash:
# squash with old iface object
currentifaceobjlist[0].squash(ifaceobj)
return
if ifaceobj.compare(currentifaceobjlist[0]):
self.logger.warn('duplicate interface %s found' %ifaceobj.name)
return
@@ -728,7 +750,10 @@ class ifupdownMain(ifupdownBase):
self.interfacesfileformat,
template_engine=self.config.get('template_engine'),
template_lookuppath=self.config.get('template_lookuppath'))
nifaces.subscribe('iface_found', self._save_iface)
if self._ifaceobj_squash or self._ifaceobj_squash_internal:
nifaces.subscribe('iface_found', self._save_iface_squash)
else:
nifaces.subscribe('iface_found', self._save_iface)
nifaces.subscribe('validateifaceattr',
self._iface_configattr_syntax_checker)
nifaces.subscribe('validateifaceobj', self._ifaceobj_syntax_checker)
@@ -1184,6 +1209,11 @@ class ifupdownMain(ifupdownBase):
self.set_type(type)
# Let us forget internal squashing when it comes to
# ifquery. It can surprise people relying of ifquery
# output
self._ifaceobj_squash_internal = False
if allow_classes:
self.flags.IFACE_CLASS = True
if self.flags.STATEMANAGER_ENABLE and ops[0] == 'query-savedstate':