def testRdiff4(self): # test trove dependencies req1 = 'soname: ELF32/lib/foo3(blah) trove:bar(1)' req2 = 'soname: ELF32/lib/foo2(blah)' prov1 = "trove:bar(1) trove:baz(1)" prov2 = "trove:bar(1) trove:baz(1) soname: ELF32/lib/foo2(blah)" rf1 = rephelp.RegularFile( contents='1\n2\n3\n4\n5\n6\n7\n8\n', perms=0644, provides=prov1, requires=req1, mtime=1176921017, ) rf2 = rephelp.RegularFile(contents='1\n2\n4\n5\n6\n7\n8\n9\n', perms=0755, provides=prov2, requires=req2, mtime=1176921317, tags=['tag2', 'tag1', 'tag3']) self.addComponent('foo:run', '1', [('/usr/bin/foo', rf1)]) self.addCollection('foo', '1', [':run']) self.addComponent('foo:run', '2', [('/usr/bin/foo', rf2)]) self.addCollection('foo', '2', [':run']) ret, outs = self._rdiff('foo=1--2') self.assertEqual(outs, expOutput4) ret, outs = self._rdiff('foo:run=1--2', deps=True) self.assertEqual(outs, expOutput4withTroveDeps)
def testIndexByPathIdConversion(self): def _testCs(repos, troves, idxLength, fileCount): job = [(x.getName(), (None, None), (x.getVersion(), x.getFlavor()), True) for x in troves] repos.createChangeSetFile(job, self.workDir + '/foo.ccs') fc = filecontainer.FileContainer( util.ExtendedFile(self.workDir + '/foo.ccs', "r", buffering=False)) info = fc.getNextFile() assert (info[0] == 'CONARYCHANGESET') info = fc.getNextFile() while info is not None: assert (len(info[0]) == idxLength) fileCount -= 1 if 'ptr' in info[1]: s = info[2].read() s = gzip.GzipFile(None, "r", fileobj=StringIO(s)).read() assert (len(s) == idxLength) info = fc.getNextFile() assert (fileCount == 0) f1 = rephelp.RegularFile(pathId='1', contents='1') f2 = rephelp.RegularFile(pathId='1', contents='2') t1 = self.addComponent('foo:runtime', fileContents=[('/1', f1)]) t2 = self.addComponent('bar:runtime', fileContents=[('/2', f2)]) repos = self.openRepository() _testCs(repos, [t1], 36, 1) _testCs(repos, [t1, t2], 36, 2) repos.c['localhost'].setProtocolVersion(41) _testCs(repos, [t1], 16, 1) self.assertRaises(changeset.PathIdsConflictError, _testCs, repos, [t1, t2], 16, 1) # now test PTR types to make sure they get converted self.resetRepository() repos = self.openRepository() f1 = rephelp.RegularFile(pathId='1', contents='1') f2 = rephelp.RegularFile(pathId='2', contents='1') t1 = self.addComponent('foo:runtime', fileContents=[('/1', f1), ('/2', f2)]) _testCs(repos, [t1], 36, 2) repos.c['localhost'].setProtocolVersion(41) _testCs(repos, [t1], 16, 2) # make sure we can install old-format changesets with PTRs self.updatePkg(['foo:runtime']) self.verifyFile(self.rootDir + '/1', '1') self.verifyFile(self.rootDir + '/2', '1')
def testRollbackFileTypeChange(self): a = self.addComponent('foo:run=1', fileContents = [ ('/foo', rephelp.RegularFile(contents = 'contents 1', initialContents = True) ) ] ) self.addComponent('foo:run=2', fileContents = [ ('/foo', rephelp.RegularFile(contents = 'contents 1', initialContents = True, version = a.getVersion())) ]) # install version 1 of the trove self.updatePkg('foo:run=1') # replace the file with a symlink (changing the file type) os.unlink(self.rootDir + '/foo') os.symlink('bar', self.rootDir + '/foo') # install version 2, and then put the symlink back self.updatePkg('foo:run=2', replaceFiles = True) os.unlink(self.rootDir + '/foo') os.symlink('bar', self.rootDir + '/foo') # the repository portion of this rollback works fine, because the file # hasn't changed so nothing happens. the local portion used to break # because the file type changed. since the local rollback wants to # make the file the same as what's already on disk it ought to work # just fine though (CNY-3340) self.rollback(self.rootDir, 1)
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'])
def testChange(self): self.addComponent('foo:runtime', '1.0-1-1', fileContents=[('/a', rephelp.RegularFile(contents="a1", pathId="1")), ('/b', rephelp.RegularFile(contents="b1", pathId="2"))]) self.addComponent('foo:runtime', '2.0-2-2', fileContents=[('/a', rephelp.RegularFile(contents="a2", pathId="1")), ('/b', rephelp.RegularFile(contents="b2", pathId="2"))]) self.updatePkg('foo:runtime=1.0-1-1') # sorted by pathIds, so /b happens last counter = Counter(1) util.sha1Uncompress = lambda *args: self.sha1UncompressStub( failPaths=['b'], *args) self.logCheck(self.assertRaises, (OSError, self.updatePkg, 'foo:runtime=2.0-2-2'), revertMsg) self.verifyFile(self.rootDir + '/a', 'a1')
def testFlavoredFileSet(self): # Make sure build flavor is used for filesets. (CNY-1127) self.addComponent( 'foo:run', '1', 'is:x86', [('/bam', rephelp.RegularFile(flavor='is:x86', contents='x86\n'))]) self.addComponent( 'foo:run', '1', 'is:x86_64', [('/bam', rephelp.RegularFile(flavor='is:x86_64', contents='x86_64\n'))]) fileSetRecipe = """\ class FilesetFoo(FilesetRecipe): name = 'fileset-foo' version = '0.1' clearBuildRequires() def setup(r): r.addFile('/bam', 'foo:run', '%(buildlabel)s') """ self.overrideBuildFlavor('is:x86') pkg = self.build(fileSetRecipe, "FilesetFoo") self.assertTrue(str(pkg.getBuildFlavor())) self.overrideBuildFlavor('is:x86_64') pkg2 = self.build(fileSetRecipe, "FilesetFoo") assert (str(pkg.getFlavor()) == 'is: x86') self.updatePkg('fileset-foo[is:x86]') self.verifyFile(self.cfg.root + '/bam', 'x86\n') assert (str(pkg2.getFlavor()) == 'is: x86_64') self.updatePkg('fileset-foo[is:x86_64]') self.verifyFile(self.cfg.root + '/bam', 'x86_64\n')
def testRdiff8(self): # CNY-1753 # Different files living on different branches raise testhelp.SkipTestException( "Unable to reproduce CNY-1753 in a test case") # Manifested in running conary rdiff # mkinitrd=conary.rpath.com@rpl:1--usplash.rb.rpath.com@rpl:1 rf1 = rephelp.RegularFile( contents='\000\001\002\003', perms=0644, mtime=1176921017, ) rf2 = rephelp.RegularFile( contents='\000\001\003\005', perms=0644, mtime=1176921317, ) v1 = versions.ThawVersion('/localhost@rpl:1/1:1-1-1') v2 = versions.ThawVersion('/localhost1@rpl:2/2:2-2-2') self.openRepository() self.openRepository(1) self.addComponent('foo:run', v1, [('/bin/foo', rf1)]) self.addCollection('foo', v1, [':run']) self.addComponent('foo:run', v2, [('/bin/foo', rf2)]) self.addCollection('foo', v2, [':run']) troveSpec = cmdline.parseChangeList('foo=%s--%s' % (v1, v2))[0] ret, outs = self.captureOutput(queryrep.diffTroves, self.cfg, troveSpec) self.assertEqual(outs, '')
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'])
def testHldrContent(self): # CNY-2596, for example self.addComponent('foo:runtime', '1.0', fileContents=[('/a', rephelp.RegularFile(contents="1"))]) self.addComponent('foo:runtime', '2.0', fileContents=[('/a', rephelp.RegularFile(contents="2"))]) self.updatePkg('foo:runtime=1.0') self.writeFile(self.rootDir + '/a', 'local') self.cfg.localRollbacks = True try: self.updatePkg('foo:runtime=2.0', replaceFiles=True) finally: self.cfg.localRollbacks = False counter = Counter(1) os.rename = lambda x, y: self.renameStub( x, y, ['a'], failAfter=True, counter=counter) self.logCheck(self.assertRaises, (OSError, self.rollback, 1), revertMsg) self.verifyFile(self.rootDir + '/a', '2')
def testDuplicateFileIds(self): # This test sets up a relative changeset that specifies two different # streams for the same fileId. For this to happen we need relative # diff's for the streams (or they get collapsed in the changeset # itself because cs.files is a dict) and the commits have to happen # carefully (or they get collapsed on the repository). This exercises # CNY-3316 repos = self.openRepository() foo1 = self.addComponent('foo:run=1', fileContents=[ ('/a', rephelp.RegularFile(contents='abc')) ]) foo2 = self.addComponent('foo:run=2', fileContents=[ ('/a', rephelp.RegularFile(contents='123', mtime=10000)) ]) fooCs = repos.createChangeSet([ ('foo:run', (None, None), foo1.getNameVersionFlavor()[1:], True) ]) fooRelCs = repos.createChangeSet([ ('foo:run', foo1.getNameVersionFlavor()[1:], foo2.getNameVersionFlavor()[1:], False) ]) self.resetRepository() repos = self.openRepository() bar1 = self.addComponent('bar:run=1', fileContents=[ ('/b', rephelp.RegularFile(contents='def')) ]) bar2 = self.addComponent('bar:run=2', fileContents=[ ('/b', rephelp.RegularFile(contents='123', mtime=10001)) ]) barCs = repos.createChangeSet([ ('bar:run', (None, None), bar1.getNameVersionFlavor()[1:], True) ]) barRelCs = repos.createChangeSet([ ('bar:run', bar1.getNameVersionFlavor()[1:], bar2.getNameVersionFlavor()[1:], False) ]) self.resetRepository() repos = self.openRepository() repos.commitChangeSet(fooCs) repos.commitChangeSet(barCs) fooRelCs.merge(barRelCs) repos.commitChangeSet(fooRelCs)
def testPrelink(self): user = pwd.getpwuid(os.getuid()).pw_name group = grp.getgrgid(os.getgid()).gr_name archivePath = resources.get_archive() self.addComponent('test:foo=1', fileContents=[ ('/prelinktest', rephelp.RegularFile( contents=open(archivePath + '/prelinktest'), owner=user, group=group, mode=0755)), ('/prelinktest-orig', rephelp.RegularFile( contents=open(archivePath + '/prelinktest'), owner=user, group=group, mode=0755)) ]) self.updatePkg('test:foo=1') db = database.Database(self.rootDir, self.cfg.dbPath) rc, str = self.captureOutput(verify.verify, ['test:foo'], db, self.cfg) self.assertEquals(str, '') binary = self.rootDir + '/prelinktest' # the test suite can't set the mtime on the file; we'll preserve # it ourself sb = os.stat(binary) os.system("cp %s/prelinktest-prelinked %s" % (archivePath, binary)) os.utime(binary, (sb.st_atime, sb.st_mtime)) self.assertEquals(files.PRELINK_CMD, ('/usr/sbin/prelink', )) oldCmd = files.PRELINK_CMD try: files.PRELINK_CMD = (archivePath + '/prelink', ) files._havePrelink = None rc, str = self.captureOutput(verify.verify, ['test:foo'], db, self.cfg, forceHashCheck=True) self.assertEquals(str, '') # Also verify a path used by addCapsule f, nlinks, devino = files.FileFromFilesystem(binary, pathId='\0' * 16, inodeInfo=True) self.assertEquals( digestlib.sha1(open(binary).read()).hexdigest(), '1114f3a978b60d76d7618dc43aaf207bc999f997') self.assertEquals(f.contents.sha1().encode('hex'), '23ad3a2c940a30809b68a5b8a13392196004efab') finally: files.PRELINK_CMD = oldCmd files._havePrelink = None
def testRdiff9(self): """Binary changes to config; using --diff""" rf1 = rephelp.RegularFile(contents='1\n2\n3\n4\n5\n6\n7\n8\n', perms=0644, mtime=1136921017, config=False) rf2 = rephelp.RegularFile(contents='1\n2\n4\n5\n6\n7\n8\n9\n', perms=0644, mtime=1136921317, config=True) self.addComponent('foo:config', '1', [('/etc/foo', rf1)]) self.addComponent('foo:config', '2', [('/etc/foo', rf2)]) ret, outs = self._rdiff('foo:config=1--2', asDiff=True) self.assertEqual(outs, expOutput9)
def testTagHandlerDoesNotExist(self): myRecipe = recipes.multiTagRecipe0 myRecipe += ' r.ComponentSpec(":tag", "%(taghandlerdir)s/")\n' multitag = self.build(myRecipe, "MultiTag", returnTrove='multitag') self.updatePkg('multitag:runtime') fooFile = rephelp.RegularFile( contents = 'foo\n', perms = 0644, tags = [ 'foo' ] ) self.addComponent('foo:runtime', [('/bam', fooFile)]) oldFuncs = (os.getuid, os.lchown, os.chroot) self.mock(os, "getuid", lambda : 0) self.mock(os, "lchown", lambda x, y, z : None) self.mock(os, "chroot", lambda x :None) # this fixes a race between new tag handler process exiting and # writing files into the pipe for that tag handler; we let the # write finish before the handler process terminates origExec = os.execve self.mock(os, "execve", lambda *args : (time.sleep(0.1), origExec(*args))) rc, txt = self.captureOutput(self.updatePkg, 'foo:runtime', _removeBokenPipeErrors=True) self.assertEquals(txt.lstrip(), '[foo] [Errno 2] No such file or directory\nerror: /usr/libexec/conary/tags/foo failed\n')
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', ) ), ] )
def testFileDisplayFlavor(self): self.addComponent('foo:runtime', '1', 'is:x86', [('/foo', rephelp.RegularFile(flavor='is:x86'))]) (rc, txt) = self.captureOutput(queryrep.displayTroves, self.cfg, ['foo:runtime'], fileFlavors=True) assert (txt == '/foo[is: x86]\n')
def testVerifyToFile(self): db = database.Database(self.rootDir, self.cfg.dbPath) os.chdir(self.workDir) user, group = self._getUserGroup() self.addComponent('foo:runtime', '1.0', fileContents=[('/foo', rephelp.RegularFile(owner=user, group=group))]) self.updatePkg('foo:runtime') s = verify.verify(['foo:runtime'], db, self.cfg, changesetPath='foo.ccs') cs = changeset.ChangeSetFromFile('foo.ccs') assert (list(cs.iterNewTroveList()) == []) f = open(self.rootDir + '/foo', "a") f.write("mod") f.close() s = self.captureOutput(verify.verify, ['foo:runtime'], db, self.cfg, changesetPath='foo.ccs') assert (not s[1]) cs = changeset.ChangeSetFromFile('foo.ccs') assert (list(cs.iterNewTroveList())[0].getName() == 'foo:runtime')
def testSharedHardLinks(self): info = { 'user': pwd.getpwuid(os.getuid())[0], 'group': grp.getgrgid(os.getgid())[0], } foo = self.addComponent('foo:runtime', '1.0-1-1', fileContents = [ ( '/a', rephelp.RegularFile(contents = "a1", pathId = "1", linkGroup = "\0" * 16, owner = info['user'], group = info['group'] ) ), ( '/foo', rephelp.RegularFile(contents = "a1", pathId = "2", linkGroup = "\0" * 16) ), ] ) bar = self.addComponent('bar:runtime', '1.0-1-1', fileContents = [ ( '/a', rephelp.RegularFile(contents = "a1", pathId = "1", linkGroup = "\1" * 16, owner = info['user'], group = info['group'] ) ), ( '/bar', rephelp.RegularFile(contents = "a1", pathId = "2", linkGroup = "\1" * 16) ), ] ) self.updatePkg('foo:runtime') self.updatePkg('bar:runtime', keepExisting = True) self.checkOwners('/a', [ foo, bar ]) # make sure we can build a group with both troves groupRecipe = r""" class GroupConflicts(GroupRecipe): name = 'group-dist' version = '1.0' clearBuildRequires() autoResolve = False def setup(r): r.VersionConflicts(exceptions = 'group-dist') r.add('foo:runtime') r.add('bar:runtime') """ built, d = self.buildRecipe(groupRecipe, "GroupConflicts")
def testRdiff2(self): # Test showing of troves with no changes req1 = 'soname: ELF32/lib/foo3(blah) trove:bar(1)' req2 = 'soname: ELF32/lib/foo2(blah)' prov1 = "trove:bar(1) trove:baz(1)" prov2 = "trove:bar(1) trove:baz(1) soname: ELF32/lib/foo2(blah)" rf1 = rephelp.RegularFile( contents='1\n2\n3\n4\n5\n6\n7\n8\n', perms=0644, provides=prov1, requires=req1, mtime=1176921017, ) rf2 = rephelp.RegularFile(contents='1\n2\n4\n5\n6\n7\n8\n9\n', perms=0755, provides=prov2, requires=req2, mtime=1176921317, tags=['tag2', 'tag1', 'tag3']) self.addComponent('foo:run', '1', 'is:x86', [('/usr/bin/foo', rf1)]) self.addComponent('foo:supdoc', '1', 'is:x86', [('/usr/doc/foo1', rf2)]) self.addCollection('foo', '1', [(x, '1', 'is:x86') for x in [':run', ':supdoc']]) self.addComponent('bar:run', '1', [('/usr/bin/bar', rf1)]) self.addCollection('bar', '1', [':run']) self.addCollection('group-bar', '1', ['bar']) self.addCollection('group-foo', '1', [('foo', '1', 'is:x86'), 'group-bar']) self.addComponent('foo:run', '2', 'is:x86', [('/usr/bin/foo', rf1)]) self.addComponent('foo:doc', '2', 'is:x86', [('/usr/doc/foo1', rf2)]) self.addCollection('foo', '2', [(x, '2', 'is:x86') for x in [':run', ':doc']]) self.addCollection('group-foo', '2', [('foo', '2', 'is:x86'), ('group-bar', '1', '')]) troveSpec = 'group-foo=1--2' ret, outs = self._rdiff(troveSpec) self.assertEqual(outs, expOutput2)
def testUnchangedConfigFileMirrorDistRepos(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.addComponent('test:runtime', '/myhost@rpl:linux/1.0-1-1', fileContents=[ ('/etc/foo', rephelp.RegularFile( version='/myhost@rpl:linux/1.0-1-1', contents='foo\n')) ], repos=src) self.addComponent('test:runtime', '/myhost@rpl:linux//myotherhost@rpl:linux/1.0-1-1', fileContents=[ ('/etc/foo', rephelp.RegularFile( version='/myhost@rpl:linux/1.0-1-1', contents='foo\n')) ], repos=src) self.addComponent( 'test:runtime', '/myhost@rpl:linux//myotherhost@rpl:linux/1.0-1.1-1', fileContents= [('/etc/foo', rephelp.RegularFile( version='/myhost@rpl:linux//myotherhost@rpl:linux/1.0-1.1-1', contents='foo\n'))], repos=src) dst = self._getMultiTarget(2, ["myhost", "myotherhost"]) # create the mirror config cfg = mirror.MirrorFileConfiguration() cfg.host = "myotherhost" self._runMirrorCfg(src, dst, cfg)
def testPathIdConflict(self): sourceRepos, targetRepos = self.createRepositories() mirrorFile = self.createConfigurationFile() self.addComponent("trove1:data", fileContents=[ ('/usr/share/t1/file1', 'this is file 1'), ('/usr/share/t1/file2', 'this is file 2'), ('/usr/share/common/file', 'this is a common file') ], repos=sourceRepos) self.addCollection("trove1", "1.0", [":data"], repos=sourceRepos) self.addComponent("trove2:data", fileContents=[ ('/usr/share/t2/file1', 'this is file 1'), ('/usr/share/t2/file2', 'this is file 2'), ('/usr/share/common/file', 'this is a common file') ], repos=sourceRepos) self.addCollection("trove2", "1.0", [":data"], repos=sourceRepos) f = rephelp.RegularFile(pathId='1', contents='foo\n') foo = rephelp.RegularFile(pathId='222', contents='foobar\n') bar = rephelp.RegularFile(pathId='222', contents='bar\n') self.addComponent('foo:runtime', '2.0-1-1', "", fileContents=[('/bin/foo', f), ('/etc/config', foo), ('/lib/file', f)], repos=sourceRepos) self.addCollection("foo", "2.0-1-1", [":runtime"], repos=sourceRepos) self.addComponent('bar:runtime', '2.0-1-1', "", fileContents=[('/bin/bar', f), ('/etc/config', bar), ('/lib/file', f)], repos=sourceRepos) self.addCollection("bar", "2.0-1-1", [":runtime"], repos=sourceRepos) self.runMirror(mirrorFile) self.compareRepositories(sourceRepos, targetRepos) self.servers.stopServer(1)
def testRdiff5(self): # CNY-1605 # Create two flavors of the same trove and add them to the same group flv1 = '~ssl' flv2 = '~!ssl' rf11 = rephelp.RegularFile(contents='1\n2\n3\n4\n5\n6\n7\n8\n', flavor=flv1) rf12 = rephelp.RegularFile(contents='1\n2\n4\n5\n6\n7\n8\n9\n', flavor=flv2) rf21 = rephelp.RegularFile(contents='1\n2\n4\n5\n6\n7\n8\n9\n', flavor=flv1) rf22 = rephelp.RegularFile(contents='1\n2\n3\n4\n5\n6\n7\n8\n', flavor=flv2) files = [(rf11, rf12), (rf21, rf22)] for v, fileobjs in zip(['1', '2'], files): file1 = fileobjs[0] file2 = fileobjs[1] t1 = self.addComponent('foo:run', v, fileContents=[('/bin/foo', file1)]) p1 = self.addCollection('foo', v, [(':run', v, t1.getFlavor())]) t2 = self.addComponent('foo:run', v, fileContents=[('/bin/foo', file2)]) p2 = self.addCollection('foo', v, [(':run', v, t2.getFlavor())]) self.addCollection('group-foo', v, [('foo', v, flv1), ('foo', v, flv2)]) troveSpec = 'group-foo=1--2' self.cfg.fullFlavors = True ret, outs = self._rdiff(troveSpec) self.cfg.fullFlavors = False self.assertEqual(outs, expOutput5)
def testUnlink(self): self.addComponent('foo:runtime', '1.0-1-1', fileContents=[('/a', rephelp.RegularFile(contents="a1", pathId="1")), ('/b', rephelp.RegularFile(contents="b1", pathId="2", perms=0644))]) self.addComponent('foo:runtime', '2.0-2-2', fileContents=[]) # files are removed in reverse path order, so /b is removed before # /a -- make sure it gets put back if removing /a fails self.updatePkg('foo:runtime=1.0-1-1') os.chmod(self.rootDir + '/b', 0600) os.unlink = lambda x: self.unlinkStub(x, ['a']) self.logCheck( self.assertRaises, (OSError, self.updatePkg, 'foo:runtime=2.0-2-2'), [revertMsg, 'error: /a could not be removed: Permission denied']) self.verifyFile(self.rootDir + '/b', 'b1') assert (os.stat(self.rootDir + '/b').st_mode & 0777 == 0600) assert ( not os.path.exists(self.rootDir + self.cfg.dbPath + '/journal')) self.logCheck2( [revertMsg, 'error: /a could not be removed: Permission denied'], self.assertRaises, OSError, self.updatePkg, 'foo:runtime=2.0-2-2', keepJournal=True) assert (os.path.exists(self.rootDir + self.cfg.dbPath + '/journal'))
def testFileTypeChange(self): self.addComponent('foo:run=1', fileContents = [ ( '/c', rephelp.RegularFile(contents = 'orig\n', mode = 0600, config=True) ), ( '/f', rephelp.RegularFile(contents = 'orig\n', mode = 0600) ) ]) self.addComponent('foo:run=2', fileContents = [ ( '/f', rephelp.Symlink(target = '/targ') ) ]) self.updatePkg('foo:run=1') os.unlink(self.rootDir + '/c') os.symlink('/', self.rootDir + '/c') os.unlink(self.rootDir + '/f') os.symlink('/', self.rootDir + '/f') rc, s = self.captureOutput(self.repairTroves, [ 'foo:run' ]) self.assertEquals(s, '') self.verifyFile(self.rootDir + '/c', 'orig\n') self.verifyFile(self.rootDir + '/f', 'orig\n') self.updatePkg('foo:run=2') os.unlink(self.rootDir + '/f') self.writeFile(self.rootDir + '/f', 'new') rc, s = self.captureOutput(self.repairTroves, [ 'foo:run' ]) self.assertEquals(s, '') self.assertEquals(os.readlink(self.rootDir + '/f'), '/targ')
def testMergeWithConflicts(self): # CNY-1278 common = "line1\nline2\nline3\nline4\nline5\nline6\nline7\n" orig = common + "ORIG BOTTOM\n" newOnParent = "TOP\n" + common + "PARENT BOTTOM\n" newOnShadow = common + "SHADOW BOTTOM\n" for version in [ '/localhost@rpl:linux/1.0-1', '/localhost@rpl:linux//shadow/1.0-1' ]: self.addComponent('test:source', version, fileContents=[ ('test.source', simpleRecipe), ('other', rephelp.RegularFile( contents=orig, version='/localhost@rpl:linux/1.0-1', config=True)) ]) self.addComponent('test:source', '/localhost@rpl:linux/1.0-2', fileContents=[('test.source', simpleRecipe), ('other', newOnParent)]) self.addComponent('test:source', '/localhost@rpl:linux//shadow/1.0-1.1', fileContents=[('test.source', simpleRecipe), ('other', newOnShadow)]) os.chdir(self.workDir) self.checkout("test", 'localhost@rpl:shadow') os.chdir("test") self.logCheck( self.merge, [], 'warning: conflicts from merging changes from head ' 'into %s/test/other saved as %s/test/other.conflicts' % (self.workDir, self.workDir)) self.logCheck( self.merge, [], 'error: outstanding merge must be committed before ' 'merging again') self.verifyFile(self.workDir + '/test/other', "TOP\n" + common + "SHADOW BOTTOM\n")
def testUnchangedConfigFileMirrorSingleRepos(self): sourceRepos, targetRepos = self.createRepositories() mirrorFile = self.createConfigurationFile() self.addComponent('test:runtime', '/localhost@rpl:linux/1.0-1-1', fileContents=[ ('/etc/foo', rephelp.RegularFile( version='/localhost@rpl:linux/1.0-1-1', contents='foo\n')) ], repos=sourceRepos) self.addComponent('test:runtime', '/localhost@rpl:linux/2.0-1-1', fileContents=[ ('/etc/foo', rephelp.RegularFile( version='/localhost@rpl:linux/2.0-1-1', contents='foo\n')) ], repos=sourceRepos) self.runMirror(mirrorFile)
def testHardLinks(self): self.addComponent('foo:runtime', '1.0-1-1', fileContents=[ ('/a', rephelp.RegularFile(contents="a1", pathId="1", linkGroup="\0" * 16)), ('/b', rephelp.RegularFile(contents="a1", pathId="2", linkGroup="\0" * 16)), ('/c', rephelp.RegularFile(contents="a1", pathId="3", linkGroup="\0" * 16)) ]) self.addComponent('foo:runtime', '2.0-2-2', fileContents=[ ('/a', rephelp.RegularFile(contents="a2", pathId="1")), ('/b', rephelp.RegularFile(contents="b2", pathId="2", linkGroup="\1" * 16)), ('/c', rephelp.RegularFile(contents="b2", pathId="3", linkGroup="\1" * 16)), ('/d', rephelp.RegularFile(contents="d2", pathId="4")), ]) self.updatePkg('foo:runtime=1.0-1-1') util.sha1Uncompress = lambda *args: self.sha1UncompressStub( failPaths=['d'], *args) self.logCheck(self.assertRaises, (OSError, self.updatePkg, 'foo:runtime=2.0-2-2'), revertMsg) assert (sorted(os.listdir(self.rootDir)) == ['a', 'b', 'c', 'var']) self.verifyFile(self.rootDir + '/a', "a1") assert (os.stat(self.rootDir + '/a').st_ino == os.stat(self.rootDir + '/b').st_ino) assert (os.stat(self.rootDir + '/a').st_ino == os.stat(self.rootDir + '/c').st_ino)
def createTroves(self, repos, start, count, version='1.0', flavor=''): md5s = rephelp.sha1helper.md5FromString for i in range(start, start + count): self.addComponent('test%d:runtime' % i, version, flavor, fileContents=[ ("/test/file%d" % x, rephelp.RegularFile( contents="hello file %d\n" % x, pathId=md5s("%032d" % x))) for x in range(0, i) ], repos=repos) self.addCollection('test%d' % i, version, [("test%d:runtime" % i, version, flavor)], repos=repos)
def testRdiff3(self): # Have a file change from regular file to symbolic link rf1 = rephelp.RegularFile(contents='1\n2\n3\n4\n5\n6\n7\n8\n', perms=0644, mtime=1136921017) lf1 = rephelp.Symlink("/etc/passwd") self.addComponent('foo:run', '1', [('/usr/bin/foo', rf1)]) self.addCollection('foo', '1', [':run']) self.addComponent('foo:run', '2', [('/etc/passwd', rf1), ('/usr/bin/foo', lf1)]) self.addCollection('foo', '2', [':run']) ret, outs = self._rdiff('foo=1--2', lsl=True) #re.sub("Symbolic", "<TIMESTRING> (Symbolic", outs) outs = re.sub(" [0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]* ", " <TIMESTRING TIMESTAMP> ", outs) self.assertEqual(outs, expOutput3)
def testFailedHardLinks(self): # 1.0 -> 2.0 update tests adding a new file, where the target of the # link already exists on the system. we fail after the rename() to # the new link name occurs, testing that the new link name gets restored # to its old contents self.addComponent('foo:runtime', '1.0-1-1', fileContents=[ ('/a', rephelp.RegularFile(contents="a1", pathId="1", linkGroup="\0" * 16)), ('/b', rephelp.RegularFile(contents="a1", pathId="2", linkGroup="\0" * 16)), ('/c', rephelp.RegularFile(contents="other", pathId="3")) ]) self.addComponent('foo:runtime', '2.0-2-2', fileContents=[ ('/a', rephelp.RegularFile(contents="a1", pathId="1", linkGroup="\0" * 16)), ('/b', rephelp.RegularFile(contents="a1", pathId="2", linkGroup="\0" * 16)), ('/c', rephelp.RegularFile(contents="a1", pathId="3", linkGroup="\0" * 16)), ]) self.updatePkg('foo:runtime=1.0-1-1') counter = Counter(1) os.rename = lambda x, y: self.renameStub( x, y, ['c'], failAfter=True, counter=counter) self.logCheck(self.assertRaises, (OSError, self.updatePkg, 'foo:runtime=2.0-2-2'), revertMsg) self.verifyFile(self.rootDir + '/a', "a1") self.verifyFile(self.rootDir + '/b', "a1") self.verifyFile(self.rootDir + '/c', "other")
def testBuildLogDisplay(self): buildlog = 'This is test buildlog' bz2compressor = bz2.BZ2Compressor() bz2compressor.compress(buildlog) contents = bz2compressor.flush() self.addComponent('foo:runtime') self.addComponent( 'foo:debuginfo', [('/usr/bin/foo', rephelp.RegularFile(contents=contents, tags=['buildlog']))]) self.addCollection('foo', [(':runtime', True), (':debuginfo', False)]) repos = self.openRepository() output = self.captureOutput(queryrep.displayTroves, self.cfg, ['foo'], [], [], queryrep.VERSION_FILTER_LATEST, queryrep.FLAVOR_FILTER_BEST, showBuildLog=True) self.assertEqual(output[1], buildlog)