Пример #1
0
def stopMonitor( self, *args):
  (obj, command, test_serialized, actionID, sync) = (args[0], args[1], args[2], args[3], args[4])
  t2 = testobj.testDefn()
  t2.deserialize(test_serialized)
  lctx.debug("stop monitor for test : " + str(t2.testobj.TestInputData.testid))

  if current_test.testid != t2.testobj.TestInputData.testid:
    lctx.debug("start mon  :  TestID dont match")
    return "ERROR"

  cfg = config.CFG("DaytonaHost", lctx)
  cfg.readCFG("config.ini")

  #stop the sar processes
  execline = cfg.daytona_mon_path + "/sar_gather_agent.pl --shutdown --root-dir=" + current_test.statsdir
  lctx.info(execline)
  exec_cmd(execline, command, sync, obj, actionID)

  #prepare mon results tarball here
  lctx.debug(current_test.statsdir)
  #os.remove(current_test.statsdir + "/sar.dat")
  os.remove(current_test.statsdir + "/sar_gather_agent_debug.out")
  #os.remove(current_test.statsdir + "/*.pid")
  lctx.debug("removed monitor temp files from : " + current_test.archivedir)

  common.make_tarfile(current_test.archivedir + "results_stats.tgz", current_test.archivedir)

  lctx.debug("Completed stop monitor")
  return "SUCCESS"
Пример #2
0
def stopMonitor(self, *args):
    (obj, command, params, actionID, sync) = (args[0], args[1], args[2], args[3], args[4])
    testid = int(params)
    current_test = get_test(testid)

    try:
        if current_test:
            lctx.debug("MONITOR OFF | " + str(current_test.testid) + " | START")

            cfg = config.CFG("DaytonaHost", lctx)
            cfg.readCFG("config.ini")

            # stop the sar processes
            execline = cfg.daytona_mon_path + "/sar_gather_agent.pl --shutdown --root-dir=" + current_test.statsdir
            lctx.info(execline)
            exec_cmd(execline, command, sync, obj, actionID, current_test)

            # prepare mon results tarball here
            lctx.debug(current_test.statsdir)
            lctx.debug("removed monitor temp files from : " + current_test.archivedir)
            common.make_tarfile(current_test.archivedir + "results.tgz", current_test.resultsdir + "/")
	    current_test.status = "MONITOR_OFF"
            save_test(current_test.testid, current_test)
            lctx.debug("MONITOR OFF | " + str(current_test.testid) + " | COMPLETE")
            return "SUCCESS"
        else:
            raise Exception("Monitor is not running for TESTID : " + str(current_test.testid))

    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 __init__(self):
        """
        Constructor initializes logger, config file reader and db handle

        """
        self.lctx = LOG.getLogger("dblog", "DH")
        self.cfg = config.CFG("DaytonaHost", self.lctx)
        self.cfg.readCFG("config.ini")
        self.db = dbaccess.DBAccess(self.cfg, self.lctx)
Пример #4
0
def checkTestRunning(testid):
    lctx = LOG.getLogger("dblog", "DH")
    cfg = config.CFG("DaytonaHost", lctx)
    cfg.readCFG("config.ini")
    db = dbaccess.DBAccess(cfg, LOG.getLogger("dblog", "DH"))
    check = db.query(
        """SELECT COUNT(*) FROM CommonFrameworkSchedulerQueue where testid=%s""",
        (testid, ), False, False)
    db.close()
    if check[0] == 0:
        return False
    else:
        return True
Пример #5
0
def startMonitor(self, *args):
    (obj, command, params, actionID, sync) = (args[0], args[1], args[2], args[3], args[4])

    testid = int(params)
    current_test = get_test(testid)

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

    try:
        if current_test:
            lctx.debug("MONITOR ON | " + str(current_test.testid) + " | START")
            cfg = config.CFG("DaytonaHost", lctx)
            cfg.readCFG("config.ini")
            if current_test.tobj.testobj.TestInputData.strace:
                execline = cfg.daytona_mon_path + "/sar_gather_agent.pl --daemonize --root-dir=" + current_test.statsdir + \
                           " --strace --strace-proc=" + current_test.tobj.testobj.TestInputData.strace_process + \
                           " --strace-delay=" + str(current_test.tobj.testobj.TestInputData.strace_delay) + \
                           " --strace-duration=" + str(current_test.tobj.testobj.TestInputData.strace_duration)
            else:
                execline = cfg.daytona_mon_path + "/sar_gather_agent.pl --daemonize --root-dir=" + current_test.statsdir

	    execline = execline + " --perf-delay=" + str(current_test.tobj.testobj.TestInputData.perf_delay) + \
                       " --perf-duration=" + str(current_test.tobj.testobj.TestInputData.perf_duration)
            if current_test.tobj.testobj.TestInputData.perf_process:
                execline += " --perf-proc=" +  current_test.tobj.testobj.TestInputData.perf_process

            lctx.info(execline)
            current_test.status = "MONITOR_ON"
            save_test(current_test.testid, current_test)
            exec_cmd(execline, command, sync, obj, actionID, current_test)
	    lctx.debug("MONITOR ON | " + str(current_test.testid) + " | COMPLETE")
            return "SUCCESS"
        else:
            raise Exception("Invalid Test ID")

    except Exception as e:
        if current_test:
            current_test.status = "ABORT"
            save_test(current_test.testid, current_test)
	lctx.error(e)
        return "ERROR"
Пример #6
0
    def init_testlogger(test, hosttype):
        """
        Initialize new test logger for particular test, used by both agent and scheduler for writing test life cycle logs

        """
        if hosttype == "EXEC":
            if test.testobj.TestInputData.testid in LOG._loggers.keys():
                del LOG._loggers[test.testobj.TestInputData.testid]

            test_logger = "test_logger" + str(test.testobj.TestInputData.testid)
            log_file = test.testobj.TestInputData.exec_results_path + str(test.testobj.TestInputData.testid) + ".log"
        else:
            if test.testid in LOG._loggers.keys():
                del LOG._loggers[test.testid]

            cfg = config.CFG("DaytonaHost", None)
            cfg.readCFG("config.ini")

            test_logger = "test_logger" + str(test.testid)
            log_file = cfg.agent_test_logs + test.stathostip + "_" + str(test.testid) + ".log"

        try:
            os.remove(log_file)
        except OSError:
            pass

        logger = logging.getLogger(test_logger)
        if logger.handlers:
            logger.handlers.pop()

        fh = logging.FileHandler(log_file)
        fh.setLevel(logging.DEBUG)
        formatter = logging.Formatter('%(asctime)s %(levelname)-6s %(message)-100s',
                                      '%Y-%m-%d %H:%M')
        fh.setFormatter(formatter)
        logger.addHandler(fh)
        logger.propagate = False
        if hosttype == "EXEC":
            LOG._loggers[test.testobj.TestInputData.testid] = logger
        else:
            LOG._loggers[test.testid] = logger
        return logger
Пример #7
0
def checkTestRunning(testid):
    """
    This function checks whether user has not initiated test termination from UI. CommonFrameworkSchedulerQueue table
    keep the list of all running test initiated by user from UI or CLI. When user terminate any running test from UI,
    daytona removes the entry of this test from CommonFrameworkSchedulerQueue table. This functions polls database to
    check if test is still present in the CommonFrameworkSchedulerQueue table

    """
    lctx = LOG.getLogger("dblog", "DH")
    cfg = config.CFG("DaytonaHost", lctx)
    cfg.readCFG("config.ini")
    db = dbaccess.DBAccess(cfg, LOG.getLogger("dblog", "DH"))
    check = db.query(
        """SELECT COUNT(*) FROM CommonFrameworkSchedulerQueue where testid=%s""",
        (testid, ), False, False)
    db.close()
    if check[0] == 0:
        return False
    else:
        return True
Пример #8
0
def startMonitor( self, *args):
  (obj, command, params, actionID, sync) = (args[0], args[1], args[2], args[3], args[4])
  lctx.debug("startMonitor")
  p = params.split(",")
  test_serialized = p[0]
  s = p[1].strip()

  try :
    current_test.tobj = testobj.testDefn()
    t2 = testobj.testDefn()
    t2.deserialize(test_serialized)
    current_test.tobj= t2
    current_test.testid = current_test.tobj.testobj.TestInputData.testid

    lctx.debug("TEST SETUP Monitor : " + str(current_test.tobj.testobj.TestInputData.testid))
    #todo : indicate a status that says this host is monitor-active
    #current_test.status = "TESTSETUP"

    cfg = config.CFG("DaytonaHost", lctx)
    cfg.readCFG("config.ini")
    prefix = cfg.daytona_agent_root + "/" + current_test.tobj.testobj.TestInputData.frameworkname + "/" + str(current_test.tobj.testobj.TestInputData.testid) + "/results/"
    current_test.statsdir = prefix + s + "/sar/"
    current_test.archivedir = prefix

    common.createdir(cfg.daytona_agent_root, lctx)
    common.createdir(current_test.statsdir, lctx)


    execline = cfg.daytona_mon_path + "/sar_gather_agent.pl --daemonize --root-dir=" + current_test.statsdir
    lctx.info(execline)
    exec_cmd(execline, command, sync, obj, actionID)

  except Exception as e:
    lctx.error(e)
    lctx.error(traceback.print_exc())
    return "ERROR"

  lctx.debug("Completed start monitor")
  return "SUCCESS"
Пример #9
0
    db = dbaccess.DBAccess(cfg, LOG.getLogger("dblog", "DH"))
    check = db.query(
        """SELECT COUNT(*) FROM CommonFrameworkSchedulerQueue where testid=%s""",
        (testid, ), False, False)
    db.close()
    if check[0] == 0:
        return False
    else:
        return True


if __name__ == "__main__":
    # Port 0 means to select an arbitrary unused port

    lctx = LOG.getLogger("schedulerlog", "DH")
    cfg = config.CFG("DaytonaHost", lctx)
    cfg.readCFG("config.ini")

    common.logger.ROLE = "DHOST"
    db = dbaccess.DaytonaDBmon(cfg, LOG.getLogger("dblog", "DH"))
    sch = Scheduler(db, cfg, LOG.getLogger("schedulerlog", "DH"))

    server.serv.role = "DH"
    ase_serv = server.serv()
    server.serv.lctx = LOG.getLogger("listenerlog", "DH")
    ser = server.serv.ThreadedTCPServer((common.get_local_ip(), sch.PORT),
                                        server.serv.ThreadedTCPRequestHandler)
    server.serv.serverInstance = ser
    ip, port = ser.server_address
    server.lctx = LOG.getLogger("listenerlog", "DH")
Пример #10
0
import threading
import SocketServer
import time
from collections import defaultdict

import server
import config
import common
import testobj
from logger import LOG

if __name__ == "__main__":
    # Port 0 means to select an arbitrary unused port
    lctx = LOG.getLogger("agentlog", "Agent")
    cfg = config.CFG("Agent", lctx)
    cfg.readCFG("config.ini")

    HOST = common.get_local_ip()
    PORT = cfg.CPORT

    common.createdir(cfg.daytona_agent_root, lctx)

    server.serv.role = "Agent"
    base_serv = server.serv()

    #server.serv.lctx = LOG.getLogger("listenerlog","Agent")
    #ser = server.serv.ThreadedTCPServer((HOST, PORT), server.serv.ThreadedTCPRequestHandler)

    ser = base_serv.ThreadedTCPServer((HOST, PORT),
                                      server.serv.ThreadedTCPRequestHandler)
Пример #11
0
 def __init__(self):
     self.lctx = LOG.getLogger("dblog", "DH")
     self.cfg = config.CFG("DaytonaHost", self.lctx)
     self.cfg.readCFG("config.ini")
     self.db = dbaccess.DBAccess(self.cfg, self.lctx)
