diff options
| -rw-r--r-- | README.rst | 18 | ||||
| -rw-r--r-- | pkg/requirements.pip | 1 | ||||
| -rw-r--r-- | src/leap/eip/exceptions.py | 7 | ||||
| -rw-r--r-- | src/leap/eip/openvpnconnection.py | 15 | ||||
| -rw-r--r-- | src/leap/eip/tests/test_openvpnconnection.py | 12 | 
5 files changed, 51 insertions, 2 deletions
| @@ -29,6 +29,13 @@ If you are installing in a virtualenv:    pip install -r pkg/requirements.pip +# **note**: I _think_ setuptools is needed for build process only.                      +# we should separate what's needed as a global lib dependency, and what's a dependency that +# still can be retrieved using pip.                                                   +                                                         +If you are installing in a virtualenv:                                                +  pip install -r pkg/requirements.pip +  Install PyQt  ------------ @@ -128,11 +135,20 @@ or  nosetests leap.util.test_leap_argparse +Colorized output +---------------- +Install rednose locally and activate it. + +  (leap_client)% pip install rednose +  (leap_client)% export NOSE_REDNOSE=1 + +enjoy :) +  Tox  ---  For running testsuite against all the supported python versions (currently 2.6 and 2.7), run: -tox -v +  tox -v  Compiling resource/ui files diff --git a/pkg/requirements.pip b/pkg/requirements.pip index d6c6713f..2406884d 100644 --- a/pkg/requirements.pip +++ b/pkg/requirements.pip @@ -1,6 +1,7 @@  argparse # only for python 2.6  requests  ping +psutil  netifaces  python-gnutls==1.1.9  # see https://bugs.launchpad.net/ubuntu/+source/python-gnutls/+bug/1027129  jsonschema diff --git a/src/leap/eip/exceptions.py b/src/leap/eip/exceptions.py index f048621f..a6216caa 100644 --- a/src/leap/eip/exceptions.py +++ b/src/leap/eip/exceptions.py @@ -93,6 +93,13 @@ class LeapBadConfigFetchedError(Warning):      message = "provider sent a malformed json file"      usermessage = "an error occurred during configuratio of leap services" + +class OpenVPNAlreadyRunning(EIPClientError): +    message = "Another OpenVPN Process is already running." +    usermessage = ("Another OpenVPN Process has been detected." +                   "Please close it before starting leap-client") + +  #  # errors still needing some love  # diff --git a/src/leap/eip/openvpnconnection.py b/src/leap/eip/openvpnconnection.py index f4d1c449..a835ead9 100644 --- a/src/leap/eip/openvpnconnection.py +++ b/src/leap/eip/openvpnconnection.py @@ -3,6 +3,7 @@ OpenVPN Connection  """  from __future__ import (print_function)  import logging +import psutil  import socket  import time  from functools import partial @@ -87,6 +88,7 @@ to be triggered for each one of them.      def run_openvpn_checks(self):          logger.debug('running openvpn checks') +        self._check_if_running_instance()          self._set_ovpn_command()          self._check_vpn_keys() @@ -156,9 +158,20 @@ to be triggered for each one of them.              raise eip_exceptions.EIPNoCommandError          if self.subp is not None:              logger.debug('cowardly refusing to launch subprocess again') -            return +          self._launch_openvpn() +    def _check_if_running_instance(self): +        """ +        check if openvpn is already running +        """ +        for process in psutil.get_process_list(): +            if process.name == "openvpn": +                logger.debug('an openvpn instance is already running.') +                raise eip_exceptions.OpenVPNAlreadyRunning + +        logger.debug('no openvpn instance found.') +      def cleanup(self):          """          terminates child subprocess diff --git a/src/leap/eip/tests/test_openvpnconnection.py b/src/leap/eip/tests/test_openvpnconnection.py index 885c80b3..61769f04 100644 --- a/src/leap/eip/tests/test_openvpnconnection.py +++ b/src/leap/eip/tests/test_openvpnconnection.py @@ -1,6 +1,7 @@  import logging  import os  import platform +import psutil  import shutil  #import socket @@ -16,6 +17,7 @@ from mock import Mock, patch  # MagicMock  from leap.eip import config as eipconfig  from leap.eip import openvpnconnection +from leap.eip import exceptions as eipexceptions  from leap.eip.udstelnet import UDSTelnet  from leap.testing.basetest import BaseLeapTest @@ -73,6 +75,16 @@ class OpenVPNConnectionTest(BaseLeapTest):      # tests      # +    def test_detect_vpn(self): +        openvpn_connection = openvpnconnection.OpenVPNConnection() +        with patch.object(psutil, "get_process_list") as mocked_psutil: +            with self.assertRaises(eipexceptions.OpenVPNAlreadyRunning): +                mocked_process = Mock() +                mocked_process.name = "openvpn" +                mocked_psutil.return_value = [mocked_process] +                openvpn_connection._check_if_running_instance() +        openvpn_connection._check_if_running_instance() +      @unittest.skipIf(_system == "Windows", "lin/mac only")      def test_lin_mac_default_init(self):          """ | 
