Skip to content

Commit

Permalink
Handle 502 from telescope_states endpoint for OCS facility status info
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon committed Sep 7, 2023
1 parent 101a4dc commit 2bb9ede
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
19 changes: 12 additions & 7 deletions tom_observations/facilities/ocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,13 +1359,18 @@ def get_facility_status(self):
"""
# make the request to the OCS API for the telescope_states
now = datetime.now()
response = make_request(
'GET',
urljoin(self.facility_settings.get_setting('portal_url'), '/api/telescope_states/'),
headers=self._portal_headers()
)
telescope_states = response.json()
logger.warning(f"Telescope states took {(datetime.now() - now).total_seconds()}")
telescope_states = {}
try:
response = make_request(
'GET',
urljoin(self.facility_settings.get_setting('portal_url'), '/api/telescope_states/'),
headers=self._portal_headers()
)
response.raise_for_status()
telescope_states = response.json()
logger.info(f"Telescope states took {(datetime.now() - now).total_seconds()}")
except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError) as e:
logger.warning(f"Error retrieving telescope_states from OCS for facility status: {repr(e)}")
# Now, transform the telescopes_state dictionary in a dictionary suitable
# for the facility_status.html template partial.

Expand Down
9 changes: 9 additions & 0 deletions tom_observations/tests/facilities/test_ocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ class TestOCSFacility(TestCase):
def setUp(self):
self.lco = OCSFacility()

@patch('tom_observations.facilities.ocs.make_request')
def test_get_requestgroup_id(self, mock_make_request):
mock_response = Response()
mock_response._content = str.encode('ConnectionError - Error retrieving telescope availability')
mock_response.status_code = 502
mock_make_request.return_value = mock_response
facility_status = self.lco.get_facility_status()
self.assertEqual(facility_status.get('sites'), [])

@patch('tom_observations.facilities.ocs.make_request')
def test_get_requestgroup_id(self, mock_make_request):
mock_response = Response()
Expand Down

0 comments on commit 2bb9ede

Please sign in to comment.