2017-05-22 13:17:43 +02:00
|
|
|
import os
|
2017-06-27 07:42:52 +02:00
|
|
|
import unittest
|
2019-07-14 12:46:28 +02:00
|
|
|
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
|
2017-05-22 13:17:43 +02:00
|
|
|
from datetime import datetime, timedelta
|
|
|
|
import subprocess
|
2019-08-09 12:24:55 +02:00
|
|
|
from time import sleep
|
2017-05-22 13:17:43 +02:00
|
|
|
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
module_name = 'pgpro560'
|
|
|
|
|
2017-05-22 13:17:43 +02:00
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
class CheckSystemID(ProbackupTest, unittest.TestCase):
|
2017-05-22 13:17:43 +02:00
|
|
|
|
|
|
|
# @unittest.skip("skip")
|
|
|
|
# @unittest.expectedFailure
|
|
|
|
def test_pgpro560_control_file_loss(self):
|
|
|
|
"""
|
|
|
|
https://jira.postgrespro.ru/browse/PGPRO-560
|
|
|
|
make node with stream support, delete control file
|
|
|
|
make backup
|
|
|
|
check that backup failed
|
|
|
|
"""
|
|
|
|
fname = self.id().split('.')[3]
|
2018-12-26 21:59:13 +02:00
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
2017-05-22 13:17:43 +02:00
|
|
|
set_replication=True,
|
2019-04-22 19:52:00 +02:00
|
|
|
initdb_params=['--data-checksums'])
|
2018-12-26 21:59:13 +02:00
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
2017-06-27 07:42:52 +02:00
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
2018-12-25 16:48:49 +02:00
|
|
|
node.slow_start()
|
2017-05-22 13:17:43 +02:00
|
|
|
|
2019-07-14 12:46:28 +02:00
|
|
|
file = os.path.join(node.base_dir, 'data', 'global', 'pg_control')
|
2017-05-22 13:17:43 +02:00
|
|
|
os.remove(file)
|
|
|
|
|
|
|
|
try:
|
2017-06-27 07:42:52 +02:00
|
|
|
self.backup_node(backup_dir, 'node', node, options=['--stream'])
|
|
|
|
# we should die here because exception is what we expect to happen
|
2019-07-14 12:46:28 +02:00
|
|
|
self.assertEqual(
|
|
|
|
1, 0,
|
|
|
|
"Expecting Error because pg_control was deleted.\n "
|
|
|
|
"Output: {0} \n CMD: {1}".format(repr(self.output), self.cmd))
|
2017-06-27 07:42:52 +02:00
|
|
|
except ProbackupException as e:
|
2017-05-22 13:17:43 +02:00
|
|
|
self.assertTrue(
|
2020-03-14 13:35:57 +02:00
|
|
|
'ERROR: Could not open file' in e.message and
|
2019-07-14 12:46:28 +02:00
|
|
|
'pg_control' in e.message,
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(e.message), self.cmd))
|
2017-06-27 07:42:52 +02:00
|
|
|
|
|
|
|
# Clean after yourself
|
2017-07-12 16:28:28 +02:00
|
|
|
self.del_test_dir(module_name, fname)
|
2017-05-22 13:17:43 +02:00
|
|
|
|
|
|
|
def test_pgpro560_systemid_mismatch(self):
|
|
|
|
"""
|
|
|
|
https://jira.postgrespro.ru/browse/PGPRO-560
|
|
|
|
make node1 and node2
|
|
|
|
feed to backup PGDATA from node1 and PGPORT from node2
|
|
|
|
check that backup failed
|
|
|
|
"""
|
|
|
|
fname = self.id().split('.')[3]
|
2018-12-26 21:59:13 +02:00
|
|
|
node1 = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node1'),
|
2017-05-22 13:17:43 +02:00
|
|
|
set_replication=True,
|
2019-04-22 19:52:00 +02:00
|
|
|
initdb_params=['--data-checksums'])
|
2018-12-26 21:59:13 +02:00
|
|
|
|
2018-12-25 16:48:49 +02:00
|
|
|
node1.slow_start()
|
2018-12-26 21:59:13 +02:00
|
|
|
node2 = self.make_simple_node(
|
|
|
|
base_dir=os.path.join(module_name, fname, 'node2'),
|
2017-05-22 13:17:43 +02:00
|
|
|
set_replication=True,
|
2019-04-22 19:52:00 +02:00
|
|
|
initdb_params=['--data-checksums'])
|
2018-12-26 21:59:13 +02:00
|
|
|
|
2018-12-25 16:48:49 +02:00
|
|
|
node2.slow_start()
|
2017-06-27 07:42:52 +02:00
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
2017-06-27 07:42:52 +02:00
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node1', node1)
|
2017-05-22 13:17:43 +02:00
|
|
|
|
|
|
|
try:
|
2017-11-30 08:14:46 +02:00
|
|
|
self.backup_node(backup_dir, 'node1', node2, options=['--stream'])
|
2017-06-27 07:42:52 +02:00
|
|
|
# we should die here because exception is what we expect to happen
|
2019-07-14 12:46:28 +02:00
|
|
|
self.assertEqual(
|
|
|
|
1, 0,
|
|
|
|
"Expecting Error because of SYSTEM ID mismatch.\n "
|
|
|
|
"Output: {0} \n CMD: {1}".format(repr(self.output), self.cmd))
|
2017-06-27 07:42:52 +02:00
|
|
|
except ProbackupException as e:
|
2019-07-14 12:46:28 +02:00
|
|
|
if self.get_version(node1) > 90600:
|
|
|
|
self.assertTrue(
|
|
|
|
'ERROR: Backup data directory was '
|
|
|
|
'initialized for system id' in e.message and
|
|
|
|
'but connected instance system id is' in e.message,
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(e.message), self.cmd))
|
|
|
|
else:
|
|
|
|
self.assertIn(
|
|
|
|
'ERROR: System identifier mismatch. '
|
|
|
|
'Connected PostgreSQL instance has system id',
|
|
|
|
e.message,
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(e.message), self.cmd))
|
2017-06-27 07:42:52 +02:00
|
|
|
|
2019-08-09 12:24:55 +02:00
|
|
|
sleep(1)
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
try:
|
2019-07-14 12:46:28 +02:00
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node1', node2,
|
|
|
|
data_dir=node1.data_dir, options=['--stream'])
|
2017-07-12 16:28:28 +02:00
|
|
|
# we should die here because exception is what we expect to happen
|
2019-07-14 12:46:28 +02:00
|
|
|
self.assertEqual(
|
|
|
|
1, 0,
|
|
|
|
"Expecting Error because of of SYSTEM ID mismatch.\n "
|
|
|
|
"Output: {0} \n CMD: {1}".format(repr(self.output), self.cmd))
|
2017-07-12 16:28:28 +02:00
|
|
|
except ProbackupException as e:
|
2019-07-14 12:46:28 +02:00
|
|
|
if self.get_version(node1) > 90600:
|
|
|
|
self.assertTrue(
|
|
|
|
'ERROR: Backup data directory was initialized '
|
|
|
|
'for system id' in e.message and
|
|
|
|
'but connected instance system id is' in e.message,
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(e.message), self.cmd))
|
|
|
|
else:
|
|
|
|
self.assertIn(
|
|
|
|
'ERROR: System identifier mismatch. '
|
|
|
|
'Connected PostgreSQL instance has system id',
|
|
|
|
e.message,
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(e.message), self.cmd))
|
2017-07-12 16:28:28 +02:00
|
|
|
|
2017-06-27 07:42:52 +02:00
|
|
|
# Clean after yourself
|
2017-07-12 16:28:28 +02:00
|
|
|
self.del_test_dir(module_name, fname)
|