Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions local/tests/simulation_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os


def get_container_id():
"""
Return the container id corresponding to the image gcbm-api
"""
container_id = ""
os.system('docker ps >> simulation.txt')
with open('simulation.txt') as file_handle:
lines = file_handle.readlines()
for line in lines:
if 'gcbm-api' in line:
container_id = line.split()[0]
os.system('rm simulation.txt')
return container_id


def get_simulation_status():
"""
If the container gcbm-api is running, the associated logs are returned
"""
container_id = get_container_id()
logs_file_name = container_id + ".txt"
if container_id != '':
logs_cmd = "docker logs " + container_id + " > " + logs_file_name + " 2>&1"
os.system(logs_cmd)
logs = []
with open(logs_file_name) as file_handle:
logs = file_handle.readlines()
os.system('rm ' + logs_file_name)
return {'container_running': True, 'logs': logs}
return {'container_running': False}

print(get_simulation_status())