Skip to content

Commit 72e6d5d

Browse files
author
v.shepard
committed
PBCKP-152 fixed test_simple and test_remote
1 parent 8c373e6 commit 72e6d5d

File tree

15 files changed

+353
-304
lines changed

15 files changed

+353
-304
lines changed

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"psutil",
1414
"packaging",
1515
"paramiko",
16-
"fabric"
16+
"fabric",
17+
"sshtunnel"
1718
]
1819

1920
# Add compatibility enum class

testgres/backup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(self,
7777
"-D", data_dir,
7878
"-X", xlog_method.value
7979
] # yapf: disable
80-
execute_utility(_params, self.log_file, self.os_ops)
80+
execute_utility(_params, self.log_file)
8181

8282
def __enter__(self):
8383
return self
@@ -139,7 +139,7 @@ def spawn_primary(self, name=None, destroy=True):
139139

140140
# Build a new PostgresNode
141141
NodeClass = self.original_node.__class__
142-
with clean_on_error(NodeClass(name=name, base_dir=base_dir)) as node:
142+
with clean_on_error(NodeClass(name=name, base_dir=base_dir, os_ops=self.original_node.os_ops)) as node:
143143

144144
# New nodes should always remove dir tree
145145
node._should_rm_dirs = True

testgres/cache.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ def cached_initdb(data_dir, logfile=None, params=None, os_ops: OsOperations = Lo
2626
"""
2727
Perform initdb or use cached node files.
2828
"""
29-
testgres_config.os_ops = os_ops
3029

31-
def call_initdb(initdb_dir, log=None):
30+
def call_initdb(initdb_dir, log=logfile):
3231
try:
3332
_params = [get_bin_path("initdb"), "-D", initdb_dir, "-N"]
34-
execute_utility(_params + (params or []), log, os_ops)
33+
execute_utility(_params + (params or []), log)
3534
except ExecUtilException as e:
3635
raise_from(InitNodeException("Failed to run initdb"), e)
3736

@@ -62,7 +61,7 @@ def call_initdb(initdb_dir, log=None):
6261

6362
# XXX: build new WAL segment with our system id
6463
_params = [get_bin_path("pg_resetwal"), "-D", data_dir, "-f"]
65-
execute_utility(_params, logfile, os_ops=os_ops)
64+
execute_utility(_params, logfile)
6665

6766
except ExecUtilException as e:
6867
msg = "Failed to reset WAL for system id"

testgres/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from contextlib import contextmanager
88

99
from .consts import TMP_CACHE
10+
from .operations.os_ops import OsOperations
1011
from .operations.local_ops import LocalOperations
1112

1213

@@ -121,6 +122,11 @@ def copy(self):
121122

122123
return copy.copy(self)
123124

125+
@staticmethod
126+
def set_os_ops(os_ops: OsOperations):
127+
testgres_config.os_ops = os_ops
128+
testgres_config.cached_initdb_dir = os_ops.mkdtemp(prefix=TMP_CACHE)
129+
124130

125131
# cached dirs to be removed
126132
cached_initdb_dirs = set()

testgres/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(self,
3737

3838
# Set default arguments
3939
dbname = dbname or default_dbname()
40-
username = username or default_username(node.os_ops)
40+
username = username or default_username()
4141

4242
self._node = node
4343

testgres/defaults.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import struct
33
import uuid
44

5-
from .operations.local_ops import LocalOperations
5+
from .config import testgres_config as tconf
66

77

88
def default_dbname():
@@ -13,11 +13,11 @@ def default_dbname():
1313
return 'postgres'
1414

1515

16-
def default_username(os_ops=LocalOperations()):
16+
def default_username():
1717
"""
1818
Return default username (current user).
1919
"""
20-
return os_ops.get_user()
20+
return tconf.os_ops.get_user()
2121

2222

2323
def generate_app_name():
@@ -28,7 +28,7 @@ def generate_app_name():
2828
return 'testgres-{}'.format(str(uuid.uuid4()))
2929

3030

31-
def generate_system_id(os_ops=LocalOperations()):
31+
def generate_system_id():
3232
"""
3333
Generate a new 64-bit unique system identifier for node.
3434
"""
@@ -43,7 +43,7 @@ def generate_system_id(os_ops=LocalOperations()):
4343
system_id = 0
4444
system_id |= (secs << 32)
4545
system_id |= (usecs << 12)
46-
system_id |= (os_ops.get_pid() & 0xFFF)
46+
system_id |= (tconf.os_ops.get_pid() & 0xFFF)
4747

4848
# pack ULL in native byte order
4949
return struct.pack('=Q', system_id)

testgres/logger.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@
55
import threading
66
import time
77

8-
98
# create logger
109
log = logging.getLogger('Testgres')
11-
log.setLevel(logging.DEBUG)
12-
# create console handler and set level to debug
13-
ch = logging.StreamHandler()
14-
ch.setLevel(logging.DEBUG)
15-
# create formatter
16-
formatter = logging.Formatter('\n%(asctime)s - %(name)s[%(levelname)s]: %(message)s')
17-
# add formatter to ch
18-
ch.setFormatter(formatter)
19-
# add ch to logger
20-
log.addHandler(ch)
10+
11+
if not log.handlers:
12+
log.setLevel(logging.WARN)
13+
# create console handler and set level to debug
14+
ch = logging.StreamHandler()
15+
ch.setLevel(logging.WARN)
16+
# create formatter
17+
formatter = logging.Formatter('\n%(asctime)s - %(name)s[%(levelname)s]: %(message)s')
18+
# add formatter to ch
19+
ch.setFormatter(formatter)
20+
# add ch to logger
21+
log.addHandler(ch)
2122

2223

2324
class TestgresLogger(threading.Thread):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy