Disable ost if connection fails post ticket select

This commit is contained in:
2Shirt 2020-01-11 20:46:45 -07:00
parent e301bff2c2
commit 426d77147f
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -74,9 +74,14 @@ class osTicket(): # pylint: disable=invalid-name
break break
# Raise exception if necessary # Raise exception if necessary
if self.db_cursor is None and not silent: if self.db_cursor is None:
LOG.error('Failed to connect to osTicket database') LOG.error('Failed to connect to osTicket database')
raise RuntimeError('Failed to connect to osTicket database') if silent:
# Don't raise exceptions, just disable ost
self.disabled = True
self.errors = True
else:
raise RuntimeError('Failed to connect to osTicket database')
def _disconnect(self): def _disconnect(self):
"""Close osTicket connection.""" """Close osTicket connection."""
@ -197,7 +202,7 @@ class osTicket(): # pylint: disable=invalid-name
"""Post a reply to a ticket in osTicket.""" """Post a reply to a ticket in osTicket."""
lines = [] lines = []
test_station = get_test_station_name() test_station = get_test_station_name()
self._connect() self._connect(silent=True)
self._verify_ticket_id() self._verify_ticket_id()
# Bail if disabled # Bail if disabled
@ -308,7 +313,7 @@ class osTicket(): # pylint: disable=invalid-name
NOTE: This will not replace a higher temp value. NOTE: This will not replace a higher temp value.
""" """
LOG.info('Setting max CPU temp to %s', temp) LOG.info('Setting max CPU temp to %s', temp)
self._connect() self._connect(silent=True)
# Bail if disabled # Bail if disabled
if self.disabled: if self.disabled:
@ -331,7 +336,7 @@ class osTicket(): # pylint: disable=invalid-name
"""Set flag as failed in osTicket for ticket_id.""" """Set flag as failed in osTicket for ticket_id."""
LOG.warning('Setting osTicket %s checkbox to FAILED', flag_name) LOG.warning('Setting osTicket %s checkbox to FAILED', flag_name)
real_flag_name = FLAG_CPU if flag_name == 'CPU' else FLAG_DISK real_flag_name = FLAG_CPU if flag_name == 'CPU' else FLAG_DISK
self._connect() self._connect(silent=True)
# Bail if disabled # Bail if disabled
if self.disabled: if self.disabled:
@ -349,7 +354,7 @@ class osTicket(): # pylint: disable=invalid-name
NOTE: This will not overwrite a failed status. NOTE: This will not overwrite a failed status.
""" """
real_flag_name = FLAG_CPU if flag_name == 'CPU' else FLAG_DISK real_flag_name = FLAG_CPU if flag_name == 'CPU' else FLAG_DISK
self._connect() self._connect(silent=True)
# Bail if disabled # Bail if disabled
if self.disabled: if self.disabled: