Esempio n. 1
0
    def testChangeFactory(self):
        repos = self.openRmakeRepository()
        helper = self.getRmakeHelper()

        # Commit factory to use
        # Warning: can't use this factory unless set it's factory to "factory"
        self.addComponent('factory-test:source',
                          '0',
                          '', [('factory-test.recipe', localFactory)],
                          factory='factory')

        # Commit recipe which won't cook successfully
        self.addComponent('simple:source', '1', '',
                          [('simple.recipe', recipes.simpleRecipe)])

        os.chdir(self.workDir)
        self.checkout('simple')
        os.chdir('simple')

        # Hack around conary's bug not notice only factory change during checkin
        self.writeFile('simple.recipe',
                       recipes.simpleRecipe + '\tr.Create("bar")\n')

        # Load CONARY state file
        stateFile = "CONARY"
        conaryState = ConaryStateFromFile(stateFile)
        sourceState = conaryState.getSourceState()

        # Verify no factory
        assert (sourceState.getFactory() == '')

        # Set factory
        sourceState.setFactory('test')
        conaryState.write(stateFile)

        # Verify build is successful
        (name, version,
         flavor) = buildcmd.getTrovesToBuild(self.buildCfg,
                                             helper.getConaryClient(),
                                             ['simple.recipe'],
                                             message='foo')[0]

        # checkout newly shadowed package
        self.checkout(name, versionStr=version.asString())

        # get state file object of newly shadowed package
        os.chdir('simple')
        conaryState = ConaryStateFromFile(stateFile)
        sourceState = conaryState.getSourceState()

        # check factory matches
        assert (sourceState.getFactory() == 'test')
Esempio n. 2
0
    def testChangeFactory(self):
        repos = self.openRmakeRepository()
        helper = self.getRmakeHelper()

        # Commit factory to use
        # Warning: can't use this factory unless set it's factory to "factory"
        self.addComponent('factory-test:source', '0', '',
                          [('factory-test.recipe', localFactory)],
                          factory='factory')

        # Commit recipe which won't cook successfully
        self.addComponent('simple:source', '1', '',
                          [ ('simple.recipe', recipes.simpleRecipe)])

        os.chdir(self.workDir)
        self.checkout('simple')
        os.chdir('simple')

        # Hack around conary's bug not notice only factory change during checkin
        self.writeFile('simple.recipe',
                        recipes.simpleRecipe + '\tr.Create("bar")\n')

        # Load CONARY state file
        stateFile = "CONARY"
        conaryState = ConaryStateFromFile(stateFile)
        sourceState = conaryState.getSourceState()

        # Verify no factory
        assert(sourceState.getFactory() == '')

        # Set factory
        sourceState.setFactory('test')
        conaryState.write(stateFile)

        # Verify build is successful
        (name,version,flavor) = buildcmd.getTrovesToBuild(self.buildCfg,
                                    helper.getConaryClient(),
                                   ['simple.recipe'], message='foo')[0]

        # checkout newly shadowed package
        self.checkout(name,versionStr=version.asString())

        # get state file object of newly shadowed package
        os.chdir('simple')
        conaryState = ConaryStateFromFile(stateFile)
        sourceState = conaryState.getSourceState()

        # check factory matches
        assert(sourceState.getFactory() == 'test')
