Skip to content
Merged
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
11 changes: 9 additions & 2 deletions src/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@

from testgres.operations.os_ops import OsOperations

from . import utils

from .utils import \
get_bin_path2, \
execute_utility2, \
clean_on_error


Expand Down Expand Up @@ -86,7 +87,13 @@ def __init__(self,
"-X", xlog_method.value
] # yapf: disable
_params += options
execute_utility2(self.os_ops, _params, self.log_file)

utils.execute_utility3(
self.os_ops,
_params,
self.log_file,
)
return

def __enter__(self):
return self
Expand Down
21 changes: 14 additions & 7 deletions src/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@

from .defaults import generate_system_id

from . import utils

from .exceptions import \
InitNodeException, \
ExecUtilException

from .utils import \
get_bin_path2, \
execute_utility2

from testgres.operations.local_ops import LocalOperations
from testgres.operations.os_ops import OsOperations

Expand All @@ -39,13 +37,17 @@ def make_utility_path(name):
if bin_path:
return os_ops.build_path(bin_path, name)

return get_bin_path2(os_ops, name)
return utils.get_bin_path2(os_ops, name)

def call_initdb(initdb_dir, log=logfile):
try:
initdb_path = make_utility_path("initdb")
_params = [initdb_path, "-D", initdb_dir, "-N"]
execute_utility2(os_ops, _params + (params or []), log)
utils.execute_utility3(
os_ops,
_params + (params or []),
log,
)
except ExecUtilException as e:
raise_from(InitNodeException("Failed to run initdb"), e)

Expand Down Expand Up @@ -78,7 +80,12 @@ def call_initdb(initdb_dir, log=logfile):

# XXX: build new WAL segment with our system id
_params = [make_utility_path("pg_resetwal"), "-D", data_dir, "-f"]
execute_utility2(os_ops, _params, logfile)

utils.execute_utility3(
os_ops,
_params,
logfile,
)

except ExecUtilException as e:
msg = "Failed to reset WAL for system id"
Expand Down
80 changes: 63 additions & 17 deletions src/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
PgVer, \
eprint, \
get_pg_version2, \
execute_utility2, \
options_string, \
clean_on_error

Expand Down Expand Up @@ -1093,11 +1092,16 @@ def get_control_data(self):
_params += ["-D"] if self._pg_version >= PgVer('9.5') else []
_params += [self.data_dir]

data = execute_utility2(self._os_ops, _params, self.utils_log_file)
exec_r = utils.execute_utility3(
self._os_ops,
_params,
self.utils_log_file,
)
assert type(exec_r.stdout) is str

out_dict = {}

for line in data.splitlines():
for line in exec_r.stdout.splitlines():
key, _, value = line.partition(':')
out_dict[key.strip()] = value.strip()

Expand Down Expand Up @@ -1248,10 +1252,17 @@ def _start(

def LOCAL__start_node():
# 'error' will be None on Windows
_, _, error = execute_utility2(self._os_ops, _params, self.utils_log_file, verbose=True, exec_env=exec_env)
assert error is None or type(error) is str
if error and 'does not exist' in error:
raise Exception(error)
exec_r = utils.execute_utility3(
self._os_ops,
_params,
self.utils_log_file,
exec_env=exec_env,
)
# TODO: WTF? Remove it!
assert exec_r.returncode == 0
assert exec_r.stderr is None or type(exec_r.stderr) is str
if exec_r.stderr is not None and 'does not exist' in exec_r.stderr:
raise ExecUtilException(exec_r.stderr)

def LOCAL__raise_cannot_start_node__std(from_exception):
assert isinstance(from_exception, Exception)
Expand Down Expand Up @@ -1338,7 +1349,11 @@ def stop(self, params=[], wait=True):
] + params # yapf: disable

try:
execute_utility2(self._os_ops, _params, self.utils_log_file)
utils.execute_utility3(
self._os_ops,
_params,
logfile=self.utils_log_file,
)
self._manually_started_pm_pid = None
finally:
# always stop the reader thread, even if pg_ctl stop failed,
Expand Down Expand Up @@ -1399,9 +1414,16 @@ def restart(self, params=[]):
] + params # yapf: disable

try:
error_code, out, error = execute_utility2(self._os_ops, _params, self.utils_log_file, verbose=True)
if error and 'could not start server' in error:
raise ExecUtilException
exec_r = utils.execute_utility3(
self._os_ops,
_params,
logfile=self.utils_log_file,
)
# TODO: WTF? Remove it!
assert exec_r.returncode == 0
assert exec_r.stderr is None or type(exec_r.stderr) is str
if exec_r.stderr is not None and 'could not start server' in exec_r.stderr:
raise ExecUtilException(exec_r.stderr)
except ExecUtilException as e:
msg = 'Cannot restart node'
files = self._collect_special_files()
Expand All @@ -1428,7 +1450,11 @@ def reload(self, params=[]):
"reload"
] + params # yapf: disable

execute_utility2(self._os_ops, _params, self.utils_log_file)
utils.execute_utility3(
self._os_ops,
_params,
logfile=self.utils_log_file,
)

return self

Expand All @@ -1450,7 +1476,11 @@ def promote(self, dbname=None, username=None):
"promote"
] # yapf: disable

execute_utility2(self._os_ops, _params, self.utils_log_file)
utils.execute_utility3(
self._os_ops,
_params,
self.utils_log_file,
)

# for versions below 10 `promote` is asynchronous so we need to wait
# until it actually becomes writable
Expand Down Expand Up @@ -1485,7 +1515,11 @@ def pg_ctl(self, params):
"-w" # wait
] + params # yapf: disable

return execute_utility2(self._os_ops, _params, self.utils_log_file)
return utils.execute_utility3(
self._os_ops,
_params,
self.utils_log_file,
).stdout

def release_resources(self):
"""
Expand Down Expand Up @@ -1740,7 +1774,11 @@ def tmpfile():
if options:
_params.extend(options)

execute_utility2(self._os_ops, _params, self.utils_log_file)
utils.execute_utility3(
self._os_ops,
_params,
self.utils_log_file,
)

return filename

Expand Down Expand Up @@ -1769,7 +1807,11 @@ def restore(self, filename, dbname=None, username=None):

# try pg_restore if dump is binary format, and psql if not
try:
execute_utility2(self._os_ops, _params, self.utils_log_file)
utils.execute_utility3(
self._os_ops,
_params,
self.utils_log_file,
)
except ExecUtilException:
self.psql(filename=filename, dbname=dbname, username=username)

Expand Down Expand Up @@ -2130,7 +2172,11 @@ def pgbench_run(self, dbname=None, username=None, options=[], **kwargs):
# should be the last one
_params.append(dbname)

return execute_utility2(self._os_ops, _params, self.utils_log_file)
return utils.execute_utility3(
self._os_ops,
_params,
self.utils_log_file,
).stdout

def connect(self,
dbname=None,
Expand Down
Loading
Loading