Exemplo n.º 1
0
 def __thaw__(class_, d):
     self = class_(**d)
     self.trove = thaw('BuildTrove', self.trove)
     self.buildCfg = thaw('BuildConfiguration', self.buildCfg)
     self.builtTroves = thaw('troveTupleList', self.builtTroves)
     self.crossTroves = thaw('troveTupleList', self.crossTroves)
     return self
Exemplo n.º 2
0
 def loadPayloadFromDict(self, d):
     self._payload.__dict__.update(d)
     self.payload.buildCfg = thaw('BuildConfiguration',
                                  self.payload.buildCfg)
     self.payload.trove = thaw('BuildTrove', self.payload.trove)
     if self.payload.logData == '':
         self.payload.logData = None
Exemplo n.º 3
0
    def testResolveResult(self):
        trv = self.addComponent('foo:runtime', '1.0', 'ssl')
        tup = trv.getNameVersionFlavor()
        job = (tup[0], (None, None), (tup[1], tup[2]), False)

        r = resolver.ResolveResult()
        r.troveResolved([job], [], [])
        r2 = thaw('ResolveResult', freeze('ResolveResult', r))
        assert(r2.getBuildReqs() == [ job  ])
        assert(r2.success)
        assert(not r2.inCycle)

        r = resolver.ResolveResult(inCycle=True)
        r.troveMissingBuildReqs(True, [('foo', None, parseFlavor('ssl'))])
        r2 = thaw('ResolveResult', freeze('ResolveResult', r))
        assert(not r2.hasMissingDeps())
        assert(r2.hasMissingBuildReqs())
        assert(r2.getMissingBuildReqs() == [(True, ('foo', '', parseFlavor('ssl')))])
        assert(not r2.success)
        assert(r2.inCycle)

        r = resolver.ResolveResult(inCycle=True)
        r.troveMissingDependencies(True, [(trv.getNameVersionFlavor(), 
                                     parseDep('trove: foo trove: bar'))])
        r2 = thaw('ResolveResult', freeze('ResolveResult', r))
        assert(r.getMissingDeps() == r2.getMissingDeps())
        assert(r2.hasMissingDeps())
        assert(not r2.success)
        assert(r2.inCycle)
Exemplo n.º 4
0
 def __thaw__(class_, d):
     self = class_()
     self.__dict__.update(d)
     self.buildReqs = thaw("installJobList", self.buildReqs)
     self.crossReqs = thaw("installJobList", self.crossReqs)
     self.bootstrapReqs = thaw("installJobList", self.bootstrapReqs)
     self.missingDeps = thaw("dependencyMissingList", self.missingDeps)
     self.missingBuildReqs = [(x[0], thaw("troveSpec", x[1])) for x in self.missingBuildReqs]
     return self
Exemplo n.º 5
0
 def _getChroots(self, cu):
     chroots = []
     for nodeName, path, jobId, name, version, flavor, active in cu:
         if jobId:
             version = thaw('version', version)
             flavor = thaw('flavor', flavor)
             troveTuple = (name, version, flavor)
         else:
             troveTuple = None
         c = chroot.Chroot(nodeName, path, jobId, troveTuple, active)
         chroots.append(c)
     return chroots
Exemplo n.º 6
0
 def commitSucceeded(self, callData, jobIds, commitMap):
     jobIds = self.db.convertToJobIds(jobIds)
     # split commitMap and recombine
     finalMap = []
     for jobId, troveMap in itertools.izip(jobIds, commitMap):
         troveMap = dict((thaw('troveContextTuple', x[0]),
                         thaw('troveTupleList', x[1])) for x in troveMap)
         finalMap.append((jobId, troveMap))
     jobs = self.db.getJobs(jobIds, withTroves=True)
     for (jobId, troveMap), job in itertools.izip(finalMap, jobs):
         self._subscribeToJob(job)
         job.jobCommitted(troveMap)
