2 # This file is part of GNUnet.
3 # (C) 2010 Christian Grothoff (and other contributing authors)
5 # GNUnet is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published
7 # by the Free Software Foundation; either version 2, or (at your
8 # option) any later version.
10 # GNUnet is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with GNUnet; see the file COPYING. If not, write to the
17 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 # Boston, MA 02111-1307, USA.
33 # This test tests if a fresh peer bootstraps from a hostlist server and then
34 # successfully connects to the server
39 testname = "test_integration_bootstrap_and_connect"
50 server_transport_connected = False
51 server_topology_connected = False
52 server_core_connected = False
54 client_transport_connected = False
55 client_topology_connected = False
56 client_core_connected = False
65 gnunet_pyexpect_dir = os.path.join (srcdir, "contrib")
66 if gnunet_pyexpect_dir not in sys.path:
67 sys.path.append (gnunet_pyexpect_dir)
68 from gnunet_pyexpect import pexpect
70 global gnunetstatistics
71 if os.name == 'posix':
72 gnunetarm = 'gnunet-arm'
73 gnunetstatistics = 'gnunet-statistics'
75 gnunetarm = 'gnunet-arm.exe'
76 gnunetstatistics = 'gnunet-statistics.exe'
78 shutil.rmtree (os.path.join (os.getenv ("TEMP"), testname), True)
80 shutil.rmtree ("/tmp/" + testname, True)
83 vprintf ("Starting bootstrap server & client")
85 server = subprocess.Popen ([gnunetarm, '-sq', '-c', './confs/c_bootstrap_server.conf'])
88 print "Can not start bootstrap server, exiting..."
91 client = subprocess.Popen ([gnunetarm, '-sq', '-c', 'confs/c_no_nat_client.conf'])
94 print "Can not start bootstrap client, exiting..."
96 vprintf ("Bootstrap server & client started")
99 vprintf ("Shutting down bootstrap server")
101 server = subprocess.Popen ([gnunetarm, '-eq', '-c', './confs/c_bootstrap_server.conf'])
102 server.communicate ()
104 print "Can not stop bootstrap server, exiting..."
107 client = subprocess.Popen ([gnunetarm, '-eq', '-c', 'confs/c_no_nat_client.conf'])
108 client.communicate ()
110 print "Can not stop bootstrap client, exiting..."
112 vprintf ("Bootstrap server & client stopped")
117 shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-ns"), True)
119 shutil.rmtree ("/tmp/gnunet-test-fs-py-ns", True)
121 def check_statistics (conf, subsystem, name, value):
122 from gnunet_pyexpect import pexpect
124 server.spawn (None, [gnunetstatistics, '-c', conf ,'-q','-n', name, '-s', subsystem ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
125 #server.expect ("stdout", re.compile (r""))
126 test = server.read("stdout", 10240)
127 if (test.find(str(value)) == -1):
141 while ((success == False) and (count <= timeout)):
142 if (True == check_statistics ('./confs/c_bootstrap_server.conf', 'transport', '# peers connected',1)):
143 vprintf ('Server transport services is connected')
144 if (True == check_statistics ('./confs/c_no_nat_client.conf', 'transport', '# peers connected',1)):
145 vprintf ('Client transport services is connected')
153 vprintf ("Running " + testname)
162 if (success == False):
163 print ('Test failed')
166 print ('Test successful')