Beispiel #1
0
    def test_empty_alertdue_SyncDataAlert(self) :
        """
            First call - no file
        """
        sync_data = SyncDataAlert(HOST_NAME, GOOD_TEST_PATH, TEST_NAME)

        self.assertTrue(sync_data.alert_due(1))
Beispiel #2
0
 def test_valid_write_SyncDataAlert(self) :
     """
         Write out a valid file - should be no exceptions
     """
     sync_data = SyncDataAlert(HOST_NAME, GOOD_TEST_PATH, TEST_NAME)
     sync_data.set_last_alerted()
     self.assertIsNone(None)
def main() :
    """
    Mess with dates for testing purposes

    """

    # Get the command line arguments
    p = optparse.OptionParser()

    p.add_option("--source_dir", action="store", dest="source_dir")
    p.add_option("--test_name", action="store", dest="test_name")

    opts, source_file_args = p.parse_args()           #pylint: disable-msg=W0612

    hostname = socket.gethostname().split('.')[0]
    
    while True :
        print "Enter Data or Alert D|A -> "
        mode = sys.stdin.readline()
        print "Enter New Date -> "
        date_string = sys.stdin.readline()

        date_object = datetime.strptime(date_string.rstrip(), '%Y %m %d %H:%M')
        
        if mode.rstrip() == 'D' :
            sync_data = SyncData(hostname, opts.source_dir, opts.test_name)
            sync_data.variable = date_object
            sync_data.write()
        else :
            sync_alert = SyncDataAlert(hostname, opts.source_dir,
                                       opts.test_name)
            sync_alert.variable = date_object
            sync_alert.write()
Beispiel #4
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 #5
0
 def test_good_write_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()
 
     last_alerted = sync_data.last_alerted
 
     sync_data = SyncDataAlert(HOST_NAME, GOOD_TEST_PATH, TEST_NAME)
     self.assertEquals(last_alerted, sync_data.last_alerted)
Beispiel #6
0
 def test_alertdue_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()
     
     self.assertFalse(sync_data.alert_due(1))
     
     sync_data.last_alerted = sync_data.last_alerted - GOOD_DIFF_TIME
 
     self.assertTrue(sync_data.alert_due(1))
Beispiel #7
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')