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

Commit2e916df

Browse files
author
v.shepard
committed
PBCKP-588 fixes after review
1 parent1b4f74a commit2e916df

File tree

9 files changed

+30
-44
lines changed

9 files changed

+30
-44
lines changed

‎testgres/logger.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,6 @@
55
importthreading
66
importtime
77

8-
# create logger
9-
log=logging.getLogger('Testgres')
10-
11-
ifnotlog.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)
22-
238

249
classTestgresLogger(threading.Thread):
2510
"""

‎testgres/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def child_processes(self):
245245
"""
246246

247247
# get a list of postmaster's children
248-
children=self.os_ops.get_remote_children(self.pid)
248+
children=self.os_ops.get_process_children(self.pid)
249249

250250
return [ProcessProxy(p)forpinchildren]
251251

‎testgres/operations/local_ops.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
importpsutil
99

1010
fromtestgres.exceptionsimportExecUtilException
11-
fromtestgres.loggerimportlog
1211

1312
from .os_opsimportOsOperations
1413
from .os_opsimportpglib
@@ -53,7 +52,6 @@ def exec_command(self, cmd, wait_exit=False, verbose=False,
5352
"""
5453
ifisinstance(cmd,list):
5554
cmd=' '.join(item.decode('utf-8')ifisinstance(item,bytes)elseitemforitemincmd)
56-
log.debug(f"Executing command: `{cmd}`")
5755

5856
ifos.name=='nt':
5957
withtempfile.NamedTemporaryFile()asbuf:
@@ -252,7 +250,7 @@ def get_pid(self):
252250
# Get current process id
253251
returnos.getpid()
254252

255-
defget_remote_children(self,pid):
253+
defget_process_children(self,pid):
256254
returnpsutil.Process(pid).children()
257255

258256
# Database control

‎testgres/operations/os_ops.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ def get_pid(self):
8888
# Get current process id
8989
raiseNotImplementedError()
9090

91+
defget_process_children(self,pid):
92+
raiseNotImplementedError()
93+
9194
# Database control
9295
defdb_connect(self,dbname,user,password=None,host="localhost",port=5432):
9396
raiseNotImplementedError()

‎testgres/operations/remote_ops.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
fromparamikoimportSSHClient
1010

1111
fromtestgres.exceptionsimportExecUtilException
12-
fromtestgres.loggerimportlog
1312

1413
from .os_opsimportOsOperations
1514
from .os_opsimportpglib
@@ -90,9 +89,9 @@ def _read_ssh_key(self):
9089
key=paramiko.RSAKey.from_private_key_file(self.ssh_key)
9190
returnkey
9291
exceptFileNotFoundError:
93-
log.error(f"No such file or directory: '{self.ssh_key}'")
92+
raiseExecUtilException(message=f"No such file or directory: '{self.ssh_key}'")
9493
exceptExceptionase:
95-
log.error(f"An error occurred while reading the ssh key:{e}")
94+
ExecUtilException(message=f"An error occurred while reading the ssh key:{e}")
9695

9796
defexec_command(self,cmd:str,wait_exit=False,verbose=False,expect_error=False,
9897
encoding=None,shell=True,text=False,input=None,stdout=None,
@@ -400,7 +399,7 @@ def get_pid(self):
400399
# Get current process id
401400
returnint(self.exec_command("echo $$",encoding='utf-8'))
402401

403-
defget_remote_children(self,pid):
402+
defget_process_children(self,pid):
404403
command=f"pgrep -P{pid}"
405404
stdin,stdout,stderr=self.ssh.exec_command(command)
406405
children=stdout.readlines()
@@ -414,8 +413,7 @@ def db_connect(self, dbname, user, password=None, host="127.0.0.1", port=5432, s
414413
- dbname (str): The name of the database to connect to.
415414
- user (str): The username for the database connection.
416415
- password (str, optional): The password for the database connection. Defaults to None.
417-
- host (str, optional): The IP address of the remote system. Defaults to "127.0.0.1".
418-
- hostname (str, optional): The hostname of the remote system. Defaults to "localhost".
416+
- host (str, optional): The IP address of the remote system. Defaults to "localhost".
419417
- port (int, optional): The port number of the PostgreSQL service. Defaults to 5432.
420418
421419
This function establishes a connection to a PostgreSQL database on the remote system using the specified
@@ -444,4 +442,4 @@ def db_connect(self, dbname, user, password=None, host="127.0.0.1", port=5432, s
444442
returnconn
445443
exceptExceptionase:
446444
self.tunnel.stop()
447-
raisee
445+
raiseExecUtilException("Could not create db tunnel.")

‎testgres/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212

1313
fromsiximportiteritems
1414

15-
15+
from .exceptionsimportExecUtilException
1616
from .configimporttestgres_configastconf
17-
from .loggerimportlog
1817

1918
# rows returned by PG_CONFIG
2019
_pg_config_data= {}
@@ -73,7 +72,7 @@ def execute_utility(args, logfile=None, verbose=False):
7372
lines= [u'\n']+ ['# '+lineforlineinout.splitlines()]+ [u'\n']
7473
tconf.os_ops.write(filename=logfile,data=lines)
7574
exceptIOError:
76-
log.warn(f"Problem with writing to logfile `{logfile}` during run command `{args}`")
75+
raiseExecUtilException(f"Problem with writing to logfile `{logfile}` during run command `{args}`")
7776
ifverbose:
7877
returnexit_status,out,error
7978
else:

‎tests/test_remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def setup(self):
1111
self.operations=RemoteOperations(
1212
host="172.18.0.3",
1313
username="dev",
14-
ssh_key='/home/vika/Desktop/work/probackup/dev-ee-probackup/container_files/postgres/ssh/id_ed25519'
14+
ssh_key='../../container_files/postgres/ssh/id_ed25519'
1515
)
1616

1717
yield

‎tests/test_simple.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ def test_init_unique_system_id(self):
151151
self.assertGreater(id2,id1)
152152

153153
deftest_node_exit(self):
154+
base_dir=None
155+
154156
withself.assertRaises(QueryException):
155157
withget_new_node().init()asnode:
156158
base_dir=node.base_dir
@@ -252,27 +254,27 @@ def test_psql(self):
252254

253255
# check returned values (1 arg)
254256
res=node.psql('select 1')
255-
self.assertEqual((0,b'1\n',b''),res)
257+
self.assertEqual(res,(0,b'1\n',b''))
256258

257259
# check returned values (2 args)
258260
res=node.psql('postgres','select 2')
259-
self.assertEqual((0,b'2\n',b''),res)
261+
self.assertEqual(res,(0,b'2\n',b''))
260262

261263
# check returned values (named)
262264
res=node.psql(query='select 3',dbname='postgres')
263-
self.assertEqual((0,b'3\n',b''),res)
265+
self.assertEqual(res,(0,b'3\n',b''))
264266

265267
# check returned values (1 arg)
266268
res=node.safe_psql('select 4')
267-
self.assertEqual(b'4\n',res)
269+
self.assertEqual(res,b'4\n')
268270

269271
# check returned values (2 args)
270272
res=node.safe_psql('postgres','select 5')
271-
self.assertEqual(b'5\n',res)
273+
self.assertEqual(res,b'5\n')
272274

273275
# check returned values (named)
274276
res=node.safe_psql(query='select 6',dbname='postgres')
275-
self.assertEqual(b'6\n',res)
277+
self.assertEqual(res,b'6\n')
276278

277279
# check feeding input
278280
node.safe_psql('create table horns (w int)')
@@ -612,7 +614,7 @@ def test_users(self):
612614
withget_new_node().init().start()asnode:
613615
node.psql('create role test_user login')
614616
value=node.safe_psql('select 1',username='test_user')
615-
self.assertEqual(b'1\n',value)
617+
self.assertEqual(value,b'1\n')
616618

617619
deftest_poll_query_until(self):
618620
withget_new_node()asnode:

‎tests/test_simple_remote.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
NodeStatus, \
3636
ProcessType, \
3737
IsolationLevel, \
38-
get_new_node,RemoteOperations
38+
get_new_node, \
39+
RemoteOperations
3940

4041
fromtestgresimport \
4142
get_bin_path, \
@@ -54,7 +55,7 @@
5455

5556
os_ops=RemoteOperations(host='172.18.0.3',
5657
username='dev',
57-
ssh_key='/home/vika/Desktop/work/probackup/dev-ee-probackup/container_files/postgres/ssh/id_ed25519')
58+
ssh_key='../../container_files/postgres/ssh/id_ed25519')
5859
testgres_config.set_os_ops(os_ops=os_ops)
5960

6061

@@ -92,8 +93,8 @@ def removing(f):
9293
os_ops.rmdirs(f,ignore_errors=True)
9394

9495

95-
defget_remote_node():
96-
returnget_new_node(host=os_ops.host,username=os_ops.username,ssh_key=os_ops.ssh_key)
96+
defget_remote_node(name=None):
97+
returnget_new_node(name=name,host=os_ops.host,username=os_ops.username,ssh_key=os_ops.ssh_key)
9798

9899

99100
classTestgresRemoteTests(unittest.TestCase):
@@ -696,7 +697,7 @@ def test_logging(self):
696697
'handlers': {
697698
'file': {
698699
'class':'logging.FileHandler',
699-
'filename':logfile.name,
700+
'filename':logfile,
700701
'formatter':'base_format',
701702
'level':logging.DEBUG,
702703
},
@@ -717,7 +718,7 @@ def test_logging(self):
717718
withscoped_config(use_python_logging=True):
718719
node_name='master'
719720

720-
withget_new_node(name=node_name)asmaster:
721+
withget_remote_node(name=node_name)asmaster:
721722
master.init().start()
722723

723724
# execute a dummy query a few times
@@ -729,7 +730,7 @@ def test_logging(self):
729730
time.sleep(0.1)
730731

731732
# check that master's port is found
732-
withopen(logfile.name,'r')aslog:
733+
withopen(logfile,'r')aslog:
733734
lines=log.readlines()
734735
self.assertTrue(any(node_nameinsforsinlines))
735736

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp