Ejemplo n.º 1
0
    def testDirectoryHandling(self):
        # test directory normalization
        self.rootDir = '/' + self.rootDir
        self.addComponent('foo:runtime',
                          '1.0-1-1',
                          fileContents=[
                              ('/a', rephelp.Directory(pathId="1")),
                              ('/a/1',
                               rephelp.RegularFile(contents="a1", pathId="2")),
                          ])

        self.addComponent('foo:runtime',
                          '2.0-2-2',
                          fileContents=[
                              ('/a', rephelp.Directory(pathId="1")),
                              ('/a/1',
                               rephelp.RegularFile(contents="a1", pathId="2")),
                              ('/a/2',
                               rephelp.RegularFile(contents="a2", pathId="3")),
                          ])

        self.updatePkg('foo:runtime=1.0-1-1')
        self.updatePkg('foo:runtime=2.0-2-2')
        assert (sorted(os.listdir(self.rootDir)) == ['a', 'var'])
        assert (sorted(os.listdir(self.rootDir + "/a")) == ['1', '2'])
Ejemplo n.º 2
0
    def testMkdir(self):
        self.addComponent('foo:runtime',
                          '1.0-1-1',
                          fileContents=[
                              ('/b',
                               rephelp.RegularFile(contents="b1", pathId="2")),
                          ])

        self.addComponent('foo:runtime',
                          '2.0-2-2',
                          fileContents=[
                              ('/a', rephelp.Directory(pathId="1")),
                              ('/b',
                               rephelp.RegularFile(contents="b2", pathId="2")),
                              ('/c',
                               rephelp.RegularFile(contents="c2", pathId="3")),
                          ])

        self.updatePkg('foo:runtime=1.0-1-1')

        util.sha1Uncompress = lambda *args: self.sha1UncompressStub(
            failPaths=['c'], *args)

        self.logCheck(self.assertRaises,
                      (OSError, self.updatePkg, 'foo:runtime=2.0-2-2'),
                      revertMsg)

        assert (sorted(os.listdir(self.rootDir)) == ['b', 'var'])
Ejemplo n.º 3
0
    def _testMirrorModeChangesets(self, singleRepos = True, protocol = None):
        # When mirroring, contents need to be included whenever a file version
        # changes because it could be a cross-repository change. mirrorMode
        # makes this happen CNY-1570.
        #
        # Similarly, mirrorMode doesn' allow file diffs across repositories,
        # since that would require crosstalk on commit. CNY-2210
        if singleRepos:
            repos = self.openRepository(serverName = [ 'localhost',
                                                       'localhost1' ])
        else:
            repos = self.openRepository(0)
            repos = self.openRepository(1)

        if protocol:
            repos.c['localhost'].setProtocolVersion(protocol)
            repos.c['localhost1'].setProtocolVersion(protocol)

        orig = self.addQuickTestComponent('test:runtime',
                 '/localhost@rpl:linux/1.0-1-1',
                 fileContents = [
                    ( '/bin/foo', rephelp.RegularFile(
                       version = '/localhost@rpl:linux/1.0-1-1',
                       contents = 'foo' ) ),
                    ('/usr/foo', rephelp.Directory(perms = 0755,
                       version = '/localhost@rpl:linux/1.0-1-1',
                    ) ),
                    ] )
Ejemplo n.º 4
0
 def testMissingDirectory(self):
     self.addComponent('foo:run=1',
         fileContents = [ ('/dir', rephelp.Directory() ) ])
     self.updatePkg('foo:run')
     os.rmdir(self.rootDir + '/dir')
     rc, s = self.captureOutput(self.repairTroves, [ 'foo:run' ])
     self.assertEquals(s, '')
     sb = os.stat(self.rootDir + '/dir')
     assert(stat.S_ISDIR(sb.st_mode))
