def test_start_with_invalid_operation(self): """ periodic.start() should swallow any error that periodic.Operation.start() may raise, and keep starting the other operations after the failed one. """ lock = threading.Lock() done = threading.Event() def _work(): with lock: self.tasks -= 1 if not self.tasks: done.set() ops = [ periodic.Operation(_work, period=1.0, scheduler=self.sched, executor=self.exc), # will raise periodic.InvalidValue periodic.Operation(lambda: None, period=0, scheduler=self.sched, executor=self.exc), periodic.Operation(_work, period=1.0, scheduler=self.sched, executor=self.exc), ] with MonkeyPatchScope([ (periodic, 'config', make_config([('sampling', 'enable', 'false')])), (periodic, '_create', lambda cif, sched: ops), ]): # Don't assume operations are started in order, # we just know all of them will be start()ed. # See the documentation of periodic.start() periodic.start(fake.ClientIF(), self.sched) done.wait(0.5) self.assertTrue(done.is_set())
def serve_clients(log): cif = None irs = None scheduler = None running = [True] def sigtermHandler(signum, frame): log.info("Received signal %s, shutting down" % signum) running[0] = False def sigusr1Handler(signum, frame): if irs: log.info("Received signal %s, stopping SPM" % signum) # pylint: disable=no-member # TODO remove when side effect removed from HSM.__init__ and # initialize it in line #63 irs.spmStop(irs.getConnectedStoragePoolsList()['poollist'][0]) sigutils.register() signal.signal(signal.SIGTERM, sigtermHandler) signal.signal(signal.SIGUSR1, sigusr1Handler) zombiereaper.registerSignalHandler() profile.start() metrics.start() libvirtconnection.start_event_loop() try: if config.getboolean('irs', 'irs_enable'): try: irs = Dispatcher(HSM()) except: panic("Error initializing IRS") scheduler = schedule.Scheduler(name="vdsm.Scheduler", clock=time.monotonic_time) scheduler.start() from vdsm.clientIF import clientIF # must import after config is read cif = clientIF.getInstance(irs, log, scheduler) jobs.start(scheduler, cif) install_manhole({'irs': irs, 'cif': cif}) cif.start() init_unprivileged_network_components(cif) periodic.start(cif, scheduler) health.start() try: while running[0]: sigutils.wait_for_signal() profile.stop() finally: metrics.stop() health.stop() periodic.stop() cif.prepareForShutdown() jobs.stop() scheduler.stop() finally: libvirtconnection.stop_event_loop(wait=False)
def serve_clients(log): cif = None irs = None scheduler = None running = [True] def sigtermHandler(signum, frame): log.info("Received signal %s, shutting down" % signum) running[0] = False def sigusr1Handler(signum, frame): if irs: log.info("Received signal %s, stopping SPM" % signum) # pylint: disable=no-member # TODO remove when side effect removed from HSM.__init__ and # initialize it in line #63 irs.spmStop( irs.getConnectedStoragePoolsList()['poollist'][0]) sigutils.register() signal.signal(signal.SIGTERM, sigtermHandler) signal.signal(signal.SIGUSR1, sigusr1Handler) zombiereaper.registerSignalHandler() profile.start() metrics.start() libvirtconnection.start_event_loop() try: if config.getboolean('irs', 'irs_enable'): try: irs = Dispatcher(HSM()) except: panic("Error initializing IRS") scheduler = schedule.Scheduler(name="vdsm.Scheduler", clock=time.monotonic_time) scheduler.start() from vdsm.clientIF import clientIF # must import after config is read cif = clientIF.getInstance(irs, log, scheduler) jobs.start(scheduler, cif) install_manhole({'irs': irs, 'cif': cif}) cif.start() init_unprivileged_network_components(cif, supervdsm.getProxy()) periodic.start(cif, scheduler) health.start() try: while running[0]: sigutils.wait_for_signal() profile.stop() finally: metrics.stop() health.stop() periodic.stop() cif.prepareForShutdown() jobs.stop() scheduler.stop() finally: libvirtconnection.stop_event_loop(wait=False)