Skip to content

Commit

Permalink
Fix remotedb backup expected files (#12645)
Browse files Browse the repository at this point in the history
(cherry picked from commit e075c5e)
  • Loading branch information
lpramuk authored and web-flow committed Sep 19, 2023
1 parent a7bf467 commit 6b79456
Showing 1 changed file with 24 additions and 33 deletions.
57 changes: 24 additions & 33 deletions tests/foreman/maintain/test_backup_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@


BASIC_FILES = {"config_files.tar.gz", ".config.snar", "metadata.yml"}
OFFLINE_FILES = {"pgsql_data.tar.gz", ".postgres.snar"} | BASIC_FILES
ONLINE_SAT_FILES = {"candlepin.dump", "foreman.dump", "pulpcore.dump"} | BASIC_FILES
ONLINE_CAPS_FILES = {"pulpcore.dump"} | BASIC_FILES
CONTENT_FILES = {"pulp_data.tar", ".pulp.snar"}
OFFLINE_FILES = {"pgsql_data.tar.gz", ".postgres.snar"}
ONLINE_SAT_FILES = {"candlepin.dump", "foreman.dump", "pulpcore.dump"}
ONLINE_CAPS_FILES = {"pulpcore.dump"}


NODIR_MSG = "ERROR: parameter 'BACKUP_DIR': no value provided"
Expand All @@ -46,22 +46,18 @@
assert_msg = "Some required backup files are missing"


def get_exp_files(sat_maintain, backup_type):
def get_exp_files(sat_maintain, backup_type, skip_pulp=False):
if type(sat_maintain) is Satellite:
if sat_maintain.is_remote_db():
expected_files = BASIC_FILES | ONLINE_SAT_FILES
else:
expected_files = (
BASIC_FILES | OFFLINE_FILES
if backup_type == 'offline'
else BASIC_FILES | ONLINE_SAT_FILES
)
else:
# for remote db you get always online backup regardless specified backup type
expected_files = (
BASIC_FILES | OFFLINE_FILES
if backup_type == 'offline'
else BASIC_FILES | ONLINE_CAPS_FILES
ONLINE_SAT_FILES
if backup_type == 'online' or sat_maintain.is_remote_db()
else OFFLINE_FILES
)
else:
expected_files = ONLINE_CAPS_FILES if backup_type == 'online' else OFFLINE_FILES
if not skip_pulp:
expected_files = expected_files | CONTENT_FILES
return expected_files


Expand Down Expand Up @@ -101,7 +97,7 @@ def test_positive_backup_preserve_directory(
files = [i for i in files if not re.compile(r'^\.*$').search(i)]

expected_files = get_exp_files(sat_maintain, backup_type)
assert set(files).issuperset(expected_files | CONTENT_FILES), assert_msg
assert set(files).issuperset(expected_files), assert_msg


@pytest.mark.include_capsule
Expand Down Expand Up @@ -149,7 +145,7 @@ def test_positive_backup_split_pulp_tar(
files = [i for i in files if not re.compile(r'^\.*$').search(i)]

expected_files = get_exp_files(sat_maintain, backup_type)
assert set(files).issuperset(expected_files | CONTENT_FILES), assert_msg
assert set(files).issuperset(expected_files), assert_msg

# Check the split works
result = sat_maintain.execute(f'du {backup_dir}/pulp_data.tar')
Expand Down Expand Up @@ -193,7 +189,7 @@ def test_positive_backup_capsule_features(
files = [i for i in files if not re.compile(r'^\.*$').search(i)]

expected_files = get_exp_files(sat_maintain, backup_type)
assert set(files).issuperset(expected_files | CONTENT_FILES), assert_msg
assert set(files).issuperset(expected_files), assert_msg


@pytest.mark.include_capsule
Expand Down Expand Up @@ -276,12 +272,12 @@ def test_positive_backup_offline_logical(sat_maintain, setup_backup_tests, modul

if type(sat_maintain) is Satellite:
if sat_maintain.is_remote_db():
expected_files = BASIC_FILES | ONLINE_SAT_FILES
expected_files = ONLINE_SAT_FILES | CONTENT_FILES
else:
expected_files = BASIC_FILES | OFFLINE_FILES | ONLINE_SAT_FILES
expected_files = OFFLINE_FILES | ONLINE_SAT_FILES | CONTENT_FILES
else:
expected_files = BASIC_FILES | OFFLINE_FILES | ONLINE_CAPS_FILES
assert set(files).issuperset(expected_files | CONTENT_FILES), assert_msg
expected_files = OFFLINE_FILES | ONLINE_CAPS_FILES | CONTENT_FILES
assert set(files).issuperset(expected_files), assert_msg


@pytest.mark.include_capsule
Expand Down Expand Up @@ -448,7 +444,7 @@ def test_positive_puppet_backup_restore(
files = [i for i in files if not re.compile(r'^\.*$').search(i)]

expected_files = get_exp_files(sat_maintain, backup_type)
assert set(files).issuperset(expected_files | CONTENT_FILES), assert_msg
assert set(files).issuperset(expected_files), assert_msg

# Run restore
sat_maintain.execute('rm -rf /var/lib/pulp/media/artifact')
Expand Down Expand Up @@ -533,11 +529,8 @@ def test_positive_backup_restore(
files = sat_maintain.execute(f'ls -a {backup_dir}').stdout.split('\n')
files = [i for i in files if not re.compile(r'^\.*$').search(i)]

expected_files = get_exp_files(sat_maintain, backup_type)
if not skip_pulp:
assert set(files).issuperset(expected_files | CONTENT_FILES), assert_msg
else:
assert set(files).issuperset(expected_files), assert_msg
expected_files = get_exp_files(sat_maintain, backup_type, skip_pulp)
assert set(files).issuperset(expected_files), assert_msg

# Run restore
if not skip_pulp:
Expand Down Expand Up @@ -639,10 +632,8 @@ def test_positive_backup_restore_incremental(
files = sat_maintain.execute(f'ls -a {inc_backup_dir}').stdout.split('\n')
files = [i for i in files if not re.compile(r'^\.*$').search(i)]

expected_files = (
BASIC_FILES | OFFLINE_FILES if backup_type == 'offline' else BASIC_FILES | ONLINE_SAT_FILES
)
assert set(files).issuperset(expected_files | CONTENT_FILES), assert_msg
expected_files = get_exp_files(sat_maintain, backup_type)
assert set(files).issuperset(expected_files), assert_msg

# restore initial backup and check system health
result = sat_maintain.cli.Restore.run(
Expand Down

0 comments on commit 6b79456

Please sign in to comment.