Skip to content

Commit

Permalink
Merge pull request #398 from HERA-Team/snap_hostname
Browse files Browse the repository at this point in the history
add get_snap_hostname_from_serial method
  • Loading branch information
bhazelton authored Sep 25, 2019
2 parents 5179b1a + e745d77 commit a1b2c86
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
47 changes: 47 additions & 0 deletions hera_mc/mc_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -2854,6 +2854,24 @@ def add_corr_snap_versions_from_corrcm(self, corr_snap_version_dict=None,
self._insert_ignoring_duplicates(SNAPConfigVersion, snap_version_list)

def _get_node_snap_from_serial(self, snap_serial, session=None):
"""
Get SNAP connection information from SNAP serial number.
Parameters
----------
snap_serial : str
SNAP serial number.
session : Session object
Session to pass to cm_handling.Handling. Defaults to self.
Returns
-------
nodeID: int
Node number.
snap_loc_num : int
SNAP location number.
"""
from hera_mc import cm_handling, cm_utils
if session is None:
session = self
Expand Down Expand Up @@ -2913,6 +2931,35 @@ def _get_node_snap_from_serial(self, snap_serial, session=None):

return nodeID, snap_loc_num

def get_snap_hostname_from_serial(self, serial_number):
"""
Get SNAP hostname from the SNAP serial number.
Parameters
----------
serial_number : str
SNAP serial number.
Returns:
--------
str or None
SNAP hostname if serial_number is found in the snap_status table,
None otherwise.
"""
from .correlator import SNAPStatus

# get most recent entry with this serial number
query = self.query(SNAPStatus).filter(
SNAPStatus.serial_number == serial_number).order_by(
desc(SNAPStatus.time)).limit(1)

result = query.all()
if len(result) < 1:
return None

return result[0].hostname

def add_snap_status(self, time, hostname, serial_number, psu_alert, pps_count,
fpga_temp, uptime_cycles, last_programmed_time):
"""
Expand Down
10 changes: 10 additions & 0 deletions hera_mc/tests/test_correlator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,16 @@ def test_get_node_snap_from_serial_errors(self):
node, snap_loc_num = self.test_session._get_node_snap_from_serial('SNPA000315')
self.assertTrue(node is None)

def test_get_snap_hostname_from_serial(self):
self.test_session.add_snap_status_from_corrcm(
snap_status_dict=snap_status_example_dict)

hostname = self.test_session.get_snap_hostname_from_serial('SNPA000222')
assert hostname == 'heraNode23Snap1'

hostname = self.test_session.get_snap_hostname_from_serial('blah')
assert hostname is None

@unittest.skipIf(not is_onsite(), 'This test only works on site')
def test_site_add_snap_status_from_corrcm(self):

Expand Down

0 comments on commit a1b2c86

Please sign in to comment.