def compress_and_check_dir(self, extension): hash_map_1 = {} for i in xrange(self.sys_random.randint(10, 20)): if i % 2 == 0: compressdir = tempfile.mkdtemp(dir=self.compressdir) else: compressdir = self.compressdir str_length = self.sys_random.randint(30, 50) fd, filename = tempfile.mkstemp(dir=compressdir, text=True) os.write(fd, data_factory.generate_random_string(str_length)) relative_path = filename.replace(self.compressdir, '') hash_map_1[relative_path] = crypto.hash_file(filename) archive_filename = self.compressdir + extension archive.compress(archive_filename, self.compressdir) archive.uncompress(archive_filename, self.decompressdir) hash_map_2 = {} for root, _, files in os.walk(self.decompressdir): for name in files: file_path = os.path.join(root, name) relative_path = file_path.replace(self.decompressdir, '') hash_map_2[relative_path] = crypto.hash_file(file_path) self.assertEqual(hash_map_1, hash_map_2)
def compress_and_check_dir(self, extension): hash_map_1 = {} for i in xrange(self.sys_random.randint(10, 20)): if i % 2 == 0: compressdir = tempfile.mkdtemp(dir=self.compressdir) else: compressdir = self.compressdir str_length = self.sys_random.randint(30, 50) fd, filename = tempfile.mkstemp(dir=compressdir, text=True) with os.fdopen(fd, 'w') as f: f.write(data_factory.generate_random_string(str_length)) relative_path = filename.replace(self.compressdir, '') hash_map_1[relative_path] = crypto.hash_file(filename) archive_filename = self.compressdir + extension archive.compress(archive_filename, self.compressdir) archive.uncompress(archive_filename, self.decompressdir) hash_map_2 = {} for root, _, files in os.walk(self.decompressdir): for name in files: file_path = os.path.join(root, name) relative_path = file_path.replace(self.decompressdir, '') hash_map_2[relative_path] = crypto.hash_file(file_path) self.assertEqual(hash_map_1, hash_map_2)
def download_tarball(self): ''' Get linux source tarball for compress/decompress ''' url = 'https://git.kernel.org/torvalds/t/linux-5.10-rc2.tar.gz' tarball = self.fetch_asset(self.params.get("linuxsrc_url", default=url)) os.chdir(self.workdir) archive.extract(tarball, self.workdir) archive.compress("%s/linux-5.10-rc2.tar" % self.workdir, self.workdir)
def download_tarball(self): ''' Get linux source tarball for compress/decompress ''' url = 'https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.tar.gz' tarball = self.fetch_asset(self.params.get("linuxsrc_url", default=url)) os.chdir(self.workdir) archive.extract(tarball, self.workdir) archive.compress("%s/linux-src.tar" % self.workdir, self.workdir)
def compress_and_check_file(self, extension): str_length = self.sys_random.randint(30, 50) fd, filename = tempfile.mkstemp(dir=self.basedir, text=True) os.write(fd, data_factory.generate_random_string(str_length)) original_hash = crypto.hash_file(filename) dstfile = filename + extension archive_filename = os.path.join(self.basedir, dstfile) archive.compress(archive_filename, filename) archive.uncompress(archive_filename, self.decompressdir) decompress_file = os.path.join(self.decompressdir, os.path.basename(filename)) decompress_hash = crypto.hash_file(decompress_file) self.assertEqual(original_hash, decompress_hash)
def update_module(self, log, srcdir, src_pkg_dir, pkg_name, tg_pkg_dir, pkg_dirname, remote_ip, username, password, mod, debug_mode): if srcdir is not None: if len(srcdir) != 0: dependency_dir = srcdir + "/dependencies" if os.path.isdir(dependency_dir): self.clean_srcdir(srcdir, log) log.info("Compress source dir to tarball ...") archive.compress(src_pkg_dir + pkg_name, srcdir) remoter = remote.RemoteRunner(host=remote_ip, username=username, password=password) result = remoter.run("rm -rf " + tg_pkg_dir) result = \ remoter.run("mkdir -p " + tg_pkg_dir + pkg_dirname) log.info("Copy %s to %s %s ..." % (src_pkg_dir + pkg_name, remote_ip, tg_pkg_dir)) remote.scp_to_remote(remote_ip, 22, username, password, src_pkg_dir + pkg_name, tg_pkg_dir) log.info("Decompress tarball %s on %s ..." % (tg_pkg_dir + pkg_name, remote_ip)) result = remoter.run("tar xvf " + tg_pkg_dir + pkg_name + " -C " + tg_pkg_dir + "/" + pkg_dirname) log.info("Update role %s %s on %s ... " % ('slave', mod, remote_ip)) result = remoter.run("cd " + tg_pkg_dir + pkg_dirname + "; ./install.sh -m " + mod + " -r " + "slave " + "-o " + "update " + debug_mode, timeout=3600) if result.exit_status == 0: log.info("Success") return True else: log.info("Failed") return False else: log.info( "Fault source dir, there is not dependencies dir.") else: log.info("Source dir does has vaule.") else: log.info("Parameter fault, give the source dir.")
def render(self, result, job): if job.config.get('archive', False): archive.compress("%s.zip" % job.logdir, job.logdir)
def render(self, result, job): if job.config.get('run.results.archive'): archive.compress("%s.zip" % job.logdir, job.logdir)
def render(self, result, job): if getattr(job.args, 'archive', False): archive.compress("%s.zip" % job.logdir, job.logdir)
def render(self, result, job): if job.config.get("run.results.archive"): archive.compress(f"{job.logdir}.zip", job.logdir)