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 committed Sep 19, 2023
1 parent ff5e818 commit 7b14145
Showing 1 changed file with 23 additions and 38 deletions.
61 changes: 23 additions & 38 deletions tests/foreman/maintain/test_backup_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +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", "pg_globals.dump"}
ONLINE_CAPS_FILES = {"pulpcore.dump"}
REMOTE_SAT_FILES = ONLINE_SAT_FILES - {"pg_globals.dump"}


NODIR_MSG = "ERROR: parameter 'BACKUP_DIR': no value provided"
Expand All @@ -47,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 | REMOTE_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 @@ -102,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 @@ -150,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 @@ -194,7 +189,7 @@ def test_positive_backup_caspule_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 @@ -277,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 | REMOTE_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 @@ -466,11 +461,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 @@ -572,15 +564,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)]

if sat_maintain.is_remote_db():
expected_files = BASIC_FILES | REMOTE_SAT_FILES
else:
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 7b14145

Please sign in to comment.