diff --git a/tests/CVE_2018_1058.py b/tests/CVE_2018_1058_test.py similarity index 99% rename from tests/CVE_2018_1058.py rename to tests/CVE_2018_1058_test.py index 3da41f116..0ea429853 100644 --- a/tests/CVE_2018_1058.py +++ b/tests/CVE_2018_1058_test.py @@ -4,6 +4,7 @@ module_name = 'CVE-2018-1058' + class CVE_2018_1058(ProbackupTest, unittest.TestCase): # @unittest.skip("skip") @@ -100,7 +101,7 @@ def test_basic_checkdb_modified_search_path(self): "END " "$$ LANGUAGE plpgsql; " "CREATE VIEW public.pg_database AS SELECT * FROM public.pg_database()") - + node.safe_psql( 'postgres', "CREATE FUNCTION public.pg_extension(OUT extname name, OUT extnamespace oid, OUT extversion text) " @@ -119,7 +120,7 @@ def test_basic_checkdb_modified_search_path(self): "$$ LANGUAGE plpgsql; " "CREATE VIEW public.pg_extension AS SELECT * FROM public.pg_extension();" "CREATE VIEW public.pg_namespace AS SELECT * FROM public.pg_namespace();" - ) + ) try: self.checkdb_node( diff --git a/tests/__init__.py b/tests/__init__.py index 79537ad78..e0f4dfd24 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,13 +1,13 @@ import unittest import os -from . import init, merge, option, show, compatibility, \ - backup, delete, delta, restore, validate, \ - retention, pgpro560, pgpro589, pgpro2068, false_positive, replica, \ - compression, page, ptrack, archive, exclude, cfs_backup, cfs_restore, \ - cfs_validate_backup, auth_test, time_stamp, logging, \ - locking, remote, external, config, checkdb, set_backup, incr_restore, \ - catchup, CVE_2018_1058, time_consuming +from . import init_test, merge_test, option_test, show_test, compatibility_test, \ + backup_test, delete_test, delta_test, restore_test, validate_test, \ + retention_test, pgpro560_test, pgpro589_test, pgpro2068_test, false_positive_test, replica_test, \ + compression_test, page_test, ptrack_test, archive_test, exclude_test, cfs_backup_test, cfs_restore_test, \ + cfs_validate_backup_test, auth_test, time_stamp_test, logging_test, \ + locking_test, remote_test, external_test, config_test, checkdb_test, set_backup_test, incr_restore_test, \ + catchup, CVE_2018_1058_test, time_consuming_test def load_tests(loader, tests, pattern): @@ -19,50 +19,50 @@ def load_tests(loader, tests, pattern): if 'PG_PROBACKUP_PTRACK' in os.environ: if os.environ['PG_PROBACKUP_PTRACK'] == 'ON': - suite.addTests(loader.loadTestsFromModule(ptrack)) + suite.addTests(loader.loadTestsFromModule(ptrack_test)) # PG_PROBACKUP_LONG section for tests that are long # by design e.g. they contain loops, sleeps and so on if 'PG_PROBACKUP_LONG' in os.environ: if os.environ['PG_PROBACKUP_LONG'] == 'ON': - suite.addTests(loader.loadTestsFromModule(time_consuming)) + suite.addTests(loader.loadTestsFromModule(time_consuming_test)) # suite.addTests(loader.loadTestsFromModule(auth_test)) - suite.addTests(loader.loadTestsFromModule(archive)) - suite.addTests(loader.loadTestsFromModule(backup)) + suite.addTests(loader.loadTestsFromModule(archive_test)) + suite.addTests(loader.loadTestsFromModule(backup_test)) suite.addTests(loader.loadTestsFromModule(catchup)) if 'PGPROBACKUPBIN_OLD' in os.environ and os.environ['PGPROBACKUPBIN_OLD']: - suite.addTests(loader.loadTestsFromModule(compatibility)) - suite.addTests(loader.loadTestsFromModule(checkdb)) - suite.addTests(loader.loadTestsFromModule(config)) -# suite.addTests(loader.loadTestsFromModule(cfs_backup)) -# suite.addTests(loader.loadTestsFromModule(cfs_restore)) -# suite.addTests(loader.loadTestsFromModule(cfs_validate_backup)) - suite.addTests(loader.loadTestsFromModule(compression)) - suite.addTests(loader.loadTestsFromModule(delete)) - suite.addTests(loader.loadTestsFromModule(delta)) - suite.addTests(loader.loadTestsFromModule(exclude)) - suite.addTests(loader.loadTestsFromModule(external)) - suite.addTests(loader.loadTestsFromModule(false_positive)) - suite.addTests(loader.loadTestsFromModule(init)) - suite.addTests(loader.loadTestsFromModule(incr_restore)) - suite.addTests(loader.loadTestsFromModule(locking)) - suite.addTests(loader.loadTestsFromModule(logging)) - suite.addTests(loader.loadTestsFromModule(merge)) - suite.addTests(loader.loadTestsFromModule(option)) - suite.addTests(loader.loadTestsFromModule(page)) - suite.addTests(loader.loadTestsFromModule(pgpro560)) - suite.addTests(loader.loadTestsFromModule(pgpro589)) - suite.addTests(loader.loadTestsFromModule(pgpro2068)) - suite.addTests(loader.loadTestsFromModule(remote)) - suite.addTests(loader.loadTestsFromModule(replica)) - suite.addTests(loader.loadTestsFromModule(restore)) - suite.addTests(loader.loadTestsFromModule(retention)) - suite.addTests(loader.loadTestsFromModule(set_backup)) - suite.addTests(loader.loadTestsFromModule(show)) - suite.addTests(loader.loadTestsFromModule(time_stamp)) - suite.addTests(loader.loadTestsFromModule(validate)) - suite.addTests(loader.loadTestsFromModule(CVE_2018_1058)) + suite.addTests(loader.loadTestsFromModule(compatibility_test)) + suite.addTests(loader.loadTestsFromModule(checkdb_test)) + suite.addTests(loader.loadTestsFromModule(config_test)) +# suite.addTests(loader.loadTestsFromModule(cfs_backup_test)) +# suite.addTests(loader.loadTestsFromModule(cfs_restore_test)) +# suite.addTests(loader.loadTestsFromModule(cfs_validate_backup_test)) + suite.addTests(loader.loadTestsFromModule(compression_test)) + suite.addTests(loader.loadTestsFromModule(delete_test)) + suite.addTests(loader.loadTestsFromModule(delta_test)) + suite.addTests(loader.loadTestsFromModule(exclude_test)) + suite.addTests(loader.loadTestsFromModule(external_test)) + suite.addTests(loader.loadTestsFromModule(false_positive_test)) + suite.addTests(loader.loadTestsFromModule(init_test)) + suite.addTests(loader.loadTestsFromModule(incr_restore_test)) + suite.addTests(loader.loadTestsFromModule(locking_test)) + suite.addTests(loader.loadTestsFromModule(logging_test)) + suite.addTests(loader.loadTestsFromModule(merge_test)) + suite.addTests(loader.loadTestsFromModule(option_test)) + suite.addTests(loader.loadTestsFromModule(page_test)) + suite.addTests(loader.loadTestsFromModule(pgpro560_test)) + suite.addTests(loader.loadTestsFromModule(pgpro589_test)) + suite.addTests(loader.loadTestsFromModule(pgpro2068_test)) + suite.addTests(loader.loadTestsFromModule(remote_test)) + suite.addTests(loader.loadTestsFromModule(replica_test)) + suite.addTests(loader.loadTestsFromModule(restore_test)) + suite.addTests(loader.loadTestsFromModule(retention_test)) + suite.addTests(loader.loadTestsFromModule(set_backup_test)) + suite.addTests(loader.loadTestsFromModule(show_test)) + suite.addTests(loader.loadTestsFromModule(time_stamp_test)) + suite.addTests(loader.loadTestsFromModule(validate_test)) + suite.addTests(loader.loadTestsFromModule(CVE_2018_1058_test)) return suite diff --git a/tests/archive.py b/tests/archive_test.py similarity index 100% rename from tests/archive.py rename to tests/archive_test.py diff --git a/tests/auth_test.py b/tests/auth_test.py index 39786d7a9..5afc4eead 100644 --- a/tests/auth_test.py +++ b/tests/auth_test.py @@ -127,7 +127,7 @@ def test_backup_via_unprivileged_user(self): node.safe_psql( "postgres", "GRANT EXECUTE ON FUNCTION pg_stop_backup(boolean) TO backup") - elif self.get_vestion(node) < self.version_to_num('15.0'): + elif self.get_version(node) < self.version_to_num('15.0'): node.safe_psql( "postgres", "GRANT EXECUTE ON FUNCTION " diff --git a/tests/backup.py b/tests/backup_test.py similarity index 100% rename from tests/backup.py rename to tests/backup_test.py diff --git a/tests/cfs_backup.py b/tests/cfs_backup_test.py similarity index 100% rename from tests/cfs_backup.py rename to tests/cfs_backup_test.py diff --git a/tests/cfs_catchup.py b/tests/cfs_catchup_test.py similarity index 100% rename from tests/cfs_catchup.py rename to tests/cfs_catchup_test.py diff --git a/tests/cfs_restore.py b/tests/cfs_restore_test.py similarity index 100% rename from tests/cfs_restore.py rename to tests/cfs_restore_test.py diff --git a/tests/cfs_validate_backup.py b/tests/cfs_validate_backup_test.py similarity index 100% rename from tests/cfs_validate_backup.py rename to tests/cfs_validate_backup_test.py diff --git a/tests/checkdb.py b/tests/checkdb_test.py similarity index 100% rename from tests/checkdb.py rename to tests/checkdb_test.py diff --git a/tests/compatibility.py b/tests/compatibility_test.py similarity index 100% rename from tests/compatibility.py rename to tests/compatibility_test.py diff --git a/tests/compression.py b/tests/compression_test.py similarity index 100% rename from tests/compression.py rename to tests/compression_test.py diff --git a/tests/config.py b/tests/config_test.py similarity index 100% rename from tests/config.py rename to tests/config_test.py diff --git a/tests/delete.py b/tests/delete_test.py similarity index 100% rename from tests/delete.py rename to tests/delete_test.py diff --git a/tests/delta.py b/tests/delta_test.py similarity index 100% rename from tests/delta.py rename to tests/delta_test.py diff --git a/tests/exclude.py b/tests/exclude_test.py similarity index 100% rename from tests/exclude.py rename to tests/exclude_test.py diff --git a/tests/external.py b/tests/external_test.py similarity index 100% rename from tests/external.py rename to tests/external_test.py diff --git a/tests/false_positive.py b/tests/false_positive_test.py similarity index 100% rename from tests/false_positive.py rename to tests/false_positive_test.py diff --git a/tests/incr_restore.py b/tests/incr_restore_test.py similarity index 100% rename from tests/incr_restore.py rename to tests/incr_restore_test.py diff --git a/tests/init.py b/tests/init_test.py similarity index 100% rename from tests/init.py rename to tests/init_test.py diff --git a/tests/locking.py b/tests/locking_test.py similarity index 100% rename from tests/locking.py rename to tests/locking_test.py diff --git a/tests/logging.py b/tests/logging_test.py similarity index 100% rename from tests/logging.py rename to tests/logging_test.py diff --git a/tests/merge.py b/tests/merge_test.py similarity index 100% rename from tests/merge.py rename to tests/merge_test.py diff --git a/tests/option.py b/tests/option_test.py similarity index 100% rename from tests/option.py rename to tests/option_test.py diff --git a/tests/page.py b/tests/page_test.py similarity index 100% rename from tests/page.py rename to tests/page_test.py diff --git a/tests/pgpro2068.py b/tests/pgpro2068_test.py similarity index 100% rename from tests/pgpro2068.py rename to tests/pgpro2068_test.py diff --git a/tests/pgpro560.py b/tests/pgpro560_test.py similarity index 100% rename from tests/pgpro560.py rename to tests/pgpro560_test.py diff --git a/tests/pgpro589.py b/tests/pgpro589_test.py similarity index 100% rename from tests/pgpro589.py rename to tests/pgpro589_test.py diff --git a/tests/ptrack.py b/tests/ptrack_test.py similarity index 100% rename from tests/ptrack.py rename to tests/ptrack_test.py diff --git a/tests/remote.py b/tests/remote_test.py similarity index 100% rename from tests/remote.py rename to tests/remote_test.py diff --git a/tests/replica.py b/tests/replica_test.py similarity index 100% rename from tests/replica.py rename to tests/replica_test.py diff --git a/tests/restore.py b/tests/restore_test.py similarity index 100% rename from tests/restore.py rename to tests/restore_test.py diff --git a/tests/retention.py b/tests/retention_test.py similarity index 100% rename from tests/retention.py rename to tests/retention_test.py diff --git a/tests/set_backup.py b/tests/set_backup_test.py similarity index 100% rename from tests/set_backup.py rename to tests/set_backup_test.py diff --git a/tests/show.py b/tests/show_test.py similarity index 100% rename from tests/show.py rename to tests/show_test.py diff --git a/tests/time_consuming.py b/tests/time_consuming_test.py similarity index 100% rename from tests/time_consuming.py rename to tests/time_consuming_test.py diff --git a/tests/time_stamp.py b/tests/time_stamp_test.py similarity index 99% rename from tests/time_stamp.py rename to tests/time_stamp_test.py index c49d183da..de4fda97f 100644 --- a/tests/time_stamp.py +++ b/tests/time_stamp_test.py @@ -1,6 +1,6 @@ import os import unittest -from .helpers.ptrack_helpers import ProbackupTest, ProbackupException +from .helpers.ptrack_helpers import ProbackupTest import subprocess from time import sleep diff --git a/tests/validate.py b/tests/validate_test.py similarity index 99% rename from tests/validate.py rename to tests/validate_test.py index 966ad81a8..804063034 100644 --- a/tests/validate.py +++ b/tests/validate_test.py @@ -3,8 +3,6 @@ from .helpers.ptrack_helpers import ProbackupTest, ProbackupException from datetime import datetime, timedelta from pathlib import Path -import subprocess -from sys import exit import time import hashlib @@ -47,7 +45,6 @@ def test_basic_validate_nullified_heap_page_backup(self): f.seek(8192) f.write(b"\x00"*8192) f.flush() - f.close self.backup_node( backup_dir, 'node', node, options=['--log-level-file=verbose']) @@ -267,7 +264,6 @@ def test_basic_validate_corrupted_intermediate_backup(self): f.seek(42) f.write(b"blah") f.flush() - f.close # Simple validate try: @@ -360,7 +356,6 @@ def test_validate_corrupted_intermediate_backups(self): f.seek(84) f.write(b"blah") f.flush() - f.close # Corrupt some file in PAGE1 backup file_page1 = os.path.join( @@ -370,7 +365,6 @@ def test_validate_corrupted_intermediate_backups(self): f.seek(42) f.write(b"blah") f.flush() - f.close # Validate PAGE1 try: @@ -686,7 +680,6 @@ def test_validate_corrupted_intermediate_backups_1(self): f.seek(84) f.write(b"blah") f.flush() - f.close file_page4 = os.path.join( backup_dir, 'backups', 'node', backup_id_6, 'database', file_page_5) @@ -694,7 +687,6 @@ def test_validate_corrupted_intermediate_backups_1(self): f.seek(42) f.write(b"blah") f.flush() - f.close # Validate PAGE3 try: @@ -891,7 +883,6 @@ def test_validate_specific_target_corrupted_intermediate_backups(self): f.seek(84) f.write(b"blah") f.flush() - f.close file_page4 = os.path.join( backup_dir, 'backups', 'node', @@ -900,7 +891,6 @@ def test_validate_specific_target_corrupted_intermediate_backups(self): f.seek(42) f.write(b"blah") f.flush() - f.close # Validate PAGE3 try: @@ -1244,7 +1234,6 @@ def test_validate_instance_with_corrupted_page(self): f.seek(84) f.write(b"blah") f.flush() - f.close # Validate Instance try: @@ -1392,7 +1381,6 @@ def test_validate_instance_with_corrupted_full_and_try_restore(self): f.seek(84) f.write(b"blah") f.flush() - f.close # Validate Instance try: @@ -1493,7 +1481,6 @@ def test_validate_instance_with_corrupted_full(self): f.seek(84) f.write(b"blah") f.flush() - f.close # Validate Instance try: @@ -1551,7 +1538,6 @@ def test_validate_corrupt_wal_1(self): f.seek(42) f.write(b"blablablaadssaaaaaaaaaaaaaaa") f.flush() - f.close # Simple validate try: @@ -1616,7 +1602,6 @@ def test_validate_corrupt_wal_2(self): f.seek(128) f.write(b"blablablaadssaaaaaaaaaaaaaaa") f.flush() - f.close # Validate to xid try: @@ -1781,7 +1766,6 @@ def test_validate_corrupt_wal_between_backups(self): f.seek(9000) f.write(b"b") f.flush() - f.close # Validate to xid try: @@ -2860,7 +2844,6 @@ def test_file_size_corruption_no_validate(self): "database", heap_path), "rb+", 0) as f: f.truncate(int(heap_size) - 4096) f.flush() - f.close node.cleanup() @@ -3635,7 +3618,6 @@ def test_validate_corrupt_tablespace_map(self): f.seek(84) f.write(b"blah") f.flush() - f.close try: self.validate_pb(backup_dir, 'node', backup_id=backup_id) @@ -3948,14 +3930,14 @@ def test_not_validate_diffenent_pg_version(self): fake_new_pg_version = pg_version + 1 with open(control_file, 'r') as f: - data = f.read(); + data = f.read() data = data.replace( "server-version = {0}".format(str(pg_version)), "server-version = {0}".format(str(fake_new_pg_version))) with open(control_file, 'w') as f: - f.write(data); + f.write(data) try: self.validate_pb(backup_dir) @@ -4007,7 +3989,6 @@ def test_validate_corrupt_page_header_map(self): f.seek(42) f.write(b"blah") f.flush() - f.close try: self.validate_pb(backup_dir, 'node', backup_id=backup_id) @@ -4080,7 +4061,6 @@ def test_validate_truncated_page_header_map(self): with open(page_header_map, "rb+", 0) as f: f.truncate(121) f.flush() - f.close try: self.validate_pb(backup_dir, 'node', backup_id=backup_id) @@ -4213,7 +4193,6 @@ def test_no_validate_tablespace_map(self): # overwrite tablespace_map file with open(tablespace_map, "w") as f: f.write("{0} {1}".format(oid, tblspace_new)) - f.close node.cleanup()