From c7771d1783ef7d7e1efb29e81aae44ad26747c5c Mon Sep 17 00:00:00 2001 From: Gijs Koning Date: Thu, 14 Jul 2022 11:49:27 +0200 Subject: [PATCH] Bump laika and catch Downloadfiles exception. --- laika_repo | 2 +- selfdrive/locationd/laikad.py | 3 ++- selfdrive/locationd/test/test_laikad.py | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/laika_repo b/laika_repo index 828612e1b8..3ce2628dfc 160000 --- a/laika_repo +++ b/laika_repo @@ -1 +1 @@ -Subproject commit 828612e1b8848ccf70072d5513c0b7977f1707da +Subproject commit 3ce2628dfc8ddba1769c518f90275e3caca9e8c6 diff --git a/selfdrive/locationd/laikad.py b/selfdrive/locationd/laikad.py index 4868e8ae52..13829b22a9 100755 --- a/selfdrive/locationd/laikad.py +++ b/selfdrive/locationd/laikad.py @@ -15,6 +15,7 @@ from cereal import log, messaging from common.params import Params, put_nonblocking from laika import AstroDog from laika.constants import SECS_IN_HR, SECS_IN_MIN +from laika.downloader import DownloadFailed from laika.ephemeris import Ephemeris, EphemerisType, convert_ublox_ephem from laika.gps_time import GPSTime from laika.helpers import ConstellationId @@ -212,7 +213,7 @@ def get_orbit_data(t: GPSTime, valid_const, auto_update, valid_ephem_types, cach astro_dog.get_orbit_data(t, only_predictions=True) cloudlog.info(f"Done parsing orbits. Took {time.monotonic() - start_time:.1f}s") return astro_dog.orbits, astro_dog.orbit_fetched_times, t - except (RuntimeError, ValueError, IOError) as e: + except (DownloadFailed, RuntimeError, ValueError, IOError) as e: cloudlog.warning(f"No orbit data found or parsing failure: {e}") return None, None, t diff --git a/selfdrive/locationd/test/test_laikad.py b/selfdrive/locationd/test/test_laikad.py index c10a470d1a..bc7a0d7fa4 100755 --- a/selfdrive/locationd/test/test_laikad.py +++ b/selfdrive/locationd/test/test_laikad.py @@ -8,6 +8,7 @@ from unittest.mock import Mock, patch from common.params import Params from laika.constants import SECS_IN_DAY +from laika.downloader import DownloadFailed from laika.ephemeris import EphemerisType, GPSEphemeris from laika.gps_time import GPSTime from laika.helpers import ConstellationId, TimeRangeHolder @@ -51,6 +52,9 @@ def get_measurement_mock(gpstime, sat_ephemeris): return meas +GPS_TIME_PREDICTION_ORBITS_RUSSIAN_SRC = GPSTime.from_datetime(datetime(2022, month=1, day=29, hour=12)) + + class TestLaikad(unittest.TestCase): @classmethod @@ -109,7 +113,7 @@ class TestLaikad(unittest.TestCase): data_mock = defaultdict(str) data_mock['sv_id'] = 1 - gpstime = GPSTime.from_datetime(datetime(2022, month=3, day=1)) + gpstime = GPS_TIME_PREDICTION_ORBITS_RUSSIAN_SRC laikad = Laikad() laikad.fetch_orbits(gpstime, block=True) meas = get_measurement_mock(gpstime, laikad.astro_dog.orbits['R01'][0]) @@ -165,7 +169,13 @@ class TestLaikad(unittest.TestCase): @mock.patch('laika.downloader.download_and_cache_file') def test_laika_offline(self, downloader_mock): - downloader_mock.side_effect = IOError + downloader_mock.side_effect = DownloadFailed("Mock download failed") + laikad = Laikad(auto_update=False) + laikad.fetch_orbits(GPS_TIME_PREDICTION_ORBITS_RUSSIAN_SRC, block=True) + + @mock.patch('laika.downloader.download_and_cache_file') + def test_download_failed_russian_source(self, downloader_mock): + downloader_mock.side_effect = DownloadFailed laikad = Laikad(auto_update=False) correct_msgs = verify_messages(self.logs, laikad) self.assertEqual(16, len(correct_msgs))