summaryrefslogtreecommitdiff
path: root/src/leap/eip/checks.py
diff options
context:
space:
mode:
authorkali <kali@leap.se>2012-10-08 07:57:42 +0900
committerkali <kali@leap.se>2012-10-08 07:57:42 +0900
commit4d195cd5b6e6600ccf0df78946cab6038a1fcaec (patch)
tree1362b2844f7e008cad8c29f26861566129af6edd /src/leap/eip/checks.py
parent3a77603eae5fea0b1efb226860e0264ccf96f41b (diff)
parent6728eb9afb21bad867e4052a6190a9bdb34c928a (diff)
Merge branch 'feature/network_check' into develop
Conflicts: src/leap/baseapp/mainwindow.py src/leap/eip/tests/test_checks.py
Diffstat (limited to 'src/leap/eip/checks.py')
-rw-r--r--src/leap/eip/checks.py83
1 files changed, 3 insertions, 80 deletions
diff --git a/src/leap/eip/checks.py b/src/leap/eip/checks.py
index 413a3467..f739c3e8 100644
--- a/src/leap/eip/checks.py
+++ b/src/leap/eip/checks.py
@@ -1,12 +1,12 @@
import logging
import ssl
-import platform
+#import platform
import time
import os
from gnutls import crypto
-import netifaces
-import ping
+#import netifaces
+#import ping
import requests
from leap import __branding as BRANDING
@@ -39,10 +39,6 @@ into base.tests to be invoked by the base leap init routines.
However, I'm testing them alltogether for the sake of having the whole unit
reachable and testable as a whole.
-LeapNetworkChecker
-------------------
-Network checks. To be moved to base.
-docs TBD
"""
@@ -52,79 +48,6 @@ def get_ca_cert():
return certs.where(ca_file)
-class LeapNetworkChecker(object):
- """
- all network related checks
- """
- # XXX to be moved to leap.base.checks
- # TODO eventually, use a more portable solution
- # like psutil
-
- def run_all(self, checker=None):
- if not checker:
- checker = self
- self.error = None # ?
-
- # for MVS
- checker.test_internet_connection()
- checker.is_internet_up()
- checker.ping_gateway()
-
- def test_internet_connection(self):
- # XXX we're not passing the error anywhere.
- # XXX we probably should raise an exception here?
- # unless we use this as smoke test
- try:
- # XXX remove this hardcoded random ip
- requests.get('http://216.172.161.165')
- except (requests.HTTPError, requests.RequestException) as e:
- self.error = e.message
- except requests.ConenctionError as e:
- if e.message == "[Errno 113] No route to host":
- if not self.is_internet_up():
- self.error = "No valid internet connection found."
- else:
- self.error = "Provider server appears to be down."
-
- def is_internet_up(self):
- iface, gateway = self.get_default_interface_gateway()
- self.ping_gateway(self)
-
- def get_default_interface_gateway(self):
- """only impletemented for linux so far."""
- if not platform.system() == "Linux":
- raise NotImplementedError
-
- f = open("/proc/net/route")
- route_table = f.readlines()
- f.close()
- #toss out header
- route_table.pop(0)
-
- default_iface = None
- gateway = None
- while route_table:
- line = route_table.pop(0)
- iface, destination, gateway = line.split('\t')[0:3]
- if destination == '00000000':
- default_iface = iface
- break
-
- if not default_iface:
- raise eipexceptions.NoDefaultInterfaceFoundError
-
- if default_iface not in netifaces.interfaces():
- raise eipexceptions.InterfaceNotFoundError
-
- return default_iface, gateway
-
- def ping_gateway(self, gateway):
- #TODO: Discuss how much packet loss (%) is acceptable.
- packet_loss = ping.quiet_ping(gateway)[0]
- if packet_loss > baseconstants.MAX_ICMP_PACKET_LOSS:
- raise eipexceptions.NoConnectionToGateway
-
-
class ProviderCertChecker(object):
"""
Several checks needed for getting