diff options
Diffstat (limited to 'src/leap/bitmask')
-rw-r--r-- | src/leap/bitmask/vpn/service.py | 9 | ||||
-rw-r--r-- | src/leap/bitmask/vpn/tunnel.py | 28 |
2 files changed, 21 insertions, 16 deletions
diff --git a/src/leap/bitmask/vpn/service.py b/src/leap/bitmask/vpn/service.py index c410f7e..c9e1890 100644 --- a/src/leap/bitmask/vpn/service.py +++ b/src/leap/bitmask/vpn/service.py @@ -112,7 +112,7 @@ class VPNService(HookableService): raise Exception('Could not start firewall') try: - self._tunnel.start() + result = yield self._tunnel.start() except Exception as exc: self._firewall.stop() # TODO get message from exception @@ -120,7 +120,12 @@ class VPNService(HookableService): self._domain = domain self._write_last(domain) - defer.returnValue({'result': 'started'}) + if result is True: + data = {'result': 'started'} + else: + data = {'result': 'failed', 'error': '%r' % result} + + defer.returnValue(data) def stop_vpn(self): if self._firewall.is_up(): diff --git a/src/leap/bitmask/vpn/tunnel.py b/src/leap/bitmask/vpn/tunnel.py index ce4707a..ae86320 100644 --- a/src/leap/bitmask/vpn/tunnel.py +++ b/src/leap/bitmask/vpn/tunnel.py @@ -99,23 +99,23 @@ class ConfiguredTunnel(object): @defer.inlineCallbacks def _start_vpn(self): - self.log.debug('VPN: start') - args = [self._vpnconfig, self._providerconfig, - self._host, self._port] - kwargs = {'openvpn_verb': 4, 'remotes': self._remotes, - 'restartfun': self._restart_vpn} - vpnproc = VPNProcess(*args, **kwargs) - self._vpnproc = vpnproc - try: + self.log.debug('VPN: start') + args = [self._vpnconfig, self._providerconfig, + self._host, self._port] + kwargs = {'openvpn_verb': 4, 'remotes': self._remotes, + 'restartfun': self._restart_vpn} + vpnproc = VPNProcess(*args, **kwargs) + self._vpnproc = vpnproc + self.__start_pre_up(vpnproc) cmd = self.__start_get_cmd(vpnproc) running = yield self.__start_spawn_proc(vpnproc, cmd) vpnproc.pid = running.pid defer.returnValue(True) except Exception: - # TODO need to propagate the error message properly. - defer.returnValue(False) + self._vpnproc.failed = True + raise def __start_pre_up(self, proc): try: @@ -130,17 +130,17 @@ class ConfiguredTunnel(object): except Exception as exc: self.log.error( 'Error while getting vpn command... {0!r}'.format(exc)) - raise + raise exc return cmd def __start_spawn_proc(self, proc, cmd): env = os.environ try: running_p = reactor.spawnProcess(proc, cmd[0], cmd, env) - except Exception as e: + except Exception as exc: self.log.error( - 'Error while spawning vpn process... {0!r}'.format(e)) - return False + 'Error while spawning vpn process... {0!r}'.format(exc)) + raise exc return running_p @defer.inlineCallbacks |