Beispiel #1
0
 def test_alerted_SyncDataAlert(self) :
     """ Write a good file based on last_stored and check its restored ok
     """
     sync_data = SyncDataAlert(HOST_NAME, GOOD_TEST_PATH, TEST_NAME)
     sync_data.set_last_alerted()
 
     sync_data = SyncDataAlert(HOST_NAME, GOOD_TEST_PATH, TEST_NAME)
 
     self.assertTrue(sync_data.alerted())
Beispiel #2
0
def run_destination_tests(hostname, data_dir, testlist, alert_function):
    """
    hostname - us
    data_dir - where the alert tracking files are stored
    testlist - contains details of the files we are looking for
    
    Methodology is simple
    *   if the file is late and an alert is outstanding - generate one
    *   if the file is on time and an alert has been sent - send out an all
        clear
    """
    
    logging.debug('sync_tests.py::run_destination_tests -> %s', hostname)

    # Run through the list and look for ones applicable to this host
    for testname, sync_test in testlist.iteritems():
        logging.debug('checking %s -> %s', hostname, testname)
        
        if hostname == sync_test.destination_host :
            # We've found one - get the status and check it
            logging.info('running test %s', testname)
            sync_data = SyncData(
                sync_test.origination_host,
                sync_test.destination_path,
                sync_test.testname )
            sync_alert = SyncDataAlert(
                hostname,
                data_dir,
                sync_test.testname)
                
            is_sync_late = sync_data.is_sync_late(sync_test.max_delay)
            if is_sync_late == SyncData.SYNC_LATE :
                # We're late - see if we have to do anthing
                if sync_alert.alert_due(sync_test.alert_frequency) :
                    logging.info('Late -> Alerting')
                    #   An Alert is due so send one out
                    sync_alert.set_last_alerted()
                    delay = sync_data.delay()
                    if int(delay) == 0 :
                        delay = "No Sender Detected"
                    alert_function(SYNC_ALERT, sync_test, delay)
                else :
                    logging.info("Late but alerted -> %s",
                                 sync_alert.last_alerted)
            elif is_sync_late == SyncData.POTENTIAL_CLOCK_DRIFT :
                logging.error('Clock Drift')
                # We're late - see if we have to do anthing
                if sync_alert.alert_due(sync_test.alert_frequency) :
                    logging.info('Alerting')
                    #   An Alert is due so send one out
                    sync_alert.set_last_alerted()
                    delay = sync_data.delay()
                    alert_function(CLOCK_DRIFT, sync_test, delay)
                    
            else :
                # We're on time - see if something had previously been sent
                if sync_alert.alerted() :
                    logging.info('Synchronisation has caught up')
                    #   It had - issue the all clear and reset
                    alert_function(SYNC_ALL_CLEAR, sync_test)
                    sync_alert.reset()
    
    logging.debug('sync_tests.py::run_destination_tests - completed')