forked from mirrors/thatmattlove-hyperglass
splitting CI tests to separate scripts
This commit is contained in:
parent
6daf7b7a23
commit
c18ebc9ca7
3 changed files with 69 additions and 52 deletions
|
|
@ -12,6 +12,7 @@ install:
|
|||
before_script:
|
||||
- bash ./ci/check_code.sh
|
||||
script:
|
||||
- python3 ./ci/ci_test_prepare.py
|
||||
- python3 ./ci/ci_test.py
|
||||
after_script:
|
||||
- bash ./ci/ci_commit.shs
|
||||
|
|
|
|||
|
|
@ -10,33 +10,6 @@ working_directory = os.path.dirname(os.path.abspath(__file__))
|
|||
parent_directory = os.path.dirname(working_directory)
|
||||
|
||||
|
||||
def ci_config():
|
||||
"""Copies test configuration files to usable config files"""
|
||||
logger.info("Migrating test config files...")
|
||||
config_dir = os.path.join(parent_directory, "hyperglass/configuration/")
|
||||
test_files = glob.iglob(os.path.join(working_directory, "*.toml"))
|
||||
config_files = glob.iglob(os.path.join(config_dir, "*.toml"))
|
||||
logger.debug(config_dir)
|
||||
logger.debug(working_directory)
|
||||
logger.debug(parent_directory)
|
||||
status = False
|
||||
for f in config_files:
|
||||
if os.path.exists(f):
|
||||
logger.debug(f"{f} already exists")
|
||||
os.remove(f)
|
||||
logger.debug(f"Deleted {f}")
|
||||
for f in test_files:
|
||||
try:
|
||||
shutil.copy(f, config_dir)
|
||||
logger.debug(f"Copied {f}")
|
||||
logger.info("Successfully migrated test config files")
|
||||
status = True
|
||||
except:
|
||||
logger.error(f"Failed to migrate {f}")
|
||||
raise
|
||||
return status
|
||||
|
||||
|
||||
def construct_test(test_query, location, test_target):
|
||||
"""Constructs JSON POST data for test_hyperglass function"""
|
||||
constructed_query = json.dumps(
|
||||
|
|
@ -190,32 +163,7 @@ def ci_hyperglass_test(
|
|||
raise
|
||||
|
||||
|
||||
def flask_dev_server(host, port):
|
||||
"""Starts Flask development server for testing without WSGI/Reverse Proxy"""
|
||||
try:
|
||||
sys.path.insert(0, parent_directory)
|
||||
|
||||
from hyperglass import hyperglass
|
||||
from hyperglass import configuration
|
||||
from hyperglass import render
|
||||
|
||||
render.css()
|
||||
logger.info("Starting Flask development server")
|
||||
hyperglass.app.run(host=host, debug=True, port=port)
|
||||
except:
|
||||
logger.error("Exception occurred while trying to start test server...")
|
||||
raise
|
||||
|
||||
|
||||
def ci_prepare():
|
||||
if ci_config():
|
||||
flask_dev_server("localhost", 5000)
|
||||
else:
|
||||
raise
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ci_prepare()
|
||||
ci_hyperglass_test(
|
||||
"pop2",
|
||||
"1.1.1.0/24",
|
||||
|
|
|
|||
68
ci/ci_test_prepare.py
Normal file
68
ci/ci_test_prepare.py
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import os
|
||||
import sys
|
||||
import glob
|
||||
import shutil
|
||||
import requests
|
||||
from logzero import logger
|
||||
|
||||
working_directory = os.path.dirname(os.path.abspath(__file__))
|
||||
parent_directory = os.path.dirname(working_directory)
|
||||
|
||||
|
||||
def ci_config():
|
||||
"""Copies test configuration files to usable config files"""
|
||||
logger.info("Migrating test config files...")
|
||||
config_dir = os.path.join(parent_directory, "hyperglass/configuration/")
|
||||
test_files = glob.iglob(os.path.join(working_directory, "*.toml"))
|
||||
config_files = glob.iglob(os.path.join(config_dir, "*.toml"))
|
||||
logger.debug(config_dir)
|
||||
logger.debug(working_directory)
|
||||
logger.debug(parent_directory)
|
||||
status = False
|
||||
for f in config_files:
|
||||
if os.path.exists(f):
|
||||
logger.debug(f"{f} already exists")
|
||||
os.remove(f)
|
||||
logger.debug(f"Deleted {f}")
|
||||
for f in test_files:
|
||||
try:
|
||||
shutil.copy(f, config_dir)
|
||||
logger.debug(f"Copied {f}")
|
||||
logger.info("Successfully migrated test config files")
|
||||
status = True
|
||||
except:
|
||||
logger.error(f"Failed to migrate {f}")
|
||||
raise
|
||||
return status
|
||||
|
||||
|
||||
def construct_test(test_query, location, test_target):
|
||||
"""Constructs JSON POST data for test_hyperglass function"""
|
||||
constructed_query = json.dumps(
|
||||
{"type": test_query, "location": location, "target": test_target}
|
||||
)
|
||||
return constructed_query
|
||||
|
||||
|
||||
def flask_dev_server(host, port):
|
||||
"""Starts Flask development server for testing without WSGI/Reverse Proxy"""
|
||||
try:
|
||||
sys.path.insert(0, parent_directory)
|
||||
|
||||
from hyperglass import hyperglass
|
||||
from hyperglass import configuration
|
||||
from hyperglass import render
|
||||
|
||||
render.css()
|
||||
logger.info("Starting Flask development server")
|
||||
hyperglass.app.run(host=host, debug=True, port=port)
|
||||
except:
|
||||
logger.error("Exception occurred while trying to start test server...")
|
||||
raise
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if ci_config():
|
||||
flask_dev_server("localhost", 5000)
|
||||
else:
|
||||
raise
|
||||
Loading…
Add table
Reference in a new issue