testgres-pg-probackup2 0.0.2__tar.gz → 0.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (15) hide show
  1. {testgres_pg_probackup2-0.0.2 → testgres_pg_probackup2-0.0.4}/PKG-INFO +2 -5
  2. {testgres_pg_probackup2-0.0.2 → testgres_pg_probackup2-0.0.4}/pg_probackup2/app.py +53 -19
  3. {testgres_pg_probackup2-0.0.2 → testgres_pg_probackup2-0.0.4}/pg_probackup2/gdb.py +4 -1
  4. {testgres_pg_probackup2-0.0.2 → testgres_pg_probackup2-0.0.4}/pg_probackup2/init_helpers.py +12 -4
  5. {testgres_pg_probackup2-0.0.2 → testgres_pg_probackup2-0.0.4}/setup.py +1 -1
  6. {testgres_pg_probackup2-0.0.2 → testgres_pg_probackup2-0.0.4}/testgres_pg_probackup2.egg-info/PKG-INFO +3 -6
  7. {testgres_pg_probackup2-0.0.2 → testgres_pg_probackup2-0.0.4}/README.md +0 -0
  8. {testgres_pg_probackup2-0.0.2 → testgres_pg_probackup2-0.0.4}/pg_probackup2/__init__.py +0 -0
  9. {testgres_pg_probackup2-0.0.2 → testgres_pg_probackup2-0.0.4}/pg_probackup2/storage/__init__.py +0 -0
  10. {testgres_pg_probackup2-0.0.2 → testgres_pg_probackup2-0.0.4}/pg_probackup2/storage/fs_backup.py +0 -0
  11. {testgres_pg_probackup2-0.0.2 → testgres_pg_probackup2-0.0.4}/setup.cfg +0 -0
  12. {testgres_pg_probackup2-0.0.2 → testgres_pg_probackup2-0.0.4}/testgres_pg_probackup2.egg-info/SOURCES.txt +0 -0
  13. {testgres_pg_probackup2-0.0.2 → testgres_pg_probackup2-0.0.4}/testgres_pg_probackup2.egg-info/dependency_links.txt +0 -0
  14. {testgres_pg_probackup2-0.0.2 → testgres_pg_probackup2-0.0.4}/testgres_pg_probackup2.egg-info/requires.txt +0 -0
  15. {testgres_pg_probackup2-0.0.2 → testgres_pg_probackup2-0.0.4}/testgres_pg_probackup2.egg-info/top_level.txt +0 -0
@@ -1,14 +1,11 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: testgres_pg_probackup2
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: Plugin for testgres that manages pg_probackup2
5
5
  Home-page: https://github.com/postgrespro/testgres
6
6
  Author: Postgres Professional
7
7
  Author-email: testgres@postgrespro.ru
8
8
  License: PostgreSQL
9
9
  Keywords: pg_probackup,testing,testgres
10
- Platform: UNKNOWN
11
10
  Description-Content-Type: text/markdown
12
-
13
- UNKNOWN
14
-
11
+ Requires-Dist: testgres>=1.9.2
@@ -1,6 +1,7 @@
1
1
  import contextlib
2
2
  import importlib
3
3
  import json
4
+ import logging
4
5
  import os
5
6
  import re
6
7
  import subprocess
@@ -43,19 +44,21 @@ fs_backup_class = FSTestBackupDir
43
44
  class ProbackupApp:
44
45
 
45
46
  def __init__(self, test_class: unittest.TestCase,
46
- pg_node, pb_log_path, test_env, auto_compress_alg, backup_dir):
47
+ pg_node, pb_log_path, test_env, auto_compress_alg, backup_dir, probackup_path=None):
47
48
  self.test_class = test_class
48
49
  self.pg_node = pg_node
49
50
  self.pb_log_path = pb_log_path
50
51
  self.test_env = test_env
51
52
  self.auto_compress_alg = auto_compress_alg
52
53
  self.backup_dir = backup_dir
53
- self.probackup_path = init_params.probackup_path
54
+ self.probackup_path = probackup_path or init_params.probackup_path
54
55
  self.probackup_old_path = init_params.probackup_old_path
55
56
  self.remote = init_params.remote
