Skip to content

Commit

Permalink
merge SEA-178
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen Z. Heroy committed Mar 5, 2024
1 parent c2d0be6 commit f458407
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 52 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ services:
- ENCRYPTION_KEY
- FQDN
- GIT_BRANCH
- GPS_MODULE
- GPS_CLASS
- GUNICORN_LOG_LEVEL
- IN_DOCKER=1
- IPS
Expand Down
2 changes: 2 additions & 0 deletions env.template
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion src/initialization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions src/initialization/action_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
44 changes: 13 additions & 31 deletions src/initialization/sensor_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
15 changes: 6 additions & 9 deletions src/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 6 additions & 7 deletions src/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/sensor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
Expand Down

0 comments on commit f458407

Please sign in to comment.