Skip to content

Commit 9de6c73

Browse files
paigerube14chaitanyaenr
authored andcommitted
adding stringio for security reasons
1 parent 9f23699 commit 9de6c73

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

run_kraken.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@
3131
KUBE_BURNER_VERSION = "0.9.1"
3232

3333

34-
def publish_kraken_status(status):
35-
with open("/tmp/kraken_status", "w+") as file:
36-
file.write(str(status))
37-
38-
3934
# Main function
4035
def main(cfg):
4136
# Start kraken
@@ -131,8 +126,8 @@ def main(cfg):
131126
port
132127
)
133128
)
134-
server.start_server(address)
135-
publish_kraken_status(run_signal)
129+
logging.info("Publishing kraken status at http://%s:%s" % (server_address, port))
130+
server.start_server(address, run_signal)
136131

137132
# Cluster info
138133
logging.info("Fetching cluster info")
@@ -179,6 +174,7 @@ def main(cfg):
179174

180175
# Capture the start time
181176
start_time = int(time.time())
177+
litmus_installed = False
182178

183179
# Loop to run the chaos starts here
184180
while int(iteration) < iterations and run_signal != "STOP":
@@ -281,6 +277,7 @@ def main(cfg):
281277
litmus_version,
282278
litmus_namespace
283279
)
280+
litmus_installed = True
284281
common_litmus.run(
285282
scenarios_list,
286283
config,

server.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from http.server import HTTPServer, BaseHTTPRequestHandler
55
from http.client import HTTPConnection
66

7+
server_status = ""
78

89
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
910
"""
@@ -19,8 +20,7 @@ def do_GET(self):
1920
def do_status(self):
2021
self.send_response(200)
2122
self.end_headers()
22-
f = open("/tmp/kraken_status", "rb")
23-
self.wfile.write(f.read())
23+
self.wfile.write(bytes(server_status, encoding='utf8'))
2424
SimpleHTTPRequestHandler.requests_served += 1
2525

2626
def do_POST(self):
@@ -34,31 +34,35 @@ def do_POST(self):
3434
def set_run(self):
3535
self.send_response(200)
3636
self.end_headers()
37-
with open("/tmp/kraken_status", "w+") as file:
38-
file.write(str("RUN"))
37+
global server_status
38+
server_status = 'RUN'
3939

4040
def set_stop(self):
4141
self.send_response(200)
4242
self.end_headers()
43-
with open("/tmp/kraken_status", "w+") as file:
44-
file.write(str("STOP"))
43+
global server_status
44+
server_status = 'STOP'
4545

4646
def set_pause(self):
4747
self.send_response(200)
4848
self.end_headers()
49-
with open("/tmp/kraken_status", "w+") as file:
50-
file.write(str("PAUSE"))
49+
global server_status
50+
server_status = 'PAUSE'
5151

52+
def publish_kraken_status(status):
53+
global server_status
54+
server_status = status
5255

53-
def start_server(address):
56+
def start_server(address, status):
5457
server = address[0]
5558
port = address[1]
5659
global httpd
5760
httpd = HTTPServer(address, SimpleHTTPRequestHandler)
5861
logging.info("Starting http server at http://%s:%s\n" % (server, port))
5962
try:
6063
_thread.start_new_thread(httpd.serve_forever, ())
61-
except Exception:
64+
publish_kraken_status(status)
65+
except Exception as e:
6266
logging.error(
6367
"Failed to start the http server \
6468
at http://%s:%s"

0 commit comments

Comments
 (0)