Unverified Commit d6e1d9c1 authored by meskio's avatar meskio

[bug] return allways a valid state from openvpn

Even if we don't recognize the state that openvpn is providing. Add
TCP_CONNECT state as well.
parent 1bb23d6c
Pipeline #18142 passed with stages
in 62 minutes and 59 seconds
......@@ -20,6 +20,7 @@ VPN State.
"""
import time
from twisted.logger import Logger
class State(object):
......@@ -29,6 +30,8 @@ class State(object):
OpenVPN Management documentation.
"""
log = Logger()
CONNECTING = 'CONNECTING'
WAIT = 'WAIT'
AUTH = 'AUTH'
......@@ -54,6 +57,7 @@ class State(object):
'ADD_ROUTES': 'Adding routes to system',
'CONNECTED': 'Initialization Sequence Completed',
'RECONNECTING': 'A restart has occurred',
'TCP_CONNECT': 'Stablishing tcp connection',
'EXITING': 'A graceful exit is in progress',
'OFF': 'Disconnected',
'FAILED': 'A failure has occurred',
......@@ -68,6 +72,7 @@ class State(object):
'ADD_ROUTES': STARTING,
'CONNECTED': ON,
'RECONNECTING': STARTING,
'TCP_CONNECT': STARTING,
'EXITING': STOPPING,
'OFF': OFF,
'FAILED': OFF
......@@ -79,11 +84,15 @@ class State(object):
@classmethod
def get_legend(cls, state):
return cls._legend.get(state)
return cls._legend.get(state, '')
@classmethod
def get_simple(cls, state):
return cls._simple.get(state)
simple = cls._simple.get(state)
if not simple:
cls.log.warn('Unkown openvpn state: %s' % state)
simple = cls.FAILED
return simple
@property
def simple(self):
......
......@@ -250,19 +250,13 @@ class _VPNProcess(protocol.ProcessProtocol):
def status(self):
if self.failed:
return {'status': 'failed', 'error': self.errmsg}
try:
state = self.getState()
if state:
_status = state.simple.lower()
status = {'status': _status, 'error': None}
except AttributeError:
raise
# BUG -- glitch due to proto.state transition?
# still needed?
# state = self.getState()
# if state:
# _status = state.simple.lower()
# status = {'status': _status, 'error': None}
state = self.getState()
if state:
_status = state.simple.lower()
else:
_status = None
status = {'status': _status, 'error': None}
if self.proto and self.proto.traffic:
remote = self.proto.remote
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment