Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expect_error to pg_upgrade #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions testgres/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@ def set_auto_conf(self, options, config='postgresql.auto.conf', rm_options={}):

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

def upgrade_from(self, old_node, options=None):
def upgrade_from(self, old_node, options=None, expect_error=False):
"""
Upgrade this node from an old node using pg_upgrade.

Expand Down Expand Up @@ -1656,10 +1656,11 @@ def upgrade_from(self, old_node, options=None):
"--new-datadir", self.data_dir,
"--old-port", str(old_node.port),
"--new-port", str(self.port),
"--copy"
]
upgrade_command += options

return self.os_ops.exec_command(upgrade_command)
return self.os_ops.exec_command(upgrade_command, expect_error=expect_error)

def _get_bin_path(self, filename):
if self.bin_dir:
Expand Down
13 changes: 9 additions & 4 deletions testgres/operations/local_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@

CMD_TIMEOUT_SEC = 60
error_markers = [b'error', b'Permission denied', b'fatal']
err_out_markers = [b'Failure']


def has_errors(output):
def has_errors(output=None, error=None):
if output:
if isinstance(output, str):
output = output.encode(get_default_encoding())
return any(marker in output for marker in error_markers)
return any(marker in output for marker in err_out_markers)
if error:
if isinstance(error, str):
error = error.encode(get_default_encoding())
return any(marker in error for marker in error_markers)
return False


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

if verbose:
return process.returncode, output, error
Expand Down