Exemple #1
0
    def testWatchImage(self):
        eventHandler = mock.MockObject()
        mock.mock(rbuilderclient, 'RbuilderClient')
        self.buildCfg.configLine('rmakeUser foo bar')
        self.buildCfg.rbuilderUrl = 'http://foo'
        mock.mock(time, 'sleep')
        trv = imagetrove.ImageTrove(1, *self.makeTroveTuple('group-foo'))
        trv.setProductName('product')
        cmd = imagecommand.ImageCommand(self.rmakeCfg, 'commandId', 1,
                                        eventHandler, self.buildCfg, trv)
        client = cmd.client
        client.server.getBuildStatus._mock.setReturns([(False, {
            'message': 'foo',
            'status': 10
        }), (False, {
            'message': 'foo',
            'status': 10
        }), (False, {
            'message': 'bar',
            'status': 300
        })], 21)
        rc, txt = self.captureOutput(cmd.watchImage, 21)
        assert (txt == '''\
21: foo
21: bar
''')
        client.server.getBuildStatus._mock.setReturns(
            [(True, 'Error with build')], 31)
        err = self.assertRaises(errors.RmakeError, cmd.watchImage, 31)
Exemple #2
0
 def testImageCommand(self):
     eventHandler = mock.MockObject()
     mock.mock(rbuilderclient, 'RbuilderClient')
     self.buildCfg.configLine('rmakeUser foo bar')
     self.buildCfg.rbuilderUrl = 'http://foo'
     trv = imagetrove.ImageTrove(1, *self.makeTroveTuple('group-foo'))
     trv.setProductName('product')
     cmd = imagecommand.ImageCommand(self.rmakeCfg, 'commandId', 1,
                                     eventHandler, self.buildCfg, trv)
     client = cmd.client
     client.newBuildWithOptions._mock.setDefaultReturn(21)
     cmd.logger = mock.MockObject()
     mock.mockMethod(cmd.watchImage)
     cmd.runAttachedCommand()
     cmd.watchImage._mock.assertCalled(21)
     client.startImage._mock.assertCalled(21)
     client.newBuildWithOptions._mock.assertCalled('product', 'group-foo',
                                                   trv.getVersion(),
                                                   trv.getFlavor(),
                                                   trv.getImageType(),
                                                   trv.getBuildName(),
                                                   trv.getImageOptions())
     client.newBuildWithOptions._mock.raiseErrorOnAccess(
         RuntimeError('error!'))
     cmd.runAttachedCommand()
     assert (trv.isFailed())
     assert (str(trv.getFailureReason()) == 'Failed while building: error!')
Exemple #3
0
    def testJobStoreImage(self):
        db = self.openRmakeDatabase()
        job = buildjob.BuildJob()
        trv = imagetrove.ImageTrove(None, *self.makeTroveTuple('group-foo'))
        trv.setProductName('product')
        trv.setImageType('imageType')
        job.addBuildTrove(trv)
        job.setMainConfig(self.buildCfg)
        db.addJob(job)
        db.subscribeToJob(job)
        newJob = db.getJob(job.jobId)
        newTrv, = newJob.troves.values()
        assert (isinstance(newTrv, imagetrove.ImageTrove))
        assert (newTrv.getProductName() == 'product')
        assert (newTrv.getImageType() == 'imageType')
        trv.setImageBuildId(31)  # should automatically update
        trv.troveBuilding()
        newTrv = db.getTrove(job.jobId, *trv.getNameVersionFlavor())
        assert (newTrv.getImageBuildId() == 31)
        newJob = db.getJob(job.jobId)
        newTrv, = newJob.troves.values()
        assert (newTrv.getImageBuildId() == 31)

        trv.setImageBuildId(32)  # should automatically update
        job.setBuildTroves(job.troves.values())
        newTrv = db.getTrove(job.jobId, *trv.getNameVersionFlavor())
        assert (newTrv.getImageBuildId() == 32)
Exemple #4
0
 def testInit(self):
     bt = buildtrove.BuildTrove(1, *self.makeTroveTuple('foo:source'))
     bt.setConfig(self.buildCfg)
     it = imagetrove.ImageTrove(1, *self.makeTroveTuple('group-foo'))
     publisher = mock.MockObject()
     dh = dephandler.DependencyHandler(publisher, None, [bt], [it])
     assert (dh.moreToDo())
     bt.troveBuilt([])
     assert (dh.hasSpecialTroves())
     assert (dh.popSpecialTrove() == it)
     assert (dh.specialTroves)
