Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Pbckp 152 multihost#78

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
demonolock merged 27 commits intomasterfromPBCKP-152-multihost
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
27 commits
Select commitHold shift + click to select a range
02c3375
PBCKP-137 update node.py
Apr 10, 2023
1512afd
PBCKP-137 up version 1.8.6
Apr 11, 2023
0d62e0e
PBCKP-137 update node.py
Apr 11, 2023
8be1b3a
PBCKP-137 update node
Apr 17, 2023
51f05de
PBCKP-152 change local function on execution by ssh
May 2, 2023
f131088
PBCKP-152 merge master
May 2, 2023
4f38bd5
PBCKP-152 multihost
May 3, 2023
0da2ee2
merge master
Jun 6, 2023
2bc17f0
testgres from PBCKP-152-multihost
Jun 6, 2023
f9b6bdb
PBCKP-152
Jun 10, 2023
ac77ef7
PBCKP-152 use black for formatting
Jun 11, 2023
b048041
PBCKP-152 fix failed tests
Jun 12, 2023
e098b97
PBCKP-152 fix failed tests
Jun 13, 2023
1c405ef
PBCKP-152 add tests for remote_ops.py
Jun 14, 2023
8c373e6
PBCKP-152 add testgres tests for remote node
Jun 14, 2023
72e6d5d
PBCKP-152 fixed test_simple and test_remote
Jun 17, 2023
2c2d2c5
PBCKP-588 test fix test_restore_after_failover
Jun 22, 2023
1b4f74a
PBCKP-588 test partially fixed test_simple_remote.py 41/43
Jun 22, 2023
2e916df
PBCKP-588 fixes after review
Jun 25, 2023
0528541
PBCKP-588 fixes after review - add ConnectionParams
Jun 26, 2023
089ab9b
PBCKP-588 fixes after review - remove f-strings
Jun 26, 2023
190d084
PBCKP-588 fixes after review - replace subprocess.run on subprocess.P…
Jun 27, 2023
0c26f77
PBCKP-588 fix failed tests - psql, set_auto_conf
Jun 28, 2023
0796bc4
PBCKP-152 - test_restore_target_time cut
Jul 26, 2023
0f14034
PBCKP-152 - node set listen address
Jul 28, 2023
12aa7ba
Add info about remote mode in README.md
Aug 1, 2023
4e7f4b0
merge master
Aug 4, 2023
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
PrevPrevious commit
NextNext commit
PBCKP-588 fixes after review - add ConnectionParams
  • Loading branch information
v.shepard committedJun 26, 2023
commit0528541e70a3a3dbe3e019b7bc02552c84e40649
4 changes: 2 additions & 2 deletionstestgres/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,7 @@
First, \
Any

from .operations.os_ops import OsOperations
from .operations.os_ops import OsOperations, ConnectionParams
from .operations.local_ops import LocalOperations
from .operations.remote_ops import RemoteOperations

Expand All@@ -60,5 +60,5 @@
"PostgresNode", "NodeApp",
"reserve_port", "release_port", "bound_ports", "get_bin_path", "get_pg_config", "get_pg_version",
"First", "Any",
"OsOperations", "LocalOperations", "RemoteOperations"
"OsOperations", "LocalOperations", "RemoteOperations", "ConnectionParams"
]
9 changes: 4 additions & 5 deletionstestgres/api.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,11 +37,10 @@ def get_new_node(name=None, base_dir=None, **kwargs):
"""
Simply a wrapper around :class:`.PostgresNode` constructor.
See :meth:`.PostgresNode.__init__` for details.
For remote connection you can add next parameters:
host='127.0.0.1',
hostname='localhost',
ssh_key=None,
username=default_username()
For remote connection you can add the next parameter:
conn_params = ConnectionParams(host='127.0.0.1',
ssh_key=None,
username=default_username())
"""
# NOTE: leave explicit 'name' and 'base_dir' for compatibility
return PostgresNode(name=name, base_dir=base_dir, **kwargs)
2 changes: 1 addition & 1 deletiontestgres/backup.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -139,7 +139,7 @@ def spawn_primary(self, name=None, destroy=True):

# Build a new PostgresNode
NodeClass = self.original_node.__class__
with clean_on_error(NodeClass(name=name, base_dir=base_dir,os_ops=self.original_node.os_ops)) as node:
with clean_on_error(NodeClass(name=name, base_dir=base_dir,conn_params=self.original_node.os_ops.conn_params)) as node:

# New nodes should always remove dir tree
node._should_rm_dirs = True
Expand Down
17 changes: 7 additions & 10 deletionstestgres/node.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -94,6 +94,7 @@

from .backup import NodeBackup

from .operations.os_ops import ConnectionParams
from .operations.local_ops import LocalOperations
from .operations.remote_ops import RemoteOperations

Expand DownExpand Up@@ -125,8 +126,7 @@ def __repr__(self):


