Initial error handling code for dropped and timed-out connections

Change-Id: I350c193350b1551e7ac01c2dc8a114e1cffcaad9
diff --git a/drivers/CiscoSX300.py b/drivers/CiscoSX300.py
index 66212b5..69f707a 100644
--- a/drivers/CiscoSX300.py
+++ b/drivers/CiscoSX300.py
@@ -29,7 +29,7 @@
     sys.path.insert(0, vlandpath)
     sys.path.insert(0, "%s/.." % vlandpath)
 
-from errors import CriticalError, InputError
+from errors import CriticalError, InputError, PExpectError
 
 class CiscoSX300(SwitchDriver):
 
@@ -432,7 +432,15 @@
     def _cli(self, text, echo=True):
         self.connection.send(text + '\r')
         if echo:
-            self.connection.expect(text)
+            try:
+                self.connection.expect(text)
+            except (pexect.EOF, pexect.TIMEOUT):
+                # Something went wrong; logout, log in and try again!
+                print "PEXPECT FAILURE, RECONNECT"
+                raise PExpectError("_cli failed on %s", % text)
+            except:
+                print "Unexpected error:", sys.exc_info()[0]
+                raise
 
 if __name__ == "__main__":
 #    p = CiscoSX300('10.172.2.52', 23)