Пример #1
0
    def testCore(self):
        pd = proddef.ProductDefinition()
        pd.setConaryRepositoryHostname('localhost')
        pd.setConaryNamespace('rpl')
        pd.setProductShortname('a')
        pd.setProductVersion('1')
        pd.addStage('foo', '')
        pd.addStage('bar', '-bar')

        productClass = mock.MockObject(stableReturnValues=True)
        productClass._mock.setReturn(pd)
        self.mock(proddef, 'ProductDefinition', productClass)

        handle = self.getRbuildHandle()
        p = abstract.ProductStore(handle)

        proddefObj = p.getProduct()
        _, kw = productClass._mock.popCall()
        kw = dict(kw)
        self.assertEquals(kw, {})  # no fromStream=

        # get trivial errors out of the way first
        self.assertRaises(errors.IncompleteInterfaceError, p.getStatus, 'asdf')
        self.assertRaises(errors.IncompleteInterfaceError, p.getPackageJobId)
        self.assertRaises(errors.IncompleteInterfaceError, p.getGroupJobId)
        self.assertRaises(errors.IncompleteInterfaceError, p.getImageJobId)
        self.assertRaises(errors.IncompleteInterfaceError, p.setPackageJobId,
                          1)
        self.assertRaises(errors.IncompleteInterfaceError, p.setGroupJobId, 1)
        self.assertRaises(errors.IncompleteInterfaceError, p.setImageJobId, 1)
        self.assertRaises(errors.IncompleteInterfaceError,
                          p.getRbuildConfigData)
        self.assertRaises(errors.RbuildError, p.getRbuildConfigPath)
        self.assertRaises(errors.IncompleteInterfaceError,
                          p.getRmakeConfigData)
        self.assertRaises(errors.RbuildError, p.getRmakeConfigPath)

        handle.product = None
        p.update()
        self.assertEquals(handle.product, proddefObj)

        self.assertEquals([x for x in p.iterStageNames()], ['foo', 'bar'])

        self.assertEquals(p.getNextStageName('foo'), 'bar')
        self.assertEquals(p.getNextStageName('bar'), None)

        self.assertRaises(errors.RbuildError, p.checkStageIsValid, 'fdsa')

        p._currentStage = None
        self.assertRaises(errors.RbuildError, p.getActiveStageName)
        mock.mockMethod(p.checkStageIsValid)
        p.setActiveStageName('foo')
        p.checkStageIsValid._mock.assertCalled('foo')
        self.assertEquals(p.getActiveStageName(), 'foo')

        self.assertEquals(p.getActiveStageLabel(), 'localhost@rpl:a-1')
Пример #2
0
    def testGetBuildDefinitionGroupToBuild(self):
        handle = self.getRbuildHandle()
        productStore = abstract.ProductStore(handle)
        product = proddef.ProductDefinition()
        handle.product = product

        mock.mockMethod(productStore.getSourceGroupMatch)
        productStore.getSourceGroupMatch._mock.setDefaultReturn(
            'group-source-match')

        product.addBuildDefinition(imageGroup='group-foo',
                                   sourceGroup='group-foo-source',
                                   flavor='is: x86')
        bd = product.buildDefinition[0]
        results = productStore.getBuildDefinitionGroupToBuild(bd)
        self.assertEquals(results, 'group-foo-source')
                                           
        product.addBuildDefinition(imageGroup='group-bar',
                                   sourceGroup='group-bar-source',
                                   flavor='is: x86')
        bd = product.buildDefinition[1]
        results = productStore.getBuildDefinitionGroupToBuild(bd)
        self.assertEquals(results, 'group-bar-source')

        product.setSourceGroup('group-toplevel-source')

        product.addBuildDefinition(imageGroup='group-bar',
                                   flavor='is: x86')
        bd = product.buildDefinition[2]
        results = productStore.getBuildDefinitionGroupToBuild(bd)
        self.assertEquals(results, 'group-toplevel-source')

        product.addBuildDefinition(imageGroup='group-bar',
                                   sourceGroup='group-bar-source',
                                   flavor='is: x86')
        bd = product.buildDefinition[3]
        results = productStore.getBuildDefinitionGroupToBuild(bd)
        self.assertEquals(results, 'group-bar-source')

        product.setSourceGroup(None)
        product.addBuildDefinition(imageGroup='group-bar',
                                   flavor='is: x86')
        bd = product.buildDefinition[4]
        results = productStore.getBuildDefinitionGroupToBuild(bd)
        self.assertEquals(results, 'group-source-match')