57
+ self.wal_tree_enabled = init_params.wal_tree_enabled
56
58
  self.verbose = init_params.verbose
57
59
  self.archive_compress = init_params.archive_compress
58
60
  self.test_class.output = None
61
+ self.execution_time = None
59
62
 
60
63
  def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
61
64
  skip_log_directory=False, expect_error=False, use_backup_dir=True):
@@ -71,9 +74,11 @@ class ProbackupApp:
71
74
  command = [command[0], *use_backup_dir.pb_args, *command[1:]]
72
75
  elif use_backup_dir:
73
76
  command = [command[0], *self.backup_dir.pb_args, *command[1:]]
77
+ else:
78
+ command = [command[0], *self.backup_dir.pb_args[2:], *command[1:]]
74
79
 
75
80
  if not self.probackup_old_path and old_binary:
76
- print('PGPROBACKUPBIN_OLD is not set')
81
+ logging.error('PGPROBACKUPBIN_OLD is not set')
77
82
  exit(1)
78
83
 
79
84
  if old_binary:
@@ -106,23 +111,23 @@ class ProbackupApp:
106
111
  return GDBobj(cmdline, self.test_class)
107
112
 
108
113
  try:
109
- result = None
110
114
  if type(gdb) is tuple and gdb[0] == 'suspend':
111
115
  # special test flow for manually debug probackup
112
116
  gdb_port = gdb[1]
113
117
  cmdline = ['gdbserver'] + ['localhost:' + str(gdb_port)] + cmdline
114
- print("pg_probackup gdb suspended, waiting gdb connection on localhost:{0}".format(gdb_port))
118
+ logging.warning("pg_probackup gdb suspended, waiting gdb connection on localhost:{0}".format(gdb_port))
115
119
 
120
+ start_time = time.time()
116
121
  self.test_class.output = subprocess.check_output(
117
122
  cmdline,
118
123
  stderr=subprocess.STDOUT,
119
124
  env=env
120
125
  ).decode('utf-8', errors='replace')
126
+ end_time = time.time()
127
+ self.execution_time = end_time - start_time
128
+
121
129
  if command[0] == 'backup' and return_id:
122
- # return backup ID
123
- for line in self.test_class.output.splitlines():
124
- if 'INFO: Backup' and 'completed' in line:
125
- result = line.split()[2]
130
+ result = self.get_backup_id()
126
131
  else:
127
132
  result = self.test_class.output
128
133
  if expect_error is True:
@@ -139,6 +144,19 @@ class ProbackupApp:
139
144
  else:
140
145
  raise ProbackupException(self.test_class.output, self.test_class.cmd)
141
146
 
147
+ def get_backup_id(self):
148
+ if init_params.major_version > 2:
149
+ pattern = re.compile(r"Backup (.*) completed successfully.")
150
+ for line in self.test_class.output.splitlines():
151
+ match = pattern.search(line)
152
+ if match:
153
+ return match.group(1)
154
+ else:
155
+ for line in self.test_class.output.splitlines():
156
+ if 'INFO: Backup' and 'completed' in line:
157
+ return line.split()[2]
158
+ return None
159
+
142
160
  def init(self, options=None, old_binary=False, skip_log_directory=False, expect_error=False, use_backup_dir=True):
143
161
  if options is None:
144
162
  options = []
@@ -149,13 +167,19 @@ class ProbackupApp:
149
167
  use_backup_dir=use_backup_dir
150
168
  )
151
169
 
152
- def add_instance(self, instance, node, old_binary=False, options=None, expect_error=False):
170
+ def add_instance(self, instance, node, old_binary=False, options=None, expect_error=False, datname=False):
153
171
  if options is None:
154
172
  options = []
173
+
174
+ if not datname:
175
+ datname = 'postgres'
176
+
155
177
  cmd = [
156
178
  'add-instance',
157
179
  '--instance={0}'.format(instance),
158
- '-D', node.data_dir
180
+ '-D', node.data_dir,
181
+ '--pgport', '%i' % node.port,
182
+ '--pgdatabase', datname
159
183
  ]
160
184
 
161
185
  # don`t forget to kill old_binary after remote ssh release
