Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pg_probackup2/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def show(
backup_list.append(backup)

if backup_id is not None:
assert False, "Failed to find backup with ID: {0}".format(backup_id)
raise RuntimeError("Failed to find backup with ID: {0}".format(backup_id))

return backup_list
else:
Expand Down Expand Up @@ -629,7 +629,7 @@ def show(
specific_record[name.strip()] = var

if not specific_record:
assert False, "Failed to find backup with ID: {0}".format(backup_id)
raise RuntimeError("Failed to find backup with ID: {0}".format(backup_id))

return specific_record

Expand Down Expand Up @@ -778,6 +778,13 @@ def set_archiving(
log_level=False, archive_timeout=False,
custom_archive_command=None):

# check instance existing
instances_json = self.show(instance=None, as_json=True, expect_error=False, as_text=True)
instances_data = json.loads(instances_json)
if not any(inst_data.get('instance') == instance for inst_data in instances_data):
raise RuntimeError("Instance '{0}' does not exist. " \
"Please add the instance first using add_instance() or init_pb_node().".format(instance))

# parse postgresql.auto.conf
options = {}
if replica:
Expand Down
25 changes: 22 additions & 3 deletions pg_probackup2/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import pytest

import testgres
from ...pg_probackup2.app import ProbackupApp
from ...pg_probackup2.init_helpers import Init, init_params
from ..storage.fs_backup import FSTestBackupDir
from pg_probackup2.app import ProbackupApp
from pg_probackup2.init_helpers import Init, init_params
from pg_probackup2.storage.fs_backup import FSTestBackupDir


class ProbackupTest:
Expand Down Expand Up @@ -102,3 +102,22 @@ def test_full_backup(self):

# Check if the backup is valid
assert f"INFO: Backup {backup_id} is valid" in out

def test_set_archiving_nonexistent_instance(self):
self.pb.init()

with pytest.raises(AssertionError) as exc_info:
self.pb.set_archiving('nonexistent_instance', None)

assert "Instance 'nonexistent_instance' does not exist" in str(exc_info.value)

def test_set_archiving_existing_instance(self):
node = self.pg_node.make_simple('node', pg_options={"fsync": "off", "synchronous_commit": "off"})

with node:
self.pb.init()
node.slow_start()
self.pb.add_instance('node', node)
self.pb.set_archiving('node', node)

assert "does not exist" not in str(self.pb.test_class.output or "")