Example #1
0
    def testUnknownFlavor(self):
        # Adding a flavor that is unknown to the current version of the
        # code

        intTag = 65535
        stringTag = "yet-to-be-defined"
        class YetToBeDefinedFlavor(DependencyClass):
            tag = intTag
            tagName = stringTag
            justOne = False
            depClass = Dependency

        flv = Flavor()
        flvName = "was"
        flvFlag = "flag1"
        flv.addDep(YetToBeDefinedFlavor,
            Dependency(flvName, [ (flvFlag, FLAG_SENSE_REQUIRED) ]))
        frozen = flv.freeze()

        x = ThawFlavor(frozen)
        # The code that implements str is very specific to what's currently
        # implemented
        self.assertEqual(str(x), '')
        # However, it's not the empty flavor
        self.assertNotEqual(x, parseFlavor(''))
        self.assertEqual(x.freeze(), '65535#was:flag1')
Example #2
0
    def testCache(self):
        dependencyCache.clear()

        flavor = parseFlavor("is: x86(mmx)").freeze()
        a = ThawFlavor(flavor)
        b = ThawFlavor(flavor)
        assert(a.members[1].members.values()[0] ==
               b.members[1].members.values()[0])
        assert(a.members[1].members.values()[0] ==
               dependencyCache['x86:mmx'])
        del a
        assert(dependencyCache)
        del b
        assert(not dependencyCache)
Example #3
0
 def __thaw__(item):
     if len(item) == 3:
         context = ''
         n, v, f = item
     else:
         n, v, f, context = item
     return (n, versions.ThawVersion(v), ThawFlavor(f), context)
Example #4
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
Example #5
0
 def __thaw__(tupList):
     results = []
     for tup in tupList:
         if len(tup) == 3 or not tup[3]:
             context = ''
         else:
             context = tup[3]
         results.append((tup[0], versions.ThawVersion(tup[1]),
                         ThawFlavor(tup[2]), context))
     return results
Example #6
0
 def _thawData(class_, data):
     parsedData = []
     lines = data.split('\000')
     for line in lines:
         troveSpec, flavor = line.split('\001')
         troveSpec = cmdline.parseTroveSpec(troveSpec)
         troveTup = troveSpec[0], versions.VersionFromString(troveSpec[1]), troveSpec[2]
         dep = ThawFlavor(flavor)
         parsedData.append((troveTup, dep))
     return parsedData
Example #7
0
 def __thaw__(frozenList):
     return [ThawFlavor(x) for x in frozenList]
Example #8
0
 def __thaw__(flavorStr):
     return ThawFlavor(flavorStr)
Example #9
0
 def __thaw__((n, v, f)):
     return (n, versions.ThawVersion(v), ThawFlavor(f))
Example #10
0
 def __thaw__(x):
     return (x[0], x[1], ThawFlavor(x[2]))
Example #11
0
 def __thaw__(tupList):
     return [(x[0], x[1], ThawFlavor(x[2])) for x in tupList]
Example #12
0
 def __thaw__(jobList):
     return [(x[0], (None, None), (versions.ThawVersion(x[1]),
                                   ThawFlavor(x[2])), x[3])
             for x in jobList]
Example #13
0
 def __thaw__(tupList):
     return [(x[0], versions.ThawVersion(x[1]), ThawFlavor(x[2]))
             for x in tupList]
