1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-12-11 11:41:33 +02:00
pg_probackup/tests/init_test.py

100 lines
4.5 KiB
Python
Raw Normal View History

import os
2017-06-27 11:43:45 +02:00
import unittest
2017-06-27 07:42:52 +02:00
from .helpers.ptrack_helpers import dir_files, ProbackupTest, ProbackupException
2017-07-12 16:28:28 +02:00
module_name = 'init'
2017-07-12 16:28:28 +02:00
class InitTest(ProbackupTest, unittest.TestCase):
2017-05-03 13:14:48 +02:00
# @unittest.skip("skip")
# @unittest.expectedFailure
2017-06-07 16:52:07 +02:00
def test_success(self):
2017-05-03 13:14:48 +02:00
"""Success normal init"""
fname = self.id().split(".")[3]
2017-07-12 16:28:28 +02:00
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
node = self.make_simple_node(base_dir=os.path.join(module_name, fname, 'node'))
2017-06-20 12:57:23 +02:00
self.init_pb(backup_dir)
2017-05-03 13:14:48 +02:00
self.assertEqual(
2017-06-20 12:57:23 +02:00
dir_files(backup_dir),
2017-06-07 16:52:07 +02:00
['backups', 'wal']
2017-05-03 13:14:48 +02:00
)
2017-06-20 12:57:23 +02:00
self.add_instance(backup_dir, 'node', node)
2017-07-12 16:28:28 +02:00
self.assertEqual("INFO: Instance 'node' successfully deleted\n", self.del_instance(backup_dir, 'node'),
2017-06-07 16:52:07 +02:00
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(self.output), self.cmd))
2017-07-12 16:28:28 +02:00
# Show non-existing instance
2017-06-07 16:52:07 +02:00
try:
2017-06-20 12:57:23 +02:00
self.show_pb(backup_dir, 'node')
2017-06-07 16:52:07 +02:00
self.assertEqual(1, 0, 'Expecting Error due to show of non-existing instance. Output: {0} \n CMD: {1}'.format(
repr(self.output), self.cmd))
2017-06-27 07:42:52 +02:00
except ProbackupException as e:
2017-06-07 16:52:07 +02:00
self.assertEqual(e.message,
2017-06-20 12:57:23 +02:00
"ERROR: Instance 'node' does not exist in this backup catalog\n",
2017-06-07 16:52:07 +02:00
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(e.message, self.cmd))
2017-07-12 16:28:28 +02:00
# Delete non-existing instance
try:
self.del_instance(backup_dir, 'node1')
self.assertEqual(1, 0, 'Expecting Error due to delete of non-existing instance. Output: {0} \n CMD: {1}'.format(
repr(self.output), self.cmd))
except ProbackupException as e:
self.assertEqual(e.message,
"ERROR: Instance 'node1' does not exist in this backup catalog\n",
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(e.message, self.cmd))
# Add instance without pgdata
try:
self.run_pb([
"add-instance",
"--instance=node1",
"-B", backup_dir
])
self.assertEqual(1, 0, 'Expecting Error due to adding instance without pgdata. Output: {0} \n CMD: {1}'.format(
repr(self.output), self.cmd))
except ProbackupException as e:
self.assertEqual(e.message,
"ERROR: Required parameter not specified: PGDATA (-D, --pgdata)\n",
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(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-06-27 07:42:52 +02:00
# @unittest.skip("skip")
2017-06-07 16:52:07 +02:00
def test_already_exist(self):
2017-05-03 13:14:48 +02:00
"""Failure with backup catalog already existed"""
fname = self.id().split(".")[3]
2017-07-12 16:28:28 +02:00
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
node = self.make_simple_node(base_dir=os.path.join(module_name, fname, 'node'))
2017-06-20 12:57:23 +02:00
self.init_pb(backup_dir)
2017-05-03 13:14:48 +02:00
try:
2017-06-20 12:57:23 +02:00
self.show_pb(backup_dir, 'node')
2017-06-07 16:52:07 +02:00
self.assertEqual(1, 0, 'Expecting Error due to initialization in non-empty directory. Output: {0} \n CMD: {1}'.format(
repr(self.output), self.cmd))
2017-06-27 07:42:52 +02:00
except ProbackupException as e:
2017-06-07 16:52:07 +02:00
self.assertEqual(e.message,
2017-06-20 12:57:23 +02:00
"ERROR: Instance 'node' does not exist in this backup catalog\n",
2017-06-07 16:52:07 +02:00
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
2017-05-03 13:14:48 +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)
2017-06-27 07:42:52 +02:00
# @unittest.skip("skip")
2017-06-07 16:52:07 +02:00
def test_abs_path(self):
2017-05-03 13:14:48 +02:00
"""failure with backup catalog should be given as absolute path"""
fname = self.id().split(".")[3]
2017-07-12 16:28:28 +02:00
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
node = self.make_simple_node(base_dir=os.path.join(module_name, fname, 'node'))
2017-05-03 13:14:48 +02:00
try:
2017-06-27 11:43:45 +02:00
self.run_pb(["init", "-B", os.path.relpath("%s/backup" % node.base_dir, self.dir_path)])
2017-06-07 16:52:07 +02:00
self.assertEqual(1, 0, 'Expecting Error due to initialization with non-absolute path in --backup-path. Output: {0} \n CMD: {1}'.format(
repr(self.output), self.cmd))
2017-06-27 07:42:52 +02:00
except ProbackupException as e:
2017-06-07 16:52:07 +02:00
self.assertEqual(e.message,
"ERROR: -B, --backup-path must be an absolute path\n",
'\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)