def test_prepare_tablespaces(self, tmpdir): """ Test tablespaces preparation for recovery """ # Prepare basic directory/files structure dest = tmpdir.mkdir('destination') wals = tmpdir.mkdir('wals') backup_info = testing_helpers.build_test_backup_info( tablespaces=[('tbs1', 16387, '/fake/location')]) # build an executor server = testing_helpers.build_real_server( main_conf={'wals_directory': wals.strpath}) executor = RecoveryExecutor(server.backup_manager) # use a mock as cmd obj cmd_mock = mock.Mock() executor._prepare_tablespaces(backup_info, cmd_mock, dest.strpath, {}) cmd_mock.create_dir_if_not_exists.assert_any_call( dest.join('pg_tblspc').strpath) cmd_mock.create_dir_if_not_exists.assert_any_call( '/fake/location') cmd_mock.delete_if_exists.assert_called_once_with( dest.join('pg_tblspc').join('16387').strpath) cmd_mock.create_symbolic_link.assert_called_once_with( '/fake/location', dest.join('pg_tblspc').join('16387').strpath)
def test_recover_standby_mode(self, tmpdir): backup_info = testing_helpers.build_test_backup_info() backup_manager = testing_helpers.build_backup_manager() executor = RecoveryExecutor(backup_manager) backup_info.version = 90300 destination = tmpdir.mkdir('destination').strpath # If standby mode is not enabled, recovery.conf is not generated executor._prepare_tablespaces = MagicMock() executor._backup_copy = MagicMock() executor._xlog_copy = MagicMock() executor._generate_recovery_conf = MagicMock() with closing(executor): executor.recover(backup_info, destination, standby_mode=None) executor._generate_recovery_conf.assert_not_called() # If standby mode is enabled, recovery.conf is generated executor._prepare_tablespaces.reset_mock() executor._backup_copy.reset_mock() executor._xlog_copy.reset_mock() executor._generate_recovery_conf.reset_mock() with closing(executor): executor.recover(backup_info, destination, standby_mode=True) executor._generate_recovery_conf.assert_called() # If standby mode is passed but PostgreSQL is older than 9.0, # we must raise an exception backup_info.version = 80000 with pytest.raises(RecoveryStandbyModeException): with closing(executor): executor.recover(backup_info, destination, standby_mode=True)
def test_prepare_tablespaces(self, tmpdir): """ Test tablespaces preparation for recovery """ # Prepare basic directory/files structure dest = tmpdir.mkdir("destination") wals = tmpdir.mkdir("wals") backup_info = testing_helpers.build_test_backup_info(tablespaces=[("tbs1", 16387, "/fake/location")]) # build an executor server = testing_helpers.build_real_server(main_conf={"wals_directory": wals.strpath}) executor = RecoveryExecutor(server.backup_manager) # use a mock as cmd obj cmd_mock = mock.Mock() executor._prepare_tablespaces(backup_info, cmd_mock, dest.strpath, {}) cmd_mock.create_dir_if_not_exists.assert_any_call(dest.join("pg_tblspc").strpath) cmd_mock.create_dir_if_not_exists.assert_any_call("/fake/location") cmd_mock.delete_if_exists.assert_called_once_with(dest.join("pg_tblspc").join("16387").strpath) cmd_mock.create_symbolic_link.assert_called_once_with( "/fake/location", dest.join("pg_tblspc").join("16387").strpath )