Ejemplo n.º 1
0
    def results(self):
        """
    Fetch the testsuite results as processed text
    """
        task = None
        actionid = \
          self.ovtDB.getActionForTestsuite(self.relatedEntities['testsuiteid'])
        if actionid == None:
            return "Unknown actionid %d" % actionid

        testrun = Testrun(self.ovtDB,
                          testrunid=self.relatedEntities['testrunid'],
                          logDB=self.ovtDB.log)
        try:
            exec("from action.A%d import *" % actionid)
            exec("task = A%d((testrun, None, None, actionid)) # %s" %
                 (actionid, str(testrun)))
            exec("del(sys.modules['action.A%d'])" % actionid)
        except ImportError:
            return "Failed to import action (A%d)\n%s" \
                   % (actionid, formatExceptionInfo())
        except SyntaxError:
            return "Failed to import action (A%d) because of syntax error\n%s" \
                   % (actionid, formatExceptionInfo())
        except Exception:
            return "Unknown exception when importing action (A%d)\n%s" \
                   % (actionid, formatExceptionInfo())

        try:
            formattedResult = task.formatResults()
        except ResultSubmissionException, e:
            formattedResult = "Testsuite formatting error:\n%s" % str(e)
Ejemplo n.º 2
0
    def getActionObject(self, actionid, testrunid, versionedactionid):
        """
    Returns A<actionid> object
    """
        task = None
        testrun = Testrun(self.ovtDB,
                          testrunid=testrunid,
                          logDB=self.ovtDB.log)
        try:
            exec("from action.A%d import *" % actionid)
            exec("task = A%d((testrun, versionedactionid, None, actionid))" %
                 (actionid))
            exec("del(sys.modules['action.A%d'])" % actionid)
        except ImportError:
            self.errorReport += "Failed to import action (A%d)\n%s\n" \
                % (actionid, formatExceptionInfo())
            task = None
        except SyntaxError:
            self.errorReport += "Failed to import action (A%d) because of syntax error\n%s\n" \
                % (actionid, formatExceptionInfo())
            task = None
        except Exception:
            self.errorReport += "Unknown exception when importing action (A%d)\n%s\n" \
                % (actionid, formatExceptionInfo())
            task = None

        return task
Ejemplo n.º 3
0
    def initResources(self, versionedactionid, testrunactionid, init=True):
        """
    Initialise all the resources for the given versionedactionid
    """
        resourcedata = self.ovtDB.getTestrunResources(self.testrunid,
                                                      versionedactionid)

        if len(resourcedata) == 0:
            raise ResourceInitFailedException(
                "Failed to find Execution Host (or any other resource)")

        if not versionedactionid in self.resources:
            self.resources[versionedactionid] = {}

        for data in resourcedata:
            resource = None
            try:
                exec("from resources.R%u import *" % (data['typeid']))
                exec(
                    "resource = R%u((self, {'versionedactionid':versionedactionid}, data))"
                    % (data['typeid']))
                exec("del(sys.modules['resources.R%u'])" % (data['typeid']))
            except ImportError, ex:
                raise ResourceInitFailedException(
                    "Failed to import module for %s resource (R%u) %s" %
                    (data['name'], data['typeid'], str(ex)))
            except SyntaxError:
                raise ResourceInitFailedException(
                    "Syntax error in %s resource module (R%u)\n%s" %
                    (data['name'], data['typeid'], formatExceptionInfo()))
Ejemplo n.º 4
0
    def fetchActionResults(self, actionObject):
        """
    Fetches results from an action without formatting.
    Also uses extendActionResults() function to add some fields.
    """

        actionResults = None
        try:
            actionResults = actionObject.actionQuery()

            if actionResults is not None:
                self.extendActionResults(actionResults, actionObject)
        except ResultSubmissionException, e:
            self.errorReport += "Failed to extract results for action (A%d)\n%s\n" \
                                % (actionObject.actionid, formatExceptionInfo())
