2016-12-09 20:30:22 +02:00
|
|
|
import unittest
|
2017-06-20 12:57:23 +02:00
|
|
|
import os
|
2017-06-27 07:42:52 +02:00
|
|
|
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
|
2016-12-09 20:30:22 +02:00
|
|
|
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
module_name = 'option'
|
|
|
|
|
2016-12-09 20:30:22 +02:00
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
class OptionTest(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-05-03 13:14:48 +02:00
|
|
|
def test_help_1(self):
|
|
|
|
"""help options"""
|
2018-08-02 10:57:39 +02:00
|
|
|
self.maxDiff = None
|
2017-05-03 13:14:48 +02:00
|
|
|
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')
|
2017-06-20 12:57:23 +02:00
|
|
|
with open(os.path.join(self.dir_path, "expected/option_help.out"), "rb") as help_out:
|
2017-05-03 13:14:48 +02:00
|
|
|
self.assertEqual(
|
|
|
|
self.run_pb(["--help"]),
|
2017-06-27 07:42:52 +02:00
|
|
|
help_out.read().decode("utf-8")
|
2017-05-03 13:14:48 +02:00
|
|
|
)
|
|
|
|
|
2017-06-20 12:57:23 +02:00
|
|
|
# @unittest.skip("skip")
|
2017-05-03 13:14:48 +02:00
|
|
|
def test_version_2(self):
|
|
|
|
"""help options"""
|
|
|
|
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')
|
2017-06-20 12:57:23 +02:00
|
|
|
with open(os.path.join(self.dir_path, "expected/option_version.out"), "rb") as version_out:
|
2017-12-13 10:15:42 +02:00
|
|
|
self.assertIn(
|
|
|
|
version_out.read().decode("utf-8"),
|
|
|
|
self.run_pb(["--version"])
|
2017-05-03 13:14:48 +02:00
|
|
|
)
|
|
|
|
|
2017-06-20 12:57:23 +02:00
|
|
|
# @unittest.skip("skip")
|
2017-05-03 13:14:48 +02:00
|
|
|
def test_without_backup_path_3(self):
|
|
|
|
"""backup command failure without backup mode option"""
|
|
|
|
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')
|
2017-05-03 13:14:48 +02:00
|
|
|
try:
|
|
|
|
self.run_pb(["backup", "-b", "full"])
|
2017-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(1, 0, "Expecting Error because '-B' parameter is not specified.\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-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(e.message, 'ERROR: required parameter not specified: BACKUP_PATH (-B, --backup-path)\n',
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
|
2017-05-03 13:14:48 +02:00
|
|
|
|
2017-06-20 12:57:23 +02:00
|
|
|
|
|
|
|
# @unittest.skip("skip")
|
2017-05-03 13:14:48 +02:00
|
|
|
def test_options_4(self):
|
|
|
|
"""check options test"""
|
|
|
|
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-05-01 12:41:17 +02:00
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node".format(module_name, fname))
|
2017-06-20 12:57:23 +02:00
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
# backup command failure without instance option
|
|
|
|
try:
|
|
|
|
self.run_pb(["backup", "-B", backup_dir, "-D", node.data_dir, "-b", "full"])
|
|
|
|
self.assertEqual(1, 0, "Expecting Error because 'instance' parameter is not specified.\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-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(e.message,
|
|
|
|
'ERROR: required parameter not specified: --instance\n',
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
|
2017-05-03 13:14:48 +02:00
|
|
|
|
|
|
|
# backup command failure without backup mode option
|
|
|
|
try:
|
2017-06-20 12:57:23 +02:00
|
|
|
self.run_pb(["backup", "-B", backup_dir, "--instance=node", "-D", node.data_dir])
|
|
|
|
self.assertEqual(1, 0, "Expecting Error because '-b' parameter is not specified.\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-12-13 10:15:42 +02:00
|
|
|
self.assertIn('ERROR: required parameter not specified: BACKUP_MODE (-b, --backup-mode)',
|
|
|
|
e.message,
|
2017-06-20 12:57:23 +02:00
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
|
2017-05-03 13:14:48 +02:00
|
|
|
|
|
|
|
# backup command failure with invalid backup mode option
|
|
|
|
try:
|
2017-06-20 12:57:23 +02:00
|
|
|
self.run_pb(["backup", "-B", backup_dir, "--instance=node", "-b", "bad"])
|
|
|
|
self.assertEqual(1, 0, "Expecting Error because backup-mode parameter is invalid.\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-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(e.message,
|
|
|
|
'ERROR: invalid backup-mode "bad"\n',
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
# delete failure without delete options
|
2017-05-03 13:14:48 +02:00
|
|
|
try:
|
2017-06-20 12:57:23 +02:00
|
|
|
self.run_pb(["delete", "-B", backup_dir, "--instance=node"])
|
2017-05-03 13:14:48 +02:00
|
|
|
# we should die here because exception is what we expect to happen
|
2017-07-12 16:28:28 +02:00
|
|
|
self.assertEqual(1, 0, "Expecting Error because delete options are omitted.\n Output: {0} \n CMD: {1}".format(
|
2017-06-20 12:57:23 +02:00
|
|
|
repr(self.output), self.cmd))
|
2017-06-27 07:42:52 +02:00
|
|
|
except ProbackupException as e:
|
2017-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(e.message,
|
2017-07-12 16:28:28 +02:00
|
|
|
'ERROR: You must specify at least one of the delete options: --expired |--wal |--backup_id\n',
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
|
|
|
|
|
|
|
|
|
|
|
|
# delete failure without ID
|
|
|
|
try:
|
|
|
|
self.run_pb(["delete", "-B", backup_dir, "--instance=node", '-i'])
|
|
|
|
# we should die here because exception is what we expect to happen
|
|
|
|
self.assertEqual(1, 0, "Expecting Error because backup ID is omitted.\n Output: {0} \n CMD: {1}".format(
|
|
|
|
repr(self.output), self.cmd))
|
|
|
|
except ProbackupException as e:
|
|
|
|
self.assertTrue("option requires an argument -- 'i'" in e.message,
|
2017-06-20 12:57:23 +02:00
|
|
|
'\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
|
2018-05-03 13:12:19 +02:00
|
|
|
self.del_test_dir(module_name, fname)
|
2017-06-27 07:42:52 +02:00
|
|
|
|
2018-05-01 12:41:17 +02:00
|
|
|
# @unittest.skip("skip")
|
2017-06-20 12:57:23 +02:00
|
|
|
def test_options_5(self):
|
|
|
|
"""check options test"""
|
|
|
|
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-05-01 12:41:17 +02:00
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node".format(module_name, fname),
|
|
|
|
pg_options={
|
|
|
|
'wal_level': 'logical',
|
|
|
|
'max_wal_senders': '2'})
|
2017-06-20 12:57:23 +02:00
|
|
|
|
2017-06-27 07:42:52 +02:00
|
|
|
self.assertEqual("INFO: Backup catalog '{0}' successfully inited\n".format(backup_dir),
|
|
|
|
self.init_pb(backup_dir))
|
2017-06-20 12:57:23 +02:00
|
|
|
self.add_instance(backup_dir, 'node', node)
|
2017-05-03 13:14:48 +02:00
|
|
|
|
|
|
|
node.start()
|
|
|
|
|
|
|
|
# syntax error in pg_probackup.conf
|
2017-06-20 12:57:23 +02:00
|
|
|
with open(os.path.join(backup_dir, "backups", "node", "pg_probackup.conf"), "a") as conf:
|
2017-05-03 13:14:48 +02:00
|
|
|
conf.write(" = INFINITE\n")
|
|
|
|
try:
|
2017-06-20 12:57:23 +02:00
|
|
|
self.backup_node(backup_dir, 'node', node)
|
2017-05-03 13:14:48 +02:00
|
|
|
# we should die here because exception is what we expect to happen
|
2017-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(1, 0, "Expecting Error because of garbage in pg_probackup.conf.\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-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(e.message,
|
|
|
|
'ERROR: syntax error in " = INFINITE"\n',
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
|
2017-05-03 13:14:48 +02:00
|
|
|
|
2017-06-20 12:57:23 +02:00
|
|
|
self.clean_pb(backup_dir)
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
2017-05-03 13:14:48 +02:00
|
|
|
|
|
|
|
# invalid value in pg_probackup.conf
|
2017-06-20 12:57:23 +02:00
|
|
|
with open(os.path.join(backup_dir, "backups", "node", "pg_probackup.conf"), "a") as conf:
|
2017-05-03 13:14:48 +02:00
|
|
|
conf.write("BACKUP_MODE=\n")
|
|
|
|
|
|
|
|
try:
|
2017-06-20 12:57:23 +02:00
|
|
|
self.backup_node(backup_dir, 'node', node, backup_type=None),
|
2017-05-03 13:14:48 +02:00
|
|
|
# we should die here because exception is what we expect to happen
|
2017-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(1, 0, "Expecting Error because of invalid backup-mode in pg_probackup.conf.\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-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(e.message,
|
|
|
|
'ERROR: invalid backup-mode ""\n',
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
|
2017-05-03 13:14:48 +02:00
|
|
|
|
2017-06-20 12:57:23 +02:00
|
|
|
self.clean_pb(backup_dir)
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
2017-05-03 13:14:48 +02:00
|
|
|
|
|
|
|
# Command line parameters should override file values
|
2017-06-20 12:57:23 +02:00
|
|
|
with open(os.path.join(backup_dir, "backups", "node", "pg_probackup.conf"), "a") as conf:
|
2017-05-03 13:14:48 +02:00
|
|
|
conf.write("retention-redundancy=1\n")
|
|
|
|
|
2017-06-27 07:42:52 +02:00
|
|
|
self.assertEqual(self.show_config(backup_dir, 'node')['retention-redundancy'], '1')
|
2017-05-03 13:14:48 +02:00
|
|
|
|
|
|
|
# User cannot send --system-identifier parameter via command line
|
|
|
|
try:
|
2017-06-20 12:57:23 +02:00
|
|
|
self.backup_node(backup_dir, 'node', node, options=["--system-identifier", "123"]),
|
2017-05-03 13:14:48 +02:00
|
|
|
# we should die here because exception is what we expect to happen
|
2017-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(1, 0, "Expecting Error because option system-identifier cannot be specified in command line.\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-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(e.message,
|
|
|
|
'ERROR: option system-identifier cannot be specified in command line\n',
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
|
2017-05-03 13:14:48 +02:00
|
|
|
|
|
|
|
# invalid value in pg_probackup.conf
|
2017-06-20 12:57:23 +02:00
|
|
|
with open(os.path.join(backup_dir, "backups", "node", "pg_probackup.conf"), "a") as conf:
|
2017-05-03 13:14:48 +02:00
|
|
|
conf.write("SMOOTH_CHECKPOINT=FOO\n")
|
|
|
|
|
|
|
|
try:
|
2017-06-20 12:57:23 +02:00
|
|
|
self.backup_node(backup_dir, 'node', node)
|
2017-05-03 13:14:48 +02:00
|
|
|
# we should die here because exception is what we expect to happen
|
2017-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(1, 0, "Expecting Error because option -C should be boolean.\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-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(e.message,
|
|
|
|
"ERROR: option -C, --smooth-checkpoint should be a boolean: 'FOO'\n",
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
|
2017-05-03 13:14:48 +02:00
|
|
|
|
2017-06-20 12:57:23 +02:00
|
|
|
self.clean_pb(backup_dir)
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
2017-05-03 13:14:48 +02:00
|
|
|
|
|
|
|
# invalid option in pg_probackup.conf
|
2018-06-09 13:59:35 +02:00
|
|
|
pbconf_path = os.path.join(backup_dir, "backups", "node", "pg_probackup.conf")
|
|
|
|
with open(pbconf_path, "a") as conf:
|
2017-05-03 13:14:48 +02:00
|
|
|
conf.write("TIMELINEID=1\n")
|
|
|
|
|
|
|
|
try:
|
2017-06-20 12:57:23 +02:00
|
|
|
self.backup_node(backup_dir, 'node', node)
|
2017-05-03 13:14:48 +02:00
|
|
|
# we should die here because exception is what we expect to happen
|
2017-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(1, 0, 'Expecting Error because of invalid option "TIMELINEID".\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-06-20 12:57:23 +02:00
|
|
|
self.assertEqual(e.message,
|
2018-06-09 13:59:35 +02:00
|
|
|
'ERROR: invalid option "TIMELINEID" in file "{0}"\n'.format(pbconf_path),
|
2017-06-20 12:57:23 +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)
|