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

Pbckp 152 multihost#78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
demonolock merged 27 commits intomasterfromPBCKP-152-multihost
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
27 commits
Select commitHold shift + click to select a range
02c3375
PBCKP-137 update node.py
Apr 10, 2023
1512afd
PBCKP-137 up version 1.8.6
Apr 11, 2023
0d62e0e
PBCKP-137 update node.py
Apr 11, 2023
8be1b3a
PBCKP-137 update node
Apr 17, 2023
51f05de
PBCKP-152 change local function on execution by ssh
May 2, 2023
f131088
PBCKP-152 merge master
May 2, 2023
4f38bd5
PBCKP-152 multihost
May 3, 2023
0da2ee2
merge master
Jun 6, 2023
2bc17f0
testgres from PBCKP-152-multihost
Jun 6, 2023
f9b6bdb
PBCKP-152
Jun 10, 2023
ac77ef7
PBCKP-152 use black for formatting
Jun 11, 2023
b048041
PBCKP-152 fix failed tests
Jun 12, 2023
e098b97
PBCKP-152 fix failed tests
Jun 13, 2023
1c405ef
PBCKP-152 add tests for remote_ops.py
Jun 14, 2023
8c373e6
PBCKP-152 add testgres tests for remote node
Jun 14, 2023
72e6d5d
PBCKP-152 fixed test_simple and test_remote
Jun 17, 2023
2c2d2c5
PBCKP-588 test fix test_restore_after_failover
Jun 22, 2023
1b4f74a
PBCKP-588 test partially fixed test_simple_remote.py 41/43
Jun 22, 2023
2e916df
PBCKP-588 fixes after review
Jun 25, 2023
0528541
PBCKP-588 fixes after review - add ConnectionParams
Jun 26, 2023
089ab9b
PBCKP-588 fixes after review - remove f-strings
Jun 26, 2023
190d084
PBCKP-588 fixes after review - replace subprocess.run on subprocess.P…
Jun 27, 2023
0c26f77
PBCKP-588 fix failed tests - psql, set_auto_conf
Jun 28, 2023
0796bc4
PBCKP-152 - test_restore_target_time cut
Jul 26, 2023
0f14034
PBCKP-152 - node set listen address
Jul 28, 2023
12aa7ba
Add info about remote mode in README.md
Aug 1, 2023
4e7f4b0
merge master
Aug 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
PBCKP-588 fixes after review
  • Loading branch information
v.shepard committedJun 25, 2023
commit2e916dfb4d044c24c421e80e4cddaa9799d0114d
15 changes: 0 additions & 15 deletionstestgres/logger.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,21 +5,6 @@
import threading
import time

# create logger
log = logging.getLogger('Testgres')

if not log.handlers:
log.setLevel(logging.WARN)
# create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(logging.WARN)
# create formatter
formatter = logging.Formatter('\n%(asctime)s - %(name)s[%(levelname)s]: %(message)s')
# add formatter to ch
ch.setFormatter(formatter)
# add ch to logger
log.addHandler(ch)


class TestgresLogger(threading.Thread):
"""
Expand Down
2 changes: 1 addition & 1 deletiontestgres/node.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -245,7 +245,7 @@ def child_processes(self):
"""

# get a list of postmaster's children
children = self.os_ops.get_remote_children(self.pid)
children = self.os_ops.get_process_children(self.pid)

return [ProcessProxy(p) for p in children]

Expand Down
4 changes: 1 addition & 3 deletionstestgres/operations/local_ops.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,7 +8,6 @@
import psutil

from testgres.exceptions import ExecUtilException
from testgres.logger import log

