]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
Fix whitespace issue + uninitialized variable issue
authorRoopa Prabhu <roopa@cumulusnetworks.com>
Fri, 13 Jun 2014 13:15:40 +0000 (06:15 -0700)
committerRoopa Prabhu <roopa@cumulusnetworks.com>
Wed, 16 Jul 2014 19:02:47 +0000 (12:02 -0700)
Ticket: CM-2997
Reviewed By: shm
Testing Done: Ran precommit

pkg/ifupdownmain.py
pkg/networkinterfaces.py

index 67c1d81b705921eefd67ac0b060c9c0f948fdb61..56107e299df613709391ed2de512306a566e9f2c 100644 (file)
@@ -408,7 +408,7 @@ class ifupdownMain(ifupdownBase):
         with open(self.addon_modules_configfile, 'r') as f:
             lines = f.readlines()
             for l in lines:
-                litems = l.rstrip(' \n').split(',')
+                litems = l.rstrip(' \n\t\r').split(',')
                 operation = litems[0]
                 mname = litems[1]
                 self.module_ops[operation].append(mname)
@@ -705,7 +705,8 @@ class ifupdownMain(ifupdownBase):
                                if self._iface_whitelisted(auto, allow_classes,
                                                 excludepats, i)]
         if not filtered_ifacenames:
-            raise Exception('no ifaces found matching given allow lists')
+            raise Exception('no ifaces found matching given allow lists ' +
+                    '(interfaces were probably never up)')
 
         if printdependency:
             self.populate_dependency_info(ops, filtered_ifacenames)
@@ -791,6 +792,7 @@ class ifupdownMain(ifupdownBase):
         """ reload interface config """
 
         allow_classes = []
+        new_ifaceobjdict = {}
 
         self.logger.debug('reloading interface config ..')
         if auto:
@@ -802,6 +804,10 @@ class ifupdownMain(ifupdownBase):
         except:
             raise
 
+        if not self.ifaceobjdict:
+            self.logger.warn("nothing to reload ..exiting.")
+            return
+
         # generate dependency graph of interfaces
         self.populate_dependency_info(upops)
         if (not usecurrentconfig and self.STATEMANAGER_ENABLE
@@ -866,6 +872,8 @@ class ifupdownMain(ifupdownBase):
 
         # Now, run 'up' with new config dict
         # reset statemanager update flag to default
+        if not new_ifaceobjdict:
+            return
         self.ifaceobjdict = new_ifaceobjdict
         self.dependency_graph = new_dependency_graph
         ifacenames = self.ifaceobjdict.keys()
index db420e51cb6b61f2f5f08bfe74c6fd001f3172ed..092e51b1733f738f06f7ddbe0d13410c72d852ee 100644 (file)
@@ -15,6 +15,8 @@ import os
 from iface import *
 from template import templateEngine
 
+whitespaces = '\n\t\r '
+
 class networkInterfaces():
 
     hotplugs = {}
@@ -80,7 +82,7 @@ class networkInterfaces():
         self.callbacks[callback_name] = callback_func
 
     def ignore_line(self, line):
-        l = line.strip('\n ')
+        l = line.strip(whitespaces)
         if not l or l[0] == '#':
             return 1
         return 0
@@ -163,7 +165,7 @@ class networkInterfaces():
         line_idx = cur_idx
 
         ifaceobj = iface()
-        iface_line = lines[cur_idx].strip('\n ')
+        iface_line = lines[cur_idx].strip(whitespaces)
         iface_attrs = iface_line.split()
         ifacename = iface_attrs[1]
 
@@ -171,7 +173,7 @@ class networkInterfaces():
     
         iface_config = collections.OrderedDict()
         for line_idx in range(cur_idx + 1, len(lines)):
-            l = lines[line_idx].strip('\n\t ')
+            l = lines[line_idx].strip(whitespaces)
             if self.ignore_line(l) == 1:
                 continue
             if self._is_keyword(l.split()[0]):
@@ -247,12 +249,15 @@ class networkInterfaces():
         line_idx = 0
         lines_consumed = 0
         raw_config = filedata.split('\n')
-        lines = [l.strip(' \n') for l in raw_config]
+        lines = [l.strip(whitespaces) for l in raw_config]
         while (line_idx < len(lines)):
             if self.ignore_line(lines[line_idx]):
                 line_idx += 1
                 continue
             words = lines[line_idx].split()
+            if not words:
+                line_idx += 1
+                continue
             # Check if first element is a supported keyword
             if self._is_keyword(words[0]):
                 keyword_func = self._get_keyword_func(words[0])