Exemplo n.º 1
0
def handle_function(function, command, message, connector, config, LOG):
    switch_uid = config.get('tsi.switch_uid', True)
    pam_enabled = config.get('tsi.open_user_sessions', False)
    cmd_spawns = command in [ "TSI_EXECUTESCRIPT", "TSI_SUBMIT", "TSI_UFTP" ]
    open_user_session = pam_enabled and cmd_spawns and switch_uid
    if open_user_session:
        # fork to avoid TSI process getting put into user slice
        pid = os.fork()
        if pid != 0:
            os.waitpid(pid, 0)
            return
    try:
        if switch_uid:
            id_info = re.search(r".*#TSI_IDENTITY (\S+) (\S+)\n.*", message, re.M)
            if id_info is None:
                raise RuntimeError("No user/group info given")
            user = id_info.group(1)
            groups = id_info.group(2).split(":")
            if open_user_session:
                pam_module = config.get('tsi.pam_module', "unicore-tsi")
                pam_session = PAM.PAM(LOG, module_name=pam_module)
                pam_session.open_session(user)
            user_switch_status = BecomeUser.become_user(user, groups, config, LOG)
            if user_switch_status is not True:
                raise RuntimeError(user_switch_status)
        function(message, connector, config, LOG)
    except:
        connector.failed(str(sys.exc_info()[1]))
        LOG.error("Error executing %s" % command)
    if switch_uid:
        BecomeUser.restore_id(config, LOG)
        if open_user_session:
            pam_session.close_session()
    if open_user_session:
        os._exit(0)
Exemplo n.º 2
0
 def pam(self, trainset, testset, k, k_for_cluster, isClassification):
     pm = PAM.PAM(k_for_cluster, trainset)
     medoids_class = pm.getClusters()
     print("medoids received")
     medoids_class = medoids_class.drop(columns=["cluster", "cost"])
     medoids_class = medoids_class[testset.columns]
     predicted = Knn.Knn().fit(medoids_class.values, testset, k,
                               isClassification)
     return predicted, testset.iloc[:, -1]
Exemplo n.º 3
0
        "tsi.enforce_os_gids": False,
        "tsi.use_id_to_resolve_gids": True,
        "tsi.fail_on_invalid_gids": True
    }
    import os, sys
    import BecomeUser, Log, PAM, Utils

    argv = sys.argv
    if len(argv) > 1:
        USER = argv[1]

    LOG = Log.Logger(verbose=True, use_syslog=False)
    LOG.info("Starting test - lauch task for %s" % USER)
    BecomeUser.initialize(config, LOG)

    pam = PAM.PAM(LOG)

    # must fork to avoid the main process
    # getting put into the user slice
    pid = os.fork()
    if pid != 0:
        # wait for the child process to
        # launch the user task
        os.waitpid(pid, 0)
    else:
        # child process - open session and then switch UID
        pam.open_session(USER)
        BecomeUser.become_user(USER, ["NONE"], config, LOG)
        # launch task in the background
        Utils.run_command("sleep 120", discard=True)
        LOG.info("Successfully launched 'sleep 120' for user %s" % USER)