Skip to content

Commit 9d8e662

Browse files
author
v.shepard
committed
Add info about remote mode in README.md
1 parent 0f14034 commit 9d8e662

File tree

5 files changed

+109
-51
lines changed

5 files changed

+109
-51
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,33 @@ with testgres.get_new_node().init() as master:
173173
Note that `default_conf()` is called by `init()` function; both of them overwrite
174174
the configuration file, which means that they should be called before `append_conf()`.
175175

176+
### Remote mode
177+
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.
178+
179+
To use this feature, you need to use the RemoteOperations class.
180+
Here is an example of how you might set this up:
181+
182+
```python
183+
from testgres import ConnectionParams, RemoteOperations, TestgresConfig, get_remote_node
184+
185+
# Set up connection params
186+
conn_params = ConnectionParams(
187+
host='your_host', # replace with your host
188+
username='user_name', # replace with your username
189+
ssh_key='path_to_ssh_key' # replace with your SSH key path
190+
)
191+
os_ops = RemoteOperations(conn_params)
192+
193+
# Add remote testgres config before test
194+
TestgresConfig.set_os_ops(os_ops=os_ops)
195+
196+
# Proceed with your test
197+
def test_basic_query(self):
198+
with get_remote_node(conn_params=conn_params) as node:
199+
node.init().start()
200+
res = node.execute('SELECT 1')
201+
self.assertEqual(res, [(1,)])
202+
```
176203

177204
## Authors
178205

testgres/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .api import get_new_node
1+
from .api import get_new_node, get_remote_node
22
from .backup import NodeBackup
33

44
from .config import \
@@ -52,6 +52,7 @@
5252

5353
__all__ = [
5454
"get_new_node",
55+
"get_remote_node",
5556
"NodeBackup",
5657
"TestgresConfig", "configure_testgres", "scoped_config", "push_config", "pop_config",
5758
"NodeConnection", "DatabaseError", "InternalError", "ProgrammingError", "OperationalError",

testgres/api.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,18 @@ def get_new_node(name=None, base_dir=None, **kwargs):
3737
"""
3838
Simply a wrapper around :class:`.PostgresNode` constructor.
3939
See :meth:`.PostgresNode.__init__` for details.
40+
"""
41+
# NOTE: leave explicit 'name' and 'base_dir' for compatibility
42+
return PostgresNode(name=name, base_dir=base_dir, **kwargs)
43+
44+
45+
def get_remote_node(name=None, conn_params=None):
46+
"""
47+
Simply a wrapper around :class:`.PostgresNode` constructor for remote node.
48+
See :meth:`.PostgresNode.__init__` for details.
4049
For remote connection you can add the next parameter:
4150
conn_params = ConnectionParams(host='127.0.0.1',
4251
ssh_key=None,
4352
username=default_username())
4453
"""
45-
# NOTE: leave explicit 'name' and 'base_dir' for compatibility
46-
return PostgresNode(name=name, base_dir=base_dir, **kwargs)
54+
return get_new_node(name=name, conn_params=conn_params)

tests/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,29 @@ export PYTHON_VERSION=3 # or 2
2727
# Run tests
2828
./run_tests.sh
2929
```
30+
31+
32+
#### Remote host tests
33+
34+
1. Start remote host or docker container
35+
2. Make sure that you run ssh
36+
```commandline
37+
sudo apt-get install openssh-server
38+
sudo systemctl start sshd
39+
```
40+
3. You need to connect to the remote host at least once to add it to the known hosts file
41+
4. Generate ssh keys
42+
5. Set up params for tests
43+
44+
```commandline
45+
conn_params = ConnectionParams(
46+
host='remote_host',
47+
username='username',
48+
ssh_key=/path/to/your/ssh/key'
49+
)
50+
os_ops = RemoteOperations(conn_params)
51+
```
52+
53+
`test_remote` - Tests for RemoteOperations class.
54+
55+
`test_simple_remote` - Tests that create node and check it. The same as `test_simple`, but for remote node.

0 commit comments

Comments
 (0)