8000 NodeApp is refactored by dmitry-lipetsk · Pull Request #278 · postgrespro/testgres · GitHub
[go: up one dir, main page]

Skip to content

NodeApp is refactored #278

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
17fb8c3
NodeApp was moved to own py-file (refactoring)
dmitry-lipetsk Jun 26, 2025
8eaa289
NodeApp is refactored totally
dmitry-lipetsk Jun 26, 2025
2246447
NodeApp::test_path is corrected
dmitry-lipetsk Jun 26, 2025
3fe3e94
Default value of 'pg_options' (NodeApp::make_simple) is None
dmitry-lipetsk Jun 27, 2025
c1afd7e
Merge branch 'master' into D20250626_001--node_app
dmitry-lipetsk Jun 27, 2025
1062a97
OsOperations::create_clone is added
dmitry-lipetsk Jun 27, 2025
1512fe7
[#277] NodeApp::make_empty does not allow None/empty base_dir
dmitry-lipetsk Jun 27, 2025
b5b0d2b
[#267] NodeApp.make_simple does not change 'initdb_params'
dmitry-lipetsk Jun 27, 2025
dffde2c
test_node_app__make_empty__base_dir_is_None is corrected
dmitry-lipetsk Jun 27, 2025
d5c3672
NodeApp::make_simple is corrected (bad assert)
dmitry-lipetsk Jun 27, 2025
aae53eb
test_node_app__make_empty__base_dir_is_xxx is updated
dmitry-lipetsk Jun 27, 2025
488d556
[#265] NodeApp.make_simple links a new node with own os_ops and port_…
dmitry-lipetsk Jun 27, 2025
688b89f
test_node_app__make_empty is corrected
dmitry-lipetsk Jun 27, 2025
4f85ce5
NodeApp::nodes_to_cleanup is RO-property
dmitry-lipetsk Jun 27, 2025
f79e9a7
flake8
dmitry-lipetsk Jun 27, 2025
5817f63
test_node_app__make_empty is fixed
dmitry-lipetsk Jun 28, 2025
0547b0b
PostgresNode::release_resources(self) is added
dmitry-lipetsk Jun 28, 2025
1b12ca3
[FIX] NodeApp::make_empty processes a failure of self._nodes_to_clean…
dmitry-lipetsk Jun 28, 2025
1af3dfa
New test test_node_app__make_empty_with_explicit_port is added
dmitry-lipetsk Jun 28, 2025
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
Prev Previous commit
Next Next commit
OsOperations::create_clone is added
  • Loading branch information
dmitry-lipetsk committed Jun 27, 2025
commit 1062a973d763651cc7a560782b0d766be72e2d81
27 changes: 26 additions & 1 deletion testgres/operations/local_ops.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import getpass
import logging
import os
Expand All @@ -11,6 +13,7 @@
import psutil
import typing
import threading
import copy

from ..exceptions import ExecUtilException
from ..exceptions import InvalidOperationException
Expand All @@ -29,13 +32,26 @@


class LocalOperations(OsOperations):
sm_dummy_conn_params = ConnectionParams()
sm_single_instance: OsOperations = None
sm_single_instance_guard = threading.Lock()

# TODO: make it read-only
conn_params: ConnectionParams
host: str
ssh_key: typing.Optional[str]
remote: bool
username: str

def __init__(self, conn_params=None):
super().__init__()

if conn_params is __class__.sm_dummy_conn_params:
return

if conn_params is None:
conn_params = ConnectionParams()
super(LocalOperations, self).__init__(conn_params.username)

self.conn_params = conn_params
self.host = conn_params.host
self.ssh_key = None
Expand All @@ -58,6 +74,15 @@ def get_single_instance() -> OsOperations:
assert type(__class__.sm_single_instance) == __class__ # noqa: E721
return __class__.sm_single_instance

def create_clone(self) -> LocalOperations:
clone = __class__(__class__.sm_dummy_conn_params)
clone.conn_params = copy.copy(self.conn_params)
clone.host = self.host
clone.ssh_key = self.ssh_key
clone.remote = self.remote
clone.username = self.username
return clone

@staticmethod
def _process_output(encoding, temp_file_path):
"""Process the output of a command from a temporary file."""
Expand Down
11 changes: 7 additions & 4 deletions testgres/operations/os_ops.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import getpass
from __future__ import annotations

import locale


Expand All @@ -17,9 +18,11 @@ def get_default_encoding():


class OsOperations:
def __init__(self, username=None):
self.ssh_key = None
self.username = username or getpass.getuser()
def __init__(self):
pass

def create_clone(self) -> OsOperations:
raise NotImplementedError()

# Command execution
def exec_command(self, cmd, **kwargs):
Expand Down
35 changes: 34 additions & 1 deletion testgres/operations/remote_ops.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import getpass
import os
import posixpath
Expand All @@ -7,6 +9,7 @@
import io
import logging
import typing
import copy

from ..exceptions import ExecUtilException
from ..exceptions import InvalidOperationException
Expand Down Expand Up @@ -42,11 +45,29 @@ def cmdline(self):


class RemoteOperations(OsOperations):
sm_dummy_conn_params = ConnectionParams()

conn_params: ConnectionParams
host: str
port: int
ssh_key: str
ssh_args: list
remote: bool
username: str
ssh_dest: str

def __init__(self, conn_params: ConnectionParams):
if not platform.system().lower() == "linux":
raise EnvironmentError("Remote operations are supported only on Linux!")

super().__init__(conn_params.username)
if conn_params is None:
raise ValueError("Argument 'conn_params' is None.")

super().__init__()

if conn_params is __class__.sm_dummy_conn_params:
return

self.conn_params = conn_params
self.host = conn_params.host
self.port = conn_params.port
Expand All @@ -63,6 +84,18 @@ def __init__(self, conn_params: ConnectionParams):
def __enter__(self):
return self

def create_clone(self) -> RemoteOperations:
clone = __class__(__class__.sm_dummy_conn_params)
clone.conn_params = copy.copy(self.conn_params)
clone.host = self.host
clone.port = self.port
clone.ssh_key = self.ssh_key
clone.ssh_args = copy.copy(self.ssh_args)
clone.remote = self.remote
clone.username = self.username
clone.ssh_dest = self.ssh_dest
return clone

def exec_command(
self, cmd, wait_exit=False, verbose=False, expect_error=False,
encoding=None, shell=True, text=False, input=None, stdin=None, stdout=None,
Expand Down
7 changes: 7 additions & 0 deletions tests/test_os_ops_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ def os_ops(self, request: pytest.FixtureRequest) -> OsOperations:
assert isinstance(request.param, OsOperations)
return request.param

def test_create_clone(self, os_ops: OsOperations):
assert isinstance(os_ops, OsOperations)
clone = os_ops.create_clone()
assert clone is not None
assert clone is not os_ops
assert type(clone) == type(os_ops) # noqa: E721

def test_exec_command_success(self, os_ops: OsOperations):
"""
Test exec_command for successful command execution.
Expand Down
0