Ejemplo n.º 1
0
    def setUpClass(cls) -> None:
        """ Setup basic config file with basic include

        :return: None
        """
        f = open("./aaa.conf", "w")
        f.write("broker amqp://tfeed@${FLOWBROKER}/\n")
        f.write("exchange xsarra\n")
        f.write("notify_only\n")
        f.close()
        cls.sarra = sr_sarra("aaa")
        cls.orig_exit = os._exit
        os._exit = sys.exit
Ejemplo n.º 2
0
def instantiate(dirconf, pgm, confname, action):

    # c stuff always requiere to spawn a call

    if pgm in ['audit', 'cpost', 'cpump']:
        # try to avoid error code while running sanity
        if action == 'sanity': return
        cfg.logger.debug("%s %s %s" % ("sr_" + pgm, action, confname))
        cfg.run_command(["sr_" + pgm, action, confname])
        return

    #print(dirconf,pgm,confname,action)

    config = re.sub(r'(\.conf)', '', confname)
    orig = sys.argv[0]

    sys.argv[0] = 'sr_' + pgm

    try:
        inst = None
        cfg.logger.debug("inst %s %s %s" % (pgm, config, action))
        if pgm == 'poll': inst = sr_poll(config, [action])
        elif pgm == 'post': inst = sr_post(config, [action])
        elif pgm == 'sarra': inst = sr_sarra(config, [action])
        elif pgm == 'sender': inst = sr_sender(config, [action])
        elif pgm == 'shovel': inst = sr_shovel(config, [action])
        elif pgm == 'subscribe': inst = sr_subscribe(config, [action])
        elif pgm == 'watch': inst = sr_watch(config, [action])
        elif pgm == 'winnow': inst = sr_winnow(config, [action])
        elif pgm == 'report': inst = sr_report(config, [action])
        elif pgm == 'audit': inst = sr_audit(config, [action])
        else:
            cfg.logger.error("code not configured for process type sr_%s" %
                             pgm)
            sys.exit(1)

        if action == 'cleanup': inst.exec_action('cleanup', False)
        elif action == 'declare': inst.exec_action('declare', False)
        elif action == 'setup': inst.exec_action('setup', False)

        elif action == 'remove': inst.exec_action('remove', False)

        sys.argv[0] = orig

    except:
        cfg.logger.error("could not instantiate and run sr_%s %s %s" %
                         (pgm, action, confname))
        sys.exit(1)