예제 #1
0
def process_main():
    """
    Virtual Infrastructure Manager Web Server - Main
    """
    global do_reload

    try:
        signal.signal(signal.SIGHUP, process_signal_handler)
        signal.signal(signal.SIGINT, process_signal_handler)
        signal.signal(signal.SIGTERM, process_signal_handler)

        parser = argparse.ArgumentParser()
        parser.add_argument('-c', '--config', help='configuration file')
        parser.add_argument('-t',
                            '--tox',
                            action="store_true",
                            help='tox test environment')
        args = parser.parse_args()
        config.load(args.config)

        if args.tox:
            # Append the tox root directory to the system path to get
            # the config.ini and debug.ini files.
            debug_ini = sys.prefix + '/' + config.CONF['debug']['config_file']
            config.CONF['debug']['config_file'] = debug_ini

        process_initialize()

        server = webserver.SimpleHttpServer(config.CONF['vim-webserver'],
                                            config.CONF['nfvi'],
                                            config.CONF['vim-api'])
        server.start()

        DLOG.info("Started")
        while stay_on:
            selobj.selobj_dispatch(PROCESS_TICK_INTERVAL_IN_MS)
            timers.timers_schedule()

            if do_reload:
                debug.debug_reload_config()
                do_reload = False

        server.stop()

    except KeyboardInterrupt:
        print("Keyboard Interrupt received.")
        pass

    except Exception as e:
        print(e)
        sys.exit(200)

    finally:
        open(PROCESS_NOT_RUNNING_FILE, 'w').close()
        process_finalize()
예제 #2
0
 def func_wrapper(*args, **kwargs):
     try:
         global _test_complete, _test_result
         _test_complete = False
         _test_result = None
         six.print_("%-40s: " % title, end='')
         result = func(*args, **kwargs)
         _test_result = result
         while not _test_complete:
             selobj.selobj_dispatch(500)
             timers.timers_schedule()
         if _test_result:
             six.print_("PASSED", end='\n')
         else:
             six.print_("%s FAILED", end='\n')
     except Exception as e:
         DLOG.exception("%s" % e)
         six.print_("%s FAILED", end='\n')
예제 #3
0
    timers.timers_initialize(500, 1000, 1000)

    parser = argparse.ArgumentParser()
    parser.add_argument('-s',
                        '--server',
                        help='server-side',
                        action="store_true")
    parser.add_argument('-c',
                        '--client',
                        help='client-side',
                        action="store_true")
    args = parser.parse_args()

    if args.server:
        tcp_server = TCPServer('127.0.0.1', '3201', message_handler)

        while True:
            selobj.selobj_dispatch(5000)

    else:
        tcp_connection = TCPConnection('127.0.0.1', '3202')
        tcp_connection.connect('127.0.0.1', '3201')

        while True:
            tcp_connection.send("HI")
            time.sleep(5)

    timers.timers_finalize()
    selobj.selobj_finalize()
    debug.debug_finalize()
예제 #4
0
def _thread_main(thread_name, progress_marker, debug_config, thread_worker,
                 work_queue):
    """
    Main loop for the thread
    """
    from ctypes import util

    PR_SET_PDEATHSIG = 1
    PR_SET_NAME = 15
    PR_SIGKILL = 9

    libc = ctypes.cdll.LoadLibrary(util.find_library("c"))
    result = libc.prctl(PR_SET_NAME, thread_name)
    if 0 != result:
        DLOG.error("PRCTL set-name failed with error=%s." % result)
        sys.exit(200)

    result = libc.prctl(PR_SET_PDEATHSIG, PR_SIGKILL)
    if 0 != result:
        DLOG.error("PRCTL set-parent-death-signal failed with error=%s." %
                   result)
        sys.exit(201)

    signal.signal(signal.SIGTERM, signal.SIG_IGN)
    signal.signal(signal.SIGINT, signal.SIG_IGN)
    signal.signal(signal.SIGHUP, signal.SIG_IGN)
    signal.signal(signal.SIGUSR1, signal.SIG_IGN)
    signal.signal(signal.SIGUSR2, signal.SIG_IGN)

    try:
        thread_state = ThreadState()

        debug.debug_initialize(debug_config, thread_name=thread_name)
        selobj.selobj_initialize()
        timers.timers_initialize(thread_worker.tick_interval_in_ms,
                                 thread_worker.tick_max_delay_in_ms,
                                 thread_worker.tick_delay_debounce_in_ms)

        DLOG.debug("Thread %s: initializing." % thread_name)
        thread_worker.initialize()

        selobj.selobj_add_read_obj(work_queue.selobj, _thread_dispatch_work,
                                   thread_state, thread_worker, work_queue)

        DLOG.debug("Thread %s: started." % thread_name)
        while thread_state.stay_on:
            progress_marker.increment()
            selobj.selobj_dispatch(thread_worker.tick_interval_in_ms)
            timers.timers_schedule()

            if not timers.timers_scheduling_on_time():
                DLOG.info("Thread %s: not scheduling on time" % thread_name)

            if thread_state.debug_reload:
                debug.debug_reload_config()
                thread_state.debug_reload = False

    except KeyboardInterrupt:
        print("Keyboard Interrupt received.")
        pass

    except Exception as e:
        DLOG.exception("%s" % e)
        sys.exit(202)

    finally:
        DLOG.info("Thread %s: shutting down." % thread_name)
        thread_worker.finalize()
        timers.timers_finalize()
        selobj.selobj_finalize()
        DLOG.info("Thread %s: shutdown." % thread_name)
        debug.debug_finalize()
