mirror of
				https://github.com/CumulusNetworks/ifupdown2.git
				synced 2024-05-06 15:54:50 +00:00 
			
		
		
		
	addons,ifupdown,sbin: adding ifquery --with-defaults option
Ticket: CM-7840 Reviewed By: Roopa Prabhu Testing Done: yes, by installing ifupdown .deb file onto dell-s3000-02 This patch adds a new argument '--with-defaults' to 'ifquery' when 'ifquery --with-defaults' is executed, running states of all interface attributes are compared against respective configured attributes from /etc/network/interfaces file, if configured. Otherwise, compared against default attributes from policy file This patch also: (1) fixes ifquery check failure for bridge-* stp attributes. (2) removes vrf-default-route and vrf-cgroup attributes from ifupdown2 policy and just have the vrf-helper attribute Signed-off-by: Nikhil <nikhil@cumulusnetworks.com>
This commit is contained in:
		@@ -14,6 +14,7 @@ class ifupdownFlags():
 | 
			
		||||
                self.NOWAIT = False
 | 
			
		||||
                self.PERFMODE = False
 | 
			
		||||
                self.CACHE = False
 | 
			
		||||
                self.WITHDEFAULTS = False
 | 
			
		||||
 | 
			
		||||
                # Flags
 | 
			
		||||
                self.CACHE_FLAGS = 0x0
 | 
			
		||||
 
 | 
			
		||||
