Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ad40c0f

Browse files
authoredOct 17, 2023
Remove using paramiko (#89)
* Remove using paramiko * Up version 1.9.1
1 parent 6cb3a80 commit ad40c0f

File tree

9 files changed

+108
-137
lines changed

9 files changed

+108
-137
lines changed
 

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ the configuration file, which means that they should be called before `append_co
176176
### Remote mode
177177
Testgres supports the creation of PostgreSQL nodes on a remote host. This is useful when you want to run distributed tests involving multiple nodes spread across different machines.
178178

179-
To use this feature, you need to use the RemoteOperations class.
179+
To use this feature, you need to use the RemoteOperations class. This feature is only supported with Linux.
180180
Here is an example of how you might set this up:
181181

182182
```python

‎setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"six>=1.9.0",
1313
"psutil",
1414
"packaging",
15-
"paramiko",
1615
"fabric",
1716
"sshtunnel"
1817
]
@@ -30,7 +29,7 @@
3029
readme = f.read()
3130

3231
setup(
33-
version='1.9.0',
32+
version='1.9.1',
3433
name='testgres',
3534
packages=['testgres', 'testgres.operations'],
3635
description='Testing utility for PostgreSQL and its extensions',

‎testgres/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@
4646
First, \
4747
Any
4848

49+
from .config import testgres_config
50+
4951
from .operations.os_ops import OsOperations, ConnectionParams
5052
from .operations.local_ops import LocalOperations
5153
from .operations.remote_ops import RemoteOperations
5254

5355
__all__ = [
5456
"get_new_node",
5557
"get_remote_node",
56-
"NodeBackup",
58+
"NodeBackup", "testgres_config",
5759
"TestgresConfig", "configure_testgres", "scoped_config", "push_config", "pop_config",
5860
"NodeConnection", "DatabaseError", "InternalError", "ProgrammingError", "OperationalError",
5961
"TestgresException", "ExecUtilException", "QueryException", "TimeoutException", "CatchUpException", "StartNodeException", "InitNodeException", "BackupException",

‎testgres/cache.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ def call_initdb(initdb_dir, log=logfile):
5757
# our initdb caching mechanism breaks this contract.
5858
pg_control = os.path.join(data_dir, XLOG_CONTROL_FILE)
5959
system_id = generate_system_id()
60-
os_ops.write(pg_control, system_id, truncate=True, binary=True, read_and_write=True)
60+
cur_pg_control = os_ops.read(pg_control, binary=True)
61+
new_pg_control = system_id + cur_pg_control[len(system_id):]
62+
os_ops.write(pg_control, new_pg_control, truncate=True, binary=True, read_and_write=True)
6163

6264
# XXX: build new WAL segment with our system id
6365
_params = [get_bin_path("pg_resetwal"), "-D", data_dir, "-f"]

‎testgres/operations/local_ops.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,15 @@ def touch(self, filename):
198198
with open(filename, "a"):
199199
os.utime(filename, None)
200200

201-
def read(self, filename, encoding=None):
202-
with open(filename, "r", encoding=encoding) as file:
203-
return file.read()
201+
def read(self, filename, encoding=None, binary=False):
202+
mode = "rb" if binary else "r"
203+
with open(filename, mode) as file:
204+
content = file.read()
205+
if binary:
206+
return content
207+
if isinstance(content, bytes):
208+
return content.decode(encoding or 'utf-8')
209+
return content
204210

205211
def readlines(self, filename, num_lines=0, binary=False, encoding=None):
206212
"""

‎testgres/operations/remote_ops.py

Lines changed: 87 additions & 123 deletions
Large diffs are not rendered by default.

‎testgres/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ def get_bin_path(filename):
118118
return filename
119119

120120

121-
def get_pg_config(pg_config_path=None):
121+
def get_pg_config(pg_config_path=None, os_ops=None):
122122
"""
123123
Return output of pg_config (provided that it is installed).
124124
NOTE: this function caches the result by default (see GlobalConfig).
125125
"""
126+
if os_ops:
127+
tconf.os_ops = os_ops
126128

127129
def cache_pg_config_data(cmd):
128130
# execute pg_config and get the output
@@ -146,7 +148,7 @@ def cache_pg_config_data(cmd):
146148
_pg_config_data = {}
147149

148150
# return cached data
149-
if _pg_config_data:
151+
if not pg_config_path and _pg_config_data:
150152
return _pg_config_data
151153

152154
# try specified pg_config path or PG_CONFIG

‎tests/test_remote.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ def setup(self):
1717
'RDBMS_TESTPOOL_SSHKEY') or '../../container_files/postgres/ssh/id_ed25519')
1818
self.operations = RemoteOperations(conn_params)
1919

20-
yield
21-
self.operations.__del__()
22-
2320
def test_exec_command_success(self):
2421
"""
2522
Test exec_command for successful command execution.

‎tests/test_simple_remote.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ def test_init_after_cleanup(self):
135135
@unittest.skipUnless(util_exists('pg_resetwal'), 'might be missing')
136136
@unittest.skipUnless(pg_version_ge('9.6'), 'requires 9.6+')
137137
def test_init_unique_system_id(self):
138-
# FAIL
139138
# this function exists in PostgreSQL 9.6+
140139
query = 'select system_identifier from pg_control_system()'
141140

0 commit comments

Comments
 (0)
Please sign in to comment.