File indexing completed on 2026-11-09 10:47:30
0001 """The room's sites take their queues and status from the queue registry
0002 (swf-epicprod docs/QUEUE_REGISTRY.md)."""
0003 import copy
0004 from unittest.mock import patch
0005
0006 from swf_epicprod import queues as registry
0007
0008 from monitor_app import comp_snapshot
0009
0010 LIVE = {
0011 'front.queues': list(registry.SEED_FRONT_QUEUES),
0012 'front.closed_queues': dict(registry.SEED_CLOSED),
0013 'comp.sites': [dict(g, queues=copy.deepcopy(r['queues']))
0014 for g, r in zip(comp_snapshot.DEFAULT_SITES, registry.SEED_ROOM)],
0015 }
0016
0017
0018 def _sites(config, groups):
0019 registry.invalidate()
0020 try:
0021 with patch.object(registry, '_config', return_value=config), \
0022 patch('monitor_app.models.SysConfig.get_setting', return_value=groups):
0023 return comp_snapshot._sites_config()
0024 finally:
0025 registry.invalidate()
0026
0027
0028 def test_derived_record_reproduces_the_room_as_it_was():
0029 sites = _sites(copy.deepcopy(LIVE), LIVE['comp.sites'])
0030 shown = {s['id']: [(q['id'], q['status']) for q in s['queues']] for s in sites}
0031 assert [s['id'] for s in sites] == ['osg', 'grex', 'compute-canada', 'nersc', 'google', 'jlab']
0032 assert shown['osg'] == [('BNL_OSG_PanDA_1', None)]
0033 assert shown['grex'] == [('UM_GREX_PanDA_1', None)]
0034 assert shown['compute-canada'] == [('ComputeCanada_PanDA_1', 'not_built')]
0035 assert shown['nersc'] == [('NERSC_Perlmutter_epic', 'off'), ('NERSC_Perlmutter_epic_es', 'off')]
0036 assert shown['google'] == [('BNL_ePIC_GOOGLE', 'off'), ('BNL_ePIC_GOOGLE_es', 'off')]
0037 assert shown['jlab'] == [('JLAB_PanDA_1', 'off')]
0038 assert sites[0]['execute_sites'] is True
0039
0040
0041 def test_adopted_record_and_stripped_groups_keep_the_room_and_follow_a_change():
0042 data = copy.deepcopy(LIVE)
0043 record, _ = registry.adopt_into(data, 'test', strip_room=True)
0044 assert all('queues' not in g for g in data['comp.sites'])
0045 registry.change(record, 'UM_GREX_PanDA_1', 'retired', reason='gone', by='test')
0046 registry.change(record, 'NERSC_Perlmutter_epic', 'production', by='test')
0047 registry.change(record, 'NEW_Q', 'commissioning', reason='new', by='test', site='elsewhere')
0048 sites = {s['id']: s for s in _sites(data, data['comp.sites'])}
0049 assert sites['grex']['queues'] == []
0050 assert sites['nersc']['queues'][0] == {'id': 'NERSC_Perlmutter_epic', 'status': None,
0051 'status_reason': ''}
0052 assert sites['elsewhere']['queues'][0]['status'] == 'off'
0053
0054
0055 def test_drift_is_a_red_report_line_naming_the_copy():
0056 items = comp_snapshot._drift_items([{'queue': 'BNL_OSG_EPIC_PROD_1', 'copy': 'harvester on osgsub01-harvester',
0057 'holds': 'online', 'expected': 'offline (retired)'}])
0058 assert items[0]['level'] == 'red'
0059 assert items[0]['text'].startswith('Queue drift, BNL_OSG_EPIC_PROD_1: harvester on osgsub01-harvester holds online')
0060 assert comp_snapshot._drift_items([]) == []