Beispiel #1
0
    def test_old_heartbeat_cleanup(self):
        pids = [self.__pid() for _ in range(2)]
        thread = self.__thread()

        live('test1', 'host0', pids[0], thread)
        live('test2', 'host0', pids[1], thread)
        live('test1', 'host1', pids[0], thread)
        live('test2', 'host1', pids[1], thread)
        live('test1', 'host2', pids[0], thread)
        live('test2', 'host2', pids[1], thread)

        assert len(list_heartbeats()) == 6

        @transactional_session
        def __forge_updated_at(session=None):
            two_days_ago = datetime.utcnow() - timedelta(days=2)
            a_dozen_hours_ago = datetime.utcnow() - timedelta(hours=12)
            session.query(Heartbeats).filter_by(hostname='host1').update(
                {'updated_at': two_days_ago})
            session.query(Heartbeats).filter_by(hostname='host2').update(
                {'updated_at': a_dozen_hours_ago})

        __forge_updated_at()

        # Default expiration delay. Host1 health checks should get removed.
        sanity_check(executable=None, hostname=None)
        assert len(list_heartbeats()) == 4

        # Custom expiration delay. Host2 health checks should get removed too.
        sanity_check('test2',
                     'host2',
                     expiration_delay=timedelta(hours=5).total_seconds())
        assert len(list_heartbeats()) == 2
Beispiel #2
0
def list_heartbeats(issuer=None, vo='def'):
    """
    Return a list of tuples of all heartbeats.

    :param issuer: The issuer account.
    :param vo: the VO for the issuer.
    :returns: List of tuples [('Executable', 'Hostname', ...), ...]
    """

    kwargs = {'issuer': issuer}
    if not permission.has_permission(issuer=issuer, vo=vo, action='list_heartbeats', kwargs=kwargs):
        raise exception.AccessDenied('%s cannot list heartbeats' % issuer)
    return heartbeat.list_heartbeats()