Exemplo n.º 7
0
 def loadPayloadFromDict(self, d):
     self._payload.__dict__.update(d)
     self.payload.buildCfg = thaw('BuildConfiguration',
                                  self.payload.buildCfg)
     self.payload.trove = thaw('BuildTrove', self.payload.trove)
     for name in ('buildReqs', 'crossReqs', 'bootstrapReqs'):
         tuples = thaw('troveTupleList', getattr(self.payload, name))
         jobs = [(x[0], (None, None), x[1:3], False) for x in tuples]
         setattr(self.payload, name, jobs)
     self.payload.builtTroves = thaw('troveTupleList',
                                     self.payload.builtTroves)
     self.payload.targetLabel = thaw('label', self.payload.targetLabel)
     if self.payload.logData == '':
         self.payload.logData = None
Exemplo n.º 8
0
 def __thaw__(class_, d):
     self = class_(**d)
     if self.troveTuple:
         self.troveTuple = thaw('troveTuple', self.troveTuple)
     else:
         self.troveTuple = None
     return self
Exemplo n.º 9
0
def getResults(results, pid, inF, csFile):
    (gotResult, status) = os.waitpid(pid, os.WNOHANG)
    if not gotResult:
        return None

    if os.WIFSIGNALED(status):
        results.setExitSignal(os.WTERMSIG(status))
    else:
        assert(os.WIFEXITED(status))
        results.setExitStatus(os.WEXITSTATUS(status))

    if results.isBuildSuccess():
        results.setChangeSetFile(csFile)
    elif results.getExitSignal():
        results.setFailureReason(BuildFailed('Build exited with signal %s' % results.getExitSignal()))
    else:
        errReason = []
        buffer = os.read(inF, 1024)
        while buffer:
            errReason.append(buffer)
            buffer = os.read(inF, 1024)
        errReason = ''.join(errReason)
        errTag, data = errReason.split('\002', 1)
        results.setFailureReason(thaw('FailureReason', (errTag, data)))
    os.close(inF)
    return results
Exemplo n.º 10
0
 def testJob(self):
     db = self.openRmakeDatabase()
     trv = self.addComponent('foo:source', '1.0', '!flavor')
     job = buildjob.NewBuildJob(db, [trv.getNameVersionFlavor()])
     job2 = apiutils.thaw('BuildJob', apiutils.freeze('BuildJob', job))
     assert(job2.jobId ==  job.jobId)
     assert(list(job2.iterTroveList()) == list(job.iterTroveList()))
Exemplo n.º 11
0
 def testFreeze(self):
     cfg = buildcfg.BuildConfiguration(readConfigFiles=False)
     os.environ['HOME'] = self.workDir
     cfg.configLine('policyDirs ~/policy')
     newCfg = apiutils.thaw('BuildConfiguration',
                            apiutils.freeze('BuildConfiguration', cfg))
     assert(newCfg.policyDirs[0]._getUnexpanded() == self.workDir + '/policy')
Exemplo n.º 12
0
    def testFreezeThawException(self):
        @api(version=1)
        @api_parameters(1, None)
        @api_return(1, None)
        def testFunc(self, foo):
            return 0

        sys.exc_clear()
        frz = apirpc._freezeException(repoerrors.OpenError('foo'))
        self.assertEquals(str(apiutils.thaw(*frz)),
        'Exception from server:\n'
        'conary.repository.errors.OpenError: foo\n'
        'None\n')
        # this is rmake's internal error
        frz = apirpc._freezeException(errors.OpenError('foo'))
        self.assertEquals(str(apiutils.thaw(*frz)), 'foo')
Exemplo n.º 13
0
    def testTroveSettings(self):
        class MyTroveSettings(trovesettings.TroveSettings):
            cfgOption = cfgtypes.CfgString 

        xx = MyTroveSettings()
        xx.cfgOption = 'foobar'
        yy = apiutils.thaw('TroveSettings', apiutils.freeze('TroveSettings', xx))
        assert(yy.cfgOption == 'foobar')
Exemplo n.º 14
0
 def __thaw__(d):
     d = d.copy()
     new = CookResults(d.pop('name'),
                       versions.VersionFromString(d.pop('version')),
                       [ ThawFlavor(x) for x in d.pop('flavorList')])
     new.__dict__.update(d)
     new.failureReason = thaw('FailureReason', new.failureReason)
     return new
Exemplo n.º 15
0
    def listNodes(self):
        """
            Lists all known nodes

            @return: list of (name, slots) for each node.
        """
        rv = self.proxy.listNodes()
        return [thaw("Node", x) for x in rv]