Ejemplo n.º 5
0
    def testNewFileOwnership(self):
        # make sure files found with --new-files get assigned to the right
        # troves
        user, group = self._getUserGroup()

        self.addComponent('foo:bin=0',
                          fileContents=[('/bin',
                                         rephelp.Directory(
                                             owner=user,
                                             group=group,
                                         ))])
        self.addComponent('foo:lib=1',
                          fileContents=[('/lib',
                                         rephelp.Directory(
                                             owner=user,
                                             group=group,
                                         ))])

        self.updatePkg(['foo:bin', 'foo:lib'])
        db = self.openDatabase()
        self.writeFile(self.rootDir + '/bin/new', 'newtext\n')
        self.writeFile(self.rootDir + '/lib/new', 'newtext\n')
        self.writeFile(self.rootDir + '/rootfile', 'newtext\n')

        os.chdir(self.workDir)
        verify.verify([],
                      db,
                      self.cfg,
                      all=True,
                      newFiles=True,
                      changesetPath='foo.ccs')
        cs = changeset.ChangeSetFromFile('foo.ccs')

        trvCsByName = dict((x.getName(), x) for x in cs.iterNewTroveList())
        self.assertEquals(
            [x[1] for x in trvCsByName['foo:bin'].getNewFileList()],
            ['/bin/new'])
        self.assertEquals(
            [x[1] for x in trvCsByName['foo:lib'].getNewFileList()],
            ['/lib/new'])
        self.assertEquals(
            [x[1] for x in trvCsByName['@new:files'].getNewFileList()],
            ['/rootfile'])
Ejemplo n.º 6
0
    def testGitDiffFileToDirectory(self):
        foo1 = self.addComponent('foo:run=1', fileContents=[
            ("/path.d", "contents\n"),
            ])

        foo2 = self.addComponent('foo:run=2', fileContents=[
            ("/path.d", rephelp.Directory()),
            ])

        repos = self.openRepository()
        cs = repos.createChangeSet([('foo:run', foo1.getNameVersionFlavor()[1:],
            foo2.getNameVersionFlavor()[1:], False)])

        diff = "".join(x for x in cs.gitDiff(repos))
        self.assertEqual(diff,
            "diff --git a/path.d b/path.d\n"
            "old mode 100644\n"
            "new mode 40755\n")
Ejemplo n.º 7
0
    def testMirrorMode(self):
        # open up two sources
        self._openRepository(0, serverName="myhost")
        self._openRepository(1, serverName="myotherhost")
        # get the repo clients
        src = self.getRepositoryClient("mirror", "mirror")

        self.addQuickTestComponent(
            'test:runtime',
            '/myhost@rpl:linux/1.0-1-1',
            fileContents=[
                ('/bin/foo',
                 rephelp.RegularFile(version='/myhost@rpl:linux/1.0-1-1',
                                     contents='foo')),
                ("/usr/foo",
                 rephelp.Directory(version='/myhost@rpl:linux/1.0-1-1',
                                   perms=0777)),
            ],
            repos=src)
        old = self.addQuickTestComponent(
            'test:runtime',
            '/myhost@rpl:linux//myotherhost@rpl:linux/1.0-1-1',
            fileContents=[
                ('/bin/foo',
                 rephelp.RegularFile(version='/myhost@rpl:linux/1.0-1-1',
                                     contents='foo')),
                ("/usr/foo",
                 rephelp.Directory(version='/myhost@rpl:linux/1.0-1-1',
                                   perms=0777)),
            ],
            repos=src)

        new = self.addQuickTestComponent(
            'test:runtime',
            '/myhost@rpl:linux//myotherhost@rpl:linux/1.0-1.1-1',
            fileContents=[
                ('/bin/foo',
                 rephelp.RegularFile(
                     version=
                     '/myhost@rpl:linux//myotherhost@rpl:linux/1.0-1.1-1',
                     contents='foo')),
                ("/usr/foo",
                 rephelp.Directory(
                     version=
                     '/myhost@rpl:linux//myotherhost@rpl:linux/1.0-1.1-1',
                     perms=0701)),
            ],
            repos=src)
        veryNew = self.addQuickTestComponent(
            'test:runtime',
            '/myhost@rpl:linux//myotherhost@rpl:linux/1.0-1.2-1',
            fileContents=[
                ('/bin/foo',
                 rephelp.RegularFile(
                     version=
                     '/myhost@rpl:linux//myotherhost@rpl:linux/1.0-1.1-1',
                     contents='foo')),
                ("/usr/foo",
                 rephelp.Directory(
                     version=
                     '/myhost@rpl:linux//myotherhost@rpl:linux/1.0-1.1-1',
                     perms=0701)),
            ],
            repos=src)
        dst = self._getMultiTarget(2, ["myhost", "myotherhost"])
        # create the mirror config
        cfg = mirror.MirrorFileConfiguration()
        cfg.host = "myotherhost"
        self._runMirrorCfg(src, dst, cfg)
Ejemplo n.º 8
0
    def testNewFiles(self):
        userDict = {}
        userDict['user'], userDict['group'] = self._getUserGroup()

        self.addComponent('foo:run=1',
                          fileContents=[
                              ('/bin/ls',
                               rephelp.RegularFile(owner=userDict['user'],
                                                   group=userDict['group'],
                                                   contents='content\n'))
                          ])
        self.updatePkg('foo:run=1')
        db = self.openDatabase()
        s = self.captureOutput(verify.verify, ['foo:run'],
                               db,
                               self.cfg,
                               asDiff=True)[1]
        self.assertEquals(s, '')

        # we don't notice the new file unless all is given because
        # nothing owns /bin
        self.writeFile(self.rootDir + '/bin/new-file', 'newtext\n')
        s = self.captureOutput(verify.verify, ['foo:run'],
                               db,
                               self.cfg,
                               asDiff=True,
                               newFiles=True)[1]
        self.assertEquals(s, '')

        s = self.captureOutput(verify.verify, [],
                               db,
                               self.cfg,
                               asDiff=True,
                               newFiles=True,
                               all=True)[1]
        self.assertEquals(
            s, 'diff --git a/bin/new-file b/bin/new-file\n'
            'new user %(user)s\n'
            'new group %(group)s\n'
            'new mode 100644\n'
            '--- a/dev/null\n'
            '+++ b/bin/new-file\n'
            '@@ -1,0 +1,1 @@\n'
            '+newtext\n' % userDict)

        # check the normal output format as well
        s = self.captureOutput(verify.verify, [],
                               db,
                               self.cfg,
                               newFiles=True,
                               all=True)[1]
        # filter out the timestamp
        s = ' '.join(s.split()[0:8] + s.split()[10:])
        self.assertEquals(
            s,
            'Install @new:files=1.0-1-1 New -rw-r--r-- 1 %(user)s %(group)s '
            '8 UTC /bin/new-file' % userDict)

        # if we add don't check /bin to the exclude list the diff should
        # go away
        oldCfg = self.cfg.verifyDirsNoNewFiles[:]
        try:
            self.cfg.verifyDirsNoNewFiles.append('/bin')
            s = self.captureOutput(verify.verify, [],
                                   db,
                                   self.cfg,
                                   asDiff=True,
                                   newFiles=True,
                                   all=True)[1]
            self.assertEquals(s, '')
        finally:
            self.cfg.verifyDirsNoNewFiles = oldCfg

        # make a package own /bin, and then verifying that package w/
        # --new-files should make it show up
        self.addComponent('foo:dir=1',
                          fileContents=[('/bin',
                                         rephelp.Directory(
                                             owner=userDict['user'],
                                             group=userDict['group'],
                                         ))])
        self.updatePkg('foo:dir=1')
        s = self.captureOutput(verify.verify, ['foo:dir'],
                               db,
                               self.cfg,
                               asDiff=True,
                               newFiles=True)[1]
        self.assertEquals(
            s, 'diff --git a/bin/new-file b/bin/new-file\n'
            'new user %(user)s\n'
            'new group %(group)s\n'
            'new mode 100644\n'
            '--- a/dev/null\n'
            '+++ b/bin/new-file\n'
            '@@ -1,0 +1,1 @@\n'
            '+newtext\n' % userDict)
