Skip to content

Commit 81ec6a1

Browse files
author
Jon
committed
Add exlclude heroic telescopes option env variable
1 parent 464841c commit 81ec6a1

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

configdb/hardware/heroic.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def send_to_heroic(api_endpoint: str, payload: dict, update: bool = False):
128128
def create_heroic_instrument(instrument: Instrument):
129129
''' Create a new instrument payload and send it to HEROIC
130130
'''
131-
if (instrument.telescope.enclosure.site.code not in settings.HEROIC_EXCLUDE_SITES):
131+
if (instrument.telescope.enclosure.site.code not in settings.HEROIC_EXCLUDE_SITES and str(instrument.telescope) not in settings.HEROIC_EXCLUDE_TELESCOPES):
132132
instrument_payload = {
133133
'id': heroic_instrument_id(instrument),
134134
'name': f"{instrument.instrument_type.name} - {instrument.code}",
@@ -145,7 +145,7 @@ def update_heroic_instrument_capabilities(instrument: Instrument):
145145
''' Send the current instrument capabilities of an instrument to HEROIC
146146
if it is not DISABLED and heroic is set up in settings.py
147147
'''
148-
if can_submit_to_heroic() and instrument.state != 'DISABLED' and instrument.telescope.enclosure.site.code not in settings.HEROIC_EXCLUDE_SITES:
148+
if can_submit_to_heroic() and instrument.state != 'DISABLED' and instrument.telescope.enclosure.site.code not in settings.HEROIC_EXCLUDE_SITES and str(instrument.telescope) not in settings.HEROIC_EXCLUDE_TELESCOPES:
149149
capabilities = instrument_to_heroic_instrument_capabilities(instrument)
150150
try:
151151
send_to_heroic('instrument-capabilities/', capabilities)
@@ -156,7 +156,7 @@ def update_heroic_instrument_capabilities(instrument: Instrument):
156156
def create_heroic_telescope(telescope: Telescope):
157157
''' Create a new telescope payload and send it to HEROIC
158158
'''
159-
if telescope.enclosure.site.code not in settings.HEROIC_EXCLUDE_SITES:
159+
if telescope.enclosure.site.code not in settings.HEROIC_EXCLUDE_SITES and str(telescope) not in settings.HEROIC_EXCLUDE_TELESCOPES:
160160
telescope_payload = telescope_to_heroic_telescope_properties(telescope)
161161
telescope_payload['id'] = heroic_telescope_id(telescope)
162162
telescope_payload['status'] = telescope_status_conversion(telescope)
@@ -171,7 +171,7 @@ def create_heroic_telescope(telescope: Telescope):
171171
def update_heroic_telescope_properties(telescope: Telescope):
172172
''' Send updated telescope properties to HEROIC when they change
173173
'''
174-
if telescope.enclosure.site.code not in settings.HEROIC_EXCLUDE_SITES:
174+
if telescope.enclosure.site.code not in settings.HEROIC_EXCLUDE_SITES and str(telescope) not in settings.HEROIC_EXCLUDE_TELESCOPES:
175175
telescope_update_payload = telescope_to_heroic_telescope_properties(telescope)
176176
try:
177177
send_to_heroic(f'telescopes/{heroic_telescope_id(telescope)}/', telescope_update_payload, update=True)

configdb/hardware/tests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,17 @@ def test_update_instrument_state_on_excluded_site_does_not_call_out_to_heroic(se
189189
)
190190
mock_send.assert_not_called()
191191

192+
@override_settings(HEROIC_EXCLUDE_TELESCOPES=['tst.doma.1m0a'])
193+
def test_update_instrument_state_on_excluded_telescope_does_not_call_out_to_heroic(self, mock_send):
194+
instrument_update = {
195+
'state': Instrument.MANUAL
196+
}
197+
self.client.patch(
198+
reverse('instrument-detail', args=(self.instrument.id,)),
199+
data=instrument_update, format='json'
200+
)
201+
mock_send.assert_not_called()
202+
192203
def test_update_instrument_cameras_calls_out_to_heroic(self, mock_send):
193204
optical_element = mixer.blend(OpticalElement, name='myOE', code='myoe1', schedulable=True)
194205
optical_element_group = mixer.blend(OpticalElementGroup, optical_elements=[optical_element], type='filters')

configdb/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def get_list_from_env(variable, default=None):
164164
HEROIC_API_TOKEN = os.getenv('HEROIC_API_TOKEN', '')
165165
HEROIC_OBSERVATORY = os.getenv('HEROIC_OBSERVATORY', '')
166166
HEROIC_EXCLUDE_SITES = get_list_from_env('HEROIC_EXCLUDE_SITES', '')
167+
HEROIC_EXCLUDE_TELESCOPES = get_list_from_env('HEROIC_EXCLUDE_TELESCOPES', '')
167168

168169
CORS_ORIGIN_ALLOW_ALL = True
169170

0 commit comments

Comments
 (0)