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)
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)
def testWriteReposRecordFile(self): file_path = os.path.join(os.path.dirname(__file__), "data/repos-out.xml") repos = [Repo(name='yum.morsi.org', url='http://yum.morsi.org'), Repo(name='apt.morsi.org', url='http://apt.morsi.org')] repo_record_file = ReposRecordFile(file_path) repo_record_file.write(repos) contents = FileManager.read_file(file_path) self.assertEqual("<repos><repo>http://yum.morsi.org</repo><repo>http://apt.morsi.org</repo></repos>", contents) os.remove(file_path)
def backup(self, basedir, include=[], exclude=[]): '''backup apt configuration and repositories''' # backup the apt config in /etc/apt repos = [] for apt_conf in FileManager.get_all_files(include=['/etc/apt']): SFile(apt_conf).copy_to(basedir) repos.append(Repo()) # FIXME parse repo info # write record file to basedir record = ReposRecordFile(basedir + "/repos.xml") record.write(repos)
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)
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)
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)
def backup(self, basedir, include=[], exclude=[]): '''backup yum configuration and repositories''' # first backup the yum config SFile("/etc/yum.conf").copy_to(basedir) # then backup the individual repo files repos = [] for yum_repo in FileManager.get_all_files(include=['/etc/yum.repos.d']): SFile(yum_repo).copy_to(basedir) # parse/extract repo info baseurl = re.compile('baseurl=(.*)\n') mirrorlist = re.compile('mirrorlist=(.*)\n') contents = FileManager.read_file(yum_repo) for match in baseurl.findall(contents): repos.append(Repo(url=match)) for match in mirrorlist.findall(contents): repos.append(Repo(url=match)) # write record file to basedir record = ReposRecordFile(basedir + "/repos.xml") record.write(repos)