class PostgresNode(object):
def __init__(self, name=None, port=None, base_dir=None,
host='127.0.0.1', hostname='localhost', ssh_key=None, username=default_username(), os_ops=None):
def __init__(self, name=None, port=None, base_dir=None, conn_params: ConnectionParams = ConnectionParams()):
"""
PostgresNode constructor.

Expand All@@ -146,17 +146,14 @@ def __init__(self, name=None, port=None, base_dir=None,
# basic
self.name = name or generate_app_name()

if os_ops:
self.os_ops = os_ops
elif ssh_key:
self.os_ops = RemoteOperations(host=host, hostname=hostname, ssh_key=ssh_key, username=username)
if conn_params.ssh_key:
self.os_ops = RemoteOperations(conn_params)
else:
self.os_ops = LocalOperations(host=host, hostname=hostname, username=username)
self.os_ops = LocalOperations(conn_params)

self.port =self.os_ops.port or reserve_port()
self.port = port or reserve_port()

self.host = self.os_ops.host
self.hostname = self.os_ops.hostname
self.ssh_key = self.os_ops.ssh_key

testgres_config.os_ops = self.os_ops
Expand DownExpand Up@@ -628,7 +625,7 @@ def status(self):
status_code, out, err = execute_utility(_params, self.utils_log_file, verbose=True)
if 'does not exist' in err:
return NodeStatus.Uninitialized
elif'no server running' in out:
elif'no server running' in out:
return NodeStatus.Stopped
return NodeStatus.Running

Expand Down
15 changes: 7 additions & 8 deletionstestgres/operations/local_ops.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,9 +7,9 @@

import psutil

fromtestgres.exceptions import ExecUtilException
from..exceptions import ExecUtilException

from .os_ops import OsOperations
from .os_ops import OsOperations, ConnectionParams
from .os_ops import pglib

try:
Expand All@@ -21,13 +21,12 @@


class LocalOperations(OsOperations):
def __init__(self, host='127.0.0.1', hostname='localhost', port=None, username=None):
super().__init__(username)
self.host = host
self.hostname = hostname
self.port = port
def __init__(self, conn_params: ConnectionParams = ConnectionParams()):
super().__init__(conn_params.username)
self.conn_params = conn_params
self.host = conn_params.host
self.ssh_key = None
self.username = username or self.get_user()
self.username =conn_params.username or self.get_user()

# Command execution
def exec_command(self, cmd, wait_exit=False, verbose=False,
Expand Down
11 changes: 8 additions & 3 deletionstestgres/operations/os_ops.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,11 +7,16 @@
raise ImportError("You must have psycopg2 or pg8000 modules installed")


class ConnectionParams:
def __init__(self, host='127.0.0.1', ssh_key=None, username=None):
self.host = host
self.ssh_key = ssh_key
self.username = username


class OsOperations:
def __init__(self, username=None):
self.hostname = "localhost"
self.remote = False
self.ssh = None
self.ssh_key = None
self.username = username

# Command execution
Expand Down
31 changes: 13 additions & 18 deletionstestgres/operations/remote_ops.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,9 +8,9 @@
import paramiko
from paramiko import SSHClient

fromtestgres.exceptions import ExecUtilException
from..exceptions import ExecUtilException

from .os_ops import OsOperations
from .os_ops import OsOperations, ConnectionParams
from .os_ops import pglib

sshtunnel.SSH_TIMEOUT = 5.0
Expand All@@ -37,15 +37,13 @@ def cmdline(self):


class RemoteOperations(OsOperations):
def __init__(self, host="127.0.0.1", hostname='localhost', port=None, ssh_key=None, username=None):
super().__init__(username)
self.host = host
self.hostname = hostname
self.port = port
self.ssh_key = ssh_key
self.remote = True
def __init__(self, conn_params: ConnectionParams):
super().__init__(conn_params.username)
self.conn_params = conn_params
self.host = conn_params.host
self.ssh_key = conn_params.ssh_key
self.ssh = self.ssh_connect()
self.username = username or self.get_user()
self.username =conn_params.username or self.get_user()
self.tunnel = None

def __enter__(self):
Expand All@@ -70,14 +68,11 @@ def close_tunnel(self):
time.sleep(0.5)

def ssh_connect(self) -> Optional[SSHClient]:
if not self.remote:
return None
else:
key = self._read_ssh_key()
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(self.host, username=self.username, pkey=key)
return ssh
key = self._read_ssh_key()
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(self.host, username=self.username, pkey=key)
return ssh

def _read_ssh_key(self):
try:
Expand Down
11 changes: 5 additions & 6 deletionstests/test_remote.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,20 +2,19 @@

from testgres import ExecUtilException
from testgres import RemoteOperations
from testgres import ConnectionParams


class TestRemoteOperations:

@pytest.fixture(scope="function", autouse=True)
def setup(self):
self.operations = RemoteOperations(
host="172.18.0.3",
username="dev",
ssh_key='../../container_files/postgres/ssh/id_ed25519'
)
conn_params = ConnectionParams(host="172.18.0.3",
username="dev",
ssh_key='../../container_files/postgres/ssh/id_ed25519')
self.operations = RemoteOperations(conn_params)

yield

self.operations.__del__()

def test_exec_command_success(self):
Expand Down
12 changes: 6 additions & 6 deletionstests/test_simple_remote.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,12 +50,12 @@
# NOTE: those are ugly imports
from testgres import bound_ports
from testgres.utils import PgVer
from testgres.node import ProcessProxy
from testgres.node import ProcessProxy, ConnectionParams


os_ops = RemoteOperations(host='172.18.0.3',
username='dev',
ssh_key='../../container_files/postgres/ssh/id_ed25519')
conn_params = ConnectionParams(host="172.18.0.3",
username="dev",
ssh_key='../../container_files/postgres/ssh/id_ed25519')
os_ops = RemoteOperations(conn_params)
testgres_config.set_os_ops(os_ops=os_ops)


Expand DownExpand Up@@ -94,7 +94,7 @@ def removing(f):


def get_remote_node(name=None):
return get_new_node(name=name,host=os_ops.host, username=os_ops.username, ssh_key=os_ops.ssh_key)
return get_new_node(name=name,conn_params=conn_params)


class TestgresRemoteTests(unittest.TestCase):
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp