@@ -627,6 +627,122 @@ def test_tablespace_handling(self):
627627 # Clean after yourself
628628 self .del_test_dir (module_name , fname )
629629
630+ # @unittest.skip("skip")
631+ def test_tablespace_handling_1 (self ):
632+ """
633+ make node with tablespace A, take full backup, check that restore with
634+ tablespace mapping of tablespace B will end with error
635+ """
636+ fname = self .id ().split ('.' )[3 ]
637+ node = self .make_simple_node (
638+ base_dir = os .path .join (module_name , fname , 'node' ),
639+ set_replication = True ,
640+ initdb_params = ['--data-checksums' ],
641+ pg_options = {
642+ 'wal_level' : 'replica' ,
643+ 'max_wal_senders' : '2' })
644+
645+ backup_dir = os .path .join (self .tmp_path , module_name , fname , 'backup' )
646+
647+ self .init_pb (backup_dir )
648+ self .add_instance (backup_dir , 'node' , node )
649+ node .slow_start ()
650+
651+ tblspace1_old_path = self .get_tblspace_path (node , 'tblspace1_old' )
652+ tblspace2_old_path = self .get_tblspace_path (node , 'tblspace2_old' )
653+
654+ tblspace_new_path = self .get_tblspace_path (node , 'tblspace_new' )
655+
656+ self .create_tblspace_in_node (
657+ node , 'tblspace1' ,
658+ tblspc_path = tblspace1_old_path )
659+
660+ self .backup_node (
661+ backup_dir , 'node' , node , backup_type = "full" ,
662+ options = ["-j" , "4" , "--stream" ])
663+
664+ node_restored = self .make_simple_node (
665+ base_dir = os .path .join (module_name , fname , 'node_restored' ))
666+ node_restored .cleanup ()
667+
668+ try :
669+ self .restore_node (
670+ backup_dir , 'node' , node_restored ,
671+ options = [
672+ "-j" , "4" ,
673+ "-T" , "{0}={1}" .format (
674+ tblspace2_old_path , tblspace_new_path )])
675+ # we should die here because exception is what we expect to happen
676+ self .assertEqual (
677+ 1 , 0 ,
678+ "Expecting Error because tablespace mapping is incorrect"
679+ "\n Output: {0} \n CMD: {1}" .format (
680+ repr (self .output ), self .cmd ))
681+ except ProbackupException as e :
682+ self .assertTrue (
683+ 'ERROR: --tablespace-mapping option' in e .message and
684+ 'have an entry in tablespace_map file' in e .message ,
685+ '\n Unexpected Error Message: {0}\n CMD: {1}' .format (
686+ repr (e .message ), self .cmd ))
687+
688+ # Clean after yourself
689+ self .del_test_dir (module_name , fname )
690+
691+ # @unittest.skip("skip")
692+ def test_tablespace_handling_2 (self ):
693+ """
694+ make node without tablespaces, take full backup, check that restore with
695+ tablespace mapping will end with error
696+ """
697+ fname = self .id ().split ('.' )[3 ]
698+ node = self .make_simple_node (
699+ base_dir = os .path .join (module_name , fname , 'node' ),
700+ set_replication = True ,
701+ initdb_params = ['--data-checksums' ],
702+ pg_options = {
703+ 'wal_level' : 'replica' ,
704+ 'max_wal_senders' : '2' })
705+
706+ backup_dir = os .path .join (self .tmp_path , module_name , fname , 'backup' )
707+
708+ self .init_pb (backup_dir )
709+ self .add_instance (backup_dir , 'node' , node )
710+ node .slow_start ()
711+
712+ tblspace1_old_path = self .get_tblspace_path (node , 'tblspace1_old' )
713+ tblspace_new_path = self .get_tblspace_path (node , 'tblspace_new' )
714+
715+ self .backup_node (
716+ backup_dir , 'node' , node , backup_type = "full" ,
717+ options = ["-j" , "4" , "--stream" ])
718+
719+ node_restored = self .make_simple_node (
720+ base_dir = os .path .join (module_name , fname , 'node_restored' ))
721+ node_restored .cleanup ()
722+
723+ try :
724+ self .restore_node (
725+ backup_dir , 'node' , node_restored ,
726+ options = [
727+ "-j" , "4" ,
728+ "-T" , "{0}={1}" .format (
729+ tblspace1_old_path , tblspace_new_path )])
730+ # we should die here because exception is what we expect to happen
731+ self .assertEqual (
732+ 1 , 0 ,
733+ "Expecting Error because tablespace mapping is incorrect"
734+ "\n Output: {0} \n CMD: {1}" .format (
735+ repr (self .output ), self .cmd ))
736+ except ProbackupException as e :
737+ self .assertTrue (
738+ 'ERROR: --tablespace-mapping option' in e .message and
739+ 'have an entry in tablespace_map file' in e .message ,
740+ '\n Unexpected Error Message: {0}\n CMD: {1}' .format (
741+ repr (e .message ), self .cmd ))
742+
743+ # Clean after yourself
744+ self .del_test_dir (module_name , fname )
745+
630746 # @unittest.skip("skip")
631747 def test_drop_rel_during_backup_delta (self ):
632748 """"""
0 commit comments