]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
Check for duplicate interfaces
authorroopa <roopa@cumulusnetworks.com>
Sun, 30 Mar 2014 15:15:06 +0000 (08:15 -0700)
committerroopa <roopa@cumulusnetworks.com>
Sun, 30 Mar 2014 15:15:06 +0000 (08:15 -0700)
Ticket: CM-2509
Reviewed By:
Testing Done: Tested interfaces file with duplicate entries

Old ifupdown allowed multiple stanza's for the same interface.
To support older files ifupdown2 will continue to support duplicate interfaces.
However this check will warn on interfaces with same config more than
once. The check is done at a higher level during parsing and hence only
does a string compare of the iface section.

pkg/ifupdownmain.py

index 3bd825ceb87bb89d3270107ca364ca228ba661cf..ea0bb2e9cb15a678c9dc38cae65f4b0cc2e69f61 100644 (file)
@@ -325,8 +325,16 @@ class ifupdownMain(ifupdownBase):
                 self.dependency_graph[i] = dlist
 
     def _save_iface(self, ifaceobj):
-        self.ifaceobjdict.setdefault(ifaceobj.name,
-                        []).append(ifaceobj)
+        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
+
+        self.ifaceobjdict[ifaceobj.name].append(ifaceobj)
 
     def _module_syntax_checker(self, attrname, attrval):
         for m, mdict in self.module_attrs.items():