1 from __future__
import print_function
6 from cvmfs_geo
import distance_on_unit_sphere
7 from cvmfs_geo
import addr_geoinfo
8 from cvmfs_geo
import name_geoinfo
9 from cvmfs_geo
import geosort_servers
18 for info
in socket.getaddrinfo(name,80,0,0,socket.IPPROTO_TCP):
20 addrs.append(info[4][0])
27 CERNname =
'cvmfs-stratum-one.cern.ch'
28 CERNaddrs =
getaddrs(CERNname, socket.AF_INET6)
29 if len(CERNaddrs) == 0:
30 CERNaddrs =
getaddrs(CERNname, socket.AF_INET)
36 FNALname =
'cvmfs.fnal.gov'
42 IHEPname =
'cvmfs-stratum-one.ihep.ac.cn'
48 RALname =
'cernvmfs.gridpp.rl.ac.uk'
50 if len(RALaddrs) == 0:
51 RALaddrs =
getaddrs(RALname, socket.AF_INET)
59 elif addr
in IHEPaddrs:
61 elif addr
in CERNaddrs:
63 elif addr
in RALaddrs:
68 return {
'location' : answer}
83 self.assertAlmostEqual(1.11458455,
85 CERNgeo[
'latitude'], CERNgeo[
'longitude']))
86 self.assertAlmostEqual(1.11458455,
88 FNALgeo[
'latitude'], FNALgeo[
'longitude']))
89 self.assertAlmostEqual(1.6622382,
91 FNALgeo[
'latitude'], FNALgeo[
'longitude']))
92 self.assertAlmostEqual(0.1274021,
94 RALgeo[
'latitude'], RALgeo[
'longitude']))
95 self.assertAlmostEqual(1.2830254,
97 RALgeo[
'latitude'], RALgeo[
'longitude']))
99 self.assertAlmostEqual(1.2878979,
101 CERNgeo[
'latitude'], CERNgeo[
'longitude']))
105 self.assertEqual(CERNgeo,
addr_geoinfo(now, CERNaddrs[0]))
106 self.assertEqual(FNALgeo,
addr_geoinfo(now, FNALaddrs[0]))
107 self.assertEqual(IHEPgeo,
addr_geoinfo(now, IHEPaddrs[0]))
108 self.assertEqual(RALgeo,
addr_geoinfo(now, RALaddrs[0]))
111 self.assertEqual(0, len(cvmfs_geo.geo_cache))
117 self.assertEqual(4, len(cvmfs_geo.geo_cache))
120 savegireader = cvmfs_geo.gireader
121 cvmfs_geo.gireader =
None
127 cvmfs_geo.gireader = savegireader
130 self.assertEqual([
True, [3, 0, 1, 2]],
132 self.assertEqual([
True, [0, 3, 2, 1]],
134 self.assertEqual([
True, [1, 0, 3, 2]],
136 self.assertEqual([
True, [2, 3, 0, 1]],
138 self.assertEqual([
True, [3, 2, 1, 0]],
142 if __name__ ==
'__main__':
def distance_on_unit_sphere
def getaddrs
Simulate a small geo IP database, since we can't always expect a full one to be available.