def testLnDir(self): tmpdir = tempfile.mkdtemp() tmpdir2 = tempfile.mkdtemp() for sub in ('a', 'b', 'c'): subdir = os.path.join(tmpdir, sub) os.mkdir(subdir) for dir in (tmpdir, subdir): for fn in [os.path.join(dir, str(x)) for x in range(10)]: f = open(fn, 'w') f.close() os.mkdir(os.path.join(tmpdir2, 'c')) splitdistro.lndir( \ tmpdir, tmpdir2, excludes = ['b', os.path.join('c', '9')]) dirList = sorted(os.listdir(tmpdir2)) self.failIf('9' not in dirList, 'File of same basename and different path as an ' 'exclusion was not copied') self.failIf('b' in dirList, "named excslusion subdir was copied") assert dirList == \ ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'c'] dirList = sorted(os.listdir(os.path.join(tmpdir2, 'c'))) self.failIf('9' in dirList, "explicitly excluded file was copied") assert dirList == \ ['0', '1', '2', '3', '4', '5', '6', '7', '8']
def testLnDirExistDirs(self): tmpdir = tempfile.mkdtemp() tmpdir2 = tempfile.mkdtemp() util.mkdirChain(os.path.join(tmpdir, 'a', 'b')) util.mkdirChain(os.path.join(tmpdir2, 'a', 'b')) splitdistro.lndir(tmpdir, tmpdir2) self.failIf(not os.path.exists(os.path.join(tmpdir2, 'a', 'b')), "Dir a/b should exist")
def testLnDirSubdirs(self): tmpdir = tempfile.mkdtemp() tmpdir2 = tempfile.mkdtemp() util.mkdirChain(os.path.join(tmpdir, 'a', 'b', 'c', 'd')) splitdistro.lndir(tmpdir, tmpdir2, excludes = [os.path.join('a', 'b')]) self.failIf(os.path.exists( \ os.path.join(tmpdir2, 'a', 'b', 'c', 'd')), "Dir a/b/c/d should not have been copied") self.failIf(os.path.exists(os.path.join(tmpdir2, 'a', 'b', 'c')), "Dir a/b/c should not have been copied") self.failIf(os.path.exists(os.path.join(tmpdir2, 'a', 'b')), "Dir a/b should not have been copied") self.failIf(not os.path.exists(os.path.join(tmpdir2, 'a')), "Dir a should have been copied")
def testCloneTree(self): def mkfile(path, fileName, contents = ""): tmpFile = open(os.path.join(path, fileName), 'w') tmpFile.write(contents) tmpFile.close() def getContents(*args): tmpFile = open(os.path.join(*args)) res = tmpFile.read() tmpFile.close() return res # prepare source dir srcDir = tempfile.mkdtemp() subDir = os.path.join(srcDir, 'subdir') os.mkdir(subDir) destDir = tempfile.mkdtemp() # stock some initial files in the source tree mkfile(srcDir, 'EULA', "Nobody expects the Spanish Inquisition!") mkfile(srcDir, 'LICENSE', "Tell him we've already got one.") mkfile(subDir, 'README', "None shall pass.") # now make a colliding dir os.mkdir(os.path.join(srcDir, 'collide')) os.mkdir(os.path.join(destDir, 'collide')) # and collide a file mkfile(destDir, 'LICENSE', "Spam, Spam, Spam, Spam...") try: splitdistro.lndir(srcDir, destDir) # ensure basic files were cloned assert(getContents(destDir, 'EULA') == getContents(srcDir, 'EULA')) # ensure initial contents were overwritten self.failUnless(getContents(destDir, 'LICENSE') == \ getContents(srcDir, 'LICENSE'), "File contents were not replaced.") # ensure sub directories were properly traversed assert(getContents(destDir, 'subdir', 'README') == \ "None shall pass.") finally: # clean up dirs util.rmtree(srcDir) util.rmtree(destDir)
def testLnDirDirs(self): tmpdir = tempfile.mkdtemp() tmpdir2 = tempfile.mkdtemp() os.mkdir(os.path.join(tmpdir, 'a')) for dirName in ('b', 'c'): util.mkdirChain(os.path.join(tmpdir, 'a', dirName)) util.mkdirChain(os.path.join(tmpdir, dirName)) splitdistro.lndir(tmpdir, tmpdir2, excludes = \ ['b', os.path.join('a', 'c')]) dirList = os.listdir(os.path.join(tmpdir2, 'a')) self.failIf('b' not in dirList, "Directory a/b should not have been excluded") self.failIf('c' in dirList, "Directory a/c should have been excluded") dirList = os.listdir(tmpdir2) self.failIf('c' not in dirList, "Directory c should not have been excluded") self.failIf('b' in dirList, "Directory b should have been excluded")
def testLnDirFiles(self): tmpdir = tempfile.mkdtemp() tmpdir2 = tempfile.mkdtemp() os.mkdir(os.path.join(tmpdir, 'a')) for fn in ('b', 'c'): f = open(os.path.join(tmpdir, 'a', fn), 'w') f.close() f = open(os.path.join(tmpdir, fn), 'w') f.close() splitdistro.lndir(tmpdir, tmpdir2, excludes = \ ['b', os.path.join('a', 'c')]) dirList = os.listdir(os.path.join(tmpdir2, 'a')) self.failIf('b' not in dirList, "File a/b should not have been excluded") self.failIf('c' in dirList, "File a/c should have been excluded") dirList = os.listdir(tmpdir2) self.failIf('c' not in dirList, "File c should not have been excluded") self.failIf('b' in dirList, "File b should have been excluded")
def write(self): topDir = os.path.join(self.workDir, 'unified') tbdir = os.path.join(topDir, self.productDir, 'tarballs') baseDir = os.path.join(topDir, self.productDir, 'base') util.mkdirChain(tbdir) util.mkdirChain(baseDir) basePath = os.path.join(self.workDir, self.basefilename) if os.path.exists(basePath): util.rmtree(basePath) util.mkdirChain(basePath) outputDir = os.path.join(constants.finishedDir, self.UUID) util.mkdirChain(outputDir) tarball = os.path.join(self.workDir, self.basefilename + '.tar.gz') cwd = os.getcwd() try: self.installFileTree(basePath, no_mbr=True) self.status('Preparing to build ISOs') os.chdir(basePath) util.execute('tar -C %s -cpPsS --to-stdout ./ | gzip > %s' % \ (basePath, tarball)) ts = TarSplit(tarball) ts.splitFile(tbdir) ts.writeTbList(os.path.join(baseDir, 'tblist')) util.rmtree(basePath, ignore_errors = True) util.rmtree(tarball, ignore_errors = True) try: os.chdir(cwd) except: # block all errors so that real ones can get through pass self.callback = installable_iso.Callback(self.status) print >> sys.stderr, "Building ISOs of size: %d Mb" % \ (self.maxIsoSize / 1048576) sys.stderr.flush() # FIXME: hack to ensure we don't trigger overburns. # there are probably cleaner ways to do this. if self.maxIsoSize > 681574400: self.maxIsoSize -= 1024 * 1024 templateDir, clientVersion = self.retrieveTemplates() csdir = self.prepareTemplates(topDir, templateDir) util.rmtree(csdir, ignore_errors=True) if self.arch == 'x86': anacondaArch = 'i386' else: anacondaArch = self.arch # write .discinfo discInfoPath = os.path.join(topDir, ".discinfo") if os.path.exists(discInfoPath): os.unlink(discInfoPath) discInfoFile = open(discInfoPath, "w") print >> discInfoFile, time.time() print >> discInfoFile, self.jobData['name'] print >> discInfoFile, anacondaArch print >> discInfoFile, "1" for x in ["base", "tarballs", 'pixmaps']: print >> discInfoFile, "%s/%s" % (self.productDir, x) discInfoFile.close() self.extractMediaTemplate(topDir) self.setupKickstart(topDir) self.writeProductImage(topDir, installable_iso.getArchFlavor(self.baseFlavor).freeze()) self.status("Building ISOs") # Mostly copied from splitdistro current = os.path.join(self.workDir, 'disc1') discnum = 1 if os.path.isdir(current): print >> sys.stderr, 'removing stale', current util.rmtree(current) print >> sys.stderr, 'creating', current os.mkdir(current) splitdistro.lndir(topDir, current, excludes=('media-template',)) # lay 'disc1' before 'all' to ensure collisions are handled correctly for cDir in ('disc1', 'all'): if 'media-template' in os.listdir(topDir) and \ cDir in os.listdir(os.path.join(topDir, 'media-template')): splitdistro.lndir(os.path.join(topDir, 'media-template', cDir), current) for cDir in ('all', 'disc1'): srcDir = os.path.join(topDir, 'media-template2', cDir) if os.path.exists(srcDir): for src in os.listdir(srcDir): call('cp', '-R', '--no-dereference', os.path.join(srcDir, src), current) outputFileList = self.buildIsos(topDir) if self.buildOVF10: self.workingDir = os.path.join(self.workDir, self.basefilename) util.mkdirChain(self.workingDir) diskFileSize = imagegen.getFileSize(outputFileList[0][0]) self.ovfImage = ovf_image.ISOOvfImage(self.basefilename, self.jobData['description'], None, outputFileList[0][0], diskFileSize, self.maxIsoSize, False, self.getBuildData('vmMemory'), self.workingDir, self.outputDir) self.ovfObj = self.ovfImage.createOvf() self.ovfXml = self.ovfImage.writeOvf() self.ovfImage.createManifest() self.ovaPath = self.ovfImage.createOva() outputFileList.append((self.ovaPath, 'Appliance ISO OVF 1.0')) # notify client that images are ready self.postOutput(outputFileList) finally: util.rmtree(os.path.normpath(os.path.join(topDir, "..")), ignore_errors = True) util.rmtree(constants.cachePath, ignore_errors = True)