2019-06-16 20:44:03 -07:00
|
|
|
#!/usr/bin/env python3
|
2019-06-16 22:04:13 -07:00
|
|
|
"""
|
2019-07-16 00:30:57 -07:00
|
|
|
Starts hyperglass with the Sanic web server
|
2019-06-16 22:04:13 -07:00
|
|
|
"""
|
2019-06-16 20:00:48 -07:00
|
|
|
import os
|
|
|
|
import sys
|
2019-06-16 22:04:13 -07:00
|
|
|
import json
|
2019-06-16 20:00:48 -07:00
|
|
|
from logzero import logger
|
|
|
|
|
|
|
|
working_directory = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
parent_directory = os.path.dirname(working_directory)
|
|
|
|
|
|
|
|
|
|
|
|
def construct_test(test_query, location, test_target):
|
2019-07-16 00:30:57 -07:00
|
|
|
"""Constructs JSON POST data for test_hyperglass function."""
|
2019-06-16 20:00:48 -07:00
|
|
|
constructed_query = json.dumps(
|
|
|
|
{"type": test_query, "location": location, "target": test_target}
|
|
|
|
)
|
|
|
|
return constructed_query
|
|
|
|
|
|
|
|
|
2019-07-16 00:30:57 -07:00
|
|
|
def test_server(host, port):
|
|
|
|
"""Starts Sanic web server for testing."""
|
2019-06-16 20:00:48 -07:00
|
|
|
try:
|
|
|
|
sys.path.insert(0, parent_directory)
|
|
|
|
|
|
|
|
from hyperglass import render
|
2019-06-16 22:04:13 -07:00
|
|
|
from hyperglass import hyperglass
|
2019-06-16 20:00:48 -07:00
|
|
|
|
|
|
|
render.css()
|
2019-07-16 00:30:57 -07:00
|
|
|
logger.info("Starting Sanic web server...")
|
2019-06-16 20:00:48 -07:00
|
|
|
hyperglass.app.run(host=host, debug=True, port=port)
|
|
|
|
except:
|
|
|
|
logger.error("Exception occurred while trying to start test server...")
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2019-07-16 00:30:57 -07:00
|
|
|
test_server("localhost", 5000)
|