示例#1
0
    def add_agent_status_check_worker(self, function):
        # TODO(enikanorov): make interval configurable rather than computed
        interval = max(cfg.CONF.agent_down_time // 2, 1)
        # add random initial delay to allow agents to check in after the
        # neutron server first starts. random to offset multiple servers
        initial_delay = random.randint(interval, interval * 2)

        check_worker = neutron_worker.PeriodicWorker(function, interval,
                                                     initial_delay)
        self.add_worker(check_worker)
示例#2
0
 def test_periodic_worker_lifecycle(self):
     check_function = mock.Mock()
     worker = neutron_worker.PeriodicWorker(check_function,
                                            interval=1,
                                            initial_delay=1)
     self.addCleanup(worker.stop)
     worker.wait()
     self.assertFalse(check_function.called)
     worker.start()
     utils.wait_until_true(
         lambda: check_function.called,
         timeout=5,
         exception=RuntimeError("check_function not called"))
     worker.stop()
     check_function.reset_mock()
     worker.wait()
     self.assertFalse(check_function.called)
     worker.reset()
     utils.wait_until_true(
         lambda: check_function.called,
         timeout=5,
         exception=RuntimeError("check_function not called"))
示例#3
0
 def get_workers():
     interval = quota_api.RESERVATION_EXPIRATION_TIMEOUT
     method = DbQuotaNoLockDriver._remove_expired_reservations
     return [neutron_worker.PeriodicWorker(method, interval, interval)]