Esempio n. 1
0
 def tearDown(self):
     for service_class in ServiceMonitor.services:
         service_class.ping = service_class._orig_ping
         delattr(service_class, "_orig_ping")
         delattr(service_class, "pings")
         service_class.MONITORING_PING_FREQUENCY = service_class._orig_monitoring_frequency
         service_class.OUTAGE_PING_FREQUENCY = service_class._orig_outage_frequency
         service_class.ERROR_PING_FREQUENCY = service_class._orig_error_frequency
         delattr(service_class, "_orig_monitoring_frequency")
         delattr(service_class, "_orig_outage_frequency")
         delattr(service_class, "_orig_error_frequency")
         
         # Clear the last_ping from each service class so as not to impact the
         # next test.
         service_class.last_ping = None
         
     self.tearDownDBSlave()
     if test_memcached:
         self.tearDownMemcached()
     if test_celery:
         self.tearDownCelery()
         
     ServiceMonitor.services = self.orig_services
     failover_settings.OUTAGE_EXCEPTION_CLASSES = self.orig_failover_exception_classes
     
     self.logger.removeHandler(self.log_handler)
     monitor_logger.removeHandler(self.log_capture_handler)
     monitor_logger.setLevel(self.orig_monitor_logger_level)
     LogCaptureHandler.records = []
Esempio n. 2
0
    def tearDown(self):
        for service_class in ServiceMonitor.services:
            service_class.ping = service_class._orig_ping
            delattr(service_class, "_orig_ping")
            delattr(service_class, "pings")
            service_class.MONITORING_PING_FREQUENCY = service_class._orig_monitoring_frequency
            service_class.OUTAGE_PING_FREQUENCY = service_class._orig_outage_frequency
            service_class.ERROR_PING_FREQUENCY = service_class._orig_error_frequency
            delattr(service_class, "_orig_monitoring_frequency")
            delattr(service_class, "_orig_outage_frequency")
            delattr(service_class, "_orig_error_frequency")

            # Clear the last_ping from each service class so as not to impact the
            # next test.
            service_class.last_ping = None

        self.tearDownDBSlave()
        if test_memcached:
            self.tearDownMemcached()
        if test_celery:
            self.tearDownCelery()

        ServiceMonitor.services = self.orig_services
        failover_settings.OUTAGE_EXCEPTION_CLASSES = self.orig_failover_exception_classes

        self.logger.removeHandler(self.log_handler)
        monitor_logger.removeHandler(self.log_capture_handler)
        monitor_logger.setLevel(self.orig_monitor_logger_level)
        LogCaptureHandler.records = []
Esempio n. 3
0
 def setUp(self):
     """Adds a slave connection to settings.DATABASES, which uses the
     sames settings as the default connection but includes a marker to
     distinguish it. Registers the test service class.
     """
     self.orig_services = ServiceMonitor.services
     ServiceMonitor.services.clear()
     
     self.setUpDBSlave()
     if test_memcached:
         self.setUpMemcached()
     if test_celery:
         self.setUpCelery()
     
     for service_class in ServiceMonitor.services:
         self.patch_ping(service_class)
         # Set ping frequencies to 0 (ping every time)
         service_class._orig_monitoring_frequency = service_class.MONITORING_PING_FREQUENCY
         service_class._orig_outage_frequency = service_class.OUTAGE_PING_FREQUENCY
         service_class._orig_error_frequency = service_class.ERROR_PING_FREQUENCY
         service_class.MONITORING_PING_FREQUENCY = 0
         service_class.OUTAGE_PING_FREQUENCY = 0
         service_class.ERROR_PING_FREQUENCY = 0
    
     # Register socket.error as an exception class that should trigger
     # monitoring.
     self.orig_failover_exception_classes = failover_settings.OUTAGE_EXCEPTION_CLASSES
     failover_settings.OUTAGE_EXCEPTION_CLASSES = (socket.error,)
     
     # Set up a logger tied to the FailoverHandler.
     self.logger = logging.getLogger("failover_test")
     self.logger.setLevel(logging.ERROR)
     self.log_handler = FailoverHandler()
     self.logger.addHandler(self.log_handler)
     
     self.log_capture_handler = LogCaptureHandler()
     monitor_logger.addHandler(self.log_capture_handler)
     self.orig_monitor_logger_level = monitor_logger.level
     monitor_logger.setLevel(logging.INFO)
     LogCaptureHandler.records = []
Esempio n. 4
0
    def setUp(self):
        """Adds a slave connection to settings.DATABASES, which uses the
        sames settings as the default connection but includes a marker to
        distinguish it. Registers the test service class.
        """
        self.orig_services = ServiceMonitor.services
        ServiceMonitor.services.clear()

        self.setUpDBSlave()
        if test_memcached:
            self.setUpMemcached()
        if test_celery:
            self.setUpCelery()

        for service_class in ServiceMonitor.services:
            self.patch_ping(service_class)
            # Set ping frequencies to 0 (ping every time)
            service_class._orig_monitoring_frequency = service_class.MONITORING_PING_FREQUENCY
            service_class._orig_outage_frequency = service_class.OUTAGE_PING_FREQUENCY
            service_class._orig_error_frequency = service_class.ERROR_PING_FREQUENCY
            service_class.MONITORING_PING_FREQUENCY = 0
            service_class.OUTAGE_PING_FREQUENCY = 0
            service_class.ERROR_PING_FREQUENCY = 0

        # Register socket.error as an exception class that should trigger
        # monitoring.
        self.orig_failover_exception_classes = failover_settings.OUTAGE_EXCEPTION_CLASSES
        failover_settings.OUTAGE_EXCEPTION_CLASSES = (socket.error, )

        # Set up a logger tied to the FailoverHandler.
        self.logger = logging.getLogger("failover_test")
        self.logger.setLevel(logging.ERROR)
        self.log_handler = FailoverHandler()
        self.logger.addHandler(self.log_handler)

        self.log_capture_handler = LogCaptureHandler()
        monitor_logger.addHandler(self.log_capture_handler)
        self.orig_monitor_logger_level = monitor_logger.level
        monitor_logger.setLevel(logging.INFO)
        LogCaptureHandler.records = []