Exemplo n.º 16
0
 def listTrovesByState(self, jobId, state=None):
     cu = self.db.cursor()
     cmd = """SELECT troveName, version, flavor, context, state 
              FROM BuildTroves 
              WHERE jobId=?"""
     params = [jobId]
     if state is not None:
         cmd += ' AND state=?'
         params.append(state)
     results = {}
     for (name, version, flavor, context, state) in cu.execute(cmd, params):
         version, flavor = thaw('version', version), thaw('flavor', flavor)
         if state in results:
             results[state].append((name, version, flavor, context))
         else:
             results[state] = [(name, version, flavor, context)]
     return results
Exemplo n.º 17
0
 def getJobConfig(self, jobId):
     cu = self.db.cursor()
     d = {}
     cu.execute("""SELECT key, value FROM JobConfig
                    WHERE jobId=? AND context='' ORDER by key, ord""", jobId)
     for key, value in cu:
         d.setdefault(key, []).append(value)
     return thaw('BuildConfiguration', d)
Exemplo n.º 18
0
 def get(self, subscriberId):
     cu = self.db.cursor()
     cu.execute('''SELECT data FROM SubscriberData WHERE subscriberId=?''',
                subscriberId)
     dataList = [ x[0] for x in cu.fetchall()]
     if not dataList:
         raise KeyError(subscriberId)
     return thaw('Subscriber', (subscriberId, dataList))
Exemplo n.º 19
0
 def listSubscribers(self, jobId):
     """
         Return subscribers for jobId
         @param jobId: jobId or UUID for job.
         @rtype: list of build.subscriber.Subscriber instances.
         @raises: JobNotFound if job does not exist.
     """
     return [ thaw('Subscriber', x)
               for x in self.proxy.listSubscribers(jobId) ]
Exemplo n.º 20
0
 def getConfig(self, jobId, context):
     cu = self.db.cursor()
     cu.execute("""SELECT  key, value
                   FROM JobConfig WHERE jobId=? AND context=?
                   ORDER by key, ord""", jobId, context)
     frozenCfg = {}
     for key, value in cu:
         frozenCfg.setdefault(key, []).append(value)
     cfg = thaw('BuildConfiguration', frozenCfg)
     return cfg
Exemplo n.º 21
0
 def startChrootSession(self, nodeName, chrootPath, command, superUser, 
                        buildTrove=None):
     nodeId = self.getDispatcher().getNodeByName(nodeName)
     passed, results = self.getNode(nodeId).startChrootSession(chrootPath,
                                                  command, superUser,
                                                  buildTrove=buildTrove)
     if passed:
         return results
     else:
         results = thaw('FailureReason', results)
         raise errors.ServerError("Could not start session at %s: %s" % (nodeId, results))
Exemplo n.º 22
0
    def testRegisterFreezableClassmap(self):
        class Freezable(object):
            def __freeze__(self):
                return {}

            @classmethod
            def __thaw__(class_, d):
                return class_()

        class Foo(Freezable):
            pass

        class Bar(Freezable):
            pass

        apiutils.register_freezable_classmap("mytype", Foo)
        apiutils.register_freezable_classmap("mytype", Bar)

        assert apiutils.thaw("mytype", apiutils.freeze("mytype", Foo())).__class__ == Foo
        assert apiutils.thaw("mytype", apiutils.freeze("mytype", Bar())).__class__ == Bar
Exemplo n.º 23
0
 def testBuildTrove(self):
     trv = self.addComponent('blah:source', '1.0')
     bt = buildtrove.BuildTrove(1, trv.getName(), trv.getVersion(),
                                trv.getFlavor())
     f = failure.MissingDependencies([(trv.getNameVersionFlavor(),
                           deps.parseDep('trove: blam trove:foo'))])
     bt.setFailureReason(f)
     frz = apiutils.freeze('BuildTrove', bt)
     bt2 = apiutils.thaw('BuildTrove', frz)
     assert(bt2.getFailureReason() == bt.getFailureReason())
     assert(bt2.getFlavor() == bt.getFlavor())
