Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4f38bd5

Browse files
author
v.shepard
committed
PBCKP-152 multihost
1 parent f131088 commit 4f38bd5

File tree

4 files changed

+18
-28
lines changed

4 files changed

+18
-28
lines changed

testgres/cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def call_initdb(initdb_dir, log=None):
3939
call_initdb(data_dir, logfile)
4040
else:
4141
# Fetch cached initdb dir
42-
cached_data_dir = testgres_config.cached_initdb_dir
42+
cached_data_dir = testgres_config.cached_initdb_dir()
4343

4444
# Initialize cached initdb
4545

testgres/config.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ def cached_initdb_dir(self):
5555
def cached_initdb_dir(self, value):
5656
self._cached_initdb_dir = value
5757

58-
# NOTE: assign initial cached dir for initdb
59-
if self.os_ops:
60-
testgres_config.cached_initdb_dir = self.os_ops.mkdtemp(prefix=TMP_CACHE)
61-
else:
62-
testgres_config.cached_initdb_dir = mkdtemp(prefix=TMP_CACHE)
63-
6458
if value:
6559
cached_initdb_dirs.add(value)
6660
return testgres_config.cached_initdb_dir
@@ -208,3 +202,7 @@ def configure_testgres(**options):
208202
"""
209203

210204
testgres_config.update(options)
205+
206+
207+
# NOTE: assign initial cached dir for initdb
208+
testgres_config.cached_initdb_dir = mkdtemp(prefix=TMP_CACHE)

testgres/connection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ def __init__(self,
4242

4343
self._node = node
4444

45-
self.os_ops = OsOperations(node.host, node.hostname, node.ssh_key, node.username)
46-
self._connection = self.os_ops.db_connect(dbname=dbname,
45+
self._connection = node.os_ops.db_connect(dbname=dbname,
4746
user=username,
4847
password=password,
4948
host=node.host,

testgres/os_ops.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -262,32 +262,25 @@ def get_user(self):
262262
user = getpass.getuser()
263263
return user
264264

265-
@contextmanager
266265
def db_connect(self, dbname, user, password=None, host='localhost', port=5432):
267266
if self.remote:
268-
with self.ssh_connect() as ssh:
269-
# Set up a local port forwarding on a random port
270-
local_port = ssh.forward_remote_port(host, port)
271-
conn = pglib.connect(
272-
host=host,
273-
port=local_port,
274-
dbname=dbname,
275-
user=user,
276-
password=password,
277-
)
278-
try:
279-
yield conn
280-
finally:
281-
conn.close()
282-
ssh.close_forwarded_tcp(local_port)
267+
local_port = self.ssh.forward_remote_port(host, port)
268+
conn = pglib.connect(
269+
host=host,
270+
port=local_port,
271+
dbname=dbname,
272+
user=user,
273+
password=password,
274+
)
283275
else:
284-
with pglib.connect(
276+
conn = pglib.connect(
285277
host=host,
286278
port=port,
287279
dbname=dbname,
288280
user=user,
289281
password=password,
290-
) as conn:
291-
yield conn
282+
)
283+
return conn
284+
292285

293286

0 commit comments

Comments
 (0)