Ejemplo n.º 5
0
    def __doClaimInitialise(self, userclaimid, options):
        """
    Initialise all the resources in a claim
    """
        resourceids, historic = self.ovtDB.getUserResources(userclaimid,
                                                            held=True)
        if len(resourceids) == 0:
            self.error(
                "Internal consistency failure... The claim resulted in no resources."
            )
            sys.exit(4)

        self.globals = {'resources': {}}
        self.userclaimid = userclaimid
        testrun = DevTestrun(self.globals, 0)
        testrun.log_helper_message = "STATUS"
        for resourceid in resourceids:
            data = self.ovtDB.getUserResource(userclaimid, resourceid)
            resource = None

            try:
                exec("from resources.R%u import *" % (data['typeid']))
                exec(
                    "resource = R%u((testrun, {'userclaimid':userclaimid, 'logdir':options['logdir']}, data))"
                    % (data['typeid']))
                exec("del(sys.modules['resources.R%u'])" % (data['typeid']))
            except ImportError, e:
                self.error("Failed to import module for %s resource (R%u)" %
                           (data['name'], data['typeid']))
                self.error(e)
                raise ResourceInitFailedException("Import error")
            except SyntaxError:
                self.error(
                    "Syntax error in %s resource module (R%u)\n%s" %
                    (data['name'], data['typeid'], formatExceptionInfo()))
                raise ResourceInitFailedException("Syntax error")
Ejemplo n.º 6
0
                    % (data['typeid']))
                exec("del(sys.modules['resources.R%u'])" % (data['typeid']))
            except ImportError, e:
                self.error("Failed to import module for %s resource (R%u)" %
                           (data['name'], data['typeid']))
                self.error(e)
                raise ResourceInitFailedException("Import error")
            except SyntaxError:
                self.error(
                    "Syntax error in %s resource module (R%u)\n%s" %
                    (data['name'], data['typeid'], formatExceptionInfo()))
                raise ResourceInitFailedException("Syntax error")
            except Exception:
                self.error(
                    "Unknown exception in %s resource module (R%u)\n%s" %
                    (data['name'], data['typeid'], formatExceptionInfo()))
                raise ResourceInitFailedException("Unknown error")

            print "Successfully claimed %s" % resource.getName()
            self.globals['resources'][resource.getType()] = resource

        # Crudely sort the resource initialisation to initialise
        # in alphabetic order
        for restype in sorted(self.globals['resources'].keys()):
            try:
                if self.globals['resources'][restype].initialiseChecked():
                    # If the resources used are not historic create them so that next
                    # time this claim is re-initialised the exact same resource config
                    # will be used. This also serves to provide a long term record
                    # of the exact resource configuration
                    if not historic:
Ejemplo n.º 7
0
class Testrun:
    debug_allow_skipping = 0  # NOTE: Do not modify, this class doesn't support it

    def __init__(self,
                 ovtDB,
                 userid=None,
                 testrunid=None,
                 dependencies=None,
                 versionedactioniddict=None,
                 logDB=None):
        self.ovtDB = ovtDB
        self.logginglist = []
        self.logginglist.append(self.ovtDB.log.write)
        if logDB != None:
            self.logginglist.append(logDB)
        self.dependencies = dependencies
        self.versionedactioniddict = versionedactioniddict
        if testrunid == None:
            self.testrunid = self.ovtDB.createTestrun(userid,
                                                      versionedactioniddict)
        else:
            self.testrunid = testrunid

        self.resources = {}

    def getTestrunid(self):
        return self.testrunid

    def logHelper(self, message):
        for log in self.logginglist:
            log("TR%u: %s" % (self.testrunid, message))

    def getDetails(self):
        """
    Fetch the relevant testrun details
    """
        return self.ovtDB.getTestrunDetails(self.testrunid)

    def getUser(self):
        """
    Fetch the user that owns this testrun
    """
        return self.ovtDB.getTestrunUser(self.testrunid)

    def getConfig(self, versionedactionid):
        if versionedactionid == None:
            return None
        return TestConfig(self, versionedactionid)

    def printTests(self, showids=False):
        if self.dependencies != None and self.versionedactioniddict != None:
            self.dependencies.printTestset(self.versionedactioniddict,
                                           ids=showids)

    def registerPID(self, versionedactionid, pid):
        """
    Register the PID for a test
    """
        self.ovtDB.registerPID(self.testrunid, versionedactionid, pid)

    def getHostPID(self):
        """
    Fetch the hostid from the database for the speicfied host
    """
        return self.ovtDB.hostpid

    def setStarted(self):
        """
    Check if the testrun is already marked as started and mark it started if not
    """
        self.ovtDB.setTestrunRunstatus(self.testrunid, "RUNNING")

    def setAborting(self, lock=False):
        """
    Assert that the testrun has failed. This will trigger an abort of everything
    """
        self.__setState("ABORTING", lock)

    def setPaused(self, lock=False):
        """
    Pause the tesrun if possible
    """
        self.__setState("PAUSED", lock)

    def __setState(self, state, lock=False):
        """
    Update a testrun's status
    """
        if lock:
            success = False
            while not success:
                try:
                    self.ovtDB.setAutoCommit(False)
                    self.ovtDB.setTestrunRunstatus(self.testrunid, state)
                    self.ovtDB.FORCECOMMIT()
                    success = True
                    self.ovtDB.setAutoCommit(True)
                except DatabaseRetryException:
                    pass
        else:
            self.ovtDB.setTestrunRunstatus(self.testrunid, state)

    def setArchiveOrDeleteInProgress(self):
        """
    Mark the testrun as archiving or deleting as appropriate
    """
        status = self.ovtDB.getTestrunRunstatus(self.testrunid)
        if status == "GRIDARCHIVE" or status == "READYTOARCHIVE" or status == "ARCHIVING":
            self.ovtDB.setTestrunRunstatus(self.testrunid, "ARCHIVING")
            return (True, False)
        if status == "GRIDDELETE" or status == "READYTODELETE" or status == "DELETING":
            self.ovtDB.setTestrunRunstatus(self.testrunid, "DELETING")
            return (True, True)
        return (False, False)

    def isAborted(self):
        """
    Return true if the testrun has been aborted
    """
        self.ovtDB.always_reconnect = False
        try:
            try:
                status = self.ovtDB.getTestrunRunstatus(self.testrunid)
                return (status == "ABORTED" or status == "ABORTING")
            except DatabaseRetryException:
                # Do not reconnect just assume no abort has occurred
                return False
        finally:
            self.ovtDB.always_reconnect = True

    def initResources(self, versionedactionid, testrunactionid, init=True):
        """
    Initialise all the resources for the given versionedactionid
    """
        resourcedata = self.ovtDB.getTestrunResources(self.testrunid,
                                                      versionedactionid)

        if len(resourcedata) == 0:
            raise ResourceInitFailedException(
                "Failed to find Execution Host (or any other resource)")

        if not versionedactionid in self.resources:
            self.resources[versionedactionid] = {}

        for data in resourcedata:
            resource = None
            try:
                exec("from resources.R%u import *" % (data['typeid']))
                exec(
                    "resource = R%u((self, {'versionedactionid':versionedactionid}, data))"
                    % (data['typeid']))
                exec("del(sys.modules['resources.R%u'])" % (data['typeid']))
            except ImportError, ex:
                raise ResourceInitFailedException(
                    "Failed to import module for %s resource (R%u) %s" %
                    (data['name'], data['typeid'], str(ex)))
            except SyntaxError:
                raise ResourceInitFailedException(
                    "Syntax error in %s resource module (R%u)\n%s" %
                    (data['name'], data['typeid'], formatExceptionInfo()))
            except Exception:
                raise ResourceInitFailedException(
                    "Unknown exception in %s resource module (R%u)\n%s" %
                    (data['name'], data['typeid'], formatExceptionInfo()))
Ejemplo n.º 8
0
                    if resource.initialiseChecked():
                        # Clone the resource to create historic entries. These historic
                        # entries are used when searching testruns instead of the real
                        # resources. This is because the real resource may change its
                        # attributes over time and also the users resource requirements
                        # may not fully specify a resource.
                        self.ovtDB.cloneResource(
                            resource.getResourceid(),
                            resource.getAttributes(),
                            testrunactionid=testrunactionid)
                except ResourceInitFailedException:
                    raise
                except Exception:
                    raise ResourceInitFailedException(
                        "Unknown exception during init of %s resource\n%s" %
                        (resource.name, formatExceptionInfo()))

    def getResource(self, versionedactionid, name):
        """
    Grab a pre-initialised resource
    """
        if versionedactionid not in self.resources or \
           name not in self.resources[versionedactionid]:
            raise ResourceException(
                "Resource %s does not exist for versioned action %d" %
                (name, versionedactionid))

        return self.resources[versionedactionid][name]

    def getNextTask(self, hostid):
        """