Esempio n. 1
0
 def test_archive_command_with_invalid_file(self, pghoard):
     # only WAL and timeline (.history) files can be archived
     bl_label = "000000010000000000000002.00000028.backup"
     bl_file = "xlog/{}".format(bl_label)
     wal_path = os.path.join(
         get_pg_wal_directory(
             pghoard.config["backup_sites"][pghoard.test_site]), bl_label)
     backup_wal_path = os.path.join(pghoard.config["backup_location"],
                                    pghoard.test_site, bl_file)
     with open(wal_path, "w") as fp:
         fp.write("jee")
     # backup labels are ignored - archiving returns success but file won't appear on disk
     archive_command(host="127.0.0.1",
                     port=pghoard.config["http_port"],
                     site=pghoard.test_site,
                     xlog=bl_label)
     assert not os.path.exists(backup_wal_path)
     # any other files raise an error
     with pytest.raises(postgres_command.PGCError) as excinfo:
         archive_command(host="127.0.0.1",
                         port=pghoard.config["http_port"],
                         site=pghoard.test_site,
                         xlog=bl_label + ".x")
     assert excinfo.value.exit_code == postgres_command.EXIT_ARCHIVE_FAIL
     assert not os.path.exists(backup_wal_path + ".x")
Esempio n. 2
0
 def test_archive_command_with_invalid_file(self, pghoard):
     # only xlog and timeline (.history) files can be archived
     bl_label = "000000010000000000000002.00000028.backup"
     bl_file = "xlog/{}".format(bl_label)
     xlog_path = os.path.join(pghoard.config["backup_sites"][pghoard.test_site]["pg_xlog_directory"], bl_label)
     backup_xlog_path = os.path.join(pghoard.config["backup_location"], pghoard.test_site, bl_file)
     with open(xlog_path, "w") as fp:
         fp.write("jee")
     with pytest.raises(postgres_command.PGCError) as excinfo:
         archive_command(host="127.0.0.1", port=pghoard.config["http_port"],
                         site=pghoard.test_site, xlog=bl_label)
     assert excinfo.value.exit_code == postgres_command.EXIT_ARCHIVE_FAIL
     assert not os.path.exists(backup_xlog_path)
Esempio n. 3
0
 def test_archiving(self, pghoard):
     store = pghoard.transfer_agents[0].get_object_storage(pghoard.test_site)
     # inject fake WAL and timeline files for testing
     for xlog_type, wal_name in [("xlog", "0000000000000000000000CC"), ("timeline", "0000000F.history")]:
         foo_path = os.path.join(get_pg_wal_directory(pghoard.config["backup_sites"][pghoard.test_site]), wal_name)
         with open(foo_path, "wb") as out_file:
             if xlog_type == "xlog":
                 out_file.write(wal_header_for_file(wal_name))
             else:
                 out_file.write(b"1 2 3\n")
         archive_command(host="localhost", port=pghoard.config["http_port"], site=pghoard.test_site, xlog=wal_name)
         archive_path = os.path.join(pghoard.test_site, xlog_type, wal_name)
         store.get_metadata_for_key(archive_path)
         store.delete_key(archive_path)
         os.unlink(foo_path)
Esempio n. 4
0
 def test_archive_command_with_invalid_file(self, pghoard):
     # only WAL and timeline (.history) files can be archived
     bl_label = "000000010000000000000002.00000028.backup"
     bl_file = "xlog/{}".format(bl_label)
     wal_path = os.path.join(get_pg_wal_directory(pghoard.config["backup_sites"][pghoard.test_site]), bl_label)
     backup_wal_path = os.path.join(pghoard.config["backup_location"], pghoard.test_site, bl_file)
     with open(wal_path, "w") as fp:
         fp.write("jee")
     # backup labels are ignored - archiving returns success but file won't appear on disk
     archive_command(host="127.0.0.1", port=pghoard.config["http_port"],
                     site=pghoard.test_site, xlog=bl_label)
     assert not os.path.exists(backup_wal_path)
     # any other files raise an error
     with pytest.raises(postgres_command.PGCError) as excinfo:
         archive_command(host="127.0.0.1", port=pghoard.config["http_port"],
                         site=pghoard.test_site, xlog=bl_label + ".x")
     assert excinfo.value.exit_code == postgres_command.EXIT_ARCHIVE_FAIL
     assert not os.path.exists(backup_wal_path + ".x")
Esempio n. 5
0
 def test_archiving(self, pghoard):
     store = pghoard.transfer_agents[0].get_object_storage(pghoard.test_site)
     # inject fake WAL and timeline files for testing
     for xlog_type, wal_name in [
             ("xlog", "0000000000000000000000CC"),
             ("timeline", "0000000F.history")]:
         foo_path = os.path.join(get_pg_wal_directory(pghoard.config["backup_sites"][pghoard.test_site]), wal_name)
         with open(foo_path, "wb") as out_file:
             if xlog_type == "xlog":
                 out_file.write(wal_header_for_file(wal_name))
             else:
                 out_file.write(b"1 2 3\n")
         archive_command(host="localhost", port=pghoard.config["http_port"],
                         site=pghoard.test_site, xlog=wal_name)
         archive_path = os.path.join(pghoard.test_site, xlog_type, wal_name)
         store.get_metadata_for_key(archive_path)
         store.delete_key(archive_path)
         os.unlink(foo_path)