@@ -164,6 +188,9 @@ class ProbackupApp:
164
188
  '--remote-proto=ssh',
165
189
  '--remote-host=localhost']
166
190
 
191
+ if self.wal_tree_enabled:
192
+ options = options + ['--wal-tree']
193
+
167
194
  return self.run(cmd + options, old_binary=old_binary, expect_error=expect_error)
168
195
 
169
196
  def set_config(self, instance, old_binary=False, options=None, expect_error=False):
@@ -212,7 +239,7 @@ class ProbackupApp:
212
239
  if options is None:
213
240
  options = []
214
241
  if not node and not data_dir:
215
- print('You must provide ether node or data_dir for backup')
242
+ logging.error('You must provide ether node or data_dir for backup')
216
243
  exit(1)
217
244
 
218
245
  if not datname:
@@ -367,6 +394,7 @@ class ProbackupApp:
367
394
  backup_mode, source_pgdata, destination_node,
368
395
  options=None,
369
396
  remote_host='localhost',
397
+ remote_port=None,
370
398
  expect_error=False,
371
399
  gdb=False
372
400
  ):
@@ -380,7 +408,9 @@ class ProbackupApp:
380
408
  '--destination-pgdata={0}'.format(destination_node.data_dir)
381
409
  ]
382
410
  if self.remote:
383
- cmd_list += ['--remote-proto=ssh', '--remote-host=%s' % remote_host]
411
+ cmd_list += ['--remote-proto=ssh', f'--remote-host={remote_host}']
412
+ if remote_port:
413
+ cmd_list.append(f'--remote-port={remote_port}')
384
414
  if self.verbose:
