Skip to content

Commit

Permalink
Fix #403: Fix the REST API server startup inside docker
Browse files Browse the repository at this point in the history
  • Loading branch information
ddutt committed Aug 13, 2021
1 parent c2d230b commit 28269dc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 36 deletions.
23 changes: 20 additions & 3 deletions suzieq/restServer/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,32 @@ def get_log_config_level(cfg):
return log_config, loglevel


def rest_main(config_file: str, no_https: bool) -> None:
def rest_main(*args) -> None:
"""The main function for the REST server
Args:
config_file (str): The suzieq config file
no_https (bool): If true, disable https
"""

config_file = sq_get_config_file(config_file)
if not args:
args = sys.argv

parser = argparse.ArgumentParser(args)
parser.add_argument(
"-c",
"--config",
type=str, help="alternate config file",
default=None
)
parser.add_argument(
"--no-https",
help="Turn off HTTPS",
default=False, action='store_true',
)
userargs = parser.parse_args()

config_file = sq_get_config_file(userargs.config)
app = app_init(config_file)
cfg = load_sq_config(config_file=config_file)
try:
Expand All @@ -135,7 +152,7 @@ def rest_main(config_file: str, no_https: bool) -> None:

logcfg, loglevel = get_log_config_level(cfg)

no_https = cfg.get('rest', {}).get('no-https', False) or no_https
no_https = cfg.get('rest', {}).get('no-https', False) or userargs.no_https

srvr_addr = cfg.get('rest', {}).get('address', '127.0.0.1')
srvr_port = cfg.get('rest', {}).get('port', 8000)
Expand Down
17 changes: 1 addition & 16 deletions suzieq/restServer/sq_rest_server.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
#!/usr/bin/env python3

import sys
import argparse

from suzieq.restServer.query import rest_main


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"-c",
"--config",
type=str, help="alternate config file",
default=None
)
parser.add_argument(
"--no-https",
help="Turn off HTTPS",
default=False, action='store_true',
)
userargs = parser.parse_args()
rest_main(userargs.config, userargs.no_https)
rest_main(sys.argv)
32 changes: 15 additions & 17 deletions tests/integration/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,29 +292,27 @@ def app_initialize():
# For some reason, putting the no_https in a for loop didn't work either
@pytest.mark.rest
def test_rest_server():
from multiprocessing import Process
import subprocess
from time import sleep
import requests

cfgfile = create_dummy_config_file(
datadir='./tests/data/multidc/parquet-out')

server = Process(target=rest_main, args=(cfgfile, True))
server.start()
assert (server.is_alive())
sleep(1)
assert (server.is_alive())
server = subprocess.Popen(
f'./suzieq/restServer/sq_rest_server.py -c {cfgfile} --no-https'.split())
sleep(5)
assert(server.pid)
assert(requests.get('http://localhost:8000/api/docs'))
server.terminate()
server.join()

server = Process(target=rest_main, args=(cfgfile, False))
server.start()
assert (server.is_alive())
sleep(1)
assert (server.is_alive())
assert (requests.get("https://localhost:8000/api/docs", verify=False))
server.terminate()
server.join()
server.kill()
sleep(5)

server = subprocess.Popen(
f'./suzieq/restServer/sq_rest_server.py -c {cfgfile} '.split())
sleep(5)
assert(server.pid)
assert(requests.get('https://localhost:8000/api/docs', verify=False))
server.kill()
sleep(5)

os.remove(cfgfile)

0 comments on commit 28269dc

Please sign in to comment.