Skip to content

Commit

Permalink
Add test for minimum_redundancy with REDUNDANCY policy
Browse files Browse the repository at this point in the history
Adds a test which verifies how minimum_redundancy interacts with the
REDUNDANCY retention policy.

This does not really make sense as a command which a user would run
however it is still a valid retention policy and Barman will apply
it.
  • Loading branch information
mikewallace1979 committed Aug 11, 2023
1 parent fd22c64 commit dc62f21
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/test_barman_cloud_backup_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,72 @@ def test_delete_by_recovery_window_policy_with_redundancy(
get_cloud_interface_mock, backup_metadata, expected_deleted_backups
)

@pytest.mark.parametrize(
("minimum_redundancy", "num_backups_deleted"),
(
# With a minimum_redundancy of zero, three of the four backups should be
# deleted (the newest is retained due to REDUNDANCY 1).
(0, 3),
# With a minimum_redundancy of one, three of the four backups should be
# deleted.
(1, 3),
# With a minimum_redundancy of two, two of the four backups should be
# deleted.
(2, 2),
# With a minimum_redundancy of three, one of the four backups should be
# deleted.
(3, 1),
# With a minimum_redundancy of four, none of the four backups should be
# deleted.
(4, 0),
),
)
@mock.patch("barman.retention_policies.datetime")
@mock.patch("barman.clients.cloud_backup_delete.CloudBackupCatalog")
@mock.patch("barman.clients.cloud_backup_delete.get_cloud_interface")
def test_delete_by_redundancy_policy_with_minimum_redundancy(
self,
get_cloud_interface_mock,
cloud_backup_catalog_mock,
datetime_mock,
minimum_redundancy,
num_backups_deleted,
):
"""
Test that the minimum redundancy value is applied to recovery window
retention policy
"""
# GIVEN a backup catalog with four daily backups and no WALs
out_of_policy_backup_ids = [
"20210723T095432", # Eligible for deletion
"20210724T095432", # Eligible for deletion
"20210725T095432", # Eligible for deletion
"20210726T095432", # Required by REDUNDANCY 1
]
backup_metadata = self._create_backup_metadata(out_of_policy_backup_ids)

# AND a CloudBackupCatalog which returns the backup_info for only those backups
cloud_backup_catalog_mock.return_value = self._create_catalog(backup_metadata)

# WHEN barman-cloud-backup-delete runs, specifying a retention policy of
# `REDUNDANCY 1` and a given minimum_redundancy.
cloud_backup_delete.main(
[
"cloud_storage_url",
"test_server",
"--retention-policy",
"REDUNDANCY 1",
"--minimum-redundancy",
str(minimum_redundancy),
]
)

# THEN only the expected backups are deleted
expected_deleted_backups = out_of_policy_backup_ids[:num_backups_deleted]
self._verify_only_these_backups_deleted(
get_cloud_interface_mock, backup_metadata, expected_deleted_backups
)

@mock.patch("barman.clients.cloud_backup_delete.CloudBackupCatalog")
@mock.patch(
"barman.clients.cloud_backup_delete.get_snapshot_interface_from_backup_info"
Expand Down

0 comments on commit dc62f21

Please sign in to comment.