def clean_old_loggger_entries(): """ Task to clean the logger data. """ result = True if not clean_logger(): logger.error("An error occurred while cleaning the logger logs.") result = False return result
def test_0003(self): """ Verify bad error stored in configuration database """ config = Config() config.conf = 'logger_storage_days_lifetime' config.value = 'ascodevida' db.session.begin() db.session.merge(config) db.session.commit() result = clean_logger() self.assertEqual(result, False)
def test_0001(self): """ Verify clean logger disables """ config = Config() config.conf = 'logger_storage_days_lifetime' config.value = 0 db.session.begin() db.session.merge(config) db.session.commit() result = clean_logger() self.assertEqual(result, True)
def test_0002(self, mock_delete_raw): """ Verify correct exit after error getting conf """ mock_delete_raw.return_value = True, "[]" config = Config() config.conf = 'logger_storage_days_lifetime' config.value = 10 db.session.begin() db.session.merge(config) db.session.commit() result = clean_logger() self.assertEqual(result, True) self.assertTrue(mock_delete_raw.called)
def make_backup(bk_type): """Make the backup and return the result""" current_tries = 0 # Current try. all_backups_ok = True result, systems = get_systems('Sensor') if not result: notifier.error("An error occurred while making the Backup [%s]. Cant' retrieve the systems " % bk_type) return False result, local_system_ip = get_system_ip_from_local(local_loopback=False) if not result: notifier.error("An error occurred while making the Backup [%s]. Cant' retrieve the systems " % bk_type) return False system_ips = [x[1] for x in systems] if local_system_ip not in system_ips: system_ips.append(local_system_ip) for system_ip in system_ips: backup_error = "" backup_made = False current_tries = 0 while current_tries < MAX_TRIES: try: data = run_backup(target=system_ip, backup_type=bk_type) if data[system_ip]['failures'] > 0 or data[system_ip]['unreachable'] > 0: backup_error = "Backup (%s) Error %s" % (bk_type, data) else: notifier.info("Backup successfully made [%s - %s] " % (system_ip,bk_type)) backup_made = True current_tries=MAX_TRIES+1 except Exception as e: backup_error = "An exception occurred while making the Backup(%s) %s" % (bk_type,str( e)) notifier.error("An exception occurred while making the Backup [%s - %s]" % (system_ip,bk_type)) finally: current_tries+=1 if not backup_made: all_backups_ok = False notifier.error("Backup(%s) Fails: %s" % (bk_type,backup_error)) #TODO: It should throw an alarm # Don't launch the clean logger if backup fails if all_backups_ok: if not clean_logger(): notifier.error("An error occurred while cleaning the logger logs.") return all_backups_ok