예제 #1
0
def main():
    try:
        # read these from config file
        section = "test_size_rotate"
        config_file = "../test_configurations/test_logSupport.yaml"
        config = yaml.load(file(config_file, 'r'))

        log_name = str(config[section]["log_name"])
        extension = str(config[section]["extension"])
        msg_types = str(config[section]["msg_types"])
        max_days = float(config[section]["max_days"])
        min_days = float(config[section]["min_days"])
        max_mbytes = float(config[section]["max_mbytes"])
        backupCount = 5
        compression = ''

        log_dir = "/tmp/%s" % log_name

        logSupport.add_processlog_handler(log_name, log_dir, msg_types, 
                    extension, max_days, min_days, max_mbytes, 
                    backupCount=backupCount, compression=compression)

        log = logging.getLogger(log_name)
        log.info("%s\n" % create_random_string(length=2048))

        return 0
    except:
        return 1
예제 #2
0
    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 at least one minute so that we don't have name collisions on rollover
            time.sleep(62)

        # 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." )
예제 #3
0
    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),
        )
예제 #4
0
def main():
    try:
        # read these from config file
        section = "test_size_rotate"
        config_file = "../test_configurations/test_logSupport.yaml"
        config = yaml.load(file(config_file, 'r'))

        log_name = str(config[section]["log_name"])
        extension = str(config[section]["extension"])
        msg_types = str(config[section]["msg_types"])
        max_days = float(config[section]["max_days"])
        min_days = float(config[section]["min_days"])
        max_mbytes = float(config[section]["max_mbytes"])
        backupCount = 5
        compression = ''

        log_dir = "/tmp/%s" % log_name

        logSupport.add_processlog_handler(log_name,
                                          log_dir,
                                          msg_types,
                                          extension,
                                          max_days,
                                          min_days,
                                          max_mbytes,
                                          backupCount=backupCount,
                                          compression=compression)

        log = logging.getLogger(log_name)
        log.info("%s\n" % create_random_string(length=2048))

        return 0
    except:
        return 1
예제 #5
0
 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
예제 #6
0
    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)
예제 #7
0
    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)