Skip to content

Commit 221ddb8

Browse files
author
v.shepard
committed
PBCKP-152 test multihost - 3
1 parent a2d9113 commit 221ddb8

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

testgres/cache.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from .consts import XLOG_CONTROL_FILE
1212

13-
from .defaults import generate_system_id
13+
from .defaults import generate_system_id, default_username
1414

1515
from .exceptions import \
1616
InitNodeException, \
@@ -21,7 +21,7 @@
2121
execute_utility
2222

2323

24-
def cached_initdb(data_dir, logfile=None, host='localhost', ssh_key=None, user='dev', params=None):
24+
def cached_initdb(data_dir, logfile=None, host='localhost', ssh_key=None, user=default_username(), params=None):
2525
"""
2626
Perform initdb or use cached node files.
2727
"""

testgres/connection.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .enums import IsolationLevel
2-
from .defaults import default_dbname
2+
from .defaults import default_dbname, default_username
33
from .exceptions import QueryException
44

55

@@ -20,7 +20,7 @@ class NodeConnection(object):
2020
def __init__(self, node, dbname=None, username=None, password=None, autocommit=False):
2121
# Set default arguments
2222
dbname = dbname or default_dbname()
23-
username = username or 'dev'
23+
username = username or default_username()
2424

2525
self._node = node
2626
self._connection = pglib.connect(database=dbname, user=username, password=password,

testgres/node.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def __repr__(self):
112112

113113
class PostgresNode(object):
114114
def __init__(self, name=None, port=None, base_dir=None,
115-
host='locahost', ssh_key=None, username='dev'):
115+
host='locahost', ssh_key=None, username=default_username()):
116116
"""
117117
PostgresNode constructor.
118118
@@ -487,6 +487,7 @@ def get_auth_method(t):
487487
auth_host = get_auth_method('host')
488488

489489
new_lines = [
490+
"local\tall\tall\t\t\ttrust\n",
490491
u"local\treplication\tall\t\t\t{}\n".format(auth_local),
491492
u"host\treplication\tall\t127.0.0.1/32\t{}\n".format(auth_host),
492493

@@ -496,15 +497,15 @@ def get_auth_method(t):
496497
u"host\treplication\tall\t::1/128\t\t{}\n".format(auth_host)
497498
] # yapf: disable
498499

499-
self.os_ops.write(hba_conf, '\n'.join(new_lines), truncate=True)
500+
self.os_ops.write(hba_conf, ''.join(new_lines), truncate=True)
500501

501502
# overwrite config file
502503
self.os_ops.write(postgres_conf, "", truncate=True)
503504

504505
self.append_conf(fsync=fsync,
505506
max_worker_processes=MAX_WORKER_PROCESSES,
506507
log_statement=log_statement,
507-
listen_addresses="'*'",
508+
listen_addresses='*',
508509
port=self.port) # yapf:disable
509510

510511
# common replication settings
@@ -825,7 +826,7 @@ def psql(self,
825826
query=None,
826827
filename=None,
827828
dbname=None,
828-
username='dev',
829+
username=default_username(),
829830
input=None,
830831
**variables):
831832
"""

testgres/os_ops.py

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import os
2-
from distutils.spawn import find_executable
32
import subprocess
43
from contextlib import contextmanager
4+
5+
from defaults import default_username
56
from testgres.logger import log
67

78
import paramiko
89

910

1011
class OsOperations:
1112

12-
def __init__(self, host, ssh_key=None, username='dev'):
13+
def __init__(self, host, ssh_key=None, username=default_username()):
1314
self.host = host
1415
self.ssh_key = ssh_key
1516
self.username = username
@@ -49,9 +50,9 @@ def exec_command(self, cmd, wait_exit=False, verbose=False):
4950
cmd = ' '.join(cmd)
5051
log.debug(f"os_ops.exec_command: `{cmd}`; remote={self.remote}")
5152
# Source global profile file + execute command
52-
cmd = f"source /etc/profile.d/custom.sh; {cmd}"
5353
try:
5454
if self.remote:
55+
cmd = f"source /etc/profile.d/custom.sh; {cmd}"
5556
with self.ssh_connect() as ssh:
5657
stdin, stdout, stderr = ssh.exec_command(cmd)
5758
exit_status = 0
@@ -60,15 +61,15 @@ def exec_command(self, cmd, wait_exit=False, verbose=False):
6061
result = stdout.read().decode('utf-8')
6162
error = stderr.read().decode('utf-8')
6263
else:
63-
process = subprocess.run(cmd, shell=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
64+
process = subprocess.run(cmd, shell=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
65+
timeout=60)
6466
exit_status = process.returncode
6567
result = process.stdout
6668
error = process.stderr
6769

68-
if exit_status != 0 or error != '':
69-
log.error(f"Problem in executing command: `{cmd}`;\nerror: `{error}`;\nexit_code: {exit_status}")
70-
if 'error' in error.lower():
71-
exit(1)
70+
if exit_status != 0 or 'error' in error.lower():
71+
log.error(f"Problem in executing command: `{cmd}`\nerror: {error}\nexit_code: {exit_status}")
72+
exit(1)
7273

7374
if verbose:
7475
return exit_status, result, error
@@ -131,20 +132,17 @@ def isfile(self, remote_file):
131132
return os.path.isfile(remote_file)
132133

133134
def find_executable(self, executable):
134-
if self.remote:
135-
search_paths = self.environ('PATH')
136-
if not search_paths:
137-
return None
135+
search_paths = self.environ('PATH')
136+
if not search_paths:
137+
return None
138138

139-
search_paths = search_paths.split(self.pathsep)
140-
for path in search_paths:
141-
remote_file = os.path.join(path, executable)
142-
if self.isfile(remote_file):
143-
return remote_file
139+
search_paths = search_paths.split(self.pathsep)
140+
for path in search_paths:
141+
remote_file = os.path.join(path, executable)
142+
if self.isfile(remote_file):
143+
return remote_file
144144

145-
return None
146-
else:
147-
return find_executable(executable)
145+
return None
148146

149147
def is_executable(self, file):
150148
# Check if the file is executable

testgres/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from packaging.version import Version
1515
from six import iteritems
1616

17+
from defaults import default_username
1718
from .os_ops import OsOperations
1819
from .config import testgres_config
1920
from .exceptions import ExecUtilException
@@ -47,7 +48,7 @@ def release_port(port):
4748
bound_ports.discard(port)
4849

4950

50-
def execute_utility(args, logfile=None, host='localhost', ssh_key=None, user='dev', wait_exit=False):
51+
def execute_utility(args, logfile=None, host='localhost', ssh_key=None, user=default_username(), wait_exit=False):
5152
"""
5253
Execute utility wrapper (pg_ctl, pg_dump etc).
5354

0 commit comments

Comments
 (0)