/
test_server.py
50 lines (37 loc) · 1.45 KB
/
test_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# Test server for Shardnado testing
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
PORT_NUMBER = 9200
class testServer(BaseHTTPRequestHandler):
# This class handles test requests for the test_shardado.py script
# Handler for the GET requests
def do_GET(self):
if self.path=="/_cat/shards":
self.send_response(200)
self.send_header('Content-type','text/plain')
self.end_headers()
# Send the html message
self.wfile.write("test_index 1 r UNASSIGNED 52679412 4.6gb 127.0.0.1 elasticsearch-node")
if self.path=="/_cat/nodes?h=host":
self.send_response(200)
self.send_header('Content-type','text/plain')
self.end_headers()
# Send the html message
self.wfile.write(" 127.0.0.1 ")
return
# Simple server doesn't do POST well
def do_POST(self):
if self.path=="/_cluster/reroute":
self.send_response(200)
self.end_headers()
return
try:
# Create a web server and define the handler to manage the
# incoming requests
server = HTTPServer(('', PORT_NUMBER), testServer)
print 'Started test server on port %s' % str(PORT_NUMBER)
# Wait forever for incoming http requests
server.serve_forever()
except KeyboardInterrupt:
print '^C received, shutting down the test server'
server.socket.close()