Esempio n. 3
0
    def testVersions(self):
        self.logFilter.add()
        oldTmpDir = self.cfg.tmpDir
        # some version control systems modify files in user's $HOME
        oldHome = os.environ['HOME']
        os.environ['HOME'] = self.workDir
        try:
            self.srcRepoPath = self.workDir + '/srcrepo/testproject'
            self.srcWorkingDir = self.workDir + '/srcwork'
            e, l = self.captureOutput(self.vcInit)
            assert not e
            e, l = self.captureOutput(self.vcCheckout, self.srcWorkingDir)
            assert not e
            os.chdir(self.srcWorkingDir)
            self.writeFile('testfile', 'contents 1\n')
            e, l = self.captureOutput(self.vcAdd, 'testfile')
            assert not e
            e, l = self.captureOutput(self.vcCommit, 'commit1')
            assert not e
            e, l = self.captureOutput(self.vcTag, 'tagged-test')
            assert not e
            os.chdir(self.workDir)
            self.newpkg('test')
            os.chdir('test')
            self.writeFile(
                'test.recipe', "class TestRecipe(PackageRecipe):\n"
                "    version = '1.0'\n"
                "    name = 'test'\n"
                "    clearBuildReqs()\n"
                "    def setup(r):\n" + "        %s\n" % self.vcAddLine() +
                "        r.Install('testfile', '/testfile')\n")
            self.addfile('test.recipe')
            e, l = self.captureOutput(self.commit)
            assert not e
            self.checkInitialCommitOutput(l)

            firstState = ConaryStateFromFile('CONARY').getSourceState()
            [
                recipePathId,
            ] = [
                x[0] for x in firstState.iterFileList()
                if x[1] == 'test.recipe'
            ]
            [
                archivePathId,
            ] = [
                x[0] for x in firstState.iterFileList()
                if x[1] != 'test.recipe'
            ]
            archivePath = firstState.getFile(archivePathId)[0]

            self.captureOutput(self.cookFromRepository, 'test')
            self.captureOutput(self.updatePkg, 'test')
            self.verifyFile(self.rootDir + '/testfile', 'contents 1\n')

            # change the archive tip, force a recommit, and make sure the
            # snapshot hasn't changed
            os.chdir(self.srcWorkingDir)
            self.writeFile('testfile', 'contents 1.1\n')
            # force the timestamp to change; svn needs this
            ts = os.stat('testfile').st_mtime + 1
            os.utime('testfile', (ts, ts))
            self.captureOutput(self.vcCommit, 'commit2')

            os.chdir(self.workDir + '/test')
            self.captureOutput(self.commit)
            newState = ConaryStateFromFile('CONARY').getSourceState()
            assert (newState == firstState)

            open('test.recipe', "a").write('\n')
            self.captureOutput(self.commit)
            newState = ConaryStateFromFile('CONARY').getSourceState()
            assert (newState.getFile(recipePathId) !=
                    firstState.getFile(recipePathId))
            assert (newState.getFile(archivePathId) == firstState.getFile(
                archivePathId))

            # a refresh should force the snapshot to get updated though
            dirName = os.getcwd()
            os.chdir('..')
            repos = self.openRepository()
            # test checkin.refresh as an API that takes directory name
            e, l = self.captureOutput(checkin.refresh,
                                      repos,
                                      self.cfg,
                                      refreshPatterns=[archivePath],
                                      dirName=dirName)
            os.chdir(dirName)
            self.checkRefreshOutput(l)
            open('test.recipe', "a").write('\n')
            self.captureOutput(self.commit)
            newState = ConaryStateFromFile('CONARY').getSourceState()
            assert (newState.getFile(recipePathId) !=
                    firstState.getFile(recipePathId))
            assert (newState.getFile(archivePathId) !=
                    firstState.getFile(archivePathId))
            self.captureOutput(self.cookFromRepository, 'test')
            self.captureOutput(self.updatePkg, 'test')
            self.verifyFile(self.rootDir + '/testfile', 'contents 1.1\n')

            # now test tagging
            self.writeFile(
                'test.recipe', "class TestRecipe(PackageRecipe):\n"
                "    version = '1.0'\n"
                "    name = 'test'\n"
                "    clearBuildReqs()\n"
                "    def setup(r):\n" +
                "        %s\n" % self.vcAddLine(tag='tagged-%(name)s') +
                "        r.Install('testfile', '/testfile')\n")
            e, l = self.captureOutput(self.commit)
            self.checkTagOutput(l)
            newState = ConaryStateFromFile('CONARY').getSourceState()
            [
                newArchivePathId,
            ] = [
                x[0] for x in newState.iterFileList() if x[1] != 'test.recipe'
            ]
            newArchivePath = newState.getFile(newArchivePathId)[0]
            assert (newArchivePathId != archivePathId)
            assert (newArchivePath != archivePath)
            self.captureOutput(self.cookFromRepository, 'test')
            self.captureOutput(self.updatePkg, 'test')
            self.verifyFile(self.rootDir + '/testfile', 'contents 1\n')

            # Mock checkPath to make sure we can still build even if we don't
            # have the version control into the path
            mockCheckPath = lambda x: None
            self.mock(util, "checkPath", mockCheckPath)
            self.logFilter.clear()
            self.logFilter.add()
            self.cookFromRepository('test')
            self.logFilter.remove()
            for es in ['tar', 'bzip2']:
                self.assertIn(
                    'warning: Failed to find possible build '
                    'requirement for path "%s"' % es, self.logFilter.records)
        finally:
            os.environ['HOME'] = oldHome
            # adding sources shouldn't tweak tmpDir
            assert (self.cfg.tmpDir == oldTmpDir)
            self.logFilter.clear()
