]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
addons: vrf: bring up vrf master when ALL or CLASS
authorRoopa Prabhu <roopa@cumulusnetworks.com>
Fri, 5 Aug 2016 18:32:21 +0000 (11:32 -0700)
committerRoopa Prabhu <roopa@cumulusnetworks.com>
Sun, 7 Aug 2016 19:41:30 +0000 (12:41 -0700)
Ticket: CM-12084
Reviewed By: julien, nikhil
Testing Done: Tested ifreload/ifup/ifdown --allow=<class>

vrf slave brings up the master if master is not up yet.
Today this is done only when ALL (auto) option is set
just as an optimization. because you dont want to bring
up the master in cases where user just wants to
bring up the vrf slave. eg ifup -v eth0.

This does not work so well, when user uses
--allow classes to bring up vrf master and slaves
together (eg mgmt vrf).

This patch removes the ALL check when bringing
up master and replaces it with an ALL or
CLASS check. ie make sure vrf master belongs to the
same class as you when CLASS is specified.

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
addons/vrf.py

index 96adb72738f6e62785c32dda7fbdeef63565bcbd..b35866c2aec64fcfefb6d17eaedf7f56c669dd93 100644 (file)
@@ -10,6 +10,7 @@ import errno
 import fcntl
 import atexit
 import re
+from sets import Set
 from ifupdown.iface import *
 from ifupdown.utils import utils
 import ifupdown.policymanager as policymanager
@@ -306,7 +307,7 @@ class vrf(moduleBase):
         return True
 
     def _up_vrf_slave_without_master(self, ifacename, vrfname, ifaceobj,
-                                      ifaceobj_getfunc):
+                                     vrf_master_objs):
         """ If we have a vrf slave that has dhcp configured, bring up the
             vrf master now. This is needed because vrf has special handling
             in dhclient hook which requires the vrf master to be present """
@@ -319,10 +320,6 @@ class vrf(moduleBase):
             self.logger.info('%s: vrf master %s exists returning'
                              %(ifacename, vrf_master))
             return
-        vrf_master_objs = ifaceobj_getfunc(vrf_master)
-        if not vrf_master_objs:
-            self.logger.warn('%s: vrf master ifaceobj not found' %ifacename)
-            return
         self.logger.info('%s: bringing up vrf master %s'
                          %(ifacename, vrf_master))
         for mobj in vrf_master_objs:
@@ -374,14 +371,26 @@ class vrf(moduleBase):
                 if not upper or upper != vrfname:
                     self._handle_existing_connections(ifaceobj, vrfname)
                     self.ipcmd.link_set(ifacename, 'master', vrfname)
-            elif ifupdownflags.flags.ALL and ifaceobj:
-                self._up_vrf_slave_without_master(ifacename, vrfname, ifaceobj,
-                                                  ifaceobj_getfunc)
+            elif ifaceobj:
+                vrf_master_objs = ifaceobj_getfunc(vrfname)
+                if not vrf_master_objs:
+                    self.logger.warn('%s: vrf master ifaceobj not found'
+                                     %ifacename)
+                    return
+                if (ifupdownflags.flags.ALL or
+                    (ifupdownflags.flags.CLASS and
+                     ifaceobj.classes and vrf_master_objs[0].classes and
+                     Set(ifaceobj.classes).intersection(vrf_master_objs[0].classes))):
+                    self._up_vrf_slave_without_master(ifacename, vrfname,
+                                                      ifaceobj,
+                                                      vrf_master_objs)
+                else:
+                    master_exists = False
             else:
                 master_exists = False
             if master_exists:
                 netlink.link_set_updown(ifacename, "up")
-            elif ifupdownflags.flags.ALL:
+            else:
                 self.log_error('vrf %s not around, skipping vrf config'
                                %(vrfname), ifaceobj)
         except Exception, e: