Esempio n. 1
0
    def write(self):
        '''create a tdl from the snapdirectory

        @raises - MissingFileError - if the tdl cannot be created
        '''
        # contents of the tdl
        contents  = "<template>\n"
        contents += "  <name>snap-</name>\n"
        contents += "  <description>snap generated tdl</description>\n"

        # temp store the working directory, before changing to the snapdirectory
        cwd = os.getcwd()
        os.chdir(self.snapdirectory)

        # TODO store generic operating system information
        contents += "  <os>\n"
        contents += "    <name></name>\n"
        contents += "    <version></version>\n"
        contents += "    <arch></arch>\n"

        # populate repo list in tdl
        record = ReposRecordFile(self.snapdirectory + "/repos.xml")
        repos = record.read()
        for repo in repos:
            contents += "    <install type='url'>\n"
            contents += "      <url>"+repo.url+"</url>\n"
            contents += "    </install>\n"

        contents += "  </os>\n"

        # populate package list in tdl
        contents += "  <packages>\n"

        record = PackagesRecordFile(self.snapdirectory + "/packages.xml")
        packages = record.read()
        for pkg in packages:
          # TODO decode package (need to use package subsystem type from snapshot metadata)
          contents += "    <package>" + pkg.name + "</package>\n"

        contents += "  </packages>\n"

        # TODO populate service list + config in tdl
        
        # TODO populate file list in tdl (how to make those files available for image creation?)

        contents += "</template>"

        # create the tdl
        tdl = open(self.tdlfile, "w")
        tdl.write(contents)
        tdl.close()

        if snap.config.options.log_level_at_least('normal'):
            snap.callback.snapcallback.message("TDL " + self.tdlfile + " created")

        # restore the working directory
        os.chdir(cwd)
Esempio n. 2
0
    def testBackupRepos(self):
        snapshot_target = snap.backends.repos.syum.Syum()
        snapshot_target.backup(self.fs_root)

        self.assertTrue(os.path.exists(self.fs_root + "/etc/yum.conf"))
        for repo in os.listdir("/etc/yum.repos.d"):
            self.assertTrue(os.path.exists(self.fs_root + "/etc/yum.repos.d/" + repo))

        repos = []
        self.assertTrue(os.path.exists(self.fs_root + "/repos.xml"))
        record = ReposRecordFile(self.fs_root + "/repos.xml")
        record_repos = record.read()
        for repo in record_repos:
            repos.append(repo.url)

        # verify repos contents
        urls = []
        for yum_repo in FileManager.get_all_files(include=['/etc/yum.repos.d']):
            baseurl = re.compile('baseurl=(.*)\n')
            mirrorlist = re.compile('mirrorlist=(.*)\n')
            contents = FileManager.read_file(yum_repo)
            for match in baseurl.findall(contents):
                urls.append(match)
            for match in mirrorlist.findall(contents):
                urls.append(match)

        for url in urls:
            self.assertIn(url, repos)
Esempio n. 3
0
    def restore(self, basedir):
        '''restore yum configuration and repositories'''
        # return if we cannot find require files
        if not os.path.isdir(basedir + "/etc/apt"):
            return

        # read files from the record file
        # tho we don't do anything with this info here
        record = ReposRecordFile(basedir + "/repos.xml")
        repos = record.read()

        # restore the apt config to /etc/apt
        for apt_conf in FileManager.get_all_files(include=[basedir + "/etc/apt"]):
            partial_path = apt_conf.replace(basedir + "/", "")
            SFile(partial_path).copy_to(self.fs_root, path_prefix=basedir)
Esempio n. 4
0
    def testBackupRepos(self):
        snapshot_target = snap.backends.repos.sapt.Sapt()
        snapshot_target.backup(self.fs_root)

        self.assertTrue(os.path.exists(self.fs_root + "/etc/apt/"))
        for afile in os.listdir("/etc/apt"):
            if not os.path.isdir("/etc/apt/" + afile) or len(os.listdir("/etc/apt/"+afile)) > 0:
                self.assertTrue(os.path.exists(self.fs_root + "/etc/apt/" + afile))

        repos = []
        self.assertTrue(os.path.exists(self.fs_root + "/repos.xml"))
        record = ReposRecordFile(self.fs_root + "/repos.xml")
        record_repos = record.read()
        for repo in record_repos:
            repos.append(repo.url)
Esempio n. 5
0
    def restore(self, basedir):
        '''restore yum configuration and repositories'''
        # return if we cannot find require files
        if not os.path.isdir(basedir + "/etc/yum.repos.d"):
            return

        # read files from the record file
        # tho we don't do anything with this info here
        record = ReposRecordFile(basedir + "/repos.xml")
        repos = record.read()

        # first restore yum configuration
        SFile("etc/yum.conf").copy_to(self.fs_root, path_prefix=basedir)

        # then restore individual repos
        for yum_repo in FileManager.get_all_files(include=[basedir + "/etc/yum.repos.d"]):
            partial_path = yum_repo.replace(basedir + "/" , "")
            SFile(partial_path).copy_to(self.fs_root, path_prefix=basedir)