Esempio n. 4
0
    def testVersions(self):
        self.logFilter.add()
        oldTmpDir = self.cfg.tmpDir
        # some version control systems modify files in user's $HOME
        oldHome = os.environ['HOME']
        os.environ['HOME'] = self.workDir
        try:
            self.srcRepoPath = self.workDir + '/srcrepo/testproject'
            self.srcWorkingDir = self.workDir + '/srcwork'
            e,l = self.captureOutput(self.vcInit)
            assert not e
            e,l = self.captureOutput(self.vcCheckout, self.srcWorkingDir)
            assert not e
            os.chdir(self.srcWorkingDir)
            self.writeFile('testfile', 'contents 1\n')
            e,l = self.captureOutput(self.vcAdd, 'testfile')
            assert not e
            e,l = self.captureOutput(self.vcCommit, 'commit1')
            assert not e
            e,l = self.captureOutput(self.vcTag, 'tagged-test')
            assert not e
            os.chdir(self.workDir)
            self.newpkg('test')
            os.chdir('test')
            self.writeFile('test.recipe',
                    "class TestRecipe(PackageRecipe):\n"
                    "    version = '1.0'\n"
                    "    name = 'test'\n"
                    "    clearBuildReqs()\n"
                    "    def setup(r):\n" +
                    "        %s\n" % self.vcAddLine() +
                    "        r.Install('testfile', '/testfile')\n")
            self.addfile('test.recipe')
            e, l = self.captureOutput(self.commit)
            assert not e
            self.checkInitialCommitOutput(l)

            firstState = ConaryStateFromFile('CONARY').getSourceState()
            [ recipePathId, ]  = [ x[0] for x in firstState.iterFileList() if
                                    x[1] == 'test.recipe' ]
            [ archivePathId, ] = [ x[0] for x in firstState.iterFileList() if
                                    x[1] != 'test.recipe' ]
            archivePath = firstState.getFile(archivePathId)[0]

            self.captureOutput(self.cookFromRepository, 'test')
            self.captureOutput(self.updatePkg, 'test')
            self.verifyFile(self.rootDir  +'/testfile', 'contents 1\n')

            # change the archive tip, force a recommit, and make sure the
            # snapshot hasn't changed
            os.chdir(self.srcWorkingDir)
            self.writeFile('testfile', 'contents 1.1\n')
            # force the timestamp to change; svn needs this
            ts = os.stat('testfile').st_mtime + 1
            os.utime('testfile', (ts, ts))
            self.captureOutput(self.vcCommit, 'commit2')

            os.chdir(self.workDir + '/test')
            self.captureOutput(self.commit)
            newState = ConaryStateFromFile('CONARY').getSourceState()
            assert(newState == firstState)

            open('test.recipe', "a").write('\n')
            self.captureOutput(self.commit)
            newState = ConaryStateFromFile('CONARY').getSourceState()
            assert(newState.getFile(recipePathId) !=
                   firstState.getFile(recipePathId))
            assert(newState.getFile(archivePathId) ==
                   firstState.getFile(archivePathId))

            # a refresh should force the snapshot to get updated though
            dirName = os.getcwd()
            os.chdir('..')
            repos = self.openRepository()
            # test checkin.refresh as an API that takes directory name
            e, l = self.captureOutput(checkin.refresh, repos, self.cfg,
                refreshPatterns=[archivePath], dirName=dirName)
            os.chdir(dirName)
            self.checkRefreshOutput(l)
            open('test.recipe', "a").write('\n')
            self.captureOutput(self.commit)
            newState = ConaryStateFromFile('CONARY').getSourceState()
            assert(newState.getFile(recipePathId) !=
                   firstState.getFile(recipePathId))
            assert(newState.getFile(archivePathId) !=
                   firstState.getFile(archivePathId))
            self.captureOutput(self.cookFromRepository, 'test')
            self.captureOutput(self.updatePkg, 'test')
            self.verifyFile(self.rootDir  +'/testfile', 'contents 1.1\n')

            # now test tagging
            self.writeFile('test.recipe',
                    "class TestRecipe(PackageRecipe):\n"
                    "    version = '1.0'\n"
                    "    name = 'test'\n"
                    "    clearBuildReqs()\n"
                    "    def setup(r):\n" +
                    "        %s\n" % self.vcAddLine(tag = 'tagged-%(name)s') +
                    "        r.Install('testfile', '/testfile')\n")
            e, l = self.captureOutput(self.commit)
            self.checkTagOutput(l)
            newState = ConaryStateFromFile('CONARY').getSourceState()
            [ newArchivePathId, ] = [ x[0] for x in newState.iterFileList() if
                                        x[1] != 'test.recipe' ]
            newArchivePath = newState.getFile(newArchivePathId)[0]
            assert(newArchivePathId != archivePathId)
            assert(newArchivePath != archivePath)
            self.captureOutput(self.cookFromRepository, 'test')
            self.captureOutput(self.updatePkg, 'test')
            self.verifyFile(self.rootDir  +'/testfile', 'contents 1\n')

            # Mock checkPath to make sure we can still build even if we don't
            # have the version control into the path
            mockCheckPath = lambda x: None
            self.mock(util, "checkPath", mockCheckPath)
            self.logFilter.clear()
            self.logFilter.add()
            self.cookFromRepository('test')
            self.logFilter.remove()
            for es in ['tar', 'bzip2']:
                self.assertIn('warning: Failed to find possible build '
                    'requirement for path "%s"' % es,
                    self.logFilter.records)
        finally:
            os.environ['HOME'] = oldHome
            # adding sources shouldn't tweak tmpDir
            assert(self.cfg.tmpDir == oldTmpDir)
            self.logFilter.clear()