示例#1
0
def fileDownload(self, *args):
    cl = client.TCPClient(LOG.getLogger("clientlog", "Agent"))
    testid = int(args[2])
    current_test = get_test(testid)
    test_logger = None
    try:
        if current_test:
            test_logger = LOG.gettestlogger(current_test, "STAT")
            lctx.debug("FILE DOWNLOAD | " + str(current_test.testid) +
                       " | START")
            lctx.debug("Preparing TAR file of system metric folder")
            test_logger.info("Preparing TAR file of system metric folder")
            common.make_tarfile(current_test.archivedir + "results.tgz",
                                current_test.resultsdir + "/")
            dest = current_test.tobj.testobj.TestInputData.stats_results_path[
                current_test.stathostip]
            download_file = current_test.archivedir + "results.tgz"
            test_logger.info("Sending TAR file to daytona host")
            cl.sendFile(current_test.serverip, current_test.serverport,
                        download_file, dest.strip())
            lctx.debug("FILE DOWNLOAD | " + str(current_test.testid) +
                       " | COMPLETE")
            return "SUCCESS"
        else:
            raise Exception("Invalid Test ID")

    except Exception as e:
        lctx.error(e)
        if test_logger:
            test_logger.error(e)
        return "ERROR"
示例#2
0
def fileDownload(self, *args):
    cl = client.TCPClient(LOG.getLogger("clientlog", "Agent"))
    testid = int(args[2])
    current_test = get_test(testid)

    if current_test:
        if current_test.status is not "MONITOR_OFF":
            lctx.error("Invalid state for START TEST action : " + current_test.status)
            current_test.status = "FAILED"
            save_test(current_test.testid, current_test)
            return "ERROR"

    try:
        if current_test:
            lctx.debug("FILE DOWNLOAD | " + str(current_test.testid) + " | START")
            dest = current_test.tobj.testobj.TestInputData.stats_results_path[current_test.stathostip]
            download_file = current_test.archivedir + "results.tgz"
            cl.sendFile(current_test.serverip, current_test.serverport, download_file, dest.strip())
            lctx.debug("FILE DOWNLOAD | " + str(current_test.testid) + " | COMPLETE")
            return "SUCCESS"
        else:
            raise Exception("Invalid Test ID")

    except Exception as e:
        if current_test:
            current_test.status = "FAILED"
            save_test(current_test.testid, current_test)
        lctx.error(e)
        return "ERROR"
示例#3
0
def fileDownload(self, *args):
  cl = client.TCPClient(LOG.getLogger("clientlog", "Agent"))
  prm = args[2].split(',')
  lctx.debug(prm)

  test_serialized = prm[3].strip()
  t2 = testobj.testDefn()
  t2.deserialize(test_serialized)

  dest =""
  if prm[4] == "RESULTS" :
    dest = t2.testobj.TestInputData.exec_results_path
  elif prm[4] == "STATS" :
    s =  prm[5]
    lctx.debug(s)
    dest = t2.testobj.TestInputData.stats_results_path[s]
  else:
    dest = ""

  lctx.debug(prm[0])
  lctx.debug(prm[1])
  lctx.debug(prm[2])
  lctx.debug(dest)

  try:
    cl.sendFile(prm[0].strip(), int(prm[1].strip()), prm[2].strip(), dest.strip())
  except CommunicationError as e:
    lctx.error(e.value)
    return e.value
  return "SUCCESS"
示例#4
0
def downloadTestLogs(testid):
    """
    This procedure just send test life cycle log file to scheduler upon test cleanup. This file provide user
    information about test execution sequence on agent

    """
    cl = client.TCPClient(LOG.getLogger("clientlog", "Agent"))
    current_test = get_test(testid)
    test_logger = None
    try:
        if current_test:
	    test_logger = LOG.gettestlogger(current_test, "STAT")
	    test_logger.info("Sending test log to daytona host")
            dest = current_test.tobj.testobj.TestInputData.stats_results_path[current_test.stathostip]
            download_file = current_test.agent_log_file
            cl.sendFile(current_test.serverip, current_test.serverport, download_file, dest.strip())
	    test_logger.info("Test log file transfer complete")
            return "SUCCESS"
        else:
            raise Exception("Invalid Test ID")

    except Exception as e:
        lctx.error(e)
	if test_logger:
            test_logger.error(e)
        return "ERROR"
