Skip to content

Commit

Permalink
Merge pull request #272 from NTIA/SEA-178_test_actions_loading
Browse files Browse the repository at this point in the history
change scos-actions, scos-tekrsa versions, don't check usb if using m…
  • Loading branch information
dboulware authored May 21, 2024
2 parents 495f6d7 + bbda375 commit 510034f
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 124 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ level setting of -25.
"frequency",
"reference_level"
],
"clock_rate_lookup_by_sample_rate": [],
"calibration_data": {
"14000000.0": {
"3545000000.0": {
Expand Down
2 changes: 2 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ services:
- ENCRYPTION_KEY
- FQDN
- GIT_BRANCH
- GPS_MODULE
- GPS_CLASS
- GUNICORN_LOG_LEVEL
- IN_DOCKER=1
- IPS
Expand Down
3 changes: 1 addition & 2 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1644,10 +1644,9 @@
"description": "[Required] The name of the action to be scheduled",
"type": "string",
"enum": [
"logger",
"test_SEA_CBRS_Measure_Baseline",
"test_monitor_sigan",
"test_multi_frequency_iq_action",
"test_nasctn_sea_data_product",
"test_single_frequency_iq_action",
"test_single_frequency_m4s_action",
"test_survey_iq_action",
Expand Down
2 changes: 2 additions & 0 deletions env.template
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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
20 changes: 16 additions & 4 deletions src/initialization/action_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,22 @@ def load_actions(
}
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:
# load scos-actions test_actions
if mock_sigan:
logger.debug(f"Loading {len(test_actions)} test actions.")
actions.update(test_actions)
# load other plugin actions
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 All @@ -111,10 +119,14 @@ def load_actions(
):
action_classes.update(discover.action_classes)

# load scos-sensor configs/actions
logger.debug(f"Loading actions in {action_dir}")
yaml_actions, yaml_test_actions = init(
action_classes=action_classes, yaml_dir=action_dir
)
actions.update(yaml_actions)
logger.debug("Finished loading and registering actions")
if mock_sigan:
actions.update(yaml_test_actions)
else:
actions.update(yaml_actions)
logger.debug("Finished loading and registering actions")
return actions
16 changes: 16 additions & 0 deletions src/initialization/sensor_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def load_sensor(
)

sigan = None
gps = None
try:
if not settings.RUNNING_MIGRATIONS:
if get_usb_device_exists():
Expand All @@ -77,6 +78,20 @@ def load_sensor(
logger.warning(f"unable to create signal analyzer: {ex}")
set_container_unhealthy()

try:
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()
else:
logger.info("GPS_MODULE and/or GPS_CLASS not specified. Not loading GPS.")
except BaseException as ex:
logger.warning(f"unable to create GPS: {ex}")

# Create sensor before handling calibrations
sensor = Sensor(
signal_analyzer=sigan,
Expand All @@ -85,6 +100,7 @@ def load_sensor(
preselector=preselector,
switches=switches,
location=location,
gps=gps,
sensor_cal=None,
differential_cal=None,
)
Expand Down
13 changes: 3 additions & 10 deletions src/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ numpy==1.24.4
# tekrsa-api-wrap
nvidia-ml-py==12.535.133
# via gpustat
oauthlib==3.2.2
# via
# -r requirements.txt
# requests-oauthlib
opencensus==0.11.3
# via ray
opencensus-context==0.1.3
Expand Down Expand Up @@ -292,11 +288,8 @@ requests==2.31.0
# its-preselector
# ray
# requests-mock
# requests-oauthlib
requests-mock==1.11.0
# via -r requirements.txt
requests-oauthlib==1.3.1
# via -r requirements.txt
rpds-py==0.13.2
# via
# -r requirements.txt
Expand All @@ -316,11 +309,11 @@ scipy==1.10.1
# via
# -r requirements.txt
# scos-actions
scos-actions @ git+https://github.com/NTIA/scos-actions@9.0.0
scos-actions @ git+https://github.com/NTIA/scos-actions@10.0.2
# via
# -r requirements.txt
# scos-tekrsa
scos-tekrsa @ git+https://github.com/NTIA/scos-tekrsa@6.0.0
scos-tekrsa @ git+https://github.com/NTIA/scos-tekrsa@7.0.1
# via -r requirements.txt
sigmf @ git+https://github.com/NTIA/SigMF@multi-recording-archive
# via
Expand All @@ -340,7 +333,7 @@ sqlparse==0.5.0
# via
# -r requirements.txt
# django
tekrsa-api-wrap==1.3.2
tekrsa-api-wrap==1.3.3
# via
# -r requirements.txt
# scos-tekrsa
Expand Down
3 changes: 1 addition & 2 deletions src/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ jsonfield>=3.0, <4.0
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/[email protected]
scos_tekrsa @ git+https://github.com/NTIA/[email protected]

# The following are sub-dependencies for which SCOS Sensor enforces a
# higher minimum patch version than the dependencies which require them.
Expand Down
11 changes: 3 additions & 8 deletions src/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ numpy==1.24.4
# scos-actions
# sigmf
# tekrsa-api-wrap
oauthlib==3.2.2
# via requests-oauthlib
packaging==23.2
# via
# -r requirements.in
Expand Down Expand Up @@ -137,11 +135,8 @@ requests==2.31.0
# its-preselector
# ray
# requests-mock
# requests-oauthlib
requests-mock==1.11.0
# via -r requirements.in
requests-oauthlib==1.3.1
# via -r requirements.in
rpds-py==0.13.2
# via
# jsonschema
Expand All @@ -152,9 +147,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@9.0.0
scos-actions @ git+https://github.com/NTIA/scos-actions@10.0.2
# via scos-tekrsa
scos-tekrsa @ git+https://github.com/NTIA/scos-tekrsa@6.0.0
scos-tekrsa @ git+https://github.com/NTIA/scos-tekrsa@7.0.1
# via -r requirements.in
sigmf @ git+https://github.com/NTIA/SigMF@multi-recording-archive
# via scos-actions
Expand All @@ -168,7 +163,7 @@ sqlparse==0.5.0
# via
# -r requirements.in
# django
tekrsa-api-wrap==1.3.2
tekrsa-api-wrap==1.3.3
# via scos-tekrsa
typing-extensions==4.8.0
# via asgiref
Expand Down
42 changes: 24 additions & 18 deletions src/schedule/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
def test_take_until(test_input, future_t, expected):
start, stop, interval = test_input
entry = ScheduleEntry(
name="t", start=start, stop=stop, interval=interval, action="logger"
name="t", start=start, stop=stop, interval=interval, action="test_monitor_sigan"
)
initial_times = list(entry.get_remaining_times())
r = []
Expand All @@ -32,32 +32,36 @@ def test_take_until(test_input, future_t, expected):


def test_undefined_start_is_now():
entry = ScheduleEntry(name="t", action="logger")
entry = ScheduleEntry(name="t", action="test_monitor_sigan")
now = utils.timefn()
assert entry.start in (now - 1, now, now + 1)


def test_undefined_stop_is_never():
entry = ScheduleEntry(name="t", action="logger", interval=1)
entry = ScheduleEntry(name="t", action="test_monitor_sigan", interval=1)
assert entry.stop is None
assert type(entry.get_remaining_times()) is itertools.count


def test_relative_stop_becomes_absolute():
e = ScheduleEntry(name="t", start=20, relative_stop=10, interval=1, action="logger")
e = ScheduleEntry(
name="t", start=20, relative_stop=10, interval=1, action="test_monitor_sigan"
)
assert e.start == 20
assert e.stop == 30
assert list(e.get_remaining_times()) == list(range(20, 30, 1))


def test_stop_before_start():
e = ScheduleEntry(name="t", start=20, stop=10, interval=1, action="logger")
e = ScheduleEntry(
name="t", start=20, stop=10, interval=1, action="test_monitor_sigan"
)
assert list(e.get_remaining_times()) == list(range(0))


def test_no_interval_is_one_shot():
"""Leaving `interval` blank should indicate "one-shot" entry."""
e = ScheduleEntry(name="t", action="logger")
e = ScheduleEntry(name="t", action="test_monitor_sigan")
remaining_times = list(e.get_remaining_times())
assert len(remaining_times) == 1

Expand All @@ -72,7 +76,7 @@ def test_no_interval_is_one_shot():

def test_no_interval_with_start_is_one_shot():
"""Specifying start should not affect number of times."""
e = ScheduleEntry(name="t", action="logger", start=1)
e = ScheduleEntry(name="t", action="test_monitor_sigan", start=1)
remaining_times = list(e.get_remaining_times())
assert len(remaining_times) == 1

Expand All @@ -88,17 +92,19 @@ def test_no_interval_with_start_is_one_shot():
def test_no_interval_future_start(testclock):
"""One-shot entry should wait for start."""
# recall current t=0 so start=1 is 1 second in the future
e = ScheduleEntry(name="t", action="logger", start=1)
e = ScheduleEntry(name="t", action="test_monitor_sigan", start=1)
assert not e.take_pending()


def test_bad_interval_raises():
with pytest.raises(ValidationError):
ScheduleEntry(name="t", interval=-1, action="logger").clean_fields()
ScheduleEntry(name="t", interval=-1, action="test_monitor_sigan").clean_fields()
with pytest.raises(ValidationError):
ScheduleEntry(name="t", interval=0, action="logger").clean_fields()
ScheduleEntry(name="t", interval=0, action="test_monitor_sigan").clean_fields()
with pytest.raises(ValidationError):
ScheduleEntry(name="t", interval=0.1, action="logger").clean_fields()
ScheduleEntry(
name="t", interval=0.1, action="test_monitor_sigan"
).clean_fields()


def test_bad_action_raises():
Expand All @@ -108,22 +114,22 @@ def test_bad_action_raises():

def test_bad_name_raises():
with pytest.raises(ValidationError): # whitespace
ScheduleEntry(name="test 1", action="logger").clean_fields()
ScheduleEntry(name="test 1", action="test_monitor_sigan").clean_fields()
with pytest.raises(ValidationError): # punctuation other than "_-"
ScheduleEntry(name="test1!", action="logger").clean_fields()
ScheduleEntry(name="test1!", action="test_monitor_sigan").clean_fields()

# ok
ScheduleEntry(name="_test-Stuff123", action="logger").clean_fields()
ScheduleEntry(name="_test-Stuff123", action="test_monitor_sigan").clean_fields()


def test_non_unique_name_raises(user):
ScheduleEntry(name="t", action="logger", owner=user).save()
ScheduleEntry(name="t", action="test_monitor_sigan", owner=user).save()
with pytest.raises(ValidationError):
ScheduleEntry(name="t", action="logger", owner=user).full_clean()
ScheduleEntry(name="t", action="test_monitor_sigan", owner=user).full_clean()


def test_defaults():
entry = ScheduleEntry(name="t", action="logger")
entry = ScheduleEntry(name="t", action="test_monitor_sigan")
assert entry.priority == DEFAULT_PRIORITY
assert entry.start is not None
assert entry.stop is None
Expand All @@ -132,4 +138,4 @@ def test_defaults():


def test_str():
str(ScheduleEntry(name="t", action="logger"))
str(ScheduleEntry(name="t", action="test_monitor_sigan"))
Loading

0 comments on commit 510034f

Please sign in to comment.