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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ classifiers = [
dependencies = [
"pg8000",
"port-for>=0.4",
"six>=1.9.0",
"psutil",
"packaging",
"testgres.os_ops>=3.3.3,<4.0.0",
Expand Down
6 changes: 2 additions & 4 deletions src/backup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# coding: utf-8

from six import raise_from

from .enums import XLogMethod

from .consts import \
Expand All @@ -22,7 +20,7 @@
clean_on_error


class NodeBackup(object):
class NodeBackup:
"""
Smart object responsible for backups
"""
Expand Down Expand Up @@ -131,7 +129,7 @@ def _prepare_dir(self, destroy):
# Copy backup to new data dir
self.os_ops.copytree(data1, data2)
except Exception as e:
raise_from(BackupException('Failed to copy files'), e)
raise BackupException('Failed to copy files') from e
else:
dest_base_dir = self.base_dir

Expand Down
8 changes: 3 additions & 5 deletions src/cache.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# coding: utf-8

from six import raise_from

from .config import testgres_config

from .consts import XLOG_CONTROL_FILE
Expand Down Expand Up @@ -49,7 +47,7 @@ def call_initdb(initdb_dir, log=logfile):
log,
)
except ExecUtilException as e:
raise_from(InitNodeException("Failed to run initdb"), e)
raise InitNodeException("Failed to run initdb") from e

if params or not testgres_config.cache_initdb or not cached:
call_initdb(data_dir, logfile)
Expand Down Expand Up @@ -89,7 +87,7 @@ def call_initdb(initdb_dir, log=logfile):

except ExecUtilException as e:
msg = "Failed to reset WAL for system id"
raise_from(InitNodeException(msg), e)
raise InitNodeException(msg) from e

except Exception as e:
raise_from(InitNodeException("Failed to spawn a node"), e)
raise InitNodeException("Failed to spawn a node") from e
2 changes: 1 addition & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
logging.basicConfig(level=log_level, format=log_format)


class GlobalConfig(object):
class GlobalConfig:
"""
Global configuration object which allows user to override default settings.
"""
Expand Down
2 changes: 1 addition & 1 deletion src/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
OperationalError = pglib.OperationalError


class NodeConnection(object):
class NodeConnection:
"""
Transaction wrapper returned by Node
"""
Expand Down
5 changes: 2 additions & 3 deletions src/decorators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import six
import functools


Expand All @@ -18,15 +17,15 @@ def some_api_func(...)

for case in special_cases:
k = len(case)
assert k not in six.iterkeys(cases), 'len must be unique'
assert k not in cases, 'len must be unique'
cases[k] = case

def decorator(function):
@functools.wraps(function)
def wrapper(*args, **kwargs):
k = len(args)

if k in six.iterkeys(cases):
if k in cases:
case = cases[k]

for i in range(0, k):
Expand Down
3 changes: 1 addition & 2 deletions src/enums.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from enum import Enum, IntEnum
from six import iteritems
from psutil import NoSuchProcess


Expand Down Expand Up @@ -83,7 +82,7 @@ def from_process(process):
if cmdline.startswith(ptype.value.replace(' ', '')):
return ptype

for ptype, names in iteritems(alternative_names):
for ptype, names in alternative_names.items():
for name in names:
if cmdline.startswith(name.replace(' ', '')):
return ptype
Expand Down
7 changes: 2 additions & 5 deletions src/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# coding: utf-8

import six
import typing

from testgres.operations.exceptions import TestgresException
Expand Down Expand Up @@ -44,7 +43,6 @@ def __repr__(self) -> str:
return result


@six.python_2_unicode_compatible
class QueryException(TestgresException):
_description: typing.Optional[str]
_query: typing.Optional[str]
Expand Down Expand Up @@ -76,7 +74,7 @@ def message(self) -> str:
if self._query:
msg.append(u'Query: {}'.format(self._query))

r = six.text_type('\n').join(msg)
r = '\n'.join(msg)
assert type(r) is str
return r

Expand Down Expand Up @@ -162,7 +160,6 @@ def __repr__(self) -> str:
return result


@six.python_2_unicode_compatible
class StartNodeException(TestgresException):
_description: typing.Optional[str]
_files: typing.Optional[typing.Iterable]
Expand Down Expand Up @@ -196,7 +193,7 @@ def message(self) -> str:
assert type(lines) in [str, bytes]
msg.append(u'{}\n----\n{}\n'.format(f, lines))

return six.text_type('\n').join(msg)
return '\n'.join(msg)

@property
def description(self) -> typing.Optional[str]:
Expand Down
2 changes: 1 addition & 1 deletion src/impl/platforms/darwin/internal_platform_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def _FindPostmaster(
)

# --------------------------------------------------------------------
def ProcessIsZombi_soft_check(
def ProcessIsZombie_soft_check(
self,
os_ops: OsOperations,
pid: int,
Expand Down
8 changes: 5 additions & 3 deletions src/impl/platforms/internal_platform_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from ...raise_error import RaiseError

import enum
import typing

Expand Down Expand Up @@ -59,13 +61,13 @@ def FindPostmaster(
assert isinstance(os_ops, OsOperations)
assert type(bin_dir) is str
assert type(data_dir) is str
raise NotImplementedError("InternalPlatformUtils::FindPostmaster is not implemented.")
RaiseError.method_is_not_implemented(__class__, "FindPostmaster")

def ProcessIsZombi_soft_check(
def ProcessIsZombie_soft_check(
self,
os_ops: OsOperations,
pid: int,
) -> typing.Optional[bool]:
assert isinstance(os_ops, OsOperations)
assert type(pid) is int
raise NotImplementedError("InternalPlatformUtils::ProcessIsZombi_soft_ver is not implemented.")
RaiseError.method_is_not_implemented(__class__, "ProcessIsZombie_soft_check")
11 changes: 7 additions & 4 deletions src/impl/platforms/linux/internal_platform_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def _FindPostmaster(
)

# --------------------------------------------------------------------
def ProcessIsZombi_soft_check(
def ProcessIsZombie_soft_check(
self,
os_ops: OsOperations,
pid: int,
Expand All @@ -264,7 +264,10 @@ def ProcessIsZombi_soft_check(

try:
# Read one line from /proc/PID/stat
stat_content = os_ops.read_binary(proc_stat_file, 0).decode("utf-8", errors="ignore")
stat_content_b = os_ops.read_binary(proc_stat_file, 0)
assert type(stat_content_b) is bytes

stat_content = stat_content_b.decode("utf-8", errors="ignore")

# We look for the closing parenthesis of the process name to ensure that
# we start from it and not depend on spaces inside the parentheses!
Expand All @@ -281,13 +284,13 @@ def ProcessIsZombi_soft_check(
result = proc_status == "Z"
except Exception as e:
# If the file disappeared right during reading, it means the process is completely erased
if __class__._is_file_not_found_exception(e):
if __class__._is_zombie_file_exception(e):
result = False

return result

@staticmethod
def _is_file_not_found_exception(e: Exception) -> bool:
def _is_zombie_file_exception(e: Exception) -> bool:
if isinstance(e, FileNotFoundError):
return True

Expand Down
2 changes: 1 addition & 1 deletion src/impl/platforms/win32/internal_platform_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def FindPostmaster(
assert type(data_dir) is str
return __class__.FindPostmasterResult.create_not_implemented()

def ProcessIsZombi_soft_check(
def ProcessIsZombie_soft_check(
self,
os_ops: OsOperations,
pid: int,
Expand Down
34 changes: 13 additions & 21 deletions src/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,14 @@
from testgres.operations.os_ops import OsProcessController
from testgres.operations.local_ops import LocalOperations

import ipaddress
import logging
import signal
import subprocess

import time
import typing

try:
from collections.abc import Iterable
except ImportError:
from collections import Iterable

# we support both pg8000 and psycopg2
try:
import psycopg2 as pglib
Expand All @@ -95,8 +91,6 @@
except ImportError:
raise ImportError("You must have psycopg2 or pg8000 modules installed")

from six import raise_from, iteritems, text_type


InternalError = pglib.InternalError
ProgrammingError = pglib.ProgrammingError
Expand All @@ -106,7 +100,7 @@
assert TimeoutException == QueryTimeoutException


class ProcessProxy(object):
class ProcessProxy:
"""
Wrapper for psutil.Process

Expand Down Expand Up @@ -150,7 +144,7 @@ def ptype(self) -> ProcessType:
return self._ptype


class PostgresNode(object):
class PostgresNode:
# a max number of node start attempts
_C_MAX_START_ATEMPTS = 5

Expand Down Expand Up @@ -756,7 +750,6 @@ def _create_recovery_conf(self, username, slot=None):

# host is tricky
try:
import ipaddress
ipaddress.ip_address(master.host)
conninfo["hostaddr"] = master.host
except ValueError:
Expand Down Expand Up @@ -1072,7 +1065,7 @@ def append_conf(self, line='', filename=PG_CONF_FILE, **kwargs):

lines = [line]

for option, value in iteritems(kwargs):
for option, value in kwargs.items():
if isinstance(value, bool):
value = 'on' if value else 'off'
elif not str(value).replace('.', '', 1).isdigit():
Expand All @@ -1086,7 +1079,7 @@ def append_conf(self, line='', filename=PG_CONF_FILE, **kwargs):
config_name = self._os_ops.build_path(self.data_dir, filename)
conf_text = ''
for line in lines:
conf_text += text_type(line) + '\n'
conf_text += str(line) + '\n'
self._os_ops.write(config_name, conf_text)

return self
Expand Down Expand Up @@ -1368,7 +1361,7 @@ def _raise_cannot_start_node(
assert from_exception is None or isinstance(from_exception, Exception)
assert type(msg) is str
files = self._collect_special_files()
raise_from(StartNodeException(msg, files), from_exception)
raise StartNodeException(msg, files) from from_exception

def stop(
self,
Expand Down Expand Up @@ -1471,7 +1464,7 @@ def restart(self, params=[]):
except ExecUtilException as e:
msg = 'Cannot restart node'
files = self._collect_special_files()
raise_from(StartNodeException(msg, files), e)
raise StartNodeException(msg, files) from e

self._maybe_start_logger()

Expand Down Expand Up @@ -1715,7 +1708,7 @@ def _psql(
] # yapf: disable

# set variables before execution
for key, value in iteritems(variables):
for key, value in variables.items():
psql_params.extend(["--set", '{}={}'.format(key, value)])

# select query source
Expand Down Expand Up @@ -2067,12 +2060,11 @@ def set_synchronous_standbys(self, standbys):

"""
if self._pg_version >= utils.PgVer('9.6'):
if isinstance(standbys, Iterable):
if isinstance(standbys, typing.Iterable):
standbys = First(1, standbys)
else:
if isinstance(standbys, Iterable):
standbys = u", ".join(u"\"{}\"".format(r.name)
for r in standbys)
if isinstance(standbys, typing.Iterable):
standbys = ", ".join("\"{}\"".format(r.name) for r in standbys)
else:
raise TestgresException(
"Feature isn't supported in "
Expand Down Expand Up @@ -2112,7 +2104,7 @@ def catchup(self, dbname=None, username=None):
max_attempts=0,
)
except Exception as e:
raise_from(CatchUpException("Failed to catch up."), e)
raise CatchUpException("Failed to catch up.") from e

def publish(self, name, **kwargs):
"""
Expand Down Expand Up @@ -2283,7 +2275,7 @@ def pgbench_run(
"-U", username or self._os_ops.username
] + options # yapf: disable

for key, value in iteritems(kwargs):
for key, value in kwargs.items():
# rename keys for pgbench
key = key.replace('_', '-')

Expand Down
7 changes: 5 additions & 2 deletions src/port_manager.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from .raise_error import RaiseError


class PortManager:
def __init__(self):
super().__init__()

def reserve_port(self) -> int:
raise NotImplementedError("PortManager::reserve_port is not implemented.")
RaiseError.method_is_not_implemented(__class__, "reserve_port")

def release_port(self, number: int) -> None:
assert type(number) is int
raise NotImplementedError("PortManager::release_port is not implemented.")
RaiseError.method_is_not_implemented(__class__, "release_port")
Loading
Loading