def test_logSupport_compression(self): section = "test_compression" log, log_dir = self.load_log(section) max_bytes = float(self.config[section]["max_mbytes"]) * 1024.0 * 1024.0 # we want to exceed the max size of the log but stop logging shortly after required_number_of_lines = (max_bytes / 100) + 100 # we are going to force a log rotate at least 7 times for _ in range(0, 8): lines = 0 while lines < required_number_of_lines: log.info(create_random_string(length=100)) lines += 1 # sleep so that we don't have name collisions on rollover time.sleep(30) # There should be 3 compressed backups file_list = os.listdir(log_dir) gzip_list = [i for i in file_list if i.endswith('gz')] # TODO: Check more than the extension (size is smaller or check that file is a correct gzip - magic number?) # e.g.: file = open(f,'rb') # if (file.read(2) == b'\x1f\x8b'): self.assertTrue( len(file_list) == len(gzip_list) + 1, "Log file rotate didn't compress the files.")
def test_backup_count(self): section = "test_backup_count" log, log_dir = self.load_log(section) max_bytes = float(self.config[section]["max_mbytes"]) * 1024.0 * 1024.0 # we want to exceed the max size of the log but stop logging shortly after line_size_bytes = 100 required_number_of_lines = (max_bytes / line_size_bytes) + 100 # we are going to force a log rotate at least 7 times for _ in range(0, 8): lines = 0 while lines < required_number_of_lines: log.info(create_random_string(length=line_size_bytes)) lines += 1 # sleep so that we don't have name collisions on rollover time.sleep(30) self.rotated_log_tests(section, log_dir) # There should be 5 backups and the current log file file_list = os.listdir(log_dir) self.assertTrue( len(file_list) == 6, "Log file rotate didn't clean up properly. Got only %s rotation but expected 6. File list in %s: %s" % (len(file_list), self.log_base_dir, file_list))
def create_archive_file(self): random_file_name = create_random_string() archive_file = "%s/%s.tar.gz" % (self.working_dir, random_file_name) tarball = GlideinTar() for f in self.files: tarball.add_file(f["path"], "/") tarball.create_tar_file(archive_file) self.assertTrue( tarball.is_tarfile(archive_file), "Tarball creation failed. tarball.is_tarfile returned False") return archive_file
def test_logSupport_size_rotate(self): section = "test_size_rotate" log, log_dir = self.load_log(section) max_bytes = float(self.config[section]["max_mbytes"]) * 1024.0 * 1024.0 # we want to exceed the max size of the log but stop logging shortly after required_number_of_lines = (max_bytes / 100) + 100 lines = 0 while lines < required_number_of_lines: log.info(create_random_string(length=100)) lines += 1 self.rotated_log_tests(section, log_dir)
def test_logSupport_time_rotate(self): section = "test_time_rotate" log, log_dir = self.load_log(section) max_lifetime_seconds = float(self.config[section]["max_days"]) * 24 * 3600 sleep_time_seconds = float(self.config[section]["sleep"]) # we want to log enough times to rotate the log and put a few lines into the new file required_number_log_attempts = (max_lifetime_seconds / sleep_time_seconds) + 5 log_attempts = 0 while log_attempts < required_number_log_attempts: log.info(create_random_string(length=100)) log_attempts += 1 time.sleep(sleep_time_seconds) self.rotated_log_tests(section, log_dir)