def check_child_signal_to_thread(): ''' This test checks the following scenario: * main thread is waiting for signal * another thread is running a subprocess * the subprocess exits before another thread dies This leads to signal being sent to another thread but not the main thread. This test makes sure main thread is woken up. ''' def thread_target(): subprocess.Popen(['true']) time.sleep(1) # sleep so SIGCHLD is delivered here. threading.Thread(target=thread_target).start() sigutils.wait_for_signal()
def check_signal_times(): sigutils.wait_for_signal() sys.stdout.write('woke up\n') sigutils.wait_for_signal() sys.stdout.write('woke up\n') sigutils.wait_for_signal() sys.stdout.write('woke up\n')
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 main(args): try: __assertSingleInstance() parser = option_parser() args = parser.parse_args(args=args) # Override user and group if called with --user and --group. constants.VDSM_USER = args.user constants.VDSM_GROUP = args.group # Override storage-repository, used to verify file access. sc.REPO_DATA_CENTER = args.data_center sc.REPO_MOUNT_DIR = os.path.join(args.data_center, sc.DOMAIN_MNT_POINT) try: logging.config.fileConfig(args.logger_conf, disable_existing_loggers=False) except Exception as e: raise FatalError("Cannot configure logging: %s" % e) log = logging.getLogger("SuperVdsm.Server") sockfile = args.sockfile pidfile = args.pidfile if not config.getboolean('vars', 'core_dump_enable'): resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) sigutils.register() zombiereaper.registerSignalHandler() def bind(func): def wrapper(_SuperVdsm, *args, **kwargs): return func(*args, **kwargs) return wrapper if args.enable_gluster: for name, func in listPublicFunctions( constants.GLUSTER_MGMT_ENABLED): setattr(_SuperVdsm, name, bind(logDecorator(func))) for _, module_name, _ in pkgutil.iter_modules( [supervdsm_api.__path__[0]]): module = importlib.import_module( '%s.%s' % (supervdsm_api.__name__, module_name)) api_funcs = [ f for _, f in six.iteritems(module.__dict__) if callable(f) and getattr(f, 'exposed_api', False) ] for func in api_funcs: setattr(_SuperVdsm, func.__name__, bind(logDecorator(func))) log.debug("Making sure I'm root - SuperVdsm") if os.geteuid() != 0: sys.exit(errno.EPERM) if pidfile: pid = str(os.getpid()) with open(pidfile, 'w') as f: f.write(pid + "\n") log.debug("Parsing cmd args") address = sockfile log.debug("Cleaning old socket %s", address) if os.path.exists(address): os.unlink(address) log.debug("Setting up keep alive thread") try: signal.signal(signal.SIGTERM, terminate) signal.signal(signal.SIGINT, terminate) log.debug("Creating remote object manager") manager = _SuperVdsmManager(address=address, authkey=b'') manager.register('instance', callable=_SuperVdsm) server = manager.get_server() servThread = concurrent.thread(server.serve_forever) servThread.start() chown(address, args.user, args.group) if args.enable_network: init_privileged_network_components() log.debug("Started serving super vdsm object") while _running: sigutils.wait_for_signal() log.debug("Terminated normally") finally: if os.path.exists(address): fileutils.rm_file(address) except Exception as e: syslog.syslog("Supervdsm failed to start: %s" % e) # Make it easy to debug via the shell raise
def main(args): try: __assertSingleInstance() parser = option_parser() args = parser.parse_args(args=args) # Override user and group if called with --user and --group. constants.VDSM_USER = args.user constants.VDSM_GROUP = args.group # Override storage-repository, used to verify file access. sc.REPO_DATA_CENTER = args.data_center sc.REPO_MOUNT_DIR = os.path.join(args.data_center, sc.DOMAIN_MNT_POINT) try: logging.config.fileConfig(args.logger_conf, disable_existing_loggers=False) except Exception as e: raise FatalError("Cannot configure logging: %s" % e) log = logging.getLogger("SuperVdsm.Server") sockfile = args.sockfile pidfile = args.pidfile if not config.getboolean('vars', 'core_dump_enable'): resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) sigutils.register() zombiereaper.registerSignalHandler() def bind(func): def wrapper(_SuperVdsm, *args, **kwargs): return func(*args, **kwargs) return wrapper if args.enable_gluster: for name, func in listPublicFunctions( constants.GLUSTER_MGMT_ENABLED): setattr(_SuperVdsm, name, bind(logDecorator(func))) for _, module_name, _ in pkgutil.iter_modules([supervdsm_api. __path__[0]]): module = importlib.import_module('%s.%s' % (supervdsm_api.__name__, module_name)) api_funcs = [f for _, f in six.iteritems(module.__dict__) if callable(f) and getattr(f, 'exposed_api', False)] for func in api_funcs: setattr(_SuperVdsm, func.__name__, bind(logDecorator(func))) log.debug("Making sure I'm root - SuperVdsm") if os.geteuid() != 0: sys.exit(errno.EPERM) if pidfile: pid = str(os.getpid()) with open(pidfile, 'w') as f: f.write(pid + "\n") log.debug("Parsing cmd args") address = sockfile log.debug("Cleaning old socket %s", address) if os.path.exists(address): os.unlink(address) log.debug("Setting up keep alive thread") try: signal.signal(signal.SIGTERM, terminate) signal.signal(signal.SIGINT, terminate) log.debug("Creating remote object manager") manager = _SuperVdsmManager(address=address, authkey=b'') manager.register('instance', callable=_SuperVdsm) server = manager.get_server() servThread = concurrent.thread(server.serve_forever) servThread.start() chown(address, args.user, args.group) if args.enable_network: init_privileged_network_components() log.debug("Started serving super vdsm object") while _running: sigutils.wait_for_signal() log.debug("Terminated normally") finally: if os.path.exists(address): fileutils.rm_file(address) except Exception as e: syslog.syslog("Supervdsm failed to start: %s" % e) # Make it easy to debug via the shell raise
def check_uninitialized(): try: sigutils.wait_for_signal() except RuntimeError: sys.stdout.write('exception\n')
def check_signal_timeout(timeout): sigutils.wait_for_signal(float(timeout))
def check_signal_received(): sigutils.wait_for_signal()
def main(args): log = logging.getLogger("SuperVdsm.Server") parser = option_parser() args = parser.parse_args(args=args) sockfile = args.sockfile pidfile = args.pidfile if not config.getboolean('vars', 'core_dump_enable'): resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) sigutils.register() zombiereaper.registerSignalHandler() def bind(func): def wrapper(_SuperVdsm, *args, **kwargs): return func(*args, **kwargs) return wrapper if _glusterEnabled: for name, func in listPublicFunctions(GLUSTER_MGMT_ENABLED): setattr(_SuperVdsm, name, bind(logDecorator(func))) for _, module_name, _ in pkgutil.iter_modules([supervdsm_api.__path__[0]]): module = importlib.import_module('%s.%s' % (supervdsm_api.__name__, module_name)) api_funcs = [ f for _, f in module.__dict__.iteritems() if callable(f) and getattr(f, 'exposed_api', False) ] for func in api_funcs: setattr(_SuperVdsm, func.__name__, bind(logDecorator(func))) try: log.debug("Making sure I'm root - SuperVdsm") if os.geteuid() != 0: sys.exit(errno.EPERM) if pidfile: pid = str(os.getpid()) with open(pidfile, 'w') as f: f.write(pid + "\n") log.debug("Parsing cmd args") address = sockfile log.debug("Cleaning old socket %s", address) if os.path.exists(address): os.unlink(address) log.debug("Setting up keep alive thread") try: signal.signal(signal.SIGTERM, terminate) signal.signal(signal.SIGINT, terminate) log.debug("Creating remote object manager") manager = _SuperVdsmManager(address=address, authkey='') manager.register('instance', callable=_SuperVdsm) server = manager.get_server() servThread = concurrent.thread(server.serve_forever) servThread.start() chown(address, getpwnam(VDSM_USER).pw_uid, METADATA_GROUP) log.debug("Started serving super vdsm object") init_privileged_network_components() while _running: sigutils.wait_for_signal() log.debug("Terminated normally") finally: if os.path.exists(address): fileutils.rm_file(address) except Exception: log.error("Could not start Super Vdsm", exc_info=True) sys.exit(1)
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)
def main(args): log = logging.getLogger("SuperVdsm.Server") parser = option_parser() args = parser.parse_args(args=args) sockfile = args.sockfile pidfile = args.pidfile if not config.getboolean('vars', 'core_dump_enable'): resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) sigutils.register() zombiereaper.registerSignalHandler() def bind(func): def wrapper(_SuperVdsm, *args, **kwargs): return func(*args, **kwargs) return wrapper if _glusterEnabled: for name, func in listPublicFunctions(GLUSTER_MGMT_ENABLED): setattr(_SuperVdsm, name, bind(logDecorator(func))) for _, module_name, _ in pkgutil.iter_modules([supervdsm_api.__path__[0]]): module = importlib.import_module('%s.%s' % (supervdsm_api.__name__, module_name)) api_funcs = [f for _, f in module.__dict__.iteritems() if callable(f) and getattr(f, 'exposed_api', False)] for func in api_funcs: setattr(_SuperVdsm, func.__name__, bind(logDecorator(func))) try: log.debug("Making sure I'm root - SuperVdsm") if os.geteuid() != 0: sys.exit(errno.EPERM) if pidfile: pid = str(os.getpid()) with open(pidfile, 'w') as f: f.write(pid + "\n") log.debug("Parsing cmd args") address = sockfile log.debug("Cleaning old socket %s", address) if os.path.exists(address): os.unlink(address) log.debug("Setting up keep alive thread") try: signal.signal(signal.SIGTERM, terminate) signal.signal(signal.SIGINT, terminate) log.debug("Creating remote object manager") manager = _SuperVdsmManager(address=address, authkey='') manager.register('instance', callable=_SuperVdsm) server = manager.get_server() servThread = concurrent.thread(server.serve_forever) servThread.start() chown(address, getpwnam(VDSM_USER).pw_uid, METADATA_GROUP) log.debug("Started serving super vdsm object") init_privileged_network_components() while _running: sigutils.wait_for_signal() log.debug("Terminated normally") finally: if os.path.exists(address): fileutils.rm_file(address) except Exception: log.error("Could not start Super Vdsm", exc_info=True) sys.exit(1)