Example #1
0
    def load(self, name, loadFn=None):
        cfg, data = self.loadFixture(name, loadFn=loadFn)

        # get a random name for this particular instance of the fixture
        # in order to create unique copies
        randomDbName = self._randomName()

        # make a copy of the data directory and update the cfg
        testDataPath = tempfile.mkdtemp(prefix = "fixture%s" % name, suffix = '.copy')
        util.copytree(os.path.join(cfg.dataPath,'*'), testDataPath)
        testCfg = copy.deepcopy(cfg)
        testCfg.dataPath = testDataPath
        testCfg.dbPath = os.path.join(testCfg.dataPath, 'mintdb')
        testCfg.imagesPath = os.path.join(testCfg.dataPath, 'images')
        testCfg.reposContentsDir = "%s %s" % (os.path.join(testCfg.dataPath, 'contents1', '%s'),
                                              os.path.join(testCfg.dataPath, 'contents2', '%s'))
        testCfg.reposPath = os.path.join(testCfg.dataPath, 'repos')

        f = open(os.path.join(testCfg.dataPath, "rbuilder.conf"), 'w')
        testCfg.display(out=f)
        f.close()

        # restore the repos dbs
        db = self.harness.getRootDB()
        cu = db.cursor()
        cu.execute("""SELECT datname FROM pg_database 
                      WHERE datname LIKE 'cr%s%%'""" % name.lower())
        for dbname in [x[0] for x in cu.fetchall()]:
            fixtureCopyReposDbName = dbname[2+len(name):]
            self._dupDb(dbname, fixtureCopyReposDbName)

        return testCfg, data
Example #2
0
    def setup(self):
        util.mkdirChain(util.joinPaths(self.image_root, 'boot', 'grub'))
        # path to grub stage1/stage2 files in rPL/rLS
        util.copytree(
            util.joinPaths(self.image_root, 'usr', 'share', 'grub', '*', '*'),
            util.joinPaths(self.image_root, 'boot', 'grub'))
        # path to grub files in SLES
        if is_SUSE(self.image_root):
            util.copytree(
                util.joinPaths(self.image_root, 'usr', 'lib', 'grub', '*'),
                util.joinPaths(self.image_root, 'boot', 'grub'))
        if is_UBUNTU(self.image_root):
            # path to grub files in x86 Ubuntu
            util.copytree(
                util.joinPaths(self.image_root, 'usr', 'lib', 'grub', 'i386-pc', '*'),
                util.joinPaths(self.image_root, 'boot', 'grub'))
            # path to grub files in x86_64 Ubuntu
            util.copytree(
                util.joinPaths(self.image_root, 'usr', 'lib', 'grub', 'x86_64-pc', '*'),
                util.joinPaths(self.image_root, 'boot', 'grub'))
        util.mkdirChain(util.joinPaths(self.image_root, 'etc'))

        # Create a stub grub.conf
        self.writeConf()

        # Create the appropriate links
        if self._get_grub_conf() != 'menu.lst':
            os.symlink('grub.conf', util.joinPaths(
                self.image_root, 'boot', 'grub', 'menu.lst'))
            os.symlink('../boot/grub/grub.conf',
                       util.joinPaths(self.image_root, 'etc', 'grub.conf'))
        if is_SUSE(self.image_root):
            self._suse_grub_stub()
Example #3
0
    def _generate(self):
        self._log.info("Generating template %s from trove %s=%s[%s]",
                self._hash, *self._troveTup)

        self._installContents(self._contentsDir, [self._troveTup])

        # Copy "unified" directly into the output.
        os.mkdir(self._outputDir)
        util.copytree(self._contentsDir + '/unified', self._outputDir + '/')

        # Process the MANIFEST file.
        for line in open(self._contentsDir + '/MANIFEST'):
            line = line.rstrip()
            if not line or line[0] == '#':
                continue
            args = line.rstrip().split(',')
            command = args.pop(0)
            commandFunc = getattr(self, '_DO_' + command, None)
            if not commandFunc:
                raise RuntimeError("Unknown command %r in MANIFEST"
                        % (command,))
            commandFunc(args)

        # Archive the results.
        digest = digestlib.sha1()
        outFile = util.AtomicFile(self._outputPath)

        proc = call(['/bin/tar', '-cC', self._outputDir, '.'],
                stdout=subprocess.PIPE, captureOutput=False, wait=False)
        util.copyfileobj(proc.stdout, outFile, digest=digest)
        proc.wait()

        # Write metadata.
        metaFile = util.AtomicFile(self._outputPath + '.metadata')
        cPickle.dump({
            'sha1sum': digest.hexdigest(),
            'trovespec': '%s=%s[%s]' % self._troveTup,
            'kernel': (self._kernelTup and ('%s=%s[%s]' % self._kernelTup)
                or '<none>'),
            # Right now, we are going to hardcode this to an older version
            # of Netclient Protocol to hint to the Conary installed on the
            # jobslave to generate old filecontainers that are compatible
            # with all versions of Conary. (See RBL-1552.)
            'netclient_protocol_version': '38',
            }, metaFile)

        metaFile.commit()
        outFile.commit()

        self._log.info("Template %s created", self._hash)
Example #4
0
 def testCopyTree(self):
     # test copying tree with different syntaxes
     d = tempfile.mkdtemp()
     subdir = os.sep.join((d, 'subdir'))
     os.mkdir(subdir)
     fn = os.sep.join((subdir, 'hello'))
     f = open(fn, 'w')
     f.write('hello')
     d2 = tempfile.mkdtemp()
     subdir2 = os.sep.join((d2, 'subdir'))
     fn2 = os.sep.join((subdir2, 'hello'))
     util.copytree(subdir, d2)
     assert(os.path.isdir(subdir2) and os.path.exists(fn2))
     util.rmtree(subdir2)
     util.copytree(subdir + '/', d2)
     assert(os.path.isdir(subdir2) and os.path.exists(fn2))
     util.rmtree(d)
Example #5
0
 def testCopyTree(self):
     # test copying tree with different syntaxes
     d = tempfile.mkdtemp()
     subdir = os.sep.join((d, 'subdir'))
     os.mkdir(subdir)
     fn = os.sep.join((subdir, 'hello'))
     f = open(fn, 'w')
     f.write('hello')
     d2 = tempfile.mkdtemp()
     subdir2 = os.sep.join((d2, 'subdir'))
     fn2 = os.sep.join((subdir2, 'hello'))
     util.copytree(subdir, d2)
     assert(os.path.isdir(subdir2) and os.path.exists(fn2))
     util.rmtree(subdir2)
     util.copytree(subdir + '/', d2)
     assert(os.path.isdir(subdir2) and os.path.exists(fn2))
     util.rmtree(d)
Example #6
0
    def load(self, name, loadFn=None):
        cfg, data = self.loadFixture(name, loadFn=loadFn)

        # make a copy of the data directory and update the cfg
        testDataPath = tempfile.mkdtemp(prefix = "fixture%s" % name, suffix = '.copy')
        self.testDataPath = testDataPath
        util.copytree(os.path.join(cfg.dataPath,'*'), testDataPath)
        testCfg = copy.deepcopy(cfg)
        testCfg.dataPath = testDataPath
        testCfg.dbPath = os.path.join(testCfg.dataPath, 'mintdb')
        testCfg.imagesPath = os.path.join(testCfg.dataPath, 'images')
        testCfg.reposContentsDir = "%s %s" % (
                os.path.join(testCfg.dataPath, 'contents1', '%s'),
                os.path.join(testCfg.dataPath, 'contents2', '%s'))
        reposDBPath = os.path.join(testCfg.dataPath, 'repos', '%s', 'sqldb')
        testCfg.configLine('database default sqlite ' + reposDBPath)
        testCfg.reposPath = os.path.join(testCfg.dataPath, 'repos')

        f = open(os.path.join(testCfg.dataPath, "rbuilder.conf"), 'w')
        testCfg.display(out=f)
        f.close()

        return testCfg, data