Пример #3
0
    def testGetSourceGroupMatch(self):
        handle = self.getRbuildHandle()
        productStore = abstract.ProductStore(handle)
        product = proddef.ProductDefinition()
        product.setBaseFlavor('ssl,readline')
        handle.product = product

        product.addBuildDefinition(imageGroup='group-foo',
                                   sourceGroup='group-foo-source',
                                   flavor='is: x86')
        product.addBuildDefinition(imageGroup='group-foo', flavor='is: x86')

        bd = product.buildDefinition[1]
        results = productStore.getSourceGroupMatch(bd)
        self.assertEquals(results, 'group-foo-source')

        product.addBuildDefinition(flavor='is: x86')
        bd = product.buildDefinition[2]
        results = productStore.getSourceGroupMatch(bd)
        self.assertEquals(results, None)
Пример #4
0
    def testGetGroupFlavors(self):
        handle = self.getRbuildHandle()
        productStore = abstract.ProductStore(handle)
        product = proddef.ProductDefinition()
        product.setBaseFlavor('ssl,readline')
        handle.product = product
        mock.mockMethod(productStore.getProduct)
        productStore.getProduct._mock.setDefaultReturn(product)
        # First, make sure that zero images defined is an error RBLD-171
        self.assertRaises(errors.MissingImageDefinitionError,
                          productStore.getGroupFlavors)

        # Now, test that the right flavor sets are found
        product.addBuildDefinition(imageGroup='group-foo', flavor='is: x86')
        product.addBuildDefinition(imageGroup='group-bar', flavor='is: x86_64')
        results = productStore.getGroupFlavors()
        # These flavors are too simplistic to work in practice! RBLD-172
        x86Flavor = 'readline,ssl is: x86'
        x8664Flavor = 'readline,ssl is: x86_64'
        assert (results == [('group-foo', x86Flavor),
                            ('group-bar', x8664Flavor)])
Пример #5
0
    def testGetBuildsWithFullFlavors(self):
        handle = self.getRbuildHandle()
        productStore = abstract.ProductStore(handle)
        product = mock.MockInstance(proddef.ProductDefinition)
        handle.product = product

        build1 = mock.MockObject()
        build1.getBuildBaseFlavor._mock.setDefaultReturn('is: x86')
        build2 = mock.MockObject()
        build2.getBuildBaseFlavor._mock.setDefaultReturn('is: x86_64')

        product.getBuildsForStage._mock.setDefaultReturn([build1, build2])
        product.getBaseFlavor._mock.setDefaultReturn('qt')

        r = productStore.getBuildsWithFullFlavors('devel')
        self.assertEquals(r, [(build1, 'qt is: x86'),
                              (build2, 'qt is: x86_64')])

        product.getBuildsForStage._mock.setDefaultReturn([])
        self.assertRaises(errors.MissingImageDefinitionError,
                          productStore.getBuildsWithFullFlavors, 'devel')
