Ejemplo n.º 1
0
    def testFreezeThawJobOrder(self):
        db = database.Database(':memory:', ':memory:')
        uJob = database.UpdateJob(db)
        uJob.setTransactionCounter(100)
        uJob.freeze(self.workDir)

        uJob = database.UpdateJob(db)
        uJob.thaw(self.workDir)
        self.assertEqual(uJob._jobPreScriptsByJob, None)
        self.assertEqual(uJob.getTransactionCounter(), 100)
        shutil.rmtree(self.workDir)
        os.mkdir(self.workDir)

        uJob = database.UpdateJob(db)
        uJob.setTransactionCounter(100)
        # The third argument is bogus, but thawing should still work
        uJob._jobPreScriptsByJob = [
            [(0, [0, 1], "junk"), (1, [2, 3], "more junk")],
            [(10, [10, 11], "junk"), (11, [12, 13], "more junk")],
            [(20, [20, 21], "junk"), (21, [22, 23], "more junk")],
            ["just junk"],
        ]
        uJob.freeze(self.workDir)

        uJob = database.UpdateJob(db)
        uJob.thaw(self.workDir)
        self.assertEqual(uJob._jobPreScriptsByJob, [
            [(0, [0, 1]), (1, [2, 3])],
            [(10, [10, 11]), (11, [12, 13])],
            [(20, [20, 21]), (21, [22, 23])],
        ])
        shutil.rmtree(self.workDir)
        os.mkdir(self.workDir)
Ejemplo n.º 2
0
    def testFreezeThawTroveMap(self):
        db = database.Database(':memory:', ':memory:')
        uJob = database.UpdateJob(db)
        uJob.setTransactionCounter(100)

        now = 1234567890.0
        v1 = VersionFromString('/a@b:c/1.0-1', timeStamps=[now])
        v2 = VersionFromString('/a@b:c/1.0-2', timeStamps=[now + 1])
        flv1 = parseFlavor("")
        flv2 = parseFlavor("is: x86")
        trv1 = trove.Trove("trove1", v1, flv1)
        trv2 = trove.Trove("trove2", v2, flv2)
        nvf1 = trv1.getNameVersionFlavor()
        nvf2 = trv2.getNameVersionFlavor()

        uJob._troveMap[nvf1] = trv1
        uJob._troveMap[nvf2] = trv2
        expKeys = set([nvf1, nvf2])

        uJob.freeze(self.workDir)

        uJob = database.UpdateJob(db)
        uJob.thaw(self.workDir)
        self.assertEqual(uJob.getTransactionCounter(), 100)
        self.assertEqual(set(uJob._troveMap.keys()), expKeys)
        self.assertEqual(
            trv1.diff(None)[0].freeze(),
            uJob._troveMap[nvf1].diff(None)[0].freeze())
        self.assertEqual(
            trv2.diff(None)[0].freeze(),
            uJob._troveMap[nvf2].diff(None)[0].freeze())
Ejemplo n.º 3
0
 def testLoadInvocationInfo(self):
     # CNY-2580
     jobFile = os.path.join(resources.get_archive(), "job-invocation")
     uJob = database.UpdateJob(None)
     uJob.loadInvocationInfo(jobFile)
     self.assertEqual(uJob.getItemList(), [('group-appliance', (None, None),
                                            (None, None), True)])
Ejemplo n.º 4
0
    def testGetOverlappingPaths(self):
        # because they are modifying the same file.
        tst1 = self.addComponent('test:run', '1.0', '',
                                 ['/tmp/foo', '/tmp/fooz', '/tmp/bam'])
        tst2 = self.addComponent('test:run', '2.0', '',
                                 ['/tmp/foo2', '/tmp/fooz2'])
        foo = self.addComponent('foo:run', '1.0', '', ['/tmp/foo', '/tmp/fooz'])
        bam = self.addComponent('bam:run', '1.0', '', ['/tmp/bam'])
        bar = self.addComponent('bar:run', '1.0', '', ['/tmp/bar'])
        baz = self.addComponent('baz:run', '1.0', '', ['/tmp/baz'])
        baz2 = self.addComponent('baz2:run', '1.0', '', ['/tmp/baz'])
        baz3 = self.addComponent('baz3:run', '1.0', '', ['/tmp/baz'])
        baz4 = self.addComponent('baz4:run', '1.0', '', ['/tmp/baz'])

        self.updatePkg('test:run=1.0')

        job = [(tst1.getName(), (tst1.getVersion(), tst1.getFlavor()),
                                (tst2.getVersion(), tst2.getFlavor()), False)]
        for trv in foo, bam, bar, baz, baz2, baz3, baz4:
            job.append((trv.getName(), (None, None),
                        (trv.getVersion(), trv.getFlavor()), False))

        cl = conaryclient.ConaryClient(self.cfg)
        uJob = database.UpdateJob(cl.db)
        repos = self.openRepository()

        cs = repos.createChangeSet(job, withFiles=False)
        uJob.getTroveSource().addChangeSet(cs)

        overlapping = cl._findOverlappingJobs(job, uJob.getTroveSource())
        overlappingNames = sorted([ sorted([y[0] for y in x]) for x in  overlapping])
        assert(overlappingNames == [['bam:run', 'foo:run', 'test:run'], ['baz2:run', 'baz3:run', 'baz4:run', 'baz:run']])
Ejemplo n.º 5
0
def doLocalCommit(db, changeSetFile):
    cs = changeset.ChangeSetFromFile(changeSetFile)
    if not cs.isLocal():
        log.error("repository changesets must be applied with update instead")
    else:
        db.commitChangeSet(cs,
                           database.UpdateJob(db),
                           rollbackPhase=db.ROLLBACK_PHASE_LOCAL,
                           updateDatabase=False)
Ejemplo n.º 6
0
    def testClose(self):
        dbobj = database.Database(':memory:', ':memory:')
        dbobj2 = database.Database(':memory:', ':memory:')
        # Make _db be non-None
        dbobj.db
        dbobj2.db

        uJob = database.UpdateJob(dbobj)
        uJob.close()
        self.assertEqual(dbobj._db, None)

        # We close correctly even if the search source object doesn't have a
        # db property
        uJob = database.UpdateJob(dbobj)
        uJob.troveSource.db = dbobj

        class MockSearchSource(object):
            pass

        uJob.setSearchSource(MockSearchSource())
        uJob.close()
        self.assertEqual(dbobj._db, None)

        # or the property is None
        uJob = database.UpdateJob(dbobj)

        class MockSearchSource(object):
            db = None

        uJob.setSearchSource(MockSearchSource())
        uJob.close()
        self.assertEqual(dbobj._db, None)

        # ... or real
        uJob = database.UpdateJob(dbobj)
        uJob = database.UpdateJob(dbobj)

        class MockSearchSource(object):
            db = dbobj2

        uJob.setSearchSource(MockSearchSource())
        uJob.close()
        self.assertEqual(dbobj._db, None)
        self.assertEqual(dbobj2._db, None)
Ejemplo n.º 7
0
    def testFreezeThawCompatClassNoneScripts(self):
        db = database.Database(':memory:', ':memory:')
        uJob = database.UpdateJob(db)
        uJob.setTransactionCounter(100)

        now = 1234567890.0
        v1 = VersionFromString('/a@b:c/1.0-1', timeStamps=[now])
        flv1 = parseFlavor("")
        js1 = ("trove1", (None, None), (v1, flv1), True)

        scripts = [
            (js1, '', None, None, 'preupdate'),
        ]

        uJob._jobPreScripts = scripts
        uJob.freeze(self.workDir)

        uJob = database.UpdateJob(db)
        uJob.thaw(self.workDir)
        self.assertEqual(uJob.getTransactionCounter(), 100)
        self.assertEqual(uJob._jobPreScripts, scripts)
Ejemplo n.º 8
0
    def testFreezeThawScriptsAlreadyRun(self):
        db = database.Database(':memory:', ':memory:')
        uJob = database.UpdateJob(db)
        uJob.setTransactionCounter(100)

        now = 1234567890.0
        v1 = VersionFromString('/a@b:c/1.0-1', timeStamps=[now])
        v2 = VersionFromString('/a@b:c/1.0-2', timeStamps=[now + 1])
        flv1 = parseFlavor("")
        flv2 = parseFlavor("is: x86")
        js1 = ("trove1", (None, None), (v1, flv1), True)
        js2 = ("trove2", (v1, flv2), (v2, flv2), True)

        runScripts = set([('preupdate', js1), ('preerase', js2)])
        uJob._jobPreScriptsAlreadyRun = set(runScripts)
        uJob.freeze(self.workDir)

        uJob = database.UpdateJob(db)
        uJob.thaw(self.workDir)
        self.assertEqual(uJob.getTransactionCounter(), 100)
        self.assertEqual(uJob._jobPreScriptsAlreadyRun, set(runScripts))
