online bottlenecks soak throughtputs
[releng.git] / modules / opnfv / utils / Connection.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2016 Orange and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10
11 import os
12 import time
13
14
15 class Connection(object):
16
17     def __init__(self):
18         pass
19
20     def verify_connectivity(self, target):
21         for x in range(0, 10):
22             ping_cmd = ("ping -c 1 -W 1 %s >/dev/null" % target)
23             response = os.system(ping_cmd)
24             if response == 0:
25                 return os.EX_OK
26             time.sleep(1)
27         return os.EX_UNAVAILABLE
28
29     def check_internet_access(self, url="www.google.com"):
30         return self.verify_connectivity(url)