2021-12-30 19:43:52 +01:00
|
|
|
#coding:utf-8
|
2022-01-27 20:08:36 +01:00
|
|
|
|
|
|
|
"""
|
|
|
|
ID: issue-6785
|
|
|
|
ISSUE: 6785
|
|
|
|
TITLE: Problem when restoring the database on FB 4.0 RC1 (gbak regression)
|
|
|
|
DESCRIPTION:
|
|
|
|
Test used database backup that was provided in the ticket.
|
|
|
|
|
|
|
|
Maximal allowed time is set here for restoring process and gbak will be
|
|
|
|
forcedly killed if it can not complete during this time.
|
|
|
|
Currently this time is 300 seconds (see 'MAX_THRESHOLD' variable).
|
|
|
|
|
|
|
|
Database is validated (using 'gfix -v -full') after successful restore finish.
|
|
|
|
Test checks that returned codes for both gbak and validation are zero.
|
|
|
|
|
|
|
|
Restore issues warnings:
|
|
|
|
gbak: WARNING:function F_DATETOSTR is not defined
|
|
|
|
gbak: WARNING: module name or entrypoint could not be found
|
|
|
|
gbak: WARNING:function F_DATETOSTR is not defined
|
|
|
|
gbak: WARNING: module name or entrypoint could not be found
|
|
|
|
All of them are ignored by this test when gbak output is parsed.
|
|
|
|
|
|
|
|
Confirmed bug on 4.0.0.2452 SS: gbak infinitely hanged.
|
|
|
|
Checked on 4.0.0.2453 SS/CS (Linux and Windows): all OK, restore lasts near 200s.
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.gh_6785
|
2022-01-27 20:08:36 +01:00
|
|
|
"""
|
2021-12-30 19:43:52 +01:00
|
|
|
|
|
|
|
import pytest
|
2022-01-27 20:08:36 +01:00
|
|
|
from firebird.qa import *
|
2021-12-30 19:43:52 +01:00
|
|
|
|
2022-01-27 20:08:36 +01:00
|
|
|
db = db_factory()
|
2021-12-30 19:43:52 +01:00
|
|
|
|
2022-01-27 20:08:36 +01:00
|
|
|
act = python_act('db')
|
2021-12-30 19:43:52 +01:00
|
|
|
|
2022-01-27 20:08:36 +01:00
|
|
|
expected_stdout = """
|
|
|
|
Restore retcode: 0
|
|
|
|
Validation retcode: 0
|
|
|
|
"""
|
2021-12-30 19:43:52 +01:00
|
|
|
|
2022-01-27 20:08:36 +01:00
|
|
|
@pytest.mark.skip('FIXME: Not IMPLEMENTED')
|
|
|
|
@pytest.mark.version('>=4.0')
|
|
|
|
def test_1(act: Action):
|
|
|
|
pytest.fail("Not IMPLEMENTED")
|
2021-12-30 19:43:52 +01:00
|
|
|
|
|
|
|
# test_script_1
|
|
|
|
#---
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# import os
|
|
|
|
# import re
|
|
|
|
# import time
|
|
|
|
# import zipfile
|
|
|
|
# import difflib
|
|
|
|
# import subprocess
|
|
|
|
# import datetime as py_dt
|
|
|
|
# from datetime import timedelta
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# os.environ["ISC_USER"] = user_name
|
|
|
|
# os.environ["ISC_PASSWORD"] = user_password
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# db_conn.close()
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# #--------------------------------------------
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# def flush_and_close( file_handle ):
|
|
|
|
# # https://docs.python.org/2/library/os.html#os.fsync
|
2022-01-25 22:55:48 +01:00
|
|
|
# # If you're starting with a Python file object f,
|
|
|
|
# # first do f.flush(), and
|
2021-12-30 19:43:52 +01:00
|
|
|
# # then do os.fsync(f.fileno()), to ensure that all internal buffers associated with f are written to disk.
|
|
|
|
# global os
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# file_handle.flush()
|
|
|
|
# if file_handle.mode not in ('r', 'rb') and file_handle.name != os.devnull:
|
|
|
|
# # otherwise: "OSError: [Errno 9] Bad file descriptor"!
|
|
|
|
# os.fsync(file_handle.fileno())
|
|
|
|
# file_handle.close()
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# #--------------------------------------------
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# def cleanup( f_names_list ):
|
|
|
|
# global os
|
|
|
|
# for i in range(len( f_names_list )):
|
|
|
|
# if type(f_names_list[i]) == file:
|
|
|
|
# del_name = f_names_list[i].name
|
|
|
|
# elif type(f_names_list[i]) == str:
|
|
|
|
# del_name = f_names_list[i]
|
|
|
|
# else:
|
|
|
|
# print('Unrecognized type of element:', f_names_list[i], ' - can not be treated as file.')
|
|
|
|
# del_name = None
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# if del_name and os.path.isfile( del_name ):
|
|
|
|
# os.remove( del_name )
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# #--------------------------------------------
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# zf = zipfile.ZipFile( os.path.join(context['files_location'],'gh_6785.zip') )
|
|
|
|
# tmpfbk = 'gh_6785.fbk'
|
|
|
|
# zf.extract( tmpfbk, '$(DATABASE_LOCATION)')
|
|
|
|
# zf.close()
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# tmpfbk = os.path.join( '$(DATABASE_LOCATION)', tmpfbk)
|
|
|
|
# tmpfdb = os.path.join( '$(DATABASE_LOCATION)', 'tmp_gh_6785.fdb')
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# #------------------------------ restore database -------------------------------
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# f_restore_log=open( os.path.join(context['temp_directory'],'tmp_gh_6785_restoring.log'), 'w')
|
|
|
|
# p_restore = subprocess.Popen([context['gbak_path'],"-rep", tmpfbk, tmpfdb], stdout=f_restore_log, stderr=subprocess.STDOUT)
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# t1=py_dt.datetime.now()
|
|
|
|
# restore_retcode = None
|
|
|
|
# i=0
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# # Maximal allowed time for restoring process, in seconds:
|
|
|
|
# ######################
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# ###################
|
|
|
|
# MAX_THRESHOLD = 300
|
|
|
|
# ###################
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# while 1:
|
|
|
|
# restore_retcode = p_restore.poll()
|
|
|
|
# if i > MAX_THRESHOLD:
|
|
|
|
# p_restore.terminate()
|
|
|
|
# restore_retcode = -1
|
|
|
|
# if restore_retcode is not None:
|
|
|
|
# break
|
|
|
|
# time.sleep(1)
|
|
|
|
# i += 1
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# t2=py_dt.datetime.now()
|
|
|
|
# d1=t2-t1
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# flush_and_close( f_restore_log )
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# #print('Restore retcode:', restore_retcode, ', total time, ms:', d1.seconds*1000 + d1.microseconds//1000)
|
|
|
|
# print('Restore retcode:', restore_retcode)
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# if restore_retcode == 0:
|
|
|
|
# #-------------------------- validate just restored database --------------------
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# f_valid_log = open( os.path.join(context['temp_directory'],'tmp_gh_6785_validation.log'), 'w')
|
|
|
|
# validation_retcode = subprocess.check_call( [ context['gfix_path'], 'localhost:'+tmpfdb, "-v", "-full" ],
|
|
|
|
# stdout = f_valid_log,
|
|
|
|
# stderr = subprocess.STDOUT
|
|
|
|
# )
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# flush_and_close( f_valid_log )
|
|
|
|
# print('Validation retcode: %d' % validation_retcode)
|
|
|
|
# with open(f_valid_log.name,'r') as f:
|
|
|
|
# for line in f:
|
|
|
|
# print('UNEXPECTED VALIDATION OUTPUT: ' + line)
|
|
|
|
# cleanup( (f_valid_log,) )
|
|
|
|
# else:
|
|
|
|
# print('Restore duration: %ds - exceeded maximal time limit: %ds' % (d1.seconds, MAX_THRESHOLD) )
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# # check results:
|
|
|
|
# ################
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# ptn_gbak_warning = re.compile('gbak:\\s*WARNING:', re.IGNORECASE) # must be supressed for this .fbk
|
|
|
|
# with open(f_restore_log.name,'r') as f:
|
|
|
|
# for line in f:
|
|
|
|
# if not ptn_gbak_warning.search(line):
|
|
|
|
# print('UNEXPECTED RESTORE OUTPUT: ' + line)
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
# # cleanup
|
|
|
|
# ##########
|
|
|
|
# time.sleep(1)
|
|
|
|
# cleanup( ( f_restore_log, tmpfdb, tmpfbk ) )
|
2022-01-25 22:55:48 +01:00
|
|
|
#
|
2021-12-30 19:43:52 +01:00
|
|
|
#---
|