Skip to content

Commit 070d7c3

Browse files
author
Stepan Neretin
committed
PBCKP-2912: add sanity check in set_archiving(instance should exists)
1 parent 1ab5e9f commit 070d7c3

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

pg_probackup2/app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,13 @@ def set_archiving(
778778
log_level=False, archive_timeout=False,
779779
custom_archive_command=None):
780780

781+
# check instance existing
782+
instances_json = self.show(instance=None, as_json=True, expect_error=False, as_text=True)
783+
instances_data = json.loads(instances_json)
784+
if not any(inst_data.get('instance') == instance for inst_data in instances_data):
785+
assert False, "Instance '{0}' does not exist. " \
786+
"Please add the instance first using add_instance() or init_pb_node().".format(instance)
787+
781788
# parse postgresql.auto.conf
782789
options = {}
783790
if replica:

pg_probackup2/tests/test_basic.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import pytest
66

77
import testgres
8-
from ...pg_probackup2.app import ProbackupApp
9-
from ...pg_probackup2.init_helpers import Init, init_params
10-
from ..storage.fs_backup import FSTestBackupDir
8+
from pg_probackup2.app import ProbackupApp
9+
from pg_probackup2.init_helpers import Init, init_params
10+
from pg_probackup2.storage.fs_backup import FSTestBackupDir
1111

1212

1313
class ProbackupTest:
@@ -102,3 +102,22 @@ def test_full_backup(self):
102102

103103
# Check if the backup is valid
104104
assert f"INFO: Backup {backup_id} is valid" in out
105+
106+
def test_set_archiving_nonexistent_instance(self):
107+
self.pb.init()
108+
109+
with pytest.raises(AssertionError) as exc_info:
110+
self.pb.set_archiving('nonexistent_instance', None)
111+
112+
assert "Instance 'nonexistent_instance' does not exist" in str(exc_info.value)
113+
114+
def test_set_archiving_existing_instance(self):
115+
node = self.pg_node.make_simple('node', pg_options={"fsync": "off", "synchronous_commit": "off"})
116+
117+
with node:
118+
self.pb.init()
119+
node.slow_start()
120+
self.pb.add_instance('node', node)
121+
self.pb.set_archiving('node', node)
122+
123+
assert "does not exist" not in str(self.pb.test_class.output or "")

0 commit comments

Comments
 (0)