예제 #5
0
def process_main():
    """
    Virtual Infrastructure Manager - Main
    """
    def _force_exit():
        os._exit(-1)

    global do_reload, dump_data_captured, reset_data_captured

    process_start_time = timers.get_monotonic_timestamp_in_ms()

    try:
        # signal.signal(signal.SIGTERM, process_signal_handler)
        signal.signal(signal.SIGINT, process_signal_handler)
        signal.signal(signal.SIGHUP, process_signal_handler)
        signal.signal(signal.SIGUSR1, process_signal_handler)
        signal.signal(signal.SIGUSR2, process_signal_handler)

        parser = argparse.ArgumentParser()
        parser.add_argument('-c', '--config', help='configuration file')
        parser.add_argument('-t', '--tox', action="store_true",
                            help='tox test environment')
        args = parser.parse_args()
        config.load(args.config)

        if args.tox:
            # Append the tox root directory to the system path to get
            # the config.ini and debug.ini files.
            debug_ini = sys.prefix + '/' + config.CONF['debug']['config_file']
            config.CONF['debug']['config_file'] = debug_ini

        init_complete = process_initialize()
        last_init_time = timers.get_monotonic_timestamp_in_ms()

        DLOG.info("Started")

        while stay_on:
            selobj.selobj_dispatch(PROCESS_TICK_INTERVAL_IN_MS)
            timers.timers_schedule()

            if not alarm.alarm_subsystem_sane():
                DLOG.error("Alarm subsystem is not sane, exiting")
                break

            if not event_log.event_log_subsystem_sane():
                DLOG.error("Event-Log subsystem is not sane, exiting")
                break

            if do_reload:
                DLOG.info("Reload signalled.")
                debug.debug_reload_config()
                DLOG.info("Reload complete.")
                do_reload = False

            if dump_data_captured:
                DLOG.info("Dump captured data signalled.")
                histogram.display_histogram_data()
                profiler.profile_memory_dump()
                DLOG.info("Dump captured data complete.")
                dump_data_captured = False

            if reset_data_captured:
                DLOG.info("Reset captured data signalled.")
                histogram.reset_histogram_data()
                profiler.profile_memory_set_reference()
                DLOG.info("Reset captured data complete.")
                reset_data_captured = False

            if not init_complete:
                # Retry initialization for up to 3 minutes.
                now_ms = timers.get_monotonic_timestamp_in_ms()
                secs_expired = (now_ms - process_start_time) / 1000
                if secs_expired < 180:
                    time_since_init = (now_ms - last_init_time) / 1000
                    # Reattempt initialization every 10 seconds.
                    if time_since_init > 10:
                        init_complete = process_reinitialize()
                        last_init_time = timers.get_monotonic_timestamp_in_ms()
                else:
                    DLOG.warn("Initialization failed - exiting.")
                    sys.exit(200)

    except KeyboardInterrupt:
        print("Keyboard Interrupt received.")

    except Exception as e:
        DLOG.exception("%s" % e)
        sys.exit(200)

    finally:
        open(PROCESS_NOT_RUNNING_FILE, 'w').close()
        # Allow up to 10 seconds for the process to shut down. If the
        # process_finalize hangs, we will do a hard exit.
        signal.signal(signal.SIGALRM, _force_exit)
        signal.alarm(10)
        process_finalize()
예제 #6
0
def process_main():
    """
    Virtual Infrastructure Manager - Main
    """
    global do_reload, dump_data_captured, reset_data_captured

    try:
        # signal.signal(signal.SIGTERM, process_signal_handler)
        signal.signal(signal.SIGINT, process_signal_handler)
        signal.signal(signal.SIGHUP, process_signal_handler)
        signal.signal(signal.SIGUSR1, process_signal_handler)
        signal.signal(signal.SIGUSR2, process_signal_handler)

        parser = argparse.ArgumentParser()
        parser.add_argument('-c', '--config', help='configuration file')
        parser.add_argument('-t',
                            '--tox',
                            action="store_true",
                            help='tox test environment')
        args = parser.parse_args()
        config.load(args.config)

        if args.tox:
            # Append the tox root directory to the system path to get
            # the config.ini and debug.ini files.
            debug_ini = sys.prefix + '/' + config.CONF['debug']['config_file']
            config.CONF['debug']['config_file'] = debug_ini

        process_initialize()

        DLOG.info("Started")

        while stay_on:
            selobj.selobj_dispatch(PROCESS_TICK_INTERVAL_IN_MS)
            timers.timers_schedule()

            if not alarm.alarm_subsystem_sane():
                DLOG.error("Alarm subsystem is not sane, exiting")
                break

            if not event_log.event_log_subsystem_sane():
                DLOG.error("Event-Log subsystem is not sane, exiting")
                break

            if do_reload:
                DLOG.info("Reload signalled.")
                debug.debug_reload_config()
                DLOG.info("Reload complete.")
                do_reload = False

            if dump_data_captured:
                DLOG.info("Dump captured data signalled.")
                histogram.display_histogram_data()
                profiler.profile_memory_dump()
                DLOG.info("Dump captured data complete.")
                dump_data_captured = False

            if reset_data_captured:
                DLOG.info("Reset captured data signalled.")
                histogram.reset_histogram_data()
                profiler.profile_memory_set_reference()
                DLOG.info("Reset captured data complete.")
                reset_data_captured = False

    except KeyboardInterrupt:
        print("Keyboard Interrupt received.")
        pass

    except Exception as e:
        DLOG.exception("%s" % e)
        sys.exit(200)

    finally:
        open(PROCESS_NOT_RUNNING_FILE, 'w').close()
        process_finalize()