Пример #6
0
def getHandle(dirName=None, prodDefLabel=None):
    """
        Initializes an rBuild handle object, with a product definition
        as defined by the C{dirName} parameter (which provides a
        C{dirstore.CheckoutProductStore} product store) or the
        C{prodDefLabel} parameter (which provides a more limited
        C{abstract.ProductStore} product store that is insufficient
        for many plugin operations).  If no parameter is specified,
        a  C{dirstore.CheckoutProductStore} product store is provided
        based on the current directory.

        @param dirName: (None) directory for product store
        @param prodDefLabel: (None) label for product definition.
        @return: C{handle} instance
        """
    cfg = handle.RbuildHandle.configClass(readConfigFiles=True)

    if prodDefLabel:
        productStore = None
    else:
        # note that if dirName is None, this defaults to current directory
        productStore = dirstore.CheckoutProductStore(baseDirectory=dirName)

    plugins = pluginloader.getPlugins([], cfg.pluginDirs)
    h = handle.RbuildHandle(cfg=cfg,
                            pluginManager=plugins,
                            productStore=productStore)

    if prodDefLabel:
        productStore = abstract.ProductStore()
        product = productStore.getProduct()
        client = h.facade.conary._getConaryClient()
        stream, _ = product._getStreamFromRepository(client, prodDefLabel)
        stream.seek(0)
        product.parseStream(stream)

    return h
Пример #7
0
    def testWarnIfOldProductDefinition(self):
        self.initProductDirectory(self.workDir)
        os.chdir(self.workDir)
        handle = self.getRbuildHandle()
        from rbuild_plugins import build as build_plugin
        proddefDir = self.workDir + '/.rbuild/product-definition'

        outputList = []

        def captureOutput(k, msg='', *args):
            outputList.append('%s' % (msg % args, ))

        self.mock(ui.UserInterface, 'write', captureOutput)

        mock.mockMethod(handle.facade.conary._getNewerRepositoryVersions)
        mock.mockMethod(handle.product.getProductName)
        handle.product.getProductName._mock.setReturn('adsf')

        mock.mock(handle.facade.conary, '_getNewerRepositoryVersions')
        handle.facade.conary._getNewerRepositoryVersions._mock.setDefaultReturn(
            None)
        handle.Build.warnIfOldProductDefinition('foo')
        self.assertEquals(outputList, [])

        handle.facade.conary._getNewerRepositoryVersions._mock.setDefaultReturn(
            ['0', '1'])

        mock.mockMethod(handle.ui.getResponse)
        handle.ui.getResponse._mock.setDefaultReturn('y')
        handle.Build.warnIfOldProductDefinition('foo', display=False)
        self.assertEquals(outputList, [
            'The local copy of the adsf product definition is out of date',
            'If any of the newer changes may affect you, answer "no",',
            'and run the command "rbuild update product" to update',
            'your local copy of the product definition.',
            '',
        ])
        handle.ui.getResponse._mock.assertCalled(
            'Proceed with foo, ignoring differences in product definition?',
            default='Y')

        del outputList[:]
        mock.mockMethod(handle.facade.conary.iterRepositoryDiff)
        handle.facade.conary.iterRepositoryDiff._mock.setReturn(['DIFF'],
                                                                proddefDir,
                                                                '1')
        mock.mockMethod(handle.facade.conary.getCheckoutLog)
        handle.facade.conary.getCheckoutLog._mock.setReturn(
            ['CHANGELOG'], proddefDir, versionList=['0', '1'])
        handle.ui.getResponse._mock.setDefaultReturn('n')
        err = self.assertRaises(build_plugin.OutdatedProductDefinitionError,
                                handle.Build.warnIfOldProductDefinition, 'foo')
        self.assertEquals(outputList, [
            'The local copy of the adsf product definition is out of date',
            'The following changes are committed to the repository,',
            'but are not included in your local copy:',
            '',
            'DIFF',
            '',
            'The following change messages describe the changes just displayed:',
            'CHANGELOG',
            '',
            'If any of the newer changes may affect you, answer "no",',
            'and run the command "rbuild update product" to update',
            'your local copy of the product definition.',
            '',
        ])
        self.assertEquals(str(err), 'adsf product definition out of date')
        handle.ui.getResponse._mock.assertCalled(
            'Proceed with foo, ignoring differences in product definition?',
            default='Y')

        handle.productStore = abstract.ProductStore()
        self.assertEquals(handle.Build.warnIfOldProductDefinition('adsf'),
                          None)