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

Commit86ef2fb

Browse files
committed
Add compatibility for tests on the remote hosts
1 parentd9fba83 commit86ef2fb

File tree

6 files changed

+70
-11
lines changed

6 files changed

+70
-11
lines changed

‎setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
fromdistutils.coreimportsetup
77

88
# Basic dependencies
9-
install_requires= ["pg8000","port-for>=0.4","six>=1.9.0","psutil"]
9+
install_requires= ["pg8000","port-for>=0.4","six>=1.9.0","psutil","fabric"]
1010

1111
# Add compatibility enum class
1212
ifsys.version_info< (3,4):
@@ -21,7 +21,7 @@
2121
readme=f.read()
2222

2323
setup(
24-
version='1.8.4',
24+
version='1.9.0',
2525
name='testgres',
2626
packages=['testgres'],
2727
description='Testing utility for PostgreSQL and its extensions',

‎testgres/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ def get_new_node(name=None, base_dir=None, **kwargs):
3838
Simply a wrapper around :class:`.PostgresNode` constructor.
3939
See :meth:`.PostgresNode.__init__` for details.
4040
"""
41+
4142
# NOTE: leave explicit 'name' and 'base_dir' for compatibility
4243
returnPostgresNode(name=name,base_dir=base_dir,**kwargs)

‎testgres/cache.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@
2121
execute_utility
2222

2323

24-
defcached_initdb(data_dir,logfile=None,params=None):
24+
defcached_initdb(data_dir,logfile=None,hostname='localhost',ssh_key=None,params=None):
2525
"""
2626
Perform initdb or use cached node files.
27-
"""
2827
28+
DDD return
29+
"""
30+
2931
defcall_initdb(initdb_dir,log=None):
3032
try:
3133
_params= [get_bin_path("initdb"),"-D",initdb_dir,"-N"]
32-
execute_utility(_params+ (paramsor []),log)
34+
35+
# DDD return executions code
36+
execute_utility(_params+ (paramsor []),log,hostname=hostname)
3337
exceptExecUtilExceptionase:
3438
raise_from(InitNodeException("Failed to run initdb"),e)
3539

@@ -59,7 +63,10 @@ def call_initdb(initdb_dir, log=None):
5963

6064
# XXX: build new WAL segment with our system id
6165
_params= [get_bin_path("pg_resetwal"),"-D",data_dir,"-f"]
62-
execute_utility(_params,logfile)
66+
67+
68+
# DDD refactor to PostgresNode method and check execute code
69+
execute_utility(_params,logfile,hostname=hostname)
6370

6471
exceptExecUtilExceptionase:
6572
msg="Failed to reset WAL for system id"

‎testgres/logger.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@
66
importtime
77

88

9+
# create logger
10+
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)
21+
22+
923
classTestgresLogger(threading.Thread):
1024
"""
1125
Helper class to implement reading from log files.

‎testgres/node.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ def __repr__(self):
106106

107107

108108
classPostgresNode(object):
109-
def__init__(self,name=None,port=None,base_dir=None):
109+
def__init__(self,name=None,port=None,base_dir=None,
110+
host='*',hostname='locahost'):
110111
"""
111112
PostgresNode constructor.
112113
@@ -124,10 +125,12 @@ def __init__(self, name=None, port=None, base_dir=None):
124125
self._master=None
125126

126127
# basic
127-
self.host='127.0.0.1'
128128
self.name=nameorgenerate_app_name()
129129
self.port=portorreserve_port()
130130

131+
self.host=host
132+
self.hostname=hostname
133+
131134
# defaults for __exit__()
132135
self.cleanup_on_good_exit=testgres_config.node_cleanup_on_good_exit
133136
self.cleanup_on_bad_exit=testgres_config.node_cleanup_on_bad_exit
@@ -415,7 +418,7 @@ def _collect_special_files(self):
415418

416419
returnresult
417420

418-
definit(self,initdb_params=None,**kwargs):
421+
definit(self,initdb_params=None,hostname='localhost',ssh_key=None,**kwargs):
419422
"""
420423
Perform initdb for this node.
421424
@@ -433,6 +436,8 @@ def init(self, initdb_params=None, **kwargs):
433436
cached_initdb(
434437
data_dir=self.data_dir,
435438
logfile=self.utils_log_file,
439+
hostname=self.hostname,
440+
ssh_key=ssh_key,
436441
params=initdb_params)
437442

438443
# initialize default config files
@@ -490,6 +495,10 @@ def get_auth_method(t):
490495
new_lines= [
491496
u"local\treplication\tall\t\t\t{}\n".format(auth_local),
492497
u"host\treplication\tall\t127.0.0.1/32\t{}\n".format(auth_host),
498+
499+
u"host\treplication\tall\t0.0.0.0/0\t{}\n".format(auth_host),
500+
u"host\tall\tall\t0.0.0.0/0\t{}\n".format(auth_host),
501+
493502
u"host\treplication\tall\t::1/128\t\t{}\n".format(auth_host)
494503
]# yapf: disable
495504

‎testgres/utils.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
importsubprocess
1010
importsys
1111
importtempfile
12+
importsocket
1213

1314
fromcontextlibimportcontextmanager
1415
fromdistutils.versionimportLooseVersion
1516
fromdistutils.spawnimportfind_executable
1617
fromsiximportiteritems
1718

19+
# Add remote host call
20+
fromfabricimportConnection
21+
1822
from .configimporttestgres_config
1923
from .exceptionsimportExecUtilException
2024

@@ -47,18 +51,42 @@ def release_port(port):
4751
bound_ports.discard(port)
4852

4953

50-
defexecute_utility(args,logfile=None):
54+
defexecute_utility(args,logfile=None,hostname='localhost',ssh_key=None):
5155
"""
52-
Execute utility (pg_ctl, pg_dump etc).
56+
Execute utility wrapper (pg_ctl, pg_dump etc).
57+
58+
# DDD pass host_params
59+
# DDD logfile ... use logging and STDOUT & FILE proxying
5360
5461
Args:
5562
args: utility + arguments (list).
63+
host_params : dict {
5664
logfile: path to file to store stdout and stderr.
5765
5866
Returns:
5967
stdout of executed utility.
6068
"""
6169

70+
71+
ifhostname!='localhost':
72+
conn=Connection(
73+
hostname,
74+
connect_kwargs={
75+
# XXX pass SSH key path
76+
"key_filename":"/mnt/ssh/id_rsa",
77+
},
78+
)
79+
80+
# TODO skip remote ssh run if we are on the localhost.
81+
# result = conn.run('hostname', hide=True)
82+
# add logger
83+
84+
cmd=' '.join(args)
85+
result=conn.run(cmd,hide=True)
86+
87+
returnresult
88+
89+
6290
# run utility
6391
ifos.name=='nt':
6492
# using output to a temporary file in Windows

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp