Skip to content

Commit

Permalink
Fix remotedb backup expected files
Browse files Browse the repository at this point in the history
  • Loading branch information
lpramuk committed Sep 18, 2023
1 parent ab21023 commit 68d79c9
Showing 1 changed file with 22 additions and 36 deletions.
58 changes: 22 additions & 36 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,13 @@
assert_msg = "Some required backup files are missing"


def get_exp_files(sat_maintain, backup_type):
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:
expected_files = (
BASIC_FILES | OFFLINE_FILES
if backup_type == 'offline'
else BASIC_FILES | ONLINE_CAPS_FILES
)
def get_exp_files(sat_maintain, backup_type, skip_pulp=False):
is_remote_db = type(sat_maintain) is Satellite and sat_maintain.is_remote_db()
expected_files = (
ONLINE_SAT_FILES if backup_type == 'online' or is_remote_db else OFFLINE_SAT_FILES
)
if not skip_pulp:
expected_files = expected_files | CONTENT_FILES
return expected_files


Expand Down Expand Up @@ -101,7 +92,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 +140,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 +184,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 +267,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 +439,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 +524,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 +627,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 68d79c9

Please sign in to comment.