def test_error_if_timeline_is_malformed(self, bad_timeline): with pytest.raises(CommandException) as exc: xlog.check_archive_usable( [], timeline=bad_timeline, ) assert ("Cannot check WAL archive with malformed timeline %s" % bad_timeline == str(exc.value))
def test_fails_if_existing_wals_malformed(self, wals): timeline = 2 with pytest.raises(WalArchiveContentError) as exc: xlog.check_archive_usable( wals, timeline=timeline, ) assert "Unexpected file %s found in WAL archive" % wals[1] == str( exc.value)
def test_fails_if_timeline_lte_wal_file_timeline( self, wals, timeline, num_expected_illegal_files): with pytest.raises(WalArchiveContentError) as exc: xlog.check_archive_usable( wals, timeline=timeline, ) assert self.EXPECTED_ARCHIVE_CONTENT_ERROR % ( num_expected_illegal_files, num_expected_illegal_files > 1 and "s" or "", timeline, ) == str(exc.value)
def main(args=None): """ The main script entry point :param list[str] args: the raw arguments list. When not provided it defaults to sys.args[1:] """ config = parse_arguments(args) configure_logging(config) try: cloud_interface = get_cloud_interface(config) if not cloud_interface.test_connectivity(): # Deliberately raise an error if we cannot connect raise NetworkErrorExit() # If test is requested, just exit after connectivity test elif config.test: raise SystemExit(0) if not cloud_interface.bucket_exists: # If the bucket does not exist then the check should pass return catalog = CloudBackupCatalog(cloud_interface, config.server_name) wals = list(catalog.get_wal_paths().keys()) check_archive_usable( wals, timeline=config.timeline, ) except WalArchiveContentError as err: logging.error( "WAL archive check failed for server %s: %s", config.server_name, force_str(err), ) raise OperationErrorExit() except Exception as exc: logging.error("Barman cloud WAL archive check exception: %s", force_str(exc)) logging.debug("Exception details:", exc_info=exc) raise GeneralErrorExit()
def test_passes_if_timeline_gt_wal_file_timeline(self, wals, timeline): xlog.check_archive_usable( wals, timeline=timeline, )
def test_passes_if_timeline_with_no_wals(self): xlog.check_archive_usable([], timeline=1)
def test_fails_if_backup_wal_exists(self): with pytest.raises(WalArchiveContentError) as exc: xlog.check_archive_usable( ["000000010000000000000001.00000028.backup"]) assert self.EXPECTED_EMPTY_MESSAGE == str(exc.value)
def test_fails_if_history_exists(self): with pytest.raises(WalArchiveContentError) as exc: xlog.check_archive_usable(["00000002.history"]) assert self.EXPECTED_EMPTY_MESSAGE == str(exc.value)
def test_passes_if_no_wals(self): xlog.check_archive_usable([])