Ejemplo n.º 9
0
    def testChrootFactory2(self):
        self.openRmakeRepository()
        repos = self.openRepository()

        self.addComponent('test1:source', '1.0', '',
                          [('test1.recipe', test1Recipe)])
        self.addComponent(
            'test1:source', '2.0', '',
            [('test1.recipe', test1Recipe.replace('1.0', '2.0'))])

        rootDir = self.rmakeCfg.getChrootDir() + '/testBuildReqs'
        self.makeSourceTrove('testBuildReqs',
                             testBuildReqsRecipe % dict(rootDir=rootDir))

        troveTup = repos.findTrove(self.cfg.buildLabel,
                                   ('testBuildReqs:source', None, None),
                                   None)[0]
        cookFlavor = deps.parseFlavor('readline,ssl,X')
        troveTup = (troveTup[0], troveTup[1], cookFlavor)

        db = self.openRmakeDatabase()
        job = self.newJob(troveTup)
        buildTrove = buildtrove.BuildTrove(job.jobId, *troveTup)
        buildTrove.setPublisher(job.getPublisher())

        cfg = buildcfg.BuildConfiguration(False,
                                          conaryConfig=self.cfg,
                                          root=self.cfg.root,
                                          serverConfig=self.rmakeCfg)
        cfg.defaultBuildReqs = []

        trv1 = self.addComponent(
            'test1:runtime', '1.0', '',
            [('/usr/bin/test1',
              rephelp.RegularFile(contents='#!/bin/sh', perms=0755))])
        trv2 = self.addCollection('test1', '1.0', [':runtime'])
        trv3 = self.addComponent(
            'test2:runtime', '1.0', '',
            [('/usr/bin/test2',
              rephelp.RegularFile(contents='#!/bin/sh', perms=0755))])
        trv4 = self.addComponent('testunreadable:runtime', '1.0', '', [
            ('/usr/untraverseable', rephelp.Directory(perms=0700)),
            ('/usr/symlink', rephelp.Symlink(target='/usr/untraverseable')),
            ('/usr/untraverseable/unreadable', rephelp.RegularFile(perms=0600))
        ])

        self.rmakeCfg.chrootUser = '******'
        mgr = rootmanager.ChrootManager(self.rmakeCfg)
        jobList = [
            (x[0], (None, None), (x[1], x[2]), False)
            for x in (trv1.getNameVersionFlavor(), trv2.getNameVersionFlavor(),
                      trv3.getNameVersionFlavor(), trv4.getNameVersionFlavor())
        ]

        logFile = logfile.LogFile(self.workDir + '/chrootlog')
        logFile.redirectOutput()
        factory = mgr.getRootFactory(cfg, jobList, [], [], buildTrove)
        factory.create()
        chrootClient = factory.start()
        try:
            logPath = chrootClient.buildTrove(cfg,
                                              cfg.getTargetLabel(troveTup[1]),
                                              *troveTup)
            result = chrootClient.checkResults(wait=20, *troveTup)
            logFile.restoreOutput()
            assert (result)
            assert result.isBuildSuccess(), repr(result.getFailureReason())
            untraverseable = mgr.baseDir + '/testBuildReqs/usr/untraverseable'
            self.assertEquals(stat.S_IMODE(os.stat(untraverseable).st_mode),
                              0705)
            unreadable = untraverseable + '/unreadable'
            self.assertEquals(stat.S_IMODE(os.stat(unreadable).st_mode), 0604)
            cs = changeset.ChangeSetFromFile(result.getChangeSetFile())
            trvCs = [
                x for x in cs.iterNewTroveList()
                if x.getName() == 'testBuildReqs:runtime'
            ][0]
            trv = trove.Trove(trvCs)
            files = [x[1] for x in trv.iterFileList()]
            # make sure the loadInstalled picked the recipe that
            # matches the installed package.
            assert ('/foo/1.0' in files)
        finally:
            chrootClient.stop()
Ejemplo n.º 10
0
                 fileContents = [
                    ( '/bin/foo', rephelp.RegularFile(
                       version = '/localhost@rpl:linux/1.0-1-1',
                       contents = 'foo' ) ),
                    ('/usr/foo', rephelp.Directory(perms = 0755,
                       version = '/localhost@rpl:linux/1.0-1-1',
                    ) ),
                    ] )

        old = self.addQuickTestComponent('test:runtime',
                 '/localhost@rpl:linux//localhost1@rpl:linux/1.0-1-1',
                 fileContents = [
                    ( '/bin/foo', rephelp.RegularFile(
                       version = '/localhost@rpl:linux/1.0-1-1',
                       contents = 'foo' ) ),
                    ('/usr/foo', rephelp.Directory(perms = 0755,
                       version = '/localhost@rpl:linux/1.0-1-1',
                    ) ),
                    ] )

        new = self.addQuickTestComponent('test:runtime',
             '/localhost@rpl:linux//localhost1@rpl:linux/1.0-1.1-1',
             fileContents = [
                ( '/bin/foo', rephelp.RegularFile(
                   version = '/localhost@rpl:linux//localhost1@rpl:linux/1.0-1.1-1',
                   contents = 'foo' ) ),
                ('/usr/foo', rephelp.Directory(perms = 0755,
                   version = '/localhost@rpl:linux//localhost1@rpl:linux/1.0-1.1-1',
                ) ),
                ] )