diff options
author | Kali Kaneko <kali@leap.se> | 2017-09-10 20:47:11 +0200 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2017-09-10 22:11:32 +0200 |
commit | 0331bcc09c5fb602366c93ee35c95a2e320b78bd (patch) | |
tree | cfb6e178cca7a0314c3151a3da58c0664c1fbed9 /src/leap/bitmask | |
parent | afff83e87bb7322c9d01f71b8b12dbdc7f9d6ffe (diff) |
[bug] mark vpn as failed if it had some problem starting
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 c410f7e4..c9e1890d 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 ce4707af..ae863203 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 |