示例#1
0
def check_status_file(  backed_up_file,
                        threshold,
                        access_file_method = None,
                        source_file = None,
                        config_dict = None):
    """
    check the backed up and determine whether it is within limits
    backed_up_file     - location of the status file post backup
    threshold          - number of days allowed before a problem
    access_file_method - optional method to access the backup
    """

    logging.debug('run_test_part2 - checking %s.  Threshold %d',
                  backed_up_file, threshold)

    try :
        if access_file_method :
            assert source_file | config_dict

            # Go retrieve the file
            access_file_method(backed_up_file, source_file, config_dict)

        backed_up_sync = SyncData(backed_up_file)
        status = backed_up_sync.is_sync_late(threshold)
    except UtilError as e :
        logging.error('run_test_part1 status update failed -> %s', str(e))
        status = -1

    return status
示例#2
0
 def test_islate_SyncData(self) :
     """ Check that delay checks are properly implemented
     """
     sync_data = SyncData(HOST_NAME, GOOD_TEST_PATH, TEST_NAME)
     self.assertEquals(sync_data.is_sync_late(2), SYNC_LATE)
     
     sync_data.set_last_stored()
     
     self.assertEquals(sync_data.is_sync_late(2), SYNC_OK)
     
     sync_data.last_stored = sync_data.last_stored - GOOD_DIFF_TIME
     sync_data.variable = sync_data.last_stored
     sync_data.write()
     
     sync_data = SyncData(
         HOST_NAME, GOOD_TEST_PATH, TEST_NAME)
     self.assertEquals(sync_data.is_sync_late(1.9), SYNC_LATE)
示例#3
0
 def test_clockdrift_SyncData(self) :
     """ Check that delay checks are properly implemented
     """
     sync_data = SyncData(HOST_NAME, GOOD_TEST_PATH, TEST_NAME)
     sync_data.set_last_stored()
     
     sync_data.last_stored = sync_data.last_stored + GOOD_DIFF_TIME
     sync_data.variable = sync_data.last_stored
     sync_data.write()
     
     sync_data = SyncData(
         HOST_NAME, GOOD_TEST_PATH, TEST_NAME)
     self.assertEquals(sync_data.is_sync_late(2),
                       POTENTIAL_CLOCK_DRIFT)
示例#4
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')