Skip to content

Commit a07f106

Browse files
author
vshepard
committed
Add expect_error to pg_upgrade
1 parent 4543f80 commit a07f106

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

testgres/node.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,7 @@ def set_auto_conf(self, options, config='postgresql.auto.conf', rm_options={}):
16271627

16281628
self.os_ops.write(path, auto_conf, truncate=True)
16291629

1630-
def upgrade_from(self, old_node, options=None):
1630+
def upgrade_from(self, old_node, options=None, expect_error=False):
16311631
"""
16321632
Upgrade this node from an old node using pg_upgrade.
16331633
@@ -1656,10 +1656,11 @@ def upgrade_from(self, old_node, options=None):
16561656
"--new-datadir", self.data_dir,
16571657
"--old-port", str(old_node.port),
16581658
"--new-port", str(self.port),
1659+
"--copy"
16591660
]
16601661
upgrade_command += options
16611662

1662-
return self.os_ops.exec_command(upgrade_command)
1663+
return self.os_ops.exec_command(upgrade_command, expect_error=expect_error)
16631664

16641665
def _get_bin_path(self, filename):
16651666
if self.bin_dir:

testgres/operations/local_ops.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@
1919

2020
CMD_TIMEOUT_SEC = 60
2121
error_markers = [b'error', b'Permission denied', b'fatal']
22+
err_out_markers = [b'Failure']
2223

2324

24-
def has_errors(output):
25+
def has_errors(output=None, error=None):
2526
if output:
2627
if isinstance(output, str):
2728
output = output.encode(get_default_encoding())
28-
return any(marker in output for marker in error_markers)
29+
return any(marker in output for marker in err_out_markers)
30+
if error:
31+
if isinstance(error, str):
32+
error = error.encode(get_default_encoding())
33+
return any(marker in error for marker in error_markers)
2934
return False
3035

3136

@@ -107,8 +112,8 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
107112
process, output, error = self._run_command(cmd, shell, input, stdin, stdout, stderr, get_process, timeout, encoding)
108113
if get_process:
109114
return process
110-
if process.returncode != 0 or (has_errors(error) and not expect_error):
111-
self._raise_exec_exception('Utility exited with non-zero code. Error `{}`', cmd, process.returncode, error)
115+
if (process.returncode != 0 or has_errors(output=output, error=error)) and not expect_error:
116+
self._raise_exec_exception('Utility exited with non-zero code. Error `{}`', cmd, process.returncode, error or output)
112117

113118
if verbose:
114119
return process.returncode, output, error

0 commit comments

Comments
 (0)