diff --git a/docker-compose.yml b/docker-compose.yml index 3aa1df8f..5e37be60 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -48,6 +48,8 @@ services: - ENCRYPTION_KEY - FQDN - GIT_BRANCH + - GPS_MODULE + - GPS_CLASS - GUNICORN_LOG_LEVEL - IN_DOCKER=1 - IPS diff --git a/env.template b/env.template index 9a73c446..c51abb17 100644 --- a/env.template +++ b/env.template @@ -49,6 +49,8 @@ ENCRYPTION_KEY="$(python3 -c 'import secrets; import base64; print(base64.b64enc FQDN="$(hostname -f)" GIT_BRANCH="git:$(git rev-parse --abbrev-ref HEAD)@$(git rev-parse --short HEAD)" +GPS_MODULE="" +GPS_CLASS="" IPS="$(hostname -I) 127.0.0.1" diff --git a/src/initialization/__init__.py b/src/initialization/__init__.py index e97def1e..5166c4a3 100644 --- a/src/initialization/__init__.py +++ b/src/initialization/__init__.py @@ -20,7 +20,7 @@ def get_usb_device_exists() -> bool: logger.debug("Checking for USB...") - if not settings.RUNNING_TESTS and settings.USB_DEVICE is not None: + if not settings.RUNNING_TESTS and settings.USB_DEVICE is not None and not settings.MOCK_SIGAN: usb_devices = check_output("lsusb").decode(sys.stdout.encoding) logger.debug("Checking for " + settings.USB_DEVICE) logger.debug("Found " + usb_devices) diff --git a/src/initialization/action_loader.py b/src/initialization/action_loader.py index f94fb5a1..3e99568b 100644 --- a/src/initialization/action_loader.py +++ b/src/initialization/action_loader.py @@ -91,18 +91,21 @@ def load_actions( discovered_plugins = { name: importlib.import_module(name) for finder, name, ispkg in pkgutil.iter_modules() - if name.startswith("scos_") and name != "scos_actions" + if name.startswith("scos_") } logger.debug(discovered_plugins) actions = {} - if mock_sigan or running_tests: + if running_tests: logger.debug(f"Loading {len(test_actions)} test actions.") actions.update(test_actions) else: for name, module in discovered_plugins.items(): logger.debug("Looking for actions in " + name + ": " + str(module)) discover = importlib.import_module(name + ".discover") - if hasattr(discover, "actions"): + if mock_sigan and hasattr(discover, "test_actions"): + logger.debug(f"loading {len(discover.test_actions)} test actions.") + actions.update(discover.test_actions) + elif hasattr(discover, "actions"): logger.debug(f"loading {len(discover.actions)} actions.") actions.update(discover.actions) if ( diff --git a/src/initialization/sensor_loader.py b/src/initialization/sensor_loader.py index 7c0376ab..0ebb7cb9 100644 --- a/src/initialization/sensor_loader.py +++ b/src/initialization/sensor_loader.py @@ -70,6 +70,7 @@ def load_sensor(sensor_capabilities: dict) -> Sensor: ) sigan = None + gps = None try: if not settings.RUNNING_MIGRATIONS: check_for_required_sigan_settings() @@ -83,52 +84,33 @@ def load_sensor(sensor_capabilities: dict) -> Sensor: sensor_cal=sensor_cal, sigan_cal=sigan_cal, switches=switches ) register_component_with_status.send(sigan, component=sigan) + + if settings.GPS_MODULE and settings.GPS_CLASS: + gps_module_setting = settings.GPS_MODULE + gps_module = importlib.import_module(gps_module_setting) + logger.info( + "Creating " + settings.GPS_CLASS + " from " + settings.GPS_MODULE + ) + gps_constructor = getattr(gps_module, settings.GPS_CLASS) + gps = gps_constructor( + sigan=sigan + ) else: logger.info("Running migrations. Not loading signal analyzer.") except Exception as ex: logger.warning(f"unable to create signal analyzer: {ex}") - gps = None - try: - if not settings.RUNNING_MIGRATIONS: - check_for_required_gps_settings() - gps_module_setting = settings.GPS_MODULE - gps_module = importlib.import_module(gps_module_setting) - logger.info( - "Creating " + settings.GPS_CLASS + " from " + settings.GPS_MODULE - ) - gps_constructor = getattr(gps_module, settings.GPS_CLASS) - gps = gps_constructor() - register_component_with_status.send(gps, component=gps) - else: - logger.info("Running migrations. Not loading GPS.") - except Exception as ex: - logger.warning(f"unable to create GPS: {ex}") - sensor = Sensor( signal_analyzer=sigan, capabilities=sensor_capabilities, preselector=preselector, switches=switches, location=location, - gps=gps, + gps=gps ) return sensor -def check_for_required_gps_settings(): - error = "" - raise_exception = False - if settings.GPS_MODULE is None: - raise_exception = True - error = "GPS_MODULE environment variable must be set. " - if settings.GPS_CLASS is None: - raise_exception = True - error += "GPS_CLASS environment variable. " - if raise_exception: - raise Exception(error) - - def check_for_required_sigan_settings(): error = "" raise_exception = False diff --git a/src/requirements-dev.txt b/src/requirements-dev.txt index 6f50321a..ca33da0e 100644 --- a/src/requirements-dev.txt +++ b/src/requirements-dev.txt @@ -78,6 +78,7 @@ django==3.2.24 # drf-yasg # jsonfield # scos-actions + # scos-usrp django-session-timeout==0.1.0 # via -r requirements.txt djangorestframework==3.14.0 @@ -90,7 +91,7 @@ environs==9.5.0 # via # -r requirements.txt # scos-actions - # scos-tekrsa + # scos-usrp exceptiongroup==1.2.0 # via pytest filelock==3.13.1 @@ -180,8 +181,8 @@ numpy==1.24.4 # ray # scipy # scos-actions + # scos-usrp # sigmf - # tekrsa-api-wrap nvidia-ml-py==12.535.133 # via gpustat oauthlib==3.2.2 @@ -315,11 +316,11 @@ scipy==1.10.1 # via # -r requirements.txt # scos-actions -scos-actions @ git+https://github.com/NTIA/scos-actions@8.0.0 +scos-actions @ git+https://github.com/NTIA/scos-actions@SEA-178_test_actions_loading # via # -r requirements.txt - # scos-tekrsa -scos-tekrsa @ git+https://github.com/NTIA/scos-tekrsa@5.0.0 + # scos-usrp +scos-usrp @ git+https://github.com/NTIA/scos-usrp@SEA-178_test_actions_loading # via -r requirements.txt sigmf @ git+https://github.com/NTIA/SigMF@multi-recording-archive # via @@ -339,10 +340,6 @@ sqlparse==0.4.4 # via # -r requirements.txt # django -tekrsa-api-wrap==1.3.2 - # via - # -r requirements.txt - # scos-tekrsa tomli==2.0.1 # via # coverage diff --git a/src/requirements.in b/src/requirements.in index 591bc41f..7354f4ae 100644 --- a/src/requirements.in +++ b/src/requirements.in @@ -11,7 +11,7 @@ packaging>=23.0, <24.0 psycopg2-binary>=2.0, <3.0 requests-mock>=1.0, <2.0 requests_oauthlib>=1.0, <2.0 -scos_tekrsa @ git+https://github.com/NTIA/scos-tekrsa@5.0.0 +scos_usrp @ git+https://github.com/NTIA/scos-usrp@SEA-178_test_actions_loading # The following are sub-dependencies for which SCOS Sensor enforces a # higher minimum patch version than the dependencies which require them. diff --git a/src/requirements.txt b/src/requirements.txt index 59c9699d..7ecd0a93 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -32,6 +32,7 @@ django==3.2.24 # drf-yasg # jsonfield # scos-actions + # scos-usrp django-session-timeout==0.1.0 # via -r requirements.in djangorestframework==3.14.0 @@ -44,7 +45,7 @@ environs==9.5.0 # via # -r requirements.in # scos-actions - # scos-tekrsa + # scos-usrp filelock==3.13.1 # via # -r requirements.in @@ -89,8 +90,8 @@ numpy==1.24.4 # ray # scipy # scos-actions + # scos-usrp # sigmf - # tekrsa-api-wrap oauthlib==3.2.2 # via requests-oauthlib packaging==23.2 @@ -149,9 +150,9 @@ ruamel-yaml-clib==0.2.8 # via ruamel-yaml scipy==1.10.1 # via scos-actions -scos-actions @ git+https://github.com/NTIA/scos-actions@8.0.0 - # via scos-tekrsa -scos-tekrsa @ git+https://github.com/NTIA/scos-tekrsa@5.0.0 +scos-actions @ git+https://github.com/NTIA/scos-actions@SEA-178_test_actions_loading + # via scos-usrp +scos-usrp @ git+https://github.com/NTIA/scos-usrp@SEA-178_test_actions_loading # via -r requirements.in sigmf @ git+https://github.com/NTIA/SigMF@multi-recording-archive # via scos-actions @@ -163,8 +164,6 @@ six==1.16.0 # sigmf sqlparse==0.4.4 # via django -tekrsa-api-wrap==1.3.2 - # via scos-tekrsa typing-extensions==4.8.0 # via asgiref uritemplate==4.1.1 diff --git a/src/sensor/settings.py b/src/sensor/settings.py index 1bc97746..a2e0fe27 100644 --- a/src/sensor/settings.py +++ b/src/sensor/settings.py @@ -334,6 +334,8 @@ DEVICE_MODEL = env("DEVICE_MODEL", default="RSA507A") SIGAN_MODULE = "scos_actions.hardware.mocks.mock_sigan" SIGAN_CLASS = "MockSignalAnalyzer" + GPS_MODULE = "scos_actions.hardware.mocks.mock_gps" + GPS_CLASS = "MockGPS" else: DATABASES = { "default": { @@ -348,6 +350,8 @@ DEVICE_MODEL = env("DEVICE_MODEL", default=None) SIGAN_MODULE = env.str("SIGAN_MODULE", default=None) SIGAN_CLASS = env.str("SIGAN_CLASS", default=None) + GPS_MODULE = env.str("GPS_MODULE", default=None) + GPS_CLASS = env.str("GPS_CLASS", default=None) if not IN_DOCKER: DATABASES["default"]["HOST"] = "localhost"