From 94c14d8addff8293697159490098d932b40099f6 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Thu, 15 Dec 2022 15:10:04 -0700 Subject: [PATCH 01/10] change healthy property to method, implement in SignalAnalyzerInterface to get iq samples --- scos_actions/hardware/sigan_iface.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/scos_actions/hardware/sigan_iface.py b/scos_actions/hardware/sigan_iface.py index 5de48a12..02ae695e 100644 --- a/scos_actions/hardware/sigan_iface.py +++ b/scos_actions/hardware/sigan_iface.py @@ -81,11 +81,22 @@ def connect(self) -> None: """ pass - @property - @abstractmethod - def healthy(self) -> bool: - """Perform a health check by collecting IQ samples.""" - pass + def healthy(self, num_samples=56000): + """Perform health check by collecting IQ samples.""" + logger.debug("Performing health check.") + + try: + measurement_result = self.acquire_time_domain_samples(num_samples, gain_adjust=False) + data = measurement_result["data"] + except Exception as e: + logger.exception("Unable to acquire samples from device.") + return False + + if not len(data) == num_samples: + logger.error("Data length doesn't match request.") + return False + + return True def power_cycle_and_connect(self, sleep_time: float = 2.0) -> None: """ From 23fa45ee8753b28d273a92df1747346bfb6e68df Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Thu, 15 Dec 2022 15:11:31 -0700 Subject: [PATCH 02/10] change version to 5.0.0 --- scos_actions/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scos_actions/__init__.py b/scos_actions/__init__.py index 064c0b35..ba7be38e 100644 --- a/scos_actions/__init__.py +++ b/scos_actions/__init__.py @@ -1 +1 @@ -__version__ = "4.0.2" +__version__ = "5.0.0" From be6e46f5f73332b9fbc5c8b77992b5360135c715 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Fri, 16 Dec 2022 14:51:12 -0700 Subject: [PATCH 03/10] add is_available check in healthy method --- scos_actions/hardware/sigan_iface.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scos_actions/hardware/sigan_iface.py b/scos_actions/hardware/sigan_iface.py index 02ae695e..c10906bc 100644 --- a/scos_actions/hardware/sigan_iface.py +++ b/scos_actions/hardware/sigan_iface.py @@ -84,7 +84,8 @@ def connect(self) -> None: def healthy(self, num_samples=56000): """Perform health check by collecting IQ samples.""" logger.debug("Performing health check.") - + if not self.is_available: + return False try: measurement_result = self.acquire_time_domain_samples(num_samples, gain_adjust=False) data = measurement_result["data"] From df64da44c5dc084b4f9c45533c317857162cf59f Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Fri, 16 Dec 2022 15:27:33 -0700 Subject: [PATCH 04/10] rename monitor_action_completed to trigger_api_restart --- scos_actions/actions/monitor_sigan.py | 6 +++--- scos_actions/actions/tests/test_monitor_radio.py | 8 ++++---- scos_actions/signals.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scos_actions/actions/monitor_sigan.py b/scos_actions/actions/monitor_sigan.py index f470dcb0..bb3f4d61 100644 --- a/scos_actions/actions/monitor_sigan.py +++ b/scos_actions/actions/monitor_sigan.py @@ -4,7 +4,7 @@ from scos_actions.actions.interfaces.action import Action from scos_actions.hardware.mocks.mock_gps import MockGPS -from scos_actions.signals import monitor_action_completed +from scos_actions.signals import trigger_api_restart logger = logging.getLogger(__name__) @@ -28,8 +28,8 @@ def __call__(self, schedule_entry_json, task_id): healthy = self.sigan.healthy if healthy: - monitor_action_completed.send(sender=self.__class__, sigan_healthy=True) + trigger_api_restart.send(sender=self.__class__, sigan_healthy=True) logger.info("signal analyzer healthy") else: logger.warning("signal analyzer unhealthy") - monitor_action_completed.send(sender=self.__class__, sigan_healthy=False) + trigger_api_restart.send(sender=self.__class__, sigan_healthy=False) diff --git a/scos_actions/actions/tests/test_monitor_radio.py b/scos_actions/actions/tests/test_monitor_radio.py index e46f1b5c..b539f163 100644 --- a/scos_actions/actions/tests/test_monitor_radio.py +++ b/scos_actions/actions/tests/test_monitor_radio.py @@ -1,5 +1,5 @@ from scos_actions.discover import test_actions as actions -from scos_actions.signals import monitor_action_completed +from scos_actions.signals import trigger_api_restart MONITOR_SIGAN_SCHEDULE = { "name": "test_monitor", @@ -17,7 +17,7 @@ def callback(sender, **kwargs): nonlocal _sigan_healthy _sigan_healthy = kwargs["sigan_healthy"] - monitor_action_completed.connect(callback) + trigger_api_restart.connect(callback) action = actions["test_monitor_sigan"] sigan = action.sigan sigan._is_available = False @@ -33,7 +33,7 @@ def callback(sender, **kwargs): nonlocal _sigan_healthy _sigan_healthy = kwargs["sigan_healthy"] - monitor_action_completed.connect(callback) + trigger_api_restart.connect(callback) action = actions["test_monitor_sigan"] sigan = action.sigan sigan._healthy = False @@ -49,7 +49,7 @@ def callback(sender, **kwargs): nonlocal _sigan_healthy _sigan_healthy = kwargs["sigan_healthy"] - monitor_action_completed.connect(callback) + trigger_api_restart.connect(callback) action = actions["test_monitor_sigan"] sigan = action.sigan sigan._is_available = True diff --git a/scos_actions/signals.py b/scos_actions/signals.py index 5a247896..cbc7eac2 100644 --- a/scos_actions/signals.py +++ b/scos_actions/signals.py @@ -7,7 +7,7 @@ location_action_completed = Signal() # Provides arguments: 'sigan_healthy' -monitor_action_completed = Signal() +trigger_api_restart = Signal() # Provides argument: 'component' register_component_with_status = Signal() From 9a27842cfda29041789b7275096db3c6a1c36290 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Fri, 16 Dec 2022 16:08:11 -0700 Subject: [PATCH 05/10] remove comment, remove is_available check from monitor action --- scos_actions/actions/monitor_sigan.py | 7 +------ scos_actions/signals.py | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/scos_actions/actions/monitor_sigan.py b/scos_actions/actions/monitor_sigan.py index bb3f4d61..1e74dbe7 100644 --- a/scos_actions/actions/monitor_sigan.py +++ b/scos_actions/actions/monitor_sigan.py @@ -20,12 +20,7 @@ def __init__(self, sigan, parameters={"name": "monitor_sigan"}, gps=None): def __call__(self, schedule_entry_json, task_id): logger.debug("Performing signal analyzer health check") - healthy = True - - if not self.sigan.is_available: - healthy = False - else: - healthy = self.sigan.healthy + healthy = self.sigan.healthy if healthy: trigger_api_restart.send(sender=self.__class__, sigan_healthy=True) diff --git a/scos_actions/signals.py b/scos_actions/signals.py index cbc7eac2..36baaf3b 100644 --- a/scos_actions/signals.py +++ b/scos_actions/signals.py @@ -6,7 +6,6 @@ # Provides arguments: 'latitude', 'longitude' location_action_completed = Signal() -# Provides arguments: 'sigan_healthy' trigger_api_restart = Signal() # Provides argument: 'component' From 53d5164a8e20984f6f68be71f3981c7c7ddf491d Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Mon, 19 Dec 2022 13:27:16 -0700 Subject: [PATCH 06/10] autoformatting --- scos_actions/hardware/sigan_iface.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scos_actions/hardware/sigan_iface.py b/scos_actions/hardware/sigan_iface.py index c10906bc..1e7f3d37 100644 --- a/scos_actions/hardware/sigan_iface.py +++ b/scos_actions/hardware/sigan_iface.py @@ -87,7 +87,9 @@ def healthy(self, num_samples=56000): if not self.is_available: return False try: - measurement_result = self.acquire_time_domain_samples(num_samples, gain_adjust=False) + measurement_result = self.acquire_time_domain_samples( + num_samples, gain_adjust=False + ) data = measurement_result["data"] except Exception as e: logger.exception("Unable to acquire samples from device.") From 7647a7e0a264ec30078b459f6655dc1e3ac5771b Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Mon, 19 Dec 2022 13:49:36 -0700 Subject: [PATCH 07/10] fix tests, fix healthy call in monitor_sigan --- scos_actions/actions/monitor_sigan.py | 2 +- .../tests/{test_monitor_radio.py => test_monitor_sigan.py} | 3 +-- scos_actions/hardware/mocks/mock_sigan.py | 5 ----- 3 files changed, 2 insertions(+), 8 deletions(-) rename scos_actions/actions/tests/{test_monitor_radio.py => test_monitor_sigan.py} (96%) diff --git a/scos_actions/actions/monitor_sigan.py b/scos_actions/actions/monitor_sigan.py index 1e74dbe7..42a01537 100644 --- a/scos_actions/actions/monitor_sigan.py +++ b/scos_actions/actions/monitor_sigan.py @@ -20,7 +20,7 @@ def __init__(self, sigan, parameters={"name": "monitor_sigan"}, gps=None): def __call__(self, schedule_entry_json, task_id): logger.debug("Performing signal analyzer health check") - healthy = self.sigan.healthy + healthy = self.sigan.healthy() if healthy: trigger_api_restart.send(sender=self.__class__, sigan_healthy=True) diff --git a/scos_actions/actions/tests/test_monitor_radio.py b/scos_actions/actions/tests/test_monitor_sigan.py similarity index 96% rename from scos_actions/actions/tests/test_monitor_radio.py rename to scos_actions/actions/tests/test_monitor_sigan.py index b539f163..96b14139 100644 --- a/scos_actions/actions/tests/test_monitor_radio.py +++ b/scos_actions/actions/tests/test_monitor_sigan.py @@ -36,10 +36,9 @@ def callback(sender, **kwargs): trigger_api_restart.connect(callback) action = actions["test_monitor_sigan"] sigan = action.sigan - sigan._healthy = False + sigan.times_to_fail_recv = 6 action(MONITOR_SIGAN_SCHEDULE, 1) assert _sigan_healthy == False - sigan._healthy = True def test_monitor_sigan_healthy(): diff --git a/scos_actions/hardware/mocks/mock_sigan.py b/scos_actions/hardware/mocks/mock_sigan.py index 1277a9ff..11c60d66 100644 --- a/scos_actions/hardware/mocks/mock_sigan.py +++ b/scos_actions/hardware/mocks/mock_sigan.py @@ -33,7 +33,6 @@ def __init__(self, randomize_values=False): self._overload = False self._capture_time = None self._is_available = True - self._healthy = True # Simulate returning less than the requested number of samples from # self.recv_num_samps @@ -144,9 +143,5 @@ def set_times_to_fail_recv(self, n): def last_calibration_time(self): return get_datetime_str_now() - @property - def healthy(self): - return self._healthy - def update_calibration(self, params): pass From 0a162904c906dad8e41829421baee234312f9e68 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Mon, 19 Dec 2022 14:24:49 -0700 Subject: [PATCH 08/10] fix healthy method call --- scos_actions/hardware/sigan_iface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scos_actions/hardware/sigan_iface.py b/scos_actions/hardware/sigan_iface.py index 1e7f3d37..69682195 100644 --- a/scos_actions/hardware/sigan_iface.py +++ b/scos_actions/hardware/sigan_iface.py @@ -151,4 +151,4 @@ def get_status(self): raise KeyError except KeyError: sigan_model = str(self.__class__) - return {"model": sigan_model, "healthy": self.healthy} + return {"model": sigan_model, "healthy": self.healthy()} From 4118f89384633d623ad5e8d9d86b0901799e7a41 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Mon, 19 Dec 2022 15:06:49 -0700 Subject: [PATCH 09/10] remove signal send when sigan healthy, remove unused signal keyword, fix tests --- scos_actions/actions/monitor_sigan.py | 3 +-- .../actions/tests/test_monitor_sigan.py | 24 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/scos_actions/actions/monitor_sigan.py b/scos_actions/actions/monitor_sigan.py index 42a01537..8bfaa5a7 100644 --- a/scos_actions/actions/monitor_sigan.py +++ b/scos_actions/actions/monitor_sigan.py @@ -23,8 +23,7 @@ def __call__(self, schedule_entry_json, task_id): healthy = self.sigan.healthy() if healthy: - trigger_api_restart.send(sender=self.__class__, sigan_healthy=True) logger.info("signal analyzer healthy") else: logger.warning("signal analyzer unhealthy") - trigger_api_restart.send(sender=self.__class__, sigan_healthy=False) + trigger_api_restart.send(sender=self.__class__) diff --git a/scos_actions/actions/tests/test_monitor_sigan.py b/scos_actions/actions/tests/test_monitor_sigan.py index 96b14139..3cd2e737 100644 --- a/scos_actions/actions/tests/test_monitor_sigan.py +++ b/scos_actions/actions/tests/test_monitor_sigan.py @@ -11,42 +11,42 @@ def test_monitor_sigan_not_available(): - _sigan_healthy = None + _api_restart_triggered = False def callback(sender, **kwargs): - nonlocal _sigan_healthy - _sigan_healthy = kwargs["sigan_healthy"] + nonlocal _api_restart_triggered + _api_restart_triggered = True trigger_api_restart.connect(callback) action = actions["test_monitor_sigan"] sigan = action.sigan sigan._is_available = False action(MONITOR_SIGAN_SCHEDULE, 1) - assert _sigan_healthy == False + assert _api_restart_triggered == True # signal sent sigan._is_available = True def test_monitor_sigan_not_healthy(): - _sigan_healthy = None + _api_restart_triggered = False def callback(sender, **kwargs): - nonlocal _sigan_healthy - _sigan_healthy = kwargs["sigan_healthy"] + nonlocal _api_restart_triggered + _api_restart_triggered = True trigger_api_restart.connect(callback) action = actions["test_monitor_sigan"] sigan = action.sigan sigan.times_to_fail_recv = 6 action(MONITOR_SIGAN_SCHEDULE, 1) - assert _sigan_healthy == False + assert _api_restart_triggered == True # signal sent def test_monitor_sigan_healthy(): - _sigan_healthy = None + _api_restart_triggered = False def callback(sender, **kwargs): - nonlocal _sigan_healthy - _sigan_healthy = kwargs["sigan_healthy"] + nonlocal _api_restart_triggered + _api_restart_triggered = True trigger_api_restart.connect(callback) action = actions["test_monitor_sigan"] @@ -54,4 +54,4 @@ def callback(sender, **kwargs): sigan._is_available = True sigan.set_times_to_fail_recv(0) action(MONITOR_SIGAN_SCHEDULE, 1) - assert _sigan_healthy == True + assert _api_restart_triggered == False # signal not sent From 0b666ad263fc0f19490f44ac06e9099879a0678a Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Mon, 19 Dec 2022 15:49:06 -0700 Subject: [PATCH 10/10] README update --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index d6236d97..84f2efe7 100644 --- a/README.md +++ b/README.md @@ -311,8 +311,7 @@ The following signals are currently offered: - `measurement_action_completed` - signal expects task_id, data, and metadata - `location_action_completed` - signal expects latitude and longitude -- `monitor_action_completed` - signal expects boolean indicating if the signal analyzer -is healthy +- `trigger_api_restart` - triggers a restart of the API docker container (where scos-sensor runs) New signals can be added. However, corresponding signal handlers must be added to scos-sensor to receive the signals and process the results.