Example #14
0
    def getJobs(self, jobIdList, withTroves=False, withConfigs=False):
        if not jobIdList:
            return []
        cu = self.db.cursor()
        jobIds = ','.join('%d' % x for x in jobIdList)
        results = cu.execute("""
            SELECT jobId, uuid, owner, state, status, start, finish,
                failureReason, failureData, pid
            FROM Jobs WHERE jobId IN (%s)
            """ % (jobIds, ))

        jobsById = {}
        for (jobId, uuid, owner, state, status, start, finish, failureReason,
             failureData, pid) in results:
            if state is None:
                # quick catch check for missing jobs
                raise KeyError, jobId

            failureReason = thaw('FailureReason',
                                 (failureReason, cu.frombinary(failureData)))
            job = buildjob.BuildJob(jobId,
                                    status=status,
                                    state=state,
                                    start=float(start),
                                    finish=float(finish),
                                    failureReason=failureReason,
                                    uuid=uuid,
                                    pid=pid,
                                    owner=owner)
            jobsById[jobId] = job

        if withTroves:
            results = cu.execute("""
                SELECT jobId, BuildTroves.troveId, troveName, version,
                    flavor, context, state, status, failureReason,
                    failureData, start, finish, logPath, pid, recipeType,
                    buildType, troveType, Chroots.path, Chroots.nodeName
                FROM BuildTroves
                LEFT JOIN Chroots USING(chrootId)
                WHERE jobId IN (%s)
            """ % (jobIds, ))

            trovesById = {}

            for (jobId, troveId, name, version, flavor, context, state, status,
                 failureReason, failureData, start, finish, logPath, pid,
                 recipeType, buildType, troveType, chrootPath,
                 chrootHost) in results:

                if chrootPath is None:
                    chrootPath = ''
                    chrootHost = ''
                version = versions.ThawVersion(version)
                flavor = ThawFlavor(flavor)
                failureReason = thaw(
                    'FailureReason',
                    (failureReason, cu.frombinary(failureData)))
                troveClass = buildtrove.getClassForTroveType(troveType)
                buildTrove = troveClass(jobId,
                                        name,
                                        version,
                                        flavor,
                                        state=state,
                                        start=float(start),
                                        finish=float(finish),
                                        logPath=logPath,
                                        status=status,
                                        failureReason=failureReason,
                                        pid=pid,
                                        recipeType=recipeType,
                                        chrootPath=chrootPath,
                                        chrootHost=chrootHost,
                                        buildType=buildType,
                                        context=context)
                trovesById[troveId] = buildTrove
                jobsById[jobId].addTrove(name, version, flavor, context,
                                         buildTrove)

            results = cu.execute("""
                SELECT BuildTroves.troveId, BinaryTroves.troveName,
                    BinaryTroves.version, BinaryTroves.flavor
                FROM BuildTroves
                JOIN BinaryTroves USING(troveId)
                WHERE jobId IN (%s)
                """ % (jobIds, ))
            builtTroves = {}
            for troveId, name, version, flavor in results:
                builtTroves.setdefault(troveId, []).append(
                    (name, ThawVersion(version), ThawFlavor(flavor)))
            for troveId, binTroves in builtTroves.iteritems():
                trv = trovesById.get(troveId)
                if trv is not None:
                    trv.setBuiltTroves(binTroves)

            cu.execute("""
                SELECT troveId, key, value
                FROM TroveSettings
                WHERE jobId IN (%s)
                ORDER BY key, ord
                """ % (jobIds, ))
            troveSettings = {}
            for troveId, key, value in cu:
                d = troveSettings.setdefault(troveId, {})
                d.setdefault(key, []).append(value)
            for troveId, settings in troveSettings.items():
                settingsClass = settings.pop('_class')[0]
                trv = trovesById.get(troveId)
                if trv is not None:
                    trv.settings = thaw('TroveSettings',
                                        (settingsClass, settings))
        else:
            results = cu.execute("""
                SELECT jobId, troveName, version, flavor, context
                FROM BuildTroves
                WHERE jobId IN (%s)
                """ % (jobIds, ))
            for (jobId, n, v, f, context) in results:
                jobsById[jobId].addTrove(n, versions.ThawVersion(v),
                                         ThawFlavor(f), context)
        if withConfigs:
            cu.execute("""
                SELECT jobId, context, key, value
                FROM JobConfig
                WHERE jobId IN (%s)
                ORDER BY key, ord
                """ % (jobIds, ))
            jobConfigD = {}
            for jobId, context, key, value in cu:
                configD = jobConfigD.setdefault(jobId, {})
                d = configD.setdefault(context, {})
                d.setdefault(key, []).append(value)
            for jobId, configD in jobConfigD.items():
                configD = dict((x[0], thaw('BuildConfiguration', x[1]))
                               for x in configD.iteritems())
                jobsById[jobId].setConfigs(configD)

        return [jobsById[jobId] for jobId in jobIdList]
Example #15
0
    def getTroves(self, troveList):
        if not troveList:
            return []
        cu = self.db.cursor()
        trovesById = {}
        trovesByNVF = {}
        for jobId, troveName, version, flavor, context in troveList:
            cu.execute(
                """
                SELECT BuildTroves.troveId, pid, state, status, failureReason,
                    failureData, start, finish, logPath, recipeType,
                    Chroots.nodeName, Chroots.path, troveType
                FROM BuildTroves
                LEFT JOIN Chroots USING(chrootId)
                WHERE jobId = ? AND troveName = ? AND version = ?
                    AND flavor = ? AND context = ?
                """, jobId, troveName, version.freeze(), flavor.freeze(),
                context)
            row = cu.fetchone()
            if not row:
                continue
            (troveId, pid, state, status, failureReason, failureData, start,
             finish, logPath, recipeType, chrootHost, chrootPath,
             troveType) = row
            if chrootPath is None:
                chrootPath = chrootHost = ''
            failureReason = thaw('FailureReason',
                                 (failureReason, cu.frombinary(failureData)))

            troveClass = buildtrove.getClassForTroveType(troveType)
            buildTrove = troveClass(jobId,
                                    troveName,
                                    version,
                                    flavor,
                                    context=context,
                                    pid=pid,
                                    state=state,
                                    start=float(start),
                                    finish=float(finish),
                                    logPath=logPath,
                                    status=status,
                                    failureReason=failureReason,
                                    recipeType=recipeType,
                                    chrootPath=chrootPath,
                                    chrootHost=chrootHost)
            trovesById[troveId] = buildTrove
            trovesByNVF[(jobId, troveName, version, flavor,
                         context)] = buildTrove
        if not trovesByNVF:
            raise KeyError(troveList[0])
        troveIds = ','.join('%d' % x for x in trovesById)

        cu.execute("""
            SELECT troveId, troveName, version, flavor
            FROM BinaryTroves
            WHERE troveId IN (%s)
            """ % (troveIds, ))
        builtTroves = {}
        for troveId, troveName, version, flavor in cu:
            builtTroves.setdefault(troveId, []).append(
                (troveName, ThawVersion(version), ThawFlavor(flavor)))
        for troveId, binTroves in builtTroves.iteritems():
            trovesById[troveId].setBuiltTroves(binTroves)

        cu.execute("""
            SELECT troveId, key, value
            FROM TroveSettings
            WHERE troveId IN (%s)
            ORDER BY key, ord
            """ % (troveIds, ))
        troveSettings = {}
        for troveId, key, value in cu:
            d = troveSettings.setdefault(troveId, {})
            d.setdefault(key, []).append(value)
        for troveId, settings in troveSettings.items():
            settingsClass = settings.pop('_class')[0]
            trovesById[troveId].settings = thaw('TroveSettings',
                                                (settingsClass, settings))

        out = []
        for tup in troveList:
            if tup in trovesByNVF:
                out.append(trovesByNVF[tup])
            else:
                raise KeyError(tup)
        return out