Improved method to find a proper ip-address for the machine running the tests. Try to pick one in a prefered order.
@@ -8,6 +8,7 @@ import time
import multiprocessing
import copy
import numbers
+import netifaces
_log = calvinlogger.get_logger(__name__)
_conf = calvinconfig.get()
@@ -396,7 +397,37 @@ def setup_test_type(request_handler, nbr=3, proxy_storage=False):
except KeyError:
import socket
# If this fails add hostname to the /etc/hosts file for 127.0.0.1
+ try:
ip_addr = socket.gethostbyname(socket.gethostname())
+ except:
+ # Go deeper to get a real IP for this machine
+ def _prefered_addr(key):
+ # Order we prefer addresses
+ if key.startswith("192.168."):
+ return 10
+ if key.startswith("10."):
+ return 20
+ if key == "0.0.0.0":
+ return 80
+ if key == "127.0.0.1":
+ return 90
+ if key.startswith("99."):
+ return 100
+ return 50
+ possible_addresses = []
+ for i in netifaces.interfaces():
+ addrs = netifaces.ifaddresses(i)
+ # Ipv4 for now
+ if netifaces.AF_INET in addrs:
+ for a in addrs[netifaces.AF_INET]:
+ possible_addresses.append(a.get('addr', '0.0.0.0'))
+ possible_addresses.sort(key=_prefered_addr)
+ try:
+ ip_addr = possible_addresses[0]
+ except:
+ _log.error("You seems to not have a valid ip-address for the machine running the test.")
+ raise Exception("You seems to not have a valid ip-address for the machine running the test.")
+
test_type = "local"
if test_type == "distributed":