Пример #12
0
def setupTest(self, *args):
    (obj, command, params, actionID, sync) = (args[0], args[1], args[2],
                                              args[3], args[4])
    test_serialized = params.split(",")[0]
    host_type = params.split(",")[1]

    t2 = testobj.testDefn()
    t2.deserialize(test_serialized)
    current_test = get_test(t2.testobj.TestInputData.testid)
    test_logger = None

    try:
        if current_test:
            test_logger = LOG.gettestlogger(current_test, "STAT")
            lctx.debug("TEST SETUP | " + str(current_test.testid) + " | START")
            test_logger.info("Test setup started")
            current_test.tobj = testobj.testDefn()
            current_test.tobj = t2
            current_test.testid = current_test.tobj.testobj.TestInputData.testid

            cfg = config.CFG("DaytonaHost", lctx)
            cfg.readCFG("config.ini")
            dir = cfg.daytona_agent_root + "/" + current_test.tobj.testobj.TestInputData.frameworkname + "/" + str(
                current_test.tobj.testobj.TestInputData.testid)
            shutil.rmtree(dir, ignore_errors=True)
            prefix = cfg.daytona_agent_root + "/" + current_test.tobj.testobj.TestInputData.frameworkname + "/" + str(
                current_test.tobj.testobj.TestInputData.testid) + "/results/"

            if host_type == "EXEC":
                current_test.execdir = prefix + current_test.tobj.testobj.TestInputData.exechostname
                current_test.logdir = prefix + current_test.tobj.testobj.TestInputData.exechostname + "/application"

            current_test.statsdir = prefix + current_test.stathostip + "/sar/"
            current_test.resultsdir = cfg.daytona_agent_root + "/" + \
                                      current_test.tobj.testobj.TestInputData.frameworkname + "/" + \
                                      str(current_test.tobj.testobj.TestInputData.testid) + "/results"
            current_test.archivedir = cfg.daytona_agent_root + "/" + \
                                      current_test.tobj.testobj.TestInputData.frameworkname + "/" + \
                                      str(current_test.tobj.testobj.TestInputData.testid) + "/"

            if host_type == "EXEC":
                common.createdir(current_test.execdir, self.lctx)
                common.createdir(current_test.logdir, self.lctx)

            common.createdir(current_test.resultsdir, self.lctx)
            common.createdir(current_test.statsdir, self.lctx)

            test_logger.info("Test directory created")

            # todo : check and validate if exec script is provided in expected format and
            # the file exists in that location

            if host_type == "EXEC":
                execscript = current_test.tobj.testobj.TestInputData.execution_script_location
                lctx.debug("TEST SETUP : " + str(execscript))
                current_test.execscriptfile = current_test.execdir + "/" + execscript
                lctx.debug(current_test.execscriptfile)

                # check if execution script is present in EXEC_SCRIPT_DIR - execute script only if it present at
                # this location

                execscript_location = EXEC_SCRIPT_DIR + execscript
                execscript_location = os.path.realpath(execscript_location)
                valid_path = os.path.commonprefix(
                    [execscript_location, EXEC_SCRIPT_DIR]) == EXEC_SCRIPT_DIR

                if valid_path:
                    if os.path.isfile(execscript_location):
                        ret = shutil.copytree(
                            os.path.dirname(execscript_location),
                            os.path.dirname(current_test.execscriptfile))
                    else:
                        raise Exception(
                            "Execution script not found at Daytona Execution Script Location : "
                            + EXEC_SCRIPT_DIR)
                else:
                    raise Exception(
                        "Access Denied : Use Daytona Execution Script Location '"
                        + EXEC_SCRIPT_DIR + "' for executing "
                        "exec scripts")
                os.chmod(current_test.execscriptfile, 0744)
                test_logger.info("Execution script copied successfully")

            save_test(current_test.testid, current_test)
            test_logger.info("Test setup complete")
            lctx.debug("TEST SETUP | " + 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"
Пример #13
0
    def construct(self, tid):
        import dbaccess
        import config

        lctx = LOG.getLogger("dblog", "DH")
        cfg = config.CFG("DaytonaHost", lctx)
        cfg.readCFG("config.ini")
        self.db = dbaccess.DBAccess(cfg, LOG.getLogger("dblog", "DH"))
        self.testobj.TestInputData.testid = tid
        query_result = self.db.query(
            """select testid, frameworkid, start_time,
                                      end_time, end_status, end_detail,
                                      exechostname, stathostname, timeout, cc_list, title, purpose, creation_time
                                      from TestInputData where testid = %s""",
            (self.testobj.TestInputData.testid, ), False, False)

        (self.testobj.TestInputData.testid,
         self.testobj.TestInputData.frameworkid,
         self.testobj.TestInputData.start_time,
         self.testobj.TestInputData.end_time,
         self.testobj.TestInputData.end_status,
         self.testobj.TestInputData.end_detail,
         self.testobj.TestInputData.exechostname,
         self.testobj.TestInputData.stathostname,
         self.testobj.TestInputData.timeout, self.testobj.TestInputData.email,
         self.testobj.TestInputData.title, self.testobj.TestInputData.purpose,
         self.testobj.TestInputData.creation_time) = query_result
        lctx.debug(query_result)

        query_result = self.db.query(
            """select ha.hostname, hat.name, hat.shared, hat.execution, hat.statistics
                                              from HostAssociation ha
                                              join  HostAssociationType hat
                                              on ha.hostassociationtypeid = hat.hostassociationtypeid
                                              where testid = %s and hat.frameworkid = %s""",
            (self.testobj.TestInputData.testid,
             self.testobj.TestInputData.frameworkid), True, False)

        for r in query_result:
            lctx.debug(r)
            if r[1] == 'statistics' and r[4] == 1:
                self.testobj.TestInputData.stathostname = r[
                    0] + "," + self.testobj.TestInputData.stathostname
            elif r[1] == 'execution' and r[3] == 1:
                self.testobj.TestInputData.exechostname = r[
                    0] + "," + self.testobj.TestInputData.exechostname

        self.testobj.TestInputData.stathostname = self.testobj.TestInputData.stathostname[:
                                                                                          -1]
        self.testobj.TestInputData.exechostname = self.testobj.TestInputData.exechostname[:
                                                                                          -1]

        lctx.debug(self.testobj.TestInputData.exechostname)
        lctx.debug(self.testobj.TestInputData.stathostname)

        query_result = self.db.query(
            """select * from TestArgs where testid = %s""",
            (self.testobj.TestInputData.testid, ), True, False)
        self.testobj.TestInputData.execScriptArgs = query_result
        lctx.debug(query_result)

        query_result = self.db.query(
            """select file_root, execution_script_location, frameworkname from ApplicationFrameworkMetadata where frameworkid = %s""",
            (self.testobj.TestInputData.frameworkid, ), False, False)
        (self.testobj.TestInputData.file_root,
         self.testobj.TestInputData.execution_script_location,
         self.testobj.TestInputData.frameworkname) = query_result
        lctx.debug(query_result)

        query_result = self.db.query(
            """select processname, delay, duration from ProfilerFramework where testid = %s and profiler = %s""",
            (self.testobj.TestInputData.testid, 'STRACE'), False, False)

        if query_result:
            self.testobj.TestInputData.strace = True
            (self.testobj.TestInputData.strace_process,
             self.testobj.TestInputData.strace_delay,
             self.testobj.TestInputData.strace_duration) = query_result

        query_result = self.db.query(
            """select processname, delay, duration from ProfilerFramework where testid = %s and profiler = %s""",
            (self.testobj.TestInputData.testid, 'PERF'), False, False)

        if query_result:
            (self.testobj.TestInputData.perf_process,
             self.testobj.TestInputData.perf_delay,
             self.testobj.TestInputData.perf_duration) = query_result
Пример #14
0
def setupTest(self, *args):
    (obj, command, params, actionID, sync) = (args[0], args[1], args[2], args[3], args[4])
    test_serialized = params.split(",")[0]
    host_type = params.split(",")[1]

    t2 = testobj.testDefn()
    t2.deserialize(test_serialized)
    current_test = get_test(t2.testobj.TestInputData.testid)

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

    try:
        if current_test:
            lctx.debug("TEST SETUP | " + str(current_test.testid) + " | START")
            current_test.tobj = testobj.testDefn()
            current_test.tobj = t2
            current_test.testid = current_test.tobj.testobj.TestInputData.testid

            lctx.debug("TEST SETUP : " + str(current_test.tobj.testobj.TestInputData.testid))
            cfg = config.CFG("DaytonaHost", lctx)
            cfg.readCFG("config.ini")
	    dir = cfg.daytona_agent_root + "/" + current_test.tobj.testobj.TestInputData.frameworkname + "/" + str(
                current_test.tobj.testobj.TestInputData.testid)
	    shutil.rmtree(dir, ignore_errors=True)
            prefix = cfg.daytona_agent_root + "/" + current_test.tobj.testobj.TestInputData.frameworkname + "/" + str(
                current_test.tobj.testobj.TestInputData.testid) + "/results/"

            if host_type == "EXEC":
                current_test.execdir = prefix + current_test.tobj.testobj.TestInputData.exechostname
                current_test.logdir = prefix + current_test.tobj.testobj.TestInputData.exechostname + "/application"

            current_test.statsdir = prefix + current_test.stathostip + "/sar/"
            current_test.resultsdir = cfg.daytona_agent_root + "/" + \
                                      current_test.tobj.testobj.TestInputData.frameworkname + "/" + \
                                      str(current_test.tobj.testobj.TestInputData.testid) + "/results"
            current_test.archivedir = cfg.daytona_agent_root + "/" + \
                                      current_test.tobj.testobj.TestInputData.frameworkname + "/" + \
                                      str(current_test.tobj.testobj.TestInputData.testid) + "/"

            common.createdir(cfg.daytona_agent_root, self.lctx)
            if host_type == "EXEC":
                common.createdir(current_test.execdir, self.lctx)
                common.createdir(current_test.logdir, self.lctx)

            common.createdir(current_test.resultsdir, self.lctx)
            common.createdir(current_test.statsdir, self.lctx)

            # todo : check and validate if exec script is provided in expected format and
            # the file exists in that location

            if host_type == "EXEC":
                execscript = current_test.tobj.testobj.TestInputData.execution_script_location
                lctx.debug("TEST SETUP : " + str(execscript))
                current_test.execscriptfile = current_test.execdir + "/" + execscript
                lctx.debug(current_test.execscriptfile)

                # check if execution script is present in '/tmp/ExecScripts/' - execute script only if it present at
                # this location

                execscript_location = EXEC_SCRIPT_DIR + execscript
                execscript_location = os.path.realpath(execscript_location)
                valid_path = os.path.commonprefix([execscript_location, EXEC_SCRIPT_DIR]) == EXEC_SCRIPT_DIR

                if valid_path:
                    if os.path.isfile(execscript_location):
                        ret = copyfile(execscript_location, current_test.execscriptfile)
                    else:
                        raise Exception(
                            "Execution script not found at Daytona Execution Script Location : " + EXEC_SCRIPT_DIR)
                else:
                    raise Exception(
                        "Access Denied : Use Daytona Execution Script Location '" + EXEC_SCRIPT_DIR + "' for executing "
                                                                                                      "exec scripts")
                os.chmod(current_test.execscriptfile, 0744)

            current_test.status = "SETUP"
            save_test(current_test.testid, current_test)
            lctx.debug("TEST SETUP | " + str(current_test.testid) + " | COMPLETE")
            return "SUCCESS"
        else:
            raise Exception("Invalid Test ID")

    except shutil.Error as err:
        if current_test:
            lctx.error("error copying file : " + str(execscript) + " to " + str(current_test.execscriptfile))
            current_test.status = "ABORT"
            save_test(current_test.testid, current_test)
        lctx.error(err)
        return "ERROR"

    except Exception as e:
        if current_test:
            current_test.status = "ABORT"
            save_test(current_test.testid, current_test)
        lctx.error(e)
        return "ERROR"
Пример #15
0
def setupTest( self, *args):
  (obj, command, test_serialized, actionID, sync) = (args[0], args[1], args[2], args[3], args[4])
  lctx.debug("setuptest")

  try :
    current_test.tobj = testobj.testDefn()
    t2 = testobj.testDefn()
    t2.deserialize(test_serialized)
    current_test.tobj= t2
    current_test.testid = current_test.tobj.testobj.TestInputData.testid

    lctx.debug("TEST SETUP : " + str(current_test.tobj.testobj.TestInputData.testid))
    current_test.status = "TESTSETUP"

    cfg = config.CFG("DaytonaHost", lctx)
    cfg.readCFG("config.ini")
    prefix = cfg.daytona_agent_root + "/" + current_test.tobj.testobj.TestInputData.frameworkname + "/" + str(current_test.tobj.testobj.TestInputData.testid) + "/results/"
    current_test.execdir = prefix + current_test.tobj.testobj.TestInputData.exechostname 
    current_test.logdir = prefix + current_test.tobj.testobj.TestInputData.exechostname + "/application"
    current_test.resultsdir = prefix
    current_test.statsdir = prefix + current_test.tobj.testobj.TestInputData.exechostname + "/sar/"
    current_test.archivedir = prefix

    common.createdir(cfg.daytona_agent_root, self.lctx)
    common.createdir(current_test.execdir, self.lctx)
    common.createdir(current_test.logdir, self.lctx)
    common.createdir(current_test.resultsdir, self.lctx)
    common.createdir(current_test.statsdir, self.lctx)

    #todo : check and validate if exec script is provided in expected format and
    #       the file exists in that location
    execscript = current_test.tobj.testobj.TestInputData.execution_script_location.split(":")[1]
    lctx.debug("TEST SETUP : " + str(execscript))

    tmp = str(execscript).split("/")
    tmp.reverse()
    lctx.debug(tmp)
    filename = tmp[0]
    current_test.execscriptfile = current_test.execdir+"/"+filename
    lctx.debug(current_test.execscriptfile)
  except Exception as e:
    lctx.error(e)
    lctx.error(traceback.print_exc())
    return "ERROR"

  try:
    ret = copyfile(execscript, current_test.execscriptfile)
  except shutil.Error as err:
    lctx.error("error copying file : " + str(execscript) + " to " + str(current_test.execscriptfile))
    return "ERROR"

  try:
    os.chmod(current_test.execscriptfile, 0744)
  except:
    lctx.error("error setting perm file : " +  str(current_test.execdir))
    return "ERROR"

  #create dirs
  #get exec script name
  #cp the exec script
  #set exec perm
  #update cur test obj with exec script
  #exec any custom setup script
  lctx.debug("Completed setuptest")
  return "SUCCESS"
Пример #16
0
 def __init__(self, lctx):
   self.lctx = lctx
   self.async_actions = []
   self.conf = config.CFG("DaytonaHost", lctx)
   self.conf.readCFG("config.ini");
Пример #17
0
def setupTest(self, *args):
    """
    Test setup is called when scheduler send "DAYTONA_SETUP_TEST" message to agent. In this procedure agent create
    all necessary file system path string and update in test object. After creating file path string it execute command
    for making all these file system directories so that agent can later save SAR data. On exec host, it copies execution
    script from Execscript folder to test specific directory in order to keep execution script seperate in case of
    multiple test execution

    :param self:
    :param args: tuple of arguments containing obj, command, parameter sent by scheduler to agent for this command,
    actionID and sync flag to denote if we need to execute this procedure in sync or async mode
    :return: SUCCESS in case everything goes well otherwise it throws ERROR

    """
    (obj, command, params, actionID, sync) = (args[0], args[1], args[2], args[3], args[4])
    test_serialized = params.split(",")[0]
    host_type = params.split(",")[1]

    t2 = testobj.testDefn()
    t2.deserialize(test_serialized)
    current_test = get_test(t2.testobj.TestInputData.testid)
    test_logger = None

    try:
        if current_test:
	    test_logger = LOG.gettestlogger(current_test, "STAT")
            lctx.debug("TEST SETUP | " + str(current_test.testid) + " | START")
	    test_logger.info("Test setup started")
            current_test.tobj = testobj.testDefn()
            current_test.tobj = t2
            current_test.testid = current_test.tobj.testobj.TestInputData.testid

            cfg = config.CFG("DaytonaHost", lctx)
            cfg.readCFG("config.ini")
	    dir = cfg.daytona_agent_root + "/" + current_test.tobj.testobj.TestInputData.frameworkname + "/" + str(
                current_test.tobj.testobj.TestInputData.testid)
	    shutil.rmtree(dir, ignore_errors=True)
            prefix = cfg.daytona_agent_root + "/" + current_test.tobj.testobj.TestInputData.frameworkname + "/" + str(
                current_test.tobj.testobj.TestInputData.testid) + "/results/"

            if host_type == "EXEC":
                current_test.execdir = prefix + current_test.tobj.testobj.TestInputData.exechostname
                current_test.logdir = prefix + current_test.tobj.testobj.TestInputData.exechostname + "/application"

            current_test.statsdir = prefix + current_test.stathostip + "/sar/"
            current_test.resultsdir = cfg.daytona_agent_root + "/" + \
                                      current_test.tobj.testobj.TestInputData.frameworkname + "/" + \
                                      str(current_test.tobj.testobj.TestInputData.testid) + "/results"
            current_test.archivedir = cfg.daytona_agent_root + "/" + \
                                      current_test.tobj.testobj.TestInputData.frameworkname + "/" + \
                                      str(current_test.tobj.testobj.TestInputData.testid) + "/"

            if host_type == "EXEC":
                common.createdir(current_test.execdir, self.lctx)
                common.createdir(current_test.logdir, self.lctx)

            common.createdir(current_test.resultsdir, self.lctx)
            common.createdir(current_test.statsdir, self.lctx)

	    test_logger.info("Test directory created")

            if host_type == "EXEC":
                execscript = current_test.tobj.testobj.TestInputData.execution_script_location
                lctx.debug("TEST SETUP : " + str(execscript))
                current_test.execscriptfile = current_test.execdir + "/" + execscript
                lctx.debug(current_test.execscriptfile)

                # check if execution script is present in EXEC_SCRIPT_DIR - execute script only if it present at
                # this location

                execscript_location = EXEC_SCRIPT_DIR + execscript
                execscript_location = os.path.realpath(execscript_location)
                valid_path = os.path.commonprefix([execscript_location, EXEC_SCRIPT_DIR]) == EXEC_SCRIPT_DIR

                if valid_path:
                    if os.path.isfile(execscript_location):
                        ret = shutil.copytree(os.path.dirname(execscript_location),
                                              os.path.dirname(current_test.execscriptfile))
                    else:
                        raise Exception(
                            "Execution script not found at Daytona Execution Script Location : " + EXEC_SCRIPT_DIR)
                else:
                    raise Exception(
                        "Access Denied : Use Daytona Execution Script Location '" + EXEC_SCRIPT_DIR + "' for executing "
                                                                                                      "exec scripts")
                os.chmod(current_test.execscriptfile, 0744)
		test_logger.info("Execution script copied successfully")

            save_test(current_test.testid, current_test)
	    test_logger.info("Test setup complete")
            lctx.debug("TEST SETUP | " + 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"