blob: 75acf3d080f3b1cf1d189a86acec81fb291e598b [file] [log] [blame]
Chetan Gaonker3533faa2016-04-25 17:50:14 -07001import SocketServer as socketserver
2import threading
3import socket
4from CordContainer import Onos
5from nose.tools import nottest
6
7##Server to handle container restart requests from test container.
8##Used now to restart ONOS from vrouter test container
9
10CORD_TEST_HOST = '172.17.0.1'
11CORD_TEST_PORT = 25000
12
13class CordTestServer(socketserver.BaseRequestHandler):
14
15 def handle(self):
16 data = self.request.recv(1024).strip()
17 if data == 'RESTART_ONOS':
18 print('Restarting ONOS')
19 onos = Onos(restart = True)
20 self.request.sendall('DONE')
21
22class ThreadedTestServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
23 pass
24
25@nottest
26def cord_test_server_start():
27 server = ThreadedTestServer( (CORD_TEST_HOST, CORD_TEST_PORT), CordTestServer)
28 task = threading.Thread(target = server.serve_forever)
29 ##terminate when main thread exits
30 task.daemon = True
31 task.start()
32 return server
33
34@nottest
35def cord_test_server_stop(server):
36 server.shutdown()
37 server.server_close()
38
39@nottest
40def cord_test_onos_restart():
41 '''Send ONOS restart to server'''
42 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
43 s.connect( (CORD_TEST_HOST, CORD_TEST_PORT) )
44 s.sendall('RESTART_ONOS\n')
45 data = s.recv(1024).strip()
46 if data == 'DONE':
47 return True
48 return False