@@ -171,7 +171,8 @@ class ifupdownMain(ifupdownBase):
 | 
			
		||||
                 cache=False, addons_enable=True, statemanager_enable=True,
 | 
			
		||||
                 interfacesfile='/etc/network/interfaces',
 | 
			
		||||
                 interfacesfileiobuf=None,
 | 
			
		||||
                 interfacesfileformat='native'):
 | 
			
		||||
                 interfacesfileformat='native',
 | 
			
		||||
                 withdefaults=False):
 | 
			
		||||
        """This member function initializes the ifupdownmain object.
 | 
			
		||||
 | 
			
		||||
        Kwargs:
 | 
			
		||||
@@ -188,6 +189,7 @@ class ifupdownMain(ifupdownBase):
 | 
			
		||||
        self.logger = logging.getLogger('ifupdown')
 | 
			
		||||
        ifupdownflags.flags.FORCE = force
 | 
			
		||||
        ifupdownflags.flags.DRYRUN = dryrun
 | 
			
		||||
        ifupdownflags.flags.WITHDEFAULTS = withdefaults
 | 
			
		||||
        ifupdownflags.flags.NOWAIT = nowait
 | 
			
		||||
        ifupdownflags.flags.PERFMODE = perfmode
 | 
			
		||||
        ifupdownflags.flags.CACHE = cache
 | 
			
		||||
@@ -895,13 +897,13 @@ class ifupdownMain(ifupdownBase):
 | 
			
		||||
                # continue reading
 | 
			
		||||
                pass
 | 
			
		||||
 | 
			
		||||
    def _sched_ifaces(self, ifacenames, ops, withdefaults=False,
 | 
			
		||||
                      skipupperifaces=False, followdependents=True, sort=False):
 | 
			
		||||
    def _sched_ifaces(self, ifacenames, ops, skipupperifaces=False,
 | 
			
		||||
                      followdependents=True, sort=False):
 | 
			
		||||
        self.logger.debug('scheduling \'%s\' for %s'
 | 
			
		||||
                          %(str(ops), str(ifacenames)))
 | 
			
		||||
        self._pretty_print_ordered_dict('dependency graph',
 | 
			
		||||
                    self.dependency_graph)
 | 
			
		||||
        ifaceScheduler.sched_ifaces(self, ifacenames, ops, withdefaults,
 | 
			
		||||
        ifaceScheduler.sched_ifaces(self, ifacenames, ops,
 | 
			
		||||
                        dependency_graph=self.dependency_graph,
 | 
			
		||||
                        order=ifaceSchedulerFlags.INORDER
 | 
			
		||||
                            if 'down' in ops[0]
 | 
			
		||||
@@ -1209,7 +1211,7 @@ class ifupdownMain(ifupdownBase):
 | 
			
		||||
    def query(self, ops, auto=False, format_list=False, allow_classes=None,
 | 
			
		||||
              ifacenames=None,
 | 
			
		||||
              excludepats=None, printdependency=None,
 | 
			
		||||
              format='native', type=None, withdefaults=False):
 | 
			
		||||
              format='native', type=None):
 | 
			
		||||
        """ query an interface """
 | 
			
		||||
 | 
			
		||||
        self.set_type(type)
 | 
			
		||||
@@ -1273,7 +1275,7 @@ class ifupdownMain(ifupdownBase):
 | 
			
		||||
        elif ops[0] == 'query-raw':
 | 
			
		||||
            return self.print_ifaceobjs_raw(filtered_ifacenames)
 | 
			
		||||
 | 
			
		||||
        ret = self._sched_ifaces(filtered_ifacenames, ops, withdefaults,
 | 
			
		||||
        ret = self._sched_ifaces(filtered_ifacenames, ops,
 | 
			
		||||
                           followdependents=True
 | 
			
		||||
                           if self.flags.WITH_DEPENDS else False)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -49,7 +49,7 @@ class ifaceScheduler():
 | 
			
		||||
        cls._SCHED_STATUS = state
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def run_iface_op(cls, ifupdownobj, ifaceobj, op, withdefaults=False, cenv=None):
 | 
			
		||||
    def run_iface_op(cls, ifupdownobj, ifaceobj, op, cenv=None):
 | 
			
		||||
        """ Runs sub operation on an interface """
 | 
			
		||||
        ifacename = ifaceobj.name
 | 
			
		||||
 | 
			
		||||
@@ -80,11 +80,11 @@ class ifaceScheduler():
 | 
			
		||||
                            continue
 | 
			
		||||
                        ifupdownobj.logger.debug(msg)
 | 
			
		||||
                        m.run(ifaceobj, op, query_ifaceobj,
 | 
			
		||||
                              ifaceobj_getfunc=ifupdownobj.get_ifaceobjs, withdefaults=withdefaults)
 | 
			
		||||
                              ifaceobj_getfunc=ifupdownobj.get_ifaceobjs)
 | 
			
		||||
                    else:
 | 
			
		||||
                        ifupdownobj.logger.debug(msg)
 | 
			
		||||
                        m.run(ifaceobj, op,
 | 
			
		||||
                              ifaceobj_getfunc=ifupdownobj.get_ifaceobjs, withdefaults=withdefaults)
 | 
			
		||||
                              ifaceobj_getfunc=ifupdownobj.get_ifaceobjs)
 | 
			
		||||
            except Exception, e:
 | 
			
		||||
                if not ifupdownobj.ignore_error(str(e)):
 | 
			
		||||
                   err = 1
 | 
			
		||||
@@ -117,7 +117,7 @@ class ifaceScheduler():
 | 
			
		||||
                    ifupdownobj.log_error(str(e))
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def run_iface_list_ops(cls, ifupdownobj, ifaceobjs, ops, withdefaults=False):
 | 
			
		||||
    def run_iface_list_ops(cls, ifupdownobj, ifaceobjs, ops):
 | 
			
		||||
        """ Runs all operations on a list of interface
 | 
			
		||||
            configurations for the same interface
 | 
			
		||||
        """
 | 
			
		||||
@@ -151,7 +151,7 @@ class ifaceScheduler():
 | 
			
		||||
                                   %(ifaceobjs[0].name, str(e)))
 | 
			
		||||
                    pass
 | 
			
		||||
            for ifaceobj in ifaceobjs:
 | 
			
		||||
                cls.run_iface_op(ifupdownobj, ifaceobj, op, withdefaults,
 | 
			
		||||
                cls.run_iface_op(ifupdownobj, ifaceobj, op,
 | 
			
		||||
                    cenv=ifupdownobj.generate_running_env(ifaceobj, op)
 | 
			
		||||
                        if ifupdownobj.config.get('addon_scripts_support',
 | 
			
		||||
                            '0') == '1' else None)
 | 
			
		||||
@@ -212,8 +212,8 @@ class ifaceScheduler():
 | 
			
		||||
        return True
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def run_iface_graph(cls, ifupdownobj, ifacename, ops, withdefaults=False,
 | 
			
		||||
                        parent=None, order=ifaceSchedulerFlags.POSTORDER,
 | 
			
		||||
    def run_iface_graph(cls, ifupdownobj, ifacename, ops, parent=None,
 | 
			
		||||
                        order=ifaceSchedulerFlags.POSTORDER,
 | 
			
		||||
                        followdependents=True):
 | 
			
		||||
        """ runs interface by traversing all nodes rooted at itself """
 | 
			
		||||
 | 
			
		||||
@@ -235,7 +235,7 @@ class ifaceScheduler():
 | 
			
		||||
 | 
			
		||||
        # If inorder, run the iface first and then its dependents
 | 
			
		||||
        if order == ifaceSchedulerFlags.INORDER:
 | 
			
		||||
            cls.run_iface_list_ops(ifupdownobj, ifaceobjs, ops, False)
 | 
			
		||||
            cls.run_iface_list_ops(ifupdownobj, ifaceobjs, ops)
 | 
			
		||||
 | 
			
		||||
        for ifaceobj in ifaceobjs:
 | 
			
		||||
            # Run lowerifaces or dependents
 | 
			
		||||
@@ -254,12 +254,11 @@ class ifaceScheduler():
 | 
			
		||||
                                    if ifupdownobj.is_iface_noconfig(d)]
 | 
			
		||||
                        if new_dlist:
 | 
			
		||||
                            cls.run_iface_list(ifupdownobj, new_dlist, ops,
 | 
			
		||||
                                           withdefaults, ifacename, order,
 | 
			
		||||
                                           followdependents,
 | 
			
		||||
                                           ifacename, order, followdependents,
 | 
			
		||||
                                           continueonfailure=False)
 | 
			
		||||
                    else:
 | 
			
		||||
                        cls.run_iface_list(ifupdownobj, dlist, ops,
 | 
			
		||||
                                            withdefaults, ifacename, order,
 | 
			
		||||
                                            ifacename, order,
 | 
			
		||||
                                            followdependents,
 | 
			
		||||
                                            continueonfailure=False)
 | 
			
		||||
                except Exception, e:
 | 
			
		||||
@@ -271,17 +270,18 @@ class ifaceScheduler():
 | 
			
		||||
                                                ifaceStatus.ERROR)
 | 
			
		||||
                        raise
 | 
			
		||||
        if order == ifaceSchedulerFlags.POSTORDER:
 | 
			
		||||
            cls.run_iface_list_ops(ifupdownobj, ifaceobjs, ops, withdefaults)
 | 
			
		||||
            cls.run_iface_list_ops(ifupdownobj, ifaceobjs, ops)
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def run_iface_list(cls, ifupdownobj, ifacenames, ops, withdefaults=False,
 | 
			
		||||
                       parent=None, order=ifaceSchedulerFlags.POSTORDER,
 | 
			
		||||
    def run_iface_list(cls, ifupdownobj, ifacenames,
 | 
			
		||||
                       ops, parent=None, order=ifaceSchedulerFlags.POSTORDER,
 | 
			
		||||
                       followdependents=True, continueonfailure=True):
 | 
			
		||||
        """ Runs interface list """
 | 
			
		||||
 | 
			
		||||
        for ifacename in ifacenames:
 | 
			
		||||
            try:
 | 
			
		||||
              cls.run_iface_graph(ifupdownobj, ifacename, ops, withdefaults,
 | 
			
		||||
                      parent, order, followdependents)
 | 
			
		||||
              cls.run_iface_graph(ifupdownobj, ifacename, ops, parent,
 | 
			
		||||
                      order, followdependents)
 | 
			
		||||
            except Exception, e:
 | 
			
		||||
                if continueonfailure:
 | 
			
		||||
                    if ifupdownobj.logger.isEnabledFor(logging.DEBUG):
 | 
			
		||||
@@ -311,7 +311,7 @@ class ifaceScheduler():
 | 
			
		||||
 | 
			
		||||
        if not skip_root:
 | 
			
		||||
            # run the iface first and then its upperifaces
 | 
			
		||||
            cls.run_iface_list_ops(ifupdownobj, ifaceobjs, ops, False)
 | 
			
		||||
            cls.run_iface_list_ops(ifupdownobj, ifaceobjs, ops)
 | 
			
		||||
        for ifaceobj in ifaceobjs:
 | 
			
		||||
            # Run upperifaces
 | 
			
		||||
            ulist = ifaceobj.upperifaces
 | 
			
		||||
@@ -405,7 +405,7 @@ class ifaceScheduler():
 | 
			
		||||
                ifaceobjs = ifupdownobj.get_ifaceobjs(u)
 | 
			
		||||
                if not ifaceobjs:
 | 
			
		||||
                   continue
 | 
			
		||||
                cls.run_iface_list_ops(ifupdownobj, ifaceobjs, ops, False)
 | 
			
		||||
                cls.run_iface_list_ops(ifupdownobj, ifaceobjs, ops)
 | 
			
		||||
            except Exception, e:
 | 
			
		||||
                if continueonfailure:
 | 
			
		||||
                   self.logger.warn('%s' %str(e))
 | 
			
		||||
@@ -434,7 +434,7 @@ class ifaceScheduler():
 | 
			
		||||
        return ifacenames_sorted
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def sched_ifaces(cls, ifupdownobj, ifacenames, ops, withdefaults=False,
 | 
			
		||||
    def sched_ifaces(cls, ifupdownobj, ifacenames, ops,
 | 
			
		||||
                dependency_graph=None, indegrees=None,
 | 
			
		||||
                order=ifaceSchedulerFlags.POSTORDER,
 | 
			
		||||
                followdependents=True, skipupperifaces=False, sort=False):
 | 
			
		||||
@@ -529,7 +529,7 @@ class ifaceScheduler():
 | 
			
		||||
                run_queue.reverse()
 | 
			
		||||
 | 
			
		||||
        # run interface list
 | 
			
		||||
        cls.run_iface_list(ifupdownobj, run_queue, ops, withdefaults,
 | 
			
		||||
        cls.run_iface_list(ifupdownobj, run_queue, ops,
 | 
			
		||||
                           parent=None, order=order,
 | 
			
		||||
                           followdependents=followdependents)
 | 
			
		||||
        if not cls.get_sched_status():
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user