2016-12-09 20:30:22 +02:00
|
|
|
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
|
2016-12-09 20:30:22 +02:00
|
|
|
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
module_name = 'init'
|
|
|
|
|
2016-12-09 20:30:22 +02:00
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
class InitTest(ProbackupTest, unittest.TestCase):
|
2017-05-03 13:14:48 +02:00
|
|
|
|
2017-05-22 13:17:43 +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')
|
2018-12-26 21:59:13 +02:00
|
|
|
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)
|
2019-05-01 01:08:51 +02:00
|
|
|
self.assertIn(
|
|
|
|
"INFO: Instance 'node' successfully deleted",
|
|
|
|
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:
|
2019-05-01 01:08:51 +02:00
|
|
|
self.assertIn(
|
|
|
|
"ERROR: Instance 'node' does not exist in this backup catalog",
|
|
|
|
e.message,
|
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:
|
2019-05-01 01:08:51 +02:00
|
|
|
self.assertIn(
|
|
|
|
"ERROR: Instance 'node1' does not exist in this backup catalog",
|
|
|
|
e.message,
|
2017-07-12 16:28:28 +02:00
|
|
|
'\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:
|
2019-05-01 01:08:51 +02:00
|
|
|
self.assertIn(
|
|
|
|
"ERROR: Required parameter not specified: PGDATA (-D, --pgdata)",
|
|
|
|
e.message,
|
2017-07-12 16:28:28 +02:00
|
|
|
'\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')
|
2018-12-26 21:59:13 +02:00
|
|
|
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:
|
2019-05-01 01:08:51 +02:00
|
|
|
self.assertIn(
|
|
|
|
"ERROR: Instance 'node' does not exist in this backup catalog",
|
|
|
|
e.message,
|
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')
|
2018-12-26 21:59:13 +02:00
|
|
|
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:
|
2019-05-01 01:08:51 +02:00
|
|
|
self.assertIn(
|
|
|
|
"ERROR: -B, --backup-path must be an absolute path",
|
|
|
|
e.message,
|
2017-06-07 16:52:07 +02:00
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
|
2016-12-09 20:30:22 +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)
|