from .os_ops import OsOperations
from .os_ops import pglib
Expand DownExpand Up@@ -53,7 +52,6 @@ def exec_command(self, cmd, wait_exit=False, verbose=False,
"""
if isinstance(cmd, list):
cmd = ' '.join(item.decode('utf-8') if isinstance(item, bytes) else item for item in cmd)
log.debug(f"Executing command: `{cmd}`")

if os.name == 'nt':
with tempfile.NamedTemporaryFile() as buf:
Expand DownExpand Up@@ -252,7 +250,7 @@ def get_pid(self):
# Get current process id
return os.getpid()

defget_remote_children(self, pid):
defget_process_children(self, pid):
return psutil.Process(pid).children()

# Database control
Expand Down
3 changes: 3 additions & 0 deletionstestgres/operations/os_ops.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -88,6 +88,9 @@ def get_pid(self):
# Get current process id
raise NotImplementedError()

def get_process_children(self, pid):
raise NotImplementedError()

# Database control
def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
raise NotImplementedError()
12 changes: 5 additions & 7 deletionstestgres/operations/remote_ops.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,6 @@
from paramiko import SSHClient

from testgres.exceptions import ExecUtilException
from testgres.logger import log

from .os_ops import OsOperations
from .os_ops import pglib
Expand DownExpand Up@@ -90,9 +89,9 @@ def _read_ssh_key(self):
key = paramiko.RSAKey.from_private_key_file(self.ssh_key)
return key
except FileNotFoundError:
log.error(f"No such file or directory: '{self.ssh_key}'")
raise ExecUtilException(message=f"No such file or directory: '{self.ssh_key}'")
except Exception as e:
log.error(f"An error occurred while reading the ssh key: {e}")
ExecUtilException(message=f"An error occurred while reading the ssh key: {e}")

def exec_command(self, cmd: str, wait_exit=False, verbose=False, expect_error=False,
encoding=None, shell=True, text=False, input=None, stdout=None,
Expand DownExpand Up@@ -400,7 +399,7 @@ def get_pid(self):
# Get current process id
return int(self.exec_command("echo $$", encoding='utf-8'))

defget_remote_children(self, pid):
defget_process_children(self, pid):
command = f"pgrep -P {pid}"
stdin, stdout, stderr = self.ssh.exec_command(command)
children = stdout.readlines()
Expand All@@ -414,8 +413,7 @@ def db_connect(self, dbname, user, password=None, host="127.0.0.1", port=5432, s
- dbname (str): The name of the database to connect to.
- user (str): The username for the database connection.
- password (str, optional): The password for the database connection. Defaults to None.
- host (str, optional): The IP address of the remote system. Defaults to "127.0.0.1".
- hostname (str, optional): The hostname of the remote system. Defaults to "localhost".
- host (str, optional): The IP address of the remote system. Defaults to "localhost".
- port (int, optional): The port number of the PostgreSQL service. Defaults to 5432.

This function establishes a connection to a PostgreSQL database on the remote system using the specified
Expand DownExpand Up@@ -444,4 +442,4 @@ def db_connect(self, dbname, user, password=None, host="127.0.0.1", port=5432, s
return conn
except Exception as e:
self.tunnel.stop()
raisee
raiseExecUtilException("Could not create db tunnel.")
5 changes: 2 additions & 3 deletionstestgres/utils.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,9 +12,8 @@

from six import iteritems


from .exceptions import ExecUtilException
from .config import testgres_config as tconf
from .logger import log

# rows returned by PG_CONFIG
_pg_config_data = {}
Expand DownExpand Up@@ -73,7 +72,7 @@ def execute_utility(args, logfile=None, verbose=False):
lines = [u'\n'] + ['# ' + line for line in out.splitlines()] + [u'\n']
tconf.os_ops.write(filename=logfile, data=lines)
except IOError:
log.warn(f"Problem with writing to logfile `{logfile}` during run command `{args}`")
raise ExecUtilException(f"Problem with writing to logfile `{logfile}` during run command `{args}`")
if verbose:
return exit_status, out, error
else:
Expand Down
2 changes: 1 addition & 1 deletiontests/test_remote.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,7 @@ def setup(self):
self.operations = RemoteOperations(
host="172.18.0.3",
username="dev",
ssh_key='/home/vika/Desktop/work/probackup/dev-ee-probackup/container_files/postgres/ssh/id_ed25519'
ssh_key='../../container_files/postgres/ssh/id_ed25519'
)

yield
Expand Down
16 changes: 9 additions & 7 deletionstests/test_simple.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -151,6 +151,8 @@ def test_init_unique_system_id(self):
self.assertGreater(id2, id1)

def test_node_exit(self):
base_dir = None

with self.assertRaises(QueryException):
with get_new_node().init() as node:
base_dir = node.base_dir
Expand DownExpand Up@@ -252,27 +254,27 @@ def test_psql(self):

# check returned values (1 arg)
res = node.psql('select 1')
self.assertEqual((0, b'1\n', b''), res)
self.assertEqual(res,(0, b'1\n', b''))

# check returned values (2 args)
res = node.psql('postgres', 'select 2')
self.assertEqual((0, b'2\n', b''), res)
self.assertEqual(res,(0, b'2\n', b''))

# check returned values (named)
res = node.psql(query='select 3', dbname='postgres')
self.assertEqual((0, b'3\n', b''), res)
self.assertEqual(res,(0, b'3\n', b''))

# check returned values (1 arg)
res = node.safe_psql('select 4')
self.assertEqual(b'4\n', res)
self.assertEqual(res,b'4\n')

# check returned values (2 args)
res = node.safe_psql('postgres', 'select 5')
self.assertEqual(b'5\n', res)
self.assertEqual(res,b'5\n')

# check returned values (named)
res = node.safe_psql(query='select 6', dbname='postgres')
self.assertEqual(b'6\n', res)
self.assertEqual(res,b'6\n')

# check feeding input
node.safe_psql('create table horns (w int)')
Expand DownExpand Up@@ -612,7 +614,7 @@ def test_users(self):
with get_new_node().init().start() as node:
node.psql('create role test_user login')
value = node.safe_psql('select 1', username='test_user')
self.assertEqual(b'1\n', value)
self.assertEqual(value,b'1\n')

def test_poll_query_until(self):
with get_new_node() as node:
Expand Down
15 changes: 8 additions & 7 deletionstests/test_simple_remote.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,7 +35,8 @@
NodeStatus, \
ProcessType, \
IsolationLevel, \
get_new_node, RemoteOperations
get_new_node, \
RemoteOperations

from testgres import \
get_bin_path, \
Expand All@@ -54,7 +55,7 @@

os_ops = RemoteOperations(host='172.18.0.3',
username='dev',
ssh_key='/home/vika/Desktop/work/probackup/dev-ee-probackup/container_files/postgres/ssh/id_ed25519')
ssh_key='../../container_files/postgres/ssh/id_ed25519')
testgres_config.set_os_ops(os_ops=os_ops)


Expand DownExpand Up@@ -92,8 +93,8 @@ def removing(f):
os_ops.rmdirs(f, ignore_errors=True)


def get_remote_node():
return get_new_node(host=os_ops.host, username=os_ops.username, ssh_key=os_ops.ssh_key)
def get_remote_node(name=None):
return get_new_node(name=name,host=os_ops.host, username=os_ops.username, ssh_key=os_ops.ssh_key)


class TestgresRemoteTests(unittest.TestCase):
Expand DownExpand Up@@ -696,7 +697,7 @@ def test_logging(self):
'handlers': {
'file': {
'class': 'logging.FileHandler',
'filename': logfile.name,
'filename': logfile,
'formatter': 'base_format',
'level': logging.DEBUG,
},
Expand All@@ -717,7 +718,7 @@ def test_logging(self):
with scoped_config(use_python_logging=True):
node_name = 'master'

withget_new_node(name=node_name) as master:
withget_remote_node(name=node_name) as master:
master.init().start()

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

# check that master's port is found
with open(logfile.name, 'r') as log:
with open(logfile, 'r') as log:
lines = log.readlines()
self.assertTrue(any(node_name in s for s in lines))

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp