Skip to content
Merged
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
77 changes: 39 additions & 38 deletions src/node_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from .node import PortManager

import os
import platform
import tempfile
import typing


Expand All @@ -16,7 +14,7 @@
class NodeApp:
_test_path: str
_os_ops: OsOperations
_port_manager: PortManager
_port_manager: typing.Optional[PortManager]
_nodes_to_cleanup: typing.List[PostgresNode]

def __init__(
Expand Down Expand Up @@ -60,7 +58,7 @@ def os_ops(self) -> OsOperations:
return self._os_ops

@property
def port_manager(self) -> PortManager:
def port_manager(self) -> typing.Optional[PortManager]:
assert self._port_manager is None or isinstance(self._port_manager, PortManager)
return self._port_manager

Expand Down Expand Up @@ -158,6 +156,8 @@ def make_simple(

# set major version
pg_version_file = self._os_ops.read(self._os_ops.build_path(node.data_dir, 'PG_VERSION'))

# What is it ???
node.major_version_str = str(pg_version_file.rstrip())
node.major_version = float(node.major_version_str)

Expand Down Expand Up @@ -200,7 +200,7 @@ def make_simple(

# Define delayed propertyes
if "unix_socket_directories" not in options.keys():
options["unix_socket_directories"] = __class__._gettempdir_for_socket()
options["unix_socket_directories"] = self._gettempdir_for_socket()

# Set config values
node.set_auto_conf(options)
Expand Down Expand Up @@ -260,49 +260,50 @@ def _paramlist_append_if_not_exist(
return updated_params
return __class__._paramlist_append(user_params, updated_params, param)

@staticmethod
def _gettempdir_for_socket() -> str:
platform_system_name = platform.system().lower()

if platform_system_name == "windows":
return __class__._gettempdir()

#
# [2025-02-17] Hot fix.
#
# Let's use hard coded path as Postgres likes.
#
# pg_config_manual.h:
#
# #ifndef WIN32
# #define DEFAULT_PGSOCKET_DIR "/tmp"
# #else
# #define DEFAULT_PGSOCKET_DIR ""
# #endif
#
# On the altlinux-10 tempfile.gettempdir() may return
# the path to "private" temp directiry - "/temp/.private/<username>/"
#
# But Postgres want to find a socket file in "/tmp" (see above).
#
def _gettempdir_for_socket(self) -> str:
assert isinstance(self._os_ops, OsOperations)

return "/tmp"
platform_name = self._os_ops.get_platform()

if platform_name == "linux":
#
# [2025-02-17] Hot fix.
#
# Let's use hard coded path as Postgres likes.
#
# pg_config_manual.h:
#
# #ifndef WIN32
# #define DEFAULT_PGSOCKET_DIR "/tmp"
# #else
# #define DEFAULT_PGSOCKET_DIR ""
# #endif
#
# On the altlinux-10 tempfile.gettempdir() may return
# the path to "private" temp directiry - "/temp/.private/<username>/"
#
# But Postgres want to find a socket file in "/tmp" (see above).
#
return "/tmp"

return self._gettempdir()

def _gettempdir(self) -> str:
assert isinstance(self._os_ops, OsOperations)

@staticmethod
def _gettempdir() -> str:
v = tempfile.gettempdir()
v = self._os_ops.get_tempdir()

#
# Paranoid checks
#
if type(v) is str:
__class__._raise_bugcheck("tempfile.gettempdir returned a value with type {0}.".format(type(v).__name__))
__class__._raise_bugcheck("os_ops.get_tempdir returned a value with type {0}.".format(type(v).__name__))

if v == "":
__class__._raise_bugcheck("tempfile.gettempdir returned an empty string.")
__class__._raise_bugcheck("os_ops.get_tempdir returned an empty string.")

if not os.path.exists(v):
__class__._raise_bugcheck("tempfile.gettempdir returned a not exist path [{0}].".format(v))
if not self._os_ops.path_exists(v):
__class__._raise_bugcheck("os_ops.get_tempdir returned a not exist path [{0}].".format(v))

# OK
return v
Expand Down