Exemplo n.º 24
0
 def getJobs(self, jobIds, withTroves=True, withConfigs=False):
     """
         Return job instance.
         @param jobId: jobId or UUID for job.
         @param withTroves: (default True) if True, include trove objects
         in job.  Otherwise only include pointers.
         @rtype: build.buildjob.BuildJob
         @raises: JobNotFound if job does not exist.
     """
     return [ thaw('BuildJob', x)
              for x in self.proxy.getJobs(jobIds, withTroves, withConfigs) ]
Exemplo n.º 25
0
 def __thaw__(class_, eventList):
     apiVer, eventList = eventList
     newEventList = []
     for ((event, subevent), data) in eventList:
         if not isinstance(data[0], int):
             data = [(data[0][0], thaw('troveContextTuple', data[0][1]))] + data[1:]
         fn = getattr(class_, 'thaw_' + event, None)
         if fn is not None:
             data = fn(apiVer, data)
         newEventList.append(((event, subevent), data))
     return apiVer, newEventList
Exemplo n.º 26
0
 def __thaw__(frzLoaded):
     d = {}
     stack = [(d, frzLoaded)]
     while stack:
         loadDict, frozenDict = stack.pop()
         for spec, (frzTroveTup, newFrzDict) in frozenDict.iteritems():
             subLoadDict = {}
             loadDict[spec] = (thaw("troveTuple", frzTroveTup), subLoadDict)
             if newFrzDict:
                 stack.append((subLoadDict, newFrzDict))
     return d
Exemplo n.º 27
0
    def checkResults(self, name, version, flavorList, wait=False):
        if not isinstance(flavorList, (list, tuple)):
            flavorList = [flavorList]
        results = self.proxy.checkResults(name, version, flavorList, wait)
        if results == '':
            return None

        results = thaw(cook.CookResults, results)
        if results.csFile:
            results.csFile = self.root + results.csFile
        return results
Exemplo n.º 28
0
    def listTrovesByState(self, jobId, state=None):
        """
            Lists troves in a job by state.
            @param jobId: jobId or uuid for job.
            @param state: (optional) state to list troves by.  All states if 
                          left blank.
            @type state: build.buildtrove.TROVE_STATE_* or None

            @return: dict of trove lists by state.
            @rtype: {TROVE_STATE_* : [(name, version, flavor)]} dict.
        """
        if state is None:
            state = ''
        results = self.proxy.listTrovesByState(jobId, state)
        return dict((x[0], thaw('troveContextTupleList', x[1])) for x in results)
Exemplo n.º 29
0
    def _returnSubscribers(self, results, subscriberCache = None):
        if subscriberCache is None:
            subscriberCache = {}
        d = {}
        for id, data in results:
            if id not in d:
                d[id] = [data]
            else:
                d[id].append(data)

        toReturn = []
        for id, data in d.iteritems():
            if id not in subscriberCache:
                subscriberCache[id] = thaw('Subscriber', (id, data))
            toReturn.append(subscriberCache[id])
        return toReturn
Exemplo n.º 30
0
    def startChrootSession(self, callData, chrootPath, command, 
                           superUser=False, buildTrove=None):
        """
            Part of rMake node XMLRPC interface.  The rMake
            server uses these methods to communicate directly to a
            node without going through the dispatcher.

            Basically a passthrough
            to worker.startSession.
            Returns (True, (hostName, port)) if the connection succeeds.
            Returns (False, FailureReason) if it fails.
        """
        if buildTrove:
            buildTrove = thaw('BuildTrove', buildTrove)
        passed, results =  self.server.startSession('_local_', chrootPath,
                                                    command, superUser, buildTrove)
        if not passed:
            results = freeze('FailureReason', results)
        return passed, results
Exemplo n.º 31
0
 def thaw(class_, d):
     self = class_(**d)
     self.buildFlavors = [thaw('flavor', x) for x in self.buildFlavors]
     self.nodeInfo = thaw('MachineInformation', self.nodeInfo)
     return self
Exemplo n.º 32
0
 def __thaw__(nodeList):
     return [thaw('ImageNode', node) for node in nodeList]
Exemplo n.º 33
0
 def __thaw__(jobList):
     return [thaw('ImageJob', job) for job in jobList]