backend with --emulate flag

This commit is contained in:
Georg-Stahn
2024-01-11 15:34:01 +01:00
parent b679382622
commit b01b01a959
27 changed files with 699 additions and 538 deletions

View File

@@ -28,6 +28,12 @@ def register_parser(parser: argparse.ArgumentParser) -> None:
help="Populate the database with dummy data",
default=False,
)
parser.add_argument(
"--emulate",
action="store_true",
help="Emulate two entities c1 and c2 + dlg and ap",
default=False,
)
parser.add_argument(
"--no-open", action="store_true", help="Don't open the browser", default=False
)

View File

@@ -127,25 +127,34 @@ def start_server(args: argparse.Namespace) -> None:
subprocess.run(cmd, check=True)
if args.emulate:
# todo move emu
from .emulate_fastapi import (app_dlg, app_ap, app_c1, app_c2)
from .api import (get_health, port_dlg, port_ap, port_client_base)
import multiprocessing as mp
port = port_dlg
host = host
# server
proc = mp.Process(
target=uvicorn.run,
args=(app_dlg,),
kwargs={"host": host, "port": port, "log_level": "info"},
daemon=True,
)
proc.start()
url = f"http://{host}:{port}"
res = get_health(url=url + "/health")
if res is None:
raise Exception(f"Couldn't reach {url} after starting server")
from config import host, port_ap, port_client_base, port_dlg
from emulate_fastapi import app_ap, app_c1, app_c2, app_dlg, get_health
app_ports = [
(app_dlg, port_dlg),
(app_ap, port_ap),
(app_c1, port_client_base),
(app_c2, port_client_base + 1),
]
urls = list()
# start servers as processes (dlg, ap, c1 and c2 for tests)
for app, port in app_ports:
breakpoint()
proc = mp.Process(
target=uvicorn.run,
args=(app,),
kwargs={"host": host, "port": port, "log_level": "info"},
daemon=True,
)
proc.start()
urls.append(f"http://{host}:{port}")
# check server health
for url in urls:
res = get_health(url=url + "/health")
if res is None:
raise Exception(f"Couldn't reach {url} after starting server")
uvicorn.run(
"clan_cli.webui.app:app",

View File

@@ -1,4 +1,4 @@
from sqlalchemy import JSON, Boolean, Column, ForeignKey, Integer, String, Text, Enum
from sqlalchemy import JSON, Boolean, Column, Enum, ForeignKey, Integer, String, Text
from sqlalchemy.orm import relationship
from .schemas import Roles
@@ -16,7 +16,8 @@ class Entity(Base):
name = Column(String, index=True, unique=True)
ip = Column(String, index=True)
network = Column(String, index=True)
role = Column(Enum(Roles), index=True)
role = Column(Enum(Roles), index=True, nullable=False) # type: ignore
# role = Column(String, index=True, nullable=False)
attached = Column(Boolean, index=True)
visible = Column(Boolean, index=True)
stop_health_task = Column(Boolean)