testgres-pg-probackup2 0.1.1__tar.gz → 0.2.1__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 (17) hide show
  1. {testgres_pg_probackup2-0.1.1 → testgres_pg_probackup2-0.2.1}/PKG-INFO +1 -1
  2. {testgres_pg_probackup2-0.1.1 → testgres_pg_probackup2-0.2.1}/README.md +3 -1
  3. {testgres_pg_probackup2-0.1.1 → testgres_pg_probackup2-0.2.1}/pg_probackup2/app.py +71 -22
  4. {testgres_pg_probackup2-0.1.1 → testgres_pg_probackup2-0.2.1}/pg_probackup2/init_helpers.py +3 -0
  5. testgres_pg_probackup2-0.2.1/pg_probackup2/storage/__init__.py +1 -0
  6. {testgres_pg_probackup2-0.1.1 → testgres_pg_probackup2-0.2.1}/setup.py +1 -1
  7. {testgres_pg_probackup2-0.1.1 → testgres_pg_probackup2-0.2.1}/testgres_pg_probackup2.egg-info/PKG-INFO +1 -1
  8. testgres_pg_probackup2-0.2.1/testgres_pg_probackup2.egg-info/dependency_links.txt +1 -0
  9. testgres_pg_probackup2-0.1.1/pg_probackup2/__init__.py +0 -0
  10. testgres_pg_probackup2-0.1.1/pg_probackup2/storage/__init__.py +0 -0
  11. /testgres_pg_probackup2-0.1.1/testgres_pg_probackup2.egg-info/dependency_links.txt → /testgres_pg_probackup2-0.2.1/pg_probackup2/__init__.py +0 -0
  12. {testgres_pg_probackup2-0.1.1 → testgres_pg_probackup2-0.2.1}/pg_probackup2/gdb.py +0 -0
  13. {testgres_pg_probackup2-0.1.1 → testgres_pg_probackup2-0.2.1}/pg_probackup2/storage/fs_backup.py +0 -0
  14. {testgres_pg_probackup2-0.1.1 → testgres_pg_probackup2-0.2.1}/setup.cfg +0 -0
  15. {testgres_pg_probackup2-0.1.1 → testgres_pg_probackup2-0.2.1}/testgres_pg_probackup2.egg-info/SOURCES.txt +0 -0
  16. {testgres_pg_probackup2-0.1.1 → testgres_pg_probackup2-0.2.1}/testgres_pg_probackup2.egg-info/requires.txt +0 -0
  17. {testgres_pg_probackup2-0.1.1 → testgres_pg_probackup2-0.2.1}/testgres_pg_probackup2.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: testgres_pg_probackup2
3
- Version: 0.1.1
3
+ Version: 0.2.1
4
4
  Summary: Plugin for testgres that manages pg_probackup2
5
5
  Home-page: https://github.com/postgrespro/testgres
6
6
  Author: Postgres Professional
@@ -1,6 +1,6 @@
1
1
  # testgres - pg_probackup2
2
2
 