Exemple #5
0
    def createImageJob(self, productName, imageList):
        allTroveSpecs = {}
        finalImageList = []
        for image in imageList:
            image = list(image)
            if len(image) < 4:
                image.append('')
            # Make it easy to append more parameters extensibly later
            image = image[0:4]
            finalImageList.append(image)

        for troveSpec, imageType, imageOptions, buildName in finalImageList:
            if isinstance(troveSpec, str):
                troveSpec = cmdline.parseTroveSpec(troveSpec)
            allTroveSpecs.setdefault(troveSpec, []).append((imageType, 
                                                            buildName,
                                                            imageOptions))
        cfg = self.buildConfig
        cfg.initializeFlavors()
        repos = self.getRepos()
        results = repos.findTroves(cfg.buildLabel, allTroveSpecs, 
                                   cfg.buildFlavor)

        def getContextName(buildName):
            return buildName.replace(' ', '_')

        contextCache = set()

        i = 1
        job = buildjob.BuildJob()
        for troveSpec, troveTupList in results.iteritems():
            for imageType, buildName, imageOptions in allTroveSpecs[troveSpec]:
                for name, version, flavor in troveTupList:
                    context = getContextName(buildName)
                    while not context or context in contextCache:
                        if buildName:
                            context = '%s_(%d)' %(context, i)
                        else:
                            context = 'Image_%d' %i
                        i += 1
                    contextCache.add(context)
                    imageTrove = imagetrove.ImageTrove(None, 
                                                       name, version, flavor,
                                                       context=context)
                    imageTrove.setImageType(imageType)
                    imageTrove.setImageOptions(imageOptions)
                    imageTrove.setProductName(productName)
                    imageTrove.setBuildName(buildName)
                    job.setTroveConfig(imageTrove, cfg)
                    job.addTrove(name, version, flavor, context, imageTrove)
        job.setMainConfig(cfg)
        return job
Exemple #6
0
 def testActOnTrove(self):
     w = worker.Worker(self.rmakeCfg, log)
     eventHandler = mock.MockObject()
     mock.mockMethod(w.queueCommand)
     trv = imagetrove.ImageTrove(1, *self.makeTroveTuple('group-foo'))
     trv.logPath = self.workDir + '/log'
     w.actOnTrove(trv.getCommand(), self.cfg, trv.jobId, trv, eventHandler,
                  None)
     # this is a horrible API
     w.queueCommand._mock.assertCalled
     assertCalled = w.queueCommand._mock.assertCalled
     assertCalled(w.commandClasses['image'], self.rmakeCfg,
                  'IMAGE-1-group-foo-1', trv.jobId, eventHandler, self.cfg,
                  trv, None, self.workDir + '/log')
Exemple #7
0
 def testImageTrove(self):
     trv = imagetrove.ImageTrove(1, *self.makeTroveTuple('group-foo'))
     assert (trv.isSpecial())
     trv.setProductName('foo')
     assert (trv.getProductName() == 'foo')
     trv.setImageBuildId(23)
     assert (trv.getImageBuildId() == 23)
     assert (trv.getCommand() == 'image')
     trv.setImageType('imageType')
     assert (trv.getImageType() == 'imageType')
     options = trv.getImageOptions()
     assert (options == {})
     trv.setImageOptions({'foo': 'bar'})
     assert (trv.getImageOptions() == {'foo': 'bar'})
Exemple #8
0
    def testDisplaySettings(self):
        trv = imagetrove.ImageTrove(1, *self.makeTroveTuple('group-foo'))
        trv.setProductName('product')
        trv.setImageType('imageType')
        job = self.newJob()
        job.addBuildTrove(trv)
        dcfg = query.DisplayConfig(mock.MockObject())
        rc, txt = self.captureOutput(query.displayTroveDetail, dcfg, job, trv)
        assert (txt == '''\
     group-foo=:linux/1-1-1
       State: Initialized         
imageType                 imageType
productName               product
urls                      []
''')
Exemple #9
0
    def testBuild(self):
        trv = imagetrove.ImageTrove(1, *self.makeTroveTuple('group-foo'))
        builderObj = mock.MockInstance(builder.Builder)
        dh = mock.MockObject()
        worker = mock.MockObject()

        dh.hasBuildableTroves._mock.setReturn(False)
        dh.hasSpecialTroves._mock.setReturns([True, False])
        dh.moreToDo._mock.setReturns([True, True, False])
        dh.popSpecialTrove._mock.setReturn(trv)
        dh.jobPassed._mock.setReturn(True)

        worker._checkForResults._mock.setReturn(False)

        builderObj._mock.set(dh=dh, worker=worker)
        builderObj._mock.enableMethod('build')
        builderObj._mock.enableMethod('actOnTrove')
        builderObj.build()
        worker.actOnTrove._mock.assertCalled(trv.getCommand(), trv.cfg,
                                             trv.jobId, trv,
                                             builderObj.eventHandler,
                                             builderObj.startTroveLogger(trv))
Exemple #10
0
 def testIsSpecial(self):
     bt = buildtrove.BuildTrove(1, *self.makeTroveTuple('foo:source'))
     assert(not bt.isSpecial())
     bt = imagetrove.ImageTrove(1, *self.makeTroveTuple('foo'))
     assert(bt.isSpecial())