2020-07-10 07:01:28 +01:00
|
|
|
import os
|
|
|
|
|
2020-06-02 22:48:57 +01:00
|
|
|
from invoke import task
|
|
|
|
|
2020-07-10 07:01:28 +01:00
|
|
|
UBUNTU = "ubuntu"
|
|
|
|
CENTOS = "centos"
|
|
|
|
DAEMON_DIR = "daemon"
|
|
|
|
VCMD_DIR = "netns"
|
|
|
|
GUI_DIR = "gui"
|
|
|
|
|
|
|
|
|
|
|
|
def get_python(c):
|
|
|
|
with c.cd(DAEMON_DIR):
|
|
|
|
venv = c.run("poetry env info -p", hide=True).stdout.strip()
|
|
|
|
return os.path.join(venv, "bin", "python")
|
|
|
|
|
|
|
|
|
|
|
|
def get_pytest(c):
|
|
|
|
with c.cd(DAEMON_DIR):
|
|
|
|
venv = c.run("poetry env info -p", hide=True).stdout.strip()
|
|
|
|
return os.path.join(venv, "bin", "pytest")
|
|
|
|
|
|
|
|
|
|
|
|
def get_os():
|
|
|
|
d = {}
|
|
|
|
with open("/etc/os-release", "r") as f:
|
|
|
|
for line in f.readlines():
|
|
|
|
line = line.strip()
|
|
|
|
key, value = line.split("=")
|
|
|
|
d[key] = value
|
|
|
|
return d["ID"]
|
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def install(c):
|
|
|
|
"""
|
|
|
|
install core
|
|
|
|
"""
|
|
|
|
# get os
|
|
|
|
os_name = get_os()
|
|
|
|
# install system dependencies
|
|
|
|
print("installing system dependencies...")
|
|
|
|
if os_name == UBUNTU:
|
|
|
|
c.run(
|
|
|
|
"sudo apt install -y automake pkg-config gcc libev-dev ebtables iproute2 "
|
|
|
|
"ethtool tk python3-tk", hide=True
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
raise Exception(f"unsupported os: {os_name}")
|
|
|
|
# install grpcio-tools for building proto files
|
|
|
|
print("installing grpcio-tools...")
|
|
|
|
c.run("python3 -m pip install --user grpcio-tools", hide=True)
|
|
|
|
# build core
|
|
|
|
print("building core...")
|
|
|
|
c.run("./bootstrap.sh", hide=True)
|
|
|
|
c.run("./configure", hide=True)
|
|
|
|
c.run("make -j", hide=True)
|
|
|
|
# install vcmd
|
|
|
|
print("installing vcmd...")
|
|
|
|
with c.cd(VCMD_DIR):
|
|
|
|
c.run("sudo make install", hide=True)
|
|
|
|
# install vcmd
|
|
|
|
print("installing gui...")
|
|
|
|
with c.cd(GUI_DIR):
|
|
|
|
c.run("sudo make install", hide=True)
|
|
|
|
# install poetry environment
|
|
|
|
print("installing poetry...")
|
|
|
|
c.run("pipx install poetry", hide=True)
|
|
|
|
with c.cd(DAEMON_DIR):
|
|
|
|
print("installing core environment using poetry...")
|
|
|
|
c.run("poetry install", hide=True)
|
|
|
|
|
2020-06-02 22:48:57 +01:00
|
|
|
|
|
|
|
@task
|
2020-07-08 07:38:12 +01:00
|
|
|
def daemon(c):
|
|
|
|
"""
|
2020-07-10 07:01:28 +01:00
|
|
|
start core-daemon
|
2020-07-08 07:38:12 +01:00
|
|
|
"""
|
2020-07-10 07:01:28 +01:00
|
|
|
python = get_python(c)
|
|
|
|
with c.cd(DAEMON_DIR):
|
2020-07-08 07:38:12 +01:00
|
|
|
c.run(
|
2020-07-10 07:01:28 +01:00
|
|
|
f"sudo {python} scripts/core-daemon "
|
|
|
|
"-f data/core.conf -l data/logging.conf",
|
|
|
|
pty=True
|
2020-07-08 07:38:12 +01:00
|
|
|
)
|
2020-06-02 22:48:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
@task
|
2020-07-08 07:38:12 +01:00
|
|
|
def gui(c):
|
|
|
|
"""
|
2020-07-10 07:01:28 +01:00
|
|
|
start core-pygui
|
2020-07-08 07:38:12 +01:00
|
|
|
"""
|
2020-07-10 07:01:28 +01:00
|
|
|
with c.cd(DAEMON_DIR):
|
|
|
|
c.run("poetry run scripts/core-pygui", pty=True)
|
2020-07-08 07:38:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def test(c):
|
|
|
|
"""
|
2020-07-10 07:01:28 +01:00
|
|
|
run core tests
|
2020-07-08 07:38:12 +01:00
|
|
|
"""
|
2020-07-10 07:01:28 +01:00
|
|
|
pytest = get_pytest(c)
|
|
|
|
with c.cd(DAEMON_DIR):
|
|
|
|
c.run(f"sudo {pytest} -v --lf -x tests", pty=True)
|
2020-07-08 07:38:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def test_mock(c):
|
|
|
|
"""
|
2020-07-10 07:01:28 +01:00
|
|
|
run core tests using mock to avoid running as sudo
|
2020-07-08 07:38:12 +01:00
|
|
|
"""
|
2020-07-10 07:01:28 +01:00
|
|
|
with c.cd(DAEMON_DIR):
|
2020-07-08 07:38:12 +01:00
|
|
|
c.run("poetry run pytest -v --mock --lf -x tests", pty=True)
|
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def test_emane(c):
|
|
|
|
"""
|
2020-07-10 07:01:28 +01:00
|
|
|
run core emane tests
|
2020-07-08 07:38:12 +01:00
|
|
|
"""
|
2020-07-10 07:01:28 +01:00
|
|
|
pytest = get_pytest(c)
|
|
|
|
with c.cd(DAEMON_DIR):
|
|
|
|
c.run(f"{pytest} -v --lf -x tests/emane", pty=True)
|