summaryrefslogtreecommitdiff
path: root/src/leap/eip/eipconnection.py
diff options
context:
space:
mode:
authorkali <kali@leap.se>2012-09-06 02:34:40 +0900
committerkali <kali@leap.se>2012-09-06 02:34:40 +0900
commitbd26d30f34104898dd6c5314dee688e27c82529b (patch)
tree226ed4f238369f8937c28e3d0f11258cbfb7b506 /src/leap/eip/eipconnection.py
parent6ef92e257ce1e605194cb26ff6cb804c7d2c3418 (diff)
parent8148bc9c8c113c41fcb18b397669b1f13447c653 (diff)
Merge branch 'feature/error-handling' into develop
Closes #504: design generic error handling solution. * app-wide logging config. * --logfile command line argument. * created basic exception hierarchy * conductor pushes exceptions to error queue * in Qt, error dialogs are created from exception attributes
Diffstat (limited to 'src/leap/eip/eipconnection.py')
-rw-r--r--src/leap/eip/eipconnection.py46
1 files changed, 26 insertions, 20 deletions
diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py
index 386b71be..5c54a986 100644
--- a/src/leap/eip/eipconnection.py
+++ b/src/leap/eip/eipconnection.py
@@ -3,15 +3,14 @@ EIP Connection Class
"""
from __future__ import (absolute_import,)
import logging
-
-logging.basicConfig()
-logger = logging.getLogger(name=__name__)
-logger.setLevel(logging.DEBUG)
+import Queue
from leap.eip.checks import EIPConfigChecker
from leap.eip import exceptions as eip_exceptions
from leap.eip.openvpnconnection import OpenVPNConnection
+logger = logging.getLogger(name=__name__)
+
class EIPConnection(OpenVPNConnection):
"""
@@ -25,8 +24,7 @@ class EIPConnection(OpenVPNConnection):
self.settingsfile = kwargs.get('settingsfile', None)
self.logfile = kwargs.get('logfile', None)
- # not used atm. but should.
- self.error_queue = []
+ self.error_queue = Queue.Queue()
status_signals = kwargs.pop('status_signals', None)
self.status = EIPConnectionStatus(callbacks=status_signals)
@@ -34,11 +32,19 @@ class EIPConnection(OpenVPNConnection):
super(EIPConnection, self).__init__(*args, **kwargs)
+ def has_errors(self):
+ return True if self.error_queue.qsize != 0 else True
+
def run_checks(self, skip_download=False):
"""
run all eip checks previous to attempting a connection
"""
- self.config_checker.run_all(skip_download=skip_download)
+ logger.debug('running conductor checks')
+ try:
+ self.config_checker.run_all(skip_download=skip_download)
+ self.run_openvpn_checks()
+ except Exception as exc:
+ self.error_queue.put(exc)
def connect(self):
"""
@@ -46,7 +52,6 @@ class EIPConnection(OpenVPNConnection):
"""
self.forget_errors()
self._try_connection()
- # XXX should capture errors?
def disconnect(self):
"""
@@ -67,11 +72,11 @@ class EIPConnection(OpenVPNConnection):
"""
return self.status.current
- def desired_connection_state(self):
- """
- returns the desired_connection state
- """
- return self.desired_con_state
+ #def desired_connection_state(self):
+ #"""
+ #returns the desired_connection state
+ #"""
+ #return self.desired_con_state
def poll_connection_state(self):
"""
@@ -109,26 +114,27 @@ class EIPConnection(OpenVPNConnection):
private method for disconnecting
"""
if self.subp is not None:
+ logger.debug('disconnecting...')
self.subp.terminate()
self.subp = None
- # XXX signal state changes! :)
- def _is_alive(self):
- """
- don't know yet
- """
- pass
+ #def _is_alive(self):
+ #"""
+ #don't know yet
+ #"""
+ #pass
def _connect(self):
"""
entry point for connection cascade methods.
"""
- #conn_result = ConState.DISCONNECTED
try:
conn_result = self._try_connection()
except eip_exceptions.UnrecoverableError as except_msg:
logger.error("FATAL: %s" % unicode(except_msg))
conn_result = self.status.UNRECOVERABLE
+
+ # XXX enqueue exceptions themselves instead?
except Exception as except_msg:
self.error_queue.append(except_msg)
logger.error("Failed Connection: %s" %