3
- Ccontrol and testing utility for [pg_probackup2](https://github.com/postgrespro/pg_probackup). Python 3.5+ is supported.
3
+ Control and testing utility for [pg_probackup2](https://github.com/postgrespro/pg_probackup). Python 3.5+ is supported.
4
4
 
5
5
 
6
6
  ## Installation
@@ -22,6 +22,8 @@ The package requires testgres~=1.9.3.
22
22
  | - | - | - | - |
23
23
  | PGPROBACKUP_TMP_DIR | No | tests/tmp_dirs | The root of the temporary directory hierarchy where tests store data and logs. Relative paths start from the current working directory. |
24
24
  | PG_PROBACKUP_TEST_BACKUP_DIR_PREFIX | No | Temporary test hierarchy | Prefix of the test backup directories. Must be an absolute path. Use this variable to store test backups in a location other than the temporary test hierarchy. |
25
+ | PG_PROBACKUP_VALGRIND | No | Not set | Run pg_probackup through valgrind if the variable is set to 'y'. Setting PG_PROBACKUP_VALGRIND_SUP (see below) to any value enables valgrind just like setting `PG_PROBACKUP_VALGRIND=y` would do. |
26
+ | PG_PROBACKUP_VALGRIND_SUP | No | Not set | Specify the path to a valgrind suppression file. If the variable is not set then a file named "valgrind.supp" is searched for in the current working directory (normally the root of pg_probackup repository). Setting PG_PROBACKUP_VALGRIND_SUP to any value enables valgrind just like setting `PG_PROBACKUP_VALGRIND=y` (see above) would do. |
25
27
 
26
28
  See [Testgres](https://github.com/postgrespro/testgres/tree/master#environment) on how to configure a custom Postgres installation using `PG_CONFIG` and `PG_BIN` environment variables.
27
29
 
@@ -60,6 +60,8 @@ class ProbackupApp:
60
60
  self.archive_compress = init_params.archive_compress
61
61
  self.test_class.output = None
62
62
  self.execution_time = None
63
+ self.valgrind = init_params.valgrind
64
+ self.valgrind_sup_path = init_params.valgrind_sup_path
63
65
 
64
66
  def form_daemon_process(self, cmdline, env):
65
67
  def stream_output(stream: subprocess.PIPE) -> None:
@@ -88,6 +90,7 @@ class ProbackupApp:
88
90
 
89
91
  return self.process.pid
90
92
 
93
+ # ---- Start run function ---- #
91
94
  def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
92
95
  skip_log_directory=False, expect_error=False, use_backup_dir=True, daemonize=False):
93
96
  """
@@ -98,26 +101,46 @@ class ProbackupApp:
98
101
  gdb: when True it returns GDBObj(), when tuple('suspend', port) it runs probackup
99
102
  in suspended gdb mode with attachable gdb port, for local debugging
100
103
  """
104
+ command = self._add_backup_dir_to_cmd(command, use_backup_dir)
105
+ # Old bin or regular one
106
+ binary_path = self._get_binary_path(old_binary)
107
+
108
+ if not env:
109
+ env = self.test_env
110
+ # Add additional options if needed
111
+ command, strcommand = self._add_options(command, skip_log_directory)
112
+
113
+ self.test_class.cmd = f"{binary_path} {strcommand}"
114
+ if self.verbose:
115
+ print(self.test_class.cmd)
116
+
117
+ cmdline = self._form_cmdline(binary_path, command)
118
+
119
+ if gdb is True:
120
+ # general test flow for using GDBObj
121
+ return GDBobj(cmdline, self.test_class)
122
+
123
+ return self._execute_command(cmdline, env, command, gdb, expect_error, return_id, daemonize)
124
+
125
+ def _add_backup_dir_to_cmd(self, command: list, use_backup_dir: TestBackupDir):
101
126
  if isinstance(use_backup_dir, TestBackupDir):
102
- command = [command[0], *use_backup_dir.pb_args, *command[1:]]
127
+ return [command[0], *use_backup_dir.pb_args, *command[1:]]
103
128
  elif use_backup_dir:
104
- command = [command[0], *self.backup_dir.pb_args, *command[1:]]
129
+ return [command[0], *self.backup_dir.pb_args, *command[1:]]
105
130
  else:
106
- command = [command[0], *self.backup_dir.pb_args[2:], *command[1:]]
107
-
108
- if not self.probackup_old_path and old_binary:
109
- logging.error('PGPROBACKUPBIN_OLD is not set')
110
- exit(1)
131
+ return [command[0], *self.backup_dir.pb_args[2:], *command[1:]]
111
132
 
133
+ def _get_binary_path(self, old_binary):
112
134
  if old_binary:
113
- binary_path = self.probackup_old_path
114
- else:
115
- binary_path = self.probackup_path
116
-
117
- if not env:
118
- env = self.test_env
135
+ if not self.probackup_old_path:
136
+ logging.error('PGPROBACKUPBIN_OLD is not set')
137
+ exit(1)
138
+ return self.probackup_old_path
139
+ return self.probackup_path
119
140
 
141
+ def _add_options(self, command: list, skip_log_directory: bool):
120
142
  strcommand = ' '.join(str(p) for p in command)
143
+
121
144
  if '--log-level-file' in strcommand and \
122
145
  '--log-directory' not in strcommand and \
123
146
  not skip_log_directory:
@@ -125,26 +148,51 @@ class ProbackupApp:
125
148
  strcommand += ' ' + command[-1]
126
149
 
127
150
  if 'pglz' in strcommand and \
128
- ' -j' not in strcommand and '--thread' not in strcommand:
151
+ ' -j' not in strcommand and \
152
+ '--thread' not in strcommand:
129
153
  command += ['-j', '1']
130
154
  strcommand += ' -j 1'
131
155
 
132
- self.test_class.cmd = binary_path + ' ' + strcommand
133
- if self.verbose:
134
- print(self.test_class.cmd)
156
+ return command, strcommand
135
157
 
158
+ def _form_cmdline(self, binary_path, command):
136
159
  cmdline = [binary_path, *command]
137
- if gdb is True:
138
- # general test flow for using GDBObj
139
- return GDBobj(cmdline, self.test_class)
140
160
 
161
+ if (self.valgrind == 'y' or self.valgrind_sup_path) and command[0] != "--version":
162
+ os.makedirs(self.pb_log_path, exist_ok=True)
163
+ valgrind_cmd = [
164
+ "valgrind",
165
+ "--gen-suppressions=all",
166
+ "--leak-check=full",
167
+ "--show-reachable=yes",
168
+ "--error-limit=no",
169
+ "--show-leak-kinds=all",
170
+ "--errors-for-leak-kinds=all",
171
+ "--error-exitcode=0",
172
+ f"--log-file={os.path.join(self.pb_log_path, f'valgrind-{command[0]}-%p.log')}"
173
+ ]
174
+ if self.valgrind_sup_path:
175
+ if os.path.isfile(self.valgrind_sup_path):
176
+ valgrind_cmd += [f"--suppressions={self.valgrind_sup_path}"]
177
+ else:
178
+ raise FileNotFoundError(f"PG_PROBACKUP_VALGRIND_SUP must be the path to a valgrind suppression file, "
179
+ f"but found: {self.valgrind_sup_path}")
180
+ else:
181
+ # Assume the tests are started from the root of pg_probackup repository
182
+ valgrind_cmd += [f"--suppressions=.valgrind.supp"]
183
+
184
+ cmdline = valgrind_cmd + cmdline
185
+
186
+ return cmdline
187
+
188
+ def _execute_command(self, cmdline, env, command, gdb, expect_error, return_id, daemonize):
141
189
  try:
142
- if type(gdb) is tuple and gdb[0] == 'suspend':
143
- # special test flow for manually debug probackup
190
+ if isinstance(gdb, tuple) and gdb[0] == 'suspend':
144
191
  gdb_port = gdb[1]
145
192
  cmdline = ['gdbserver'] + ['localhost:' + str(gdb_port)] + cmdline
146
193
  logging.warning("pg_probackup gdb suspended, waiting gdb connection on localhost:{0}".format(gdb_port))
147
194
 
195
+ # Execute command
148
196
  start_time = time.time()
149
197
  if daemonize:
150
198
  return self.form_daemon_process(cmdline, env)
@@ -174,6 +222,7 @@ class ProbackupApp:
174
222
  return self.test_class.output
175
223
  else:
176
224
  raise ProbackupException(self.test_class.output, self.test_class.cmd)
225
+ # ---- End run function ---- #
177
226
 
178
227
  def get_backup_id(self):
179
228
  if init_params.major_version > 2:
@@ -214,6 +214,9 @@ class Init(object):
214
214
  else:
215
215
  raise Exception('Can\'t process pg_probackup version \"{}\": the major version is expected to be a number'.format(self.probackup_version))
216
216
 
217
+ self.valgrind = test_env.get('PG_PROBACKUP_VALGRIND')
218
+ self.valgrind_sup_path = test_env.get('PG_PROBACKUP_VALGRIND_SUP')
219
+
217
220
  def test_env(self):
218
221
  return self._test_env.copy()
219
222
 
@@ -4,7 +4,7 @@ except ImportError:
4
4
  from distutils.core import setup
5
5
 
6
6
  setup(
7
- version='0.1.1',
7
+ version='0.2.1',
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: testgres-pg-probackup2
3
- Version: 0.1.1
3
+ Version: 0.2.1
4
4
  Summary: Plugin for testgres that manages pg_probackup2
5
5
  Home-page: https://github.com/postgrespro/testgres
6
6
  Author: Postgres Professional
File without changes