示例#5
0
def fileDownload(self, *args):
    """
    On test completion, agent execute this procedure when it receive DAYTONA_FILE_DOWNLOAD message from scheduler.
    We create a TAR file called results.tgz and save it test location, then we send this file to scheduler and save it
    in scheduler side file system

    """
    cl = client.TCPClient(LOG.getLogger("clientlog", "Agent"))
    testid = int(args[2])
    current_test = get_test(testid)
    test_logger = None
    try:
        if current_test:
	    test_logger = LOG.gettestlogger(current_test, "STAT")
            lctx.debug("FILE DOWNLOAD | " + str(current_test.testid) + " | START")
	    lctx.debug("Preparing TAR file of system metric folder")
	    test_logger.info("Preparing TAR file of system metric folder")
            common.make_tarfile(current_test.archivedir + "results.tgz", current_test.resultsdir + "/")
            dest = current_test.tobj.testobj.TestInputData.stats_results_path[current_test.stathostip]
            download_file = current_test.archivedir + "results.tgz"
	    test_logger.info("Sending TAR file to daytona host")
            cl.sendFile(current_test.serverip, current_test.serverport, download_file, dest.strip())
            lctx.debug("FILE DOWNLOAD | " + str(current_test.testid) + " | COMPLETE")
            return "SUCCESS"
        else:
            raise Exception("Invalid Test ID")

    except Exception as e:
        lctx.error(e)
	if test_logger:
	    test_logger.error(e)
        return "ERROR"
示例#6
0
def scheduler_handshake(current_test):
    cl = client.TCPClient(LOG.getLogger("clientlog", "Agent"))
    env = envelope.DaytonaEnvelope()
    ret = cl.send(current_test.serverip, current_test.serverport,
                  env.construct("DAYTONA_HANDSHAKE", "handshake2"))
    if ret == "SUCCESS":
        return True
    else:
        return False
示例#7
0
    def __init__(self, db, cfg, lctx):
        self.dbinstance = db
        self.cfg = cfg
        self.testmap = db.tests_to_run
        self.cl = client.TCPClient(LOG.getLogger("clientlog", "DH"))
        self.ev = envelope.DaytonaEnvelope()
        self.HOST = common.get_local_ip()
        self.PORT = cfg.DHPORT
        self.CPORT = cfg.CPORT

        self.scheduler_thread = common.FuncThread(self.dispatch, True)
        self.testmon_thread = common.FuncThread(self.testmon, True)
        self.lctx = lctx
示例#8
0
    def __init__(self, db, cfg, lctx):
        """
        Scheduler class constructor which initialize class variables and other threads

        """
        self.dbinstance = db
        self.cfg = cfg
        self.testmap = db.tests_to_run
        self.cl = client.TCPClient(LOG.getLogger("clientlog", "DH"))
        self.ev = envelope.DaytonaEnvelope()
        self.HOST = common.get_local_ip()
        self.PORT = cfg.DHPORT
        self.CPORT = cfg.CPORT

        self.scheduler_thread = common.FuncThread(self.dispatch, True)
        self.testmon_thread = common.FuncThread(self.testmon, True)
        self.lctx = lctx
示例#9
0
def scheduler_handshake(current_test):
    """
    This procedure is a part of 2-way handshake between scheduler and agent. If agent receive handshake message from
    scheduler, then agent also send a handshake message to scheduler to check if agent can communicate with scheduler
    on scheduler port. This part is important as later we need to transfer log files to scheduler using scheduler port

    :param current_test: Test object
    :return: true if scheduler respond otherwise false

    """
    cl = client.TCPClient(LOG.getLogger("clientlog", "Agent"))
    env = envelope.DaytonaEnvelope()
    ret = cl.send(current_test.serverip, current_test.serverport, env.construct("DAYTONA_HANDSHAKE", "handshake2"))
    if ret == "SUCCESS":
        return True
    else:
        return False
示例#10
0
def downloadTestLogs(testid):
    cl = client.TCPClient(LOG.getLogger("clientlog", "Agent"))
    current_test = get_test(testid)
    test_logger = None
    try:
        if current_test:
            test_logger = LOG.gettestlogger(current_test, "STAT")
            test_logger.info("Sending test log to daytona host")
            dest = current_test.tobj.testobj.TestInputData.stats_results_path[
                current_test.stathostip]
            download_file = current_test.agent_log_file
            cl.sendFile(current_test.serverip, current_test.serverport,
                        download_file, dest.strip())
            test_logger.info("Test log file transfer complete")
            return "SUCCESS"
        else:
            raise Exception("Invalid Test ID")

    except Exception as e:
        lctx.error(e)
        if test_logger:
            test_logger.error(e)
        return "ERROR"
示例#11
0
def exec_cmd(cmd, daytona_cmd, sync, obj, actionid, current_test):
    lctx.debug("Execute cmd : " + cmd)
    sfile = None
    cl = None

    ########
    if daytona_cmd == "DAYTONA_START_TEST":
        cl = client.TCPClient(LOG.getLogger("clientlog", "Agent"))
        (current_test.stream, sfile) = cl.stream_start(
            current_test.serverip, current_test.serverport,
            str(current_test.tobj.testobj.TestInputData.exec_log_path))
    ########

    if sfile is not None:
        sfile.flush()
    cthread = commandThread(cmd, daytona_cmd, sfile, current_test.execdir,
                            current_test.testid)
    current_test.exec_thread = cthread
    cthread.start()

    (t, aid, tst, ts) = (None, None, None, None)
    if sync == "T":
        lctx.debug("Execute cmd in Sync ctx")
        cthread.join()
        if sfile is not None:
            sfile.flush()
    else:
        # async action entry in the server table (need this to check self alive below)
        for tp in obj.async_actions:
            if tp[1] == actionid:
                (t, aid, tst, ts) = tp

        lctx.debug("Execute cmd in asSync ctx : " + str(actionid))

        timer_expire = False
        while True:
            lctx.debug("waiting for async action to complete : " +
                       str(actionid))
            if cthread.stdout is not None:
                lctx.debug("printting output of stream ")

            if sfile is not None:
                sfile.flush()

            if tst.testobj.TestInputData.timeout > 0:
                if time.time() - ts > tst.testobj.TestInputData.timeout:
                    lctx.error(
                        "Timer expired for this test, need to end this async action"
                    )
                    timer_expire = True

            # todo : breakout of while after a timer event and exit after terminating thread
            # timeout is monitored outside in the scheduler server , for all async ops , the thread is paused from
            # there via a CMD (ENDTEST)
            if t.check() == False or cthread.is_alive(
            ) == False or timer_expire:
                if daytona_cmd == "DAYTONA_START_TEST":
                    if cthread.is_alive():
                        exec_script_lock.acquire()
                        if current_test.testid in exec_script_pid:
                            p = exec_script_pid[current_test.testid]
                            del exec_script_pid[current_test.testid]
                        exec_script_lock.release()
                        if p:
                            os.killpg(p.pid, signal.SIGTERM)

                    lctx.debug("end stream")
                    cl.stream_end(
                        current_test.serverip, current_test.serverport,
                        str(current_test.tobj.testobj.TestInputData.
                            exec_log_path), current_test.stream, sfile)

                # callback
                # removeactionid
                lctx.debug("Callback here removing item")
                obj.removeActionItem(actionid)
                break
            time.sleep(3)

    if daytona_cmd == "DAYTONA_START_TEST":
        # todo : verify the TEST END on filesystem OR Failure
        if timer_expire:
            current_test.status = "TIMEOUT"
        else:
            lctx.debug("Setting current test status to TESTEND")
            current_test.status = "TESTEND"

    lctx.debug(daytona_cmd + " END [" + str(actionid) + "]")

    if save_test(current_test.testid, current_test):
        return "SUCCESS"
    else:
        return "ERROR"
示例#12
0
            else:
                print "Unknown response received from host"
                print response
                sys.exit()
        else:
            print "Error - Unknown response received from host"
            print retsend
            sys.exit()
    else:
        print "Error - No response received from host"
        sys.exit()


if __name__ == "__main__":
    read_arguments()
    tcp_client = client.TCPClient(LOG.getLogger("tcpclientlog", "daytona-cli"))
    env = envelope.DaytonaEnvelope()
    check_host_hearbeat(tcp_client, env)
    if action == 0:
        define_test(tcp_client, env)
    elif action == 1:
        add_test(tcp_client, env)
    elif action == 2:
        update_test(tcp_client, env)
    elif action == 3:
        run_test(tcp_client, env)
    elif action == 5:
        get_result(tcp_client, env)
    else:
        print "Error - Invalid action"
        display_usage()