385
415
  cmd_list += [
386
416
  '--log-level-file=VERBOSE',
@@ -478,7 +508,7 @@ class ProbackupApp:
478
508
  if i == '':
479
509
  backup_record_split.remove(i)
480
510
  if len(header_split) != len(backup_record_split):
481
- print(warning.format(
511
+ logging.error(warning.format(
482
512
  header=header, body=body,
483
513
  header_split=header_split,
484
514
  body_split=backup_record_split)
@@ -557,7 +587,7 @@ class ProbackupApp:
557
587
  else:
558
588
  show_splitted = self.run(cmd_list + options, old_binary=old_binary,
559
589
  expect_error=expect_error).splitlines()
560
- print(show_splitted)
590
+ logging.error(show_splitted)
561
591
  exit(1)
562
592
 
563
593
  def validate(
@@ -681,9 +711,13 @@ class ProbackupApp:
681
711
  if overwrite:
682
712
  archive_command += ' --overwrite'
683
713
 
684
- archive_command += ' --log-level-console=VERBOSE'
685
- archive_command += ' -j 5'
686
- archive_command += ' --batch-size 10'
714
+ if init_params.major_version > 2:
715
+ archive_command += ' --log-level-console=trace'
716
+ else:
717
+ archive_command += ' --log-level-console=VERBOSE'
718
+ archive_command += ' -j 5'
719
+ archive_command += ' --batch-size 10'
720
+
687
721
  archive_command += ' --no-sync'
688
722
 
689
723
  if archive_timeout:
@@ -745,7 +779,7 @@ class ProbackupApp:
745
779
  if fs_type:
746
780
  implementation = fs_type
747
781
 
748
- print("Using ", implementation)
782
+ logging.info("Using ", implementation)
749
783
  module_name, class_name = implementation.rsplit(sep='.', maxsplit=1)
750
784
 
751
785
  module = importlib.import_module(module_name)
@@ -37,7 +37,7 @@ class GDBobj:
37
37
  " to run GDB tests")
38
38
  raise GdbException("No gdb usage possible.")
39
39
 
40
- # Check gdb presense
40
+ # Check gdb presence
41
41
  try:
42
42
  gdb_version, _ = subprocess.Popen(
43
43
  ['gdb', '--version'],
@@ -108,6 +108,9 @@ class GDBobj:
108
108
  self.proc.stdin.close()
109
109
  self.proc.stdout.close()
110
110
 
111
+ def terminate_subprocess(self):
112
+ self._execute('kill')
113
+
111
114
  def set_breakpoint(self, location):
112
115
 
113
116
  result = self._execute('break ' + location)
@@ -1,3 +1,4 @@
1
+ import logging
1
2
  from functools import reduce
2
3
  import getpass
3
4
  import os
@@ -31,7 +32,7 @@ try:
31
32
  cached_initdb_dir=False,
32
33
  node_cleanup_full=delete_logs)
33
34
  except Exception as e:
34
- print("Can't configure testgres: {0}".format(e))
35
+ logging.warning("Can't configure testgres: {0}".format(e))
35
36
 
36
37
 
37
38
  class Init(object):
@@ -104,7 +105,7 @@ class Init(object):
104
105
 
105
106
  if os.path.isfile(probackup_path_tmp):
106
107
  if not os.access(probackup_path_tmp, os.X_OK):
107
- print('{0} is not an executable file'.format(
108
+ logging.warning('{0} is not an executable file'.format(
108
109
  probackup_path_tmp))
109
110
  else:
110
111
  self.probackup_path = probackup_path_tmp
@@ -114,13 +115,13 @@ class Init(object):
114
115
 
115
116
  if os.path.isfile(probackup_path_tmp):
116
117
  if not os.access(probackup_path_tmp, os.X_OK):
117
- print('{0} is not an executable file'.format(
118
+ logging.warning('{0} is not an executable file'.format(
118
119
  probackup_path_tmp))
119
120
  else:
120
121
  self.probackup_path = probackup_path_tmp
121
122
 
122
123
  if not self.probackup_path:
123
- print('pg_probackup binary is not found')
124
+ logging.error('pg_probackup binary is not found')
124
125
  exit(1)
125
126
 
126
127
  if os.name == 'posix':
@@ -169,6 +170,7 @@ class Init(object):
169
170
 
170
171
  self.remote = test_env.get('PGPROBACKUP_SSH_REMOTE', None) == 'ON'
171
172
  self.ptrack = test_env.get('PG_PROBACKUP_PTRACK', None) == 'ON' and self.pg_config_version >= 110000
173
+ self.wal_tree_enabled = test_env.get('PG_PROBACKUP_WAL_TREE_ENABLED', None) == 'ON'
172
174
 
173
175
  self.paranoia = test_env.get('PG_PROBACKUP_PARANOIA', None) == 'ON'
174
176
  env_compress = test_env.get('ARCHIVE_COMPRESSION', None)
@@ -204,6 +206,12 @@ class Init(object):
204
206
  os.environ["PGAPPNAME"] = "pg_probackup"
205
207
  self.delete_logs = delete_logs
206
208
 
209
+ if self.probackup_version.split('.')[0].isdigit():
210
+ self.major_version = int(self.probackup_version.split('.')[0])
211
+ else:
212
+ logging.error('Can\'t process pg_probackup version \"{}\": the major version is expected to be a number'.format(self.probackup_version))
213
+ sys.exit(1)
214
+
207
215
  def test_env(self):
208
216
  return self._test_env.copy()
209
217
 
@@ -4,7 +4,7 @@ except ImportError:
4
4
  from distutils.core import setup
5
5
 
6
6
  setup(
7
- version='0.0.2',
7
+ version='0.0.4',
8
8
  name='testgres_pg_probackup2',
9
9
  packages=['pg_probackup2', 'pg_probackup2.storage'],
10
10
  description='Plugin for testgres that manages pg_probackup2',
@@ -1,14 +1,11 @@
1
1
  Metadata-Version: 2.1
2
- Name: testgres-pg-probackup2
3
- Version: 0.0.2
2
+ Name: testgres_pg_probackup2
3
+ Version: 0.0.4
4
4
  Summary: Plugin for testgres that manages pg_probackup2
5
5
  Home-page: https://github.com/postgrespro/testgres
6
6
  Author: Postgres Professional
7
7
  Author-email: testgres@postgrespro.ru
8
8
  License: PostgreSQL
9
9
  Keywords: pg_probackup,testing,testgres
10
- Platform: UNKNOWN
11
10
  Description-Content-Type: text/markdown
12
-
13
- UNKNOWN
14
-
11
+ Requires-Dist: testgres>=1.9.2