Test client done and working. Added an env var for the cli client to enable testmode by passing a connection directory to use instead of TNC.

This commit is contained in:
Michael Woods
2025-03-16 16:52:46 -04:00
parent dd17042008
commit 412eec1d6a
6 changed files with 119 additions and 11 deletions

View File

@@ -83,7 +83,11 @@ def cli(ctx, conf, server, agwpe, port, callsign, keep_log):
storage = ZODB.FileStorage.FileStorage(os.path.join(cfg['cli']['directory'], DEFAULT_DB_FILE))
db = ZODB.DB(storage)
client = Client(ctx.obj['agwpe_server'], ctx.obj['port'], ctx.obj['callsign'], keep_log=ctx.obj['keep_log'])
if 'TEST_SERVER_DIR' in os.environ:
from packetserver.client.testing import TestClient
client = TestClient(os.environ['TEST_SERVER_DIR'], ctx.obj['callsign'])
else:
client = Client(ctx.obj['agwpe_server'], ctx.obj['port'], ctx.obj['callsign'], keep_log=ctx.obj['keep_log'])
try:
client.start()
except Exception as e:

View File

@@ -9,6 +9,7 @@ import ax25
from threading import Lock
import logging
import os.path
import datetime
from shutil import rmtree
class TestClient(Client):
@@ -55,7 +56,12 @@ class TestClient(Client):
def receive(self, req: Request, conn: Union[PacketServerConnection,SimpleDirectoryConnection], timeout: int = 300):
if type(conn) is SimpleDirectoryConnection:
conn.check_for_data()
time.sleep(1)
cutoff_date = datetime.datetime.now() + datetime.timedelta(seconds=timeout)
while datetime.datetime.now() < cutoff_date:
logging.debug(f"Client {self.callsign} checking for connection conn {conn}")
if conn.check_for_data():
break
return super().receive(req, conn, timeout=timeout)
def clear_connections(self):
@@ -71,8 +77,9 @@ class TestClient(Client):
time.sleep(.5)
pass
def start(self): # TODO
pass
def start(self):
self.started = True
def stop(self): # TODO
pass
def stop(self):
self.clear_connections()
self.started = False

View File

@@ -252,14 +252,17 @@ class SimpleDirectoryConnection:
except msgpack.OutOfData as e:
pass
def check_for_data(self):
def check_for_data(self) -> bool:
"""Monitors connection directory for data."""
if self.closing:
self._state = ConnectionState.DISCONNECTED
if self.check_closed():
return
return False
if os.path.isfile(self.remote_file_path):
data = open(self.remote_file_path, 'rb').read()
os.remove(self.remote_file_path)
logging.debug(f"[SIMPLE] {self.local_callsign} detected data from {self.remote_callsign}: {data}")
self.data.feed(data)
return True
else:
return False

View File

@@ -1,5 +1,5 @@
"""Module for handling requests as they arrive to connection objects and servers."""
import ax25
from msgpack.exceptions import OutOfData
from packetserver.common import Message, Request, Response, PacketServerConnection, send_response, send_blank_response
from .bulletin import bulletin_root_handler
@@ -28,10 +28,11 @@ def handle_root_get(req: Request, conn: PacketServerConnection,
jobs_enabled = storage.root.config['jobs_enabled']
logging.debug(f"Root handler retrieved config. {operator} - {motd}")
logging.debug("Running user_authorized")
base = ax25.Address(conn.remote_callsign).call
if user_authorized(conn, db):
user_message = f"User {conn.remote_callsign} is enabled."
user_message = f"User {base} is enabled."
else:
user_message = f"User {conn.remote_callsign} is not enabled."
user_message = f"User {base} is not enabled."
logging.debug(f"User authorized: {user_message}")
response.payload = {
'operator': operator,