|
1 | 1 | import os
|
| 2 | +import signal |
2 | 3 | import unittest
|
3 | 4 | from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
|
4 | 5 |
|
@@ -525,6 +526,176 @@ def test_local_tablespace_without_mapping(self):
|
525 | 526 | e.message,
|
526 | 527 | '\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
|
527 | 528 |
|
| 529 | + # Cleanup |
| 530 | + src_pg.stop() |
| 531 | + self.del_test_dir(module_name, self.fname) |
| 532 | + |
| 533 | + def test_running_dest_postmaster(self): |
| 534 | + """ |
| 535 | + Test that we detect running postmaster in destination |
| 536 | + """ |
| 537 | + # preparation 1: source |
| 538 | + src_pg = self.make_simple_node( |
| 539 | + base_dir = os.path.join(module_name, self.fname, 'src'), |
| 540 | + set_replication = True, |
| 541 | + pg_options = { 'wal_log_hints': 'on' } |
| 542 | + ) |
| 543 | + src_pg.slow_start() |
| 544 | + |
| 545 | + # preparation 2: destination |
| 546 | + dst_pg = self.make_empty_node(os.path.join(module_name, self.fname, 'dst')) |
| 547 | + self.catchup_node( |
| 548 | + backup_mode = 'FULL', |
| 549 | + source_pgdata = src_pg.data_dir, |
| 550 | + destination_node = dst_pg, |
| 551 | + options = ['-d', 'postgres', '-p', str(src_pg.port), '--stream'] |
| 552 | + ) |
| 553 | + dst_options = {} |
| 554 | + dst_options['port'] = str(dst_pg.port) |
| 555 | + self.set_auto_conf(dst_pg, dst_options) |
| 556 | + dst_pg.slow_start() |
| 557 | + # leave running destination postmaster |
| 558 | + #dst_pg.stop() |
| 559 | + |
| 560 | + # try delta catchup |
| 561 | + try: |
| 562 | + self.catchup_node( |
| 563 | + backup_mode = 'DELTA', |
| 564 | + source_pgdata = src_pg.data_dir, |
| 565 | + destination_node = dst_pg, |
| 566 | + options = ['-d', 'postgres', '-p', str(src_pg.port), '--stream'] |
| 567 | + ) |
| 568 | + self.assertEqual(1, 0, "Expecting Error because postmaster in destination is running.\n Output: {0} \n CMD: {1}".format( |
| 569 | + repr(self.output), self.cmd)) |
| 570 | + except ProbackupException as e: |
| 571 | + self.assertIn( |
| 572 | + 'ERROR: Postmaster with pid ', |
| 573 | + e.message, |
| 574 | + '\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd)) |
| 575 | + |
| 576 | + # Cleanup |
| 577 | + src_pg.stop() |
| 578 | + self.del_test_dir(module_name, self.fname) |
| 579 | + |
| 580 | + def test_same_db_id(self): |
| 581 | + """ |
| 582 | + Test that we detect different id's of source and destination |
| 583 | + """ |
| 584 | + # preparation: |
| 585 | + # source |
| 586 | + src_pg = self.make_simple_node( |
| 587 | + base_dir = os.path.join(module_name, self.fname, 'src'), |
| 588 | + set_replication = True |
| 589 | + ) |
| 590 | + src_pg.slow_start() |
| 591 | + # destination |
| 592 | + dst_pg = self.make_empty_node(os.path.join(module_name, self.fname, 'dst')) |
| 593 | + self.catchup_node( |
| 594 | + backup_mode = 'FULL', |
| 595 | + source_pgdata = src_pg.data_dir, |
| 596 | + destination_node = dst_pg, |
| 597 | + options = ['-d', 'postgres', '-p', str(src_pg.port), '--stream'] |
| 598 | + ) |
| 599 | + # fake destination |
| 600 | + fake_dst_pg = self.make_simple_node(base_dir = os.path.join(module_name, self.fname, 'fake_dst')) |
| 601 | + # fake source |
| 602 | + fake_src_pg = self.make_simple_node(base_dir = os.path.join(module_name, self.fname, 'fake_src')) |
| 603 | + |
| 604 | + # try delta catchup (src (with correct src conn), fake_dst) |
| 605 | + try: |
| 606 | + self.catchup_node( |
| 607 | + backup_mode = 'DELTA', |
| 608 | + source_pgdata = src_pg.data_dir, |
| 609 | + destination_node = fake_dst_pg, |
| 610 | + options = ['-d', 'postgres', '-p', str(src_pg.port), '--stream'] |
| 611 | + ) |
| 612 | + self.assertEqual(1, 0, "Expecting Error because database identifiers mismatch.\n Output: {0} \n CMD: {1}".format( |
| 613 | + repr(self.output), self.cmd)) |
| 614 | + except ProbackupException as e: |
| 615 | + self.assertIn( |
| 616 | + 'ERROR: Database identifiers mismatch: ', |
| 617 | + e.message, |
| 618 | + '\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd)) |
| 619 | + |
| 620 | + # try delta catchup (fake_src (with wrong src conn), dst) |
| 621 | + try: |
| 622 | + self.catchup_node( |
| 623 | + backup_mode = 'DELTA', |
| 624 | + source_pgdata = fake_src_pg.data_dir, |
| 625 | + destination_node = dst_pg, |
| 626 | + options = ['-d', 'postgres', '-p', str(src_pg.port), '--stream'] |
| 627 | + ) |
| 628 | + self.assertEqual(1, 0, "Expecting Error because database identifiers mismatch.\n Output: {0} \n CMD: {1}".format( |
| 629 | + repr(self.output), self.cmd)) |
| 630 | + except ProbackupException as e: |
| 631 | + self.assertIn( |
| 632 | + 'ERROR: Database identifiers mismatch: ', |
| 633 | + e.message, |
| 634 | + '\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd)) |
| 635 | + |
| 636 | + # Cleanup |
| 637 | + src_pg.stop() |
| 638 | + self.del_test_dir(module_name, self.fname) |
| 639 | + |
| 640 | + def test_destination_dbstate(self): |
| 641 | + """ |
| 642 | + Test that we detect that destination pg is not cleanly shutdowned |
| 643 | + """ |
| 644 | + # preparation 1: source |
| 645 | + src_pg = self.make_simple_node( |
| 646 | + base_dir = os.path.join(module_name, self.fname, 'src'), |
| 647 | + set_replication = True, |
| 648 | + pg_options = { 'wal_log_hints': 'on' } |
| 649 | + ) |
| 650 | + src_pg.slow_start() |
| 651 | + |
| 652 | + # preparation 2: destination |
| 653 | + dst_pg = self.make_empty_node(os.path.join(module_name, self.fname, 'dst')) |
| 654 | + self.catchup_node( |
| 655 | + backup_mode = 'FULL', |
| 656 | + source_pgdata = src_pg.data_dir, |
| 657 | + destination_node = dst_pg, |
| 658 | + options = ['-d', 'postgres', '-p', str(src_pg.port), '--stream'] |
| 659 | + ) |
| 660 | + |
| 661 | + # try #1 |
| 662 | + try: |
| 663 | + self.catchup_node( |
| 664 | + backup_mode = 'DELTA', |
| 665 | + source_pgdata = src_pg.data_dir, |
| 666 | + destination_node = dst_pg, |
| 667 | + options = ['-d', 'postgres', '-p', str(src_pg.port), '--stream'] |
| 668 | + ) |
| 669 | + self.assertEqual(1, 0, "Expecting Error because destination pg is not cleanly shutdowned.\n Output: {0} \n CMD: {1}".format( |
| 670 | + repr(self.output), self.cmd)) |
| 671 | + except ProbackupException as e: |
| 672 | + self.assertIn( |
| 673 | + 'ERROR: Destination directory contains "backup_label" file', |
| 674 | + e.message, |
| 675 | + '\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd)) |
| 676 | + |
| 677 | + # try #2 |
| 678 | + dst_options = {} |
| 679 | + dst_options['port'] = str(dst_pg.port) |
| 680 | + self.set_auto_conf(dst_pg, dst_options) |
| 681 | + dst_pg.slow_start() |
| 682 | + self.assertNotEqual(dst_pg.pid, 0, "Cannot detect pid of running postgres") |
| 683 | + os.kill(dst_pg.pid, signal.SIGKILL) |
| 684 | + try: |
| 685 | + self.catchup_node( |
| 686 | + backup_mode = 'DELTA', |
| 687 | + source_pgdata = src_pg.data_dir, |
| 688 | + destination_node = dst_pg, |
| 689 | + options = ['-d', 'postgres', '-p', str(src_pg.port), '--stream'] |
| 690 | + ) |
| 691 | + self.assertEqual(1, 0, "Expecting Error because destination pg is not cleanly shutdowned.\n Output: {0} \n CMD: {1}".format( |
| 692 | + repr(self.output), self.cmd)) |
| 693 | + except ProbackupException as e: |
| 694 | + self.assertIn( |
| 695 | + 'must be stopped cleanly', |
| 696 | + e.message, |
| 697 | + '\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd)) |
| 698 | + |
| 699 | + # Cleanup |
528 | 700 | src_pg.stop()
|
529 |
| - # Clean after yourself |
530 | 701 | self.del_test_dir(module_name, self.fname)
|
0 commit comments