Ejemplo n.º 9
0
    def testUpdateJobiterJobPreScriptsForJobSet(self):
        db = database.Database(':memory:', ':memory:')
        uJob = database.UpdateJob(db)

        js1 = ("trove1", (None, None), ('/a@b:c/1.0-1', ""), True)
        js2 = ("trove2", ('/a@b:c/1.0-1', None), ('/a@b:c/1.0-2', ""), True)
        js3 = ("trove3", (None, None), ('/a@b:c/1.0-1', ""), True)
        js4 = ("trove4", ('/a@b:c/1.0-1', None), ('/a@b:c/1.0-2', ""), True)
        js5 = ("trove5", ('/a@b:c/1.0-1', None), (None, None), True)
        js6 = ("trove6", ('/a@b:c/1.0-1', None), (None, None), True)

        uJob.jobs = [[js1, js2, js5], [js3, js4, js6]]

        sc1 = (js1, "preinst1", 0, 1, "preinstall")
        sc2 = (js3, "preinst3", 0, 1, "preinstall")
        sc3 = (js2, "preup2", 0, 1, "preupdate")
        sc4 = (js4, "preup4", 0, 1, "preupdate")
        sc5 = (js5, "preer5", 0, 1, "preerase")
        sc6 = (js6, "preer6", 0, 1, "preerase")
        sc7 = (js2, "prerb2", 0, 1, "prerollback")
        sc8 = (js4, "prerb4", 0, 1, "prerollback")
        uJob._jobPreScripts = [sc1, sc2, sc3, sc4, sc5, sc6, sc7, sc8]

        uJob._jobPreScriptsByJob = [
            [(0, [6]), (1, [7])],
            [(0, [0]), (1, [1])],
            [(0, [2]), (1, [3])],
            [(0, [4]), (1, [5])],
        ]
        ret = list(uJob.iterJobPreScriptsForJobSet(0))
        self.assertEqual(ret, [sc7, sc1, sc3, sc5])

        ret = list(uJob.iterJobPreScriptsForJobSet(1))
        self.assertEqual(ret, [sc8, sc2, sc4, sc6])

        # Trigger an AssertionError
        uJob._jobPreScriptsByJob = [[], [(0, [2]), (1, [3])], [], []]
        self.assertRaises(AssertionError, list,
                          uJob.iterJobPreScriptsForJobSet(0))

        # No data
        uJob._jobPreScripts = []
        uJob._jobPreScriptsByJob = None
        ret = list(uJob.iterJobPreScriptsForJobSet(0))
        self.assertEqual(ret, [])
Ejemplo n.º 10
0
    def _resolve(self,
                 cfg,
                 resolveResult,
                 trove,
                 searchSource,
                 resolveSource,
                 installLabelPath,
                 searchFlavor,
                 reqs,
                 isCross=False):
        resolveSource.setLabelPath(installLabelPath)
        client = conaryclient.ConaryClient(cfg)

        # we allow build requirements to be matched against anywhere on the
        # install label.  Create a list of all of this trove's labels,
        # from latest on branch to earliest to use as search labels.

        # don't follow redirects when resolving buildReqs
        result = searchSource.findTroves(
            installLabelPath,
            reqs,
            searchFlavor,
            allowMissing=True,
            acrossLabels=False,
            troveTypes=trovesource.TROVE_QUERY_NORMAL)
        okay = True

        buildReqTups = []
        missingBuildReqs = []
        for troveSpec in reqs:
            solutions = result.get(troveSpec, [])
            if not solutions:
                missingBuildReqs.append(troveSpec)
                okay = False
            else:
                sol = _findBestSolution(trove, troveSpec, solutions,
                                        searchFlavor, resolveSource)
                if sol is None:
                    missingBuildReqs.append(troveSpec)
                    okay = False
                buildReqTups.append(sol)

        if not okay:
            self.logger.info('Could not find all buildreqs: %s' %
                             (missingBuildReqs, ))
            resolveResult.troveMissingBuildReqs(isCross, missingBuildReqs)
            return False, None

        itemList = [(x[0], (None, None), (x[1], x[2]), True)
                    for x in buildReqTups]

        uJob = database.UpdateJob(None)
        uJob.setSearchSource(searchSource)
        jobSet = client._updateChangeSet(itemList, uJob, useAffinity=False)
        (depList, suggMap, cannotResolve) = \
        client.resolver.resolveDependencies(uJob, jobSet,
                                            resolveDeps=True,
                                            useRepos=False, split=False,
                                            resolveSource=resolveSource)[0:3]

        jobSet.update((x[0], (None, None), (x[1], x[2]), False)
                      for x in itertools.chain(*suggMap.itervalues()))
        if cannotResolve or depList:
            self.logger.info('Missing: %s' % ((depList + cannotResolve), ))
            resolveResult.troveMissingDependencies(isCross,
                                                   depList + cannotResolve)
            client.close()
            return False, resolveResult

        self._addPackages(searchSource, jobSet)
        client.close()
        return True, jobSet