From af2db33a0ebab98700c3c03ea84a6ba9b987c5b5 Mon Sep 17 00:00:00 2001 From: Jonas Bjurel Date: Fri, 30 Sep 2016 20:28:22 +0200 Subject: Preparing the experimental branch for improved Danube CI/CD experiments Fast forwarded to commit:cf93e6ee11c96de090b04196cc96b4a6b0948928 Change-Id: I13d10d870e8ffc7317ab03f8810592d5b2205875 Signed-off-by: Jonas Bjurel --- build/select_closest_fuel_mirror.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 build/select_closest_fuel_mirror.py (limited to 'build/select_closest_fuel_mirror.py') diff --git a/build/select_closest_fuel_mirror.py b/build/select_closest_fuel_mirror.py new file mode 100755 index 000000000..0fdc69eac --- /dev/null +++ b/build/select_closest_fuel_mirror.py @@ -0,0 +1,35 @@ +#!/usr/bin/python +############################################################################## +# Copyright (c) 2016 Ericsson AB and others. +# stefan.k.berg@ericsson.com +# jonas.bjurel@ericsson.com +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +# Select closest fuel mirror based on latency measured with ping. +# Failsafe: The us1 mirror + +from subprocess import Popen,PIPE +import re +from operator import itemgetter + +mirrors = [ "us1", "cz1" ] +FNULL = open('/dev/null', 'w') +try: + re_avg = re.compile(r'.* = [^/]*/([^/]*).*') + + pingtime = {} + for mirror in mirrors: + fqdn = "mirror.seed-"+mirror+".fuel-infra.org" + pingtime[fqdn] = 0 + pipe = Popen("ping -c 3 " + fqdn + " | tail -1",shell = True, stdout=PIPE, stderr=FNULL) + avg = pipe.communicate()[0] + pipe.stdout.close() + pingtime[fqdn] = float(re_avg.split(avg)[1]) + + print sorted(pingtime.items(), key=itemgetter(1))[0][0] +except: + print "mirror.seed-"+mirrors[0]+".fuel-infra.org" -- cgit 1.2.3-korg