6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-02-02 10:50:42 +01:00

Added/Updated bugs\core_6392_test.py. Checked on 3.0.8.33535, 4.0.1.2692, 5.0.0.591

This commit is contained in:
zotov 2022-07-24 12:33:00 +03:00
parent 60f5fc0272
commit 166d14668d

View File

@ -5,224 +5,125 @@ ID: issue-6630
ISSUE: 6630 ISSUE: 6630
TITLE: Space in database path prevent working gbak -se ... -b "pat to/database" backup TITLE: Space in database path prevent working gbak -se ... -b "pat to/database" backup
DESCRIPTION: DESCRIPTION:
Test creates windows BATCH file for main job:
* create folder with spaces and some non-alphabetic characters (use "[", "]", "(", ")" etc);
* create .sql script which will make database with spaces and non-alphabetic characters in this folder;
* try to backup and restore using "simple" gbak commend (i.e. without "-se" command switch);
* try to backup and restore using "-se" command switch;
* try to backup and restore using services manager.
Batch output is redirected to log and then we parse this log with expectation to find there messages
which prove successful results for each action.
Confirmed bug on 4.0.0.2173.
Checked on 3.0.7.33358; 4.0.0.2180 SS/SC/CS: all fine.
::: NOTE :::
Some problem still exists when DB file or folder has name which last character is '.' or ' ' (dot or space).
Database will be created but attempt to backup raises: "gbak: ERROR:cannot open backup file ..."
JIRA: CORE-6392 JIRA: CORE-6392
FBTEST: bugs.core_6392 FBTEST: bugs.core_6392
NOTES:
[24.07.2022] pzotov
Reproduced problem on 4.0.0.2173.
gbak: ERROR:multiple sources or destinations specified
gbak: ERROR: Exiting before completion due to errors
gbak:Exiting before completion due to errors
::: NOTE :::
Problem exists when DB file or folder has trailing character = '.' or ' ' (dot or space).
Test does not use such case.
Checked on 3.0.8.33535, 4.0.1.2692, 5.0.0.591
""" """
import shutil
import re
import subprocess
from pathlib import Path
import pytest import pytest
from firebird.qa import * from firebird.qa import *
import time
db = db_factory() db = db_factory()
bkp_log = temp_file('backup_log.tmp')
res_log = temp_file('restore_log.tmp')
act = python_act('db', substitutions=[('[\t ]+', ' ')]) act = python_act('db', substitutions=[('[\t ]+', ' ')])
expected_stdout = """ expected_backup_out = 'Backup completed OK.'
CHECK POINT. Trying to create database. expected_restore_out = 'Restore completed OK.'
CHECK POINT. Result: SUCCESS.
CHECK POINT. Trying to BACKUP without "-se" switch.
closing file, committing, and finishing
CHECK POINT. Trying to restore without "-se".
finishing, closing, and going home
CHECK POINT. Trying to backup using gbak WITH "-se" switch.
closing file, committing, and finishing
CHECK POINT. Trying to restore using gbak WITH "-se" switch.
finishing, closing, and going home
CHECK POINT. Trying to backup using fbsvcmgr.
closing file, committing, and finishing
CHECK POINT. Trying to restore using fbsvcmgr.
finishing, closing, and going home
"""
@pytest.mark.skip('FIXME: Not IMPLEMENTED')
@pytest.mark.version('>=3.0.7') @pytest.mark.version('>=3.0.7')
@pytest.mark.platform('Windows') @pytest.mark.platform('Windows')
def test_1(act: Action): # gbak: ERROR:cannot open status and error output file <function temp_file.<locals>.temp_file_fixture at 0x0000024389962040>
pytest.fail("Not IMPLEMENTED") # gbak:Exiting before completion due to errors
def test_1(act: Action, bkp_log: Path, res_log: Path, capsys):
p_base = Path(act.db.db_path).parent
p_work = p_base / "..str@nge (path; folder & name),"
Path(p_work).mkdir(parents=True, exist_ok=False)
# test_script_1 shutil.copy2(act.db.db_path, str(p_work))
#--- tmp_fdb = Path(p_work, Path(act.db.db_path).name)
# tmp_fbk = Path(p_work, Path(act.db.db_path).stem + ". fbk")
# import os
# import sys error_pattern = re.compile(r'gbak:\s*ERROR(:)?', re.IGNORECASE)
# import time successful_backup_pattern = re.compile(r'gbak:closing file, committing, and finishing. \d+ bytes written', re.IGNORECASE)
# import subprocess successful_restore_pattern = re.compile( r'gbak:finishing, closing, and going home', re.IGNORECASE )
# import re
# from fdb import services #-------------------------------------------------------
# # Backup using FB services API:
# os.environ["ISC_USER"] = user_name #
# os.environ["ISC_PASSWORD"] = user_password act.svcmgr(switches=[ 'action_backup', 'dbname', str(tmp_fdb), 'bkp_file', str(tmp_fbk), 'verbint', '999999'])
# svc_log = act.stdout
# #--------------------------------------------- svc_err = act.stderr
#
# def flush_and_close(file_handle): for line in svc_err.split('\n'):
# # https://docs.python.org/2/library/os.html#os.fsync print(line)
# # If you're starting with a Python file object f,
# # first do f.flush(), and for line in svc_log.split('\n'):
# # then do os.fsync(f.fileno()), to ensure that all internal buffers associated with f are written to disk. if successful_backup_pattern.search(line):
# global os print(expected_backup_out)
# break
# file_handle.flush()
# if file_handle.mode not in ('r', 'rb'): act.expected_stdout = expected_backup_out
# # otherwise: "OSError: [Errno 9] Bad file descriptor"! act.stdout = capsys.readouterr().out
# os.fsync(file_handle.fileno()) assert act.clean_stdout == act.clean_expected_stdout
# file_handle.close() act.reset()
#
# #-------------------------------------------- #-------------------------------------------------------
# # Restore using FB services API:
# def cleanup( f_names_list ): #
# global os act.svcmgr(switches=[ 'action_restore', 'bkp_file', str(tmp_fbk), 'dbname', str(tmp_fdb), 'verbint', '999999', 'res_replace'])
# for i in range(len( f_names_list )): svc_log = act.stdout
# if os.path.isfile( f_names_list[i]): svc_err = act.stderr
# os.remove( f_names_list[i] )
# #-------------------------------------------- for line in svc_err.split('\n'):
# print(line)
# fb_home = os.path.split( services.connect(host='localhost', user= user_name, password= user_password).get_home_directory() )[0]
# db_conn.close() for line in svc_log.split('\n'):
# if successful_restore_pattern.search(line):
# # tmpdir='c:\\\\temp\\\\folder with spaces ' print(expected_restore_out)
# # gbak: ERROR:cannot open backup file c: emp break
# older with spaces \\db with spaces. . .fbk
# act.expected_stdout = expected_restore_out
# # tmpdir='c:\\\\temp\\\\folder with spaces..' act.stdout = capsys.readouterr().out
# # gbak: ERROR:cannot open backup file c: emp assert act.clean_stdout == act.clean_expected_stdout
# older with spaces..\\db with spaces. . .fbk act.reset()
#
# #tmpdir='c:\\\\temp\\\\^!very strange^! folder with (many) spaces; created temporary, only for core-6392^! ' #-------------------------------------------------------
# # Backup via 'gbak -se' (this failed on 4.0.0.2173):
# #dbname='(strange name^!) DB with #lot# of excessive spaces; created temporary, only for core-6392^!. . .fdb' #
# # gbak: ERROR:cannot open backup file // but database is created OK. act.gbak(switches=['-b', '-se', 'localhost:service_mgr', '-verbint', '99999', '-y', str(bkp_log), str(tmp_fdb), str(tmp_fbk)])
# with open(bkp_log, 'r') as f:
# #dbname='(strange name^!) DB with #lot# of excessive spaces, created temporary, only for core-6392^!. . .fdb' for line in f:
# # gbak: ERROR:cannot open backup file // but database is created OK. if error_pattern.search(line):
# print('Backup FAILED:', line)
# tmpdir='c:\\\\temp\\\\ [[[ strange ]]] folder with {{{ lot of }}} spaces^!' break
# dbname='DB with very^! ))) strange ((( name; created for core-6392.fdb' if successful_backup_pattern.search(line):
# print(expected_backup_out)
# bkname=( '.'.join( dbname.split('.')[:-1] )+'.fbk' if '.' in dbname else dbname+'.fbk' ) break
# act.expected_stdout = expected_backup_out
# extbat=os.path.join(context['temp_directory'],'tmp_6392.bat') act.stdout = capsys.readouterr().out
# extlog=os.path.splitext(extbat)[0]+'.log' assert act.clean_stdout == act.clean_expected_stdout
# exterr=os.path.splitext(extbat)[0]+'.err' act.reset()
#
# chksql="iif( upper(mon$database_name) = upper( q'{%(tmpdir)s\\%(dbname)s}' ), 'SUCCESS.', '### ERROR: DB HAS DIFFERENT NAME ###')" % locals() #-------------------------------------------------------
# chksql=chksql.replace('^', '^^').replace(')', '^)') # Restore via 'gbak -se':
# # echo select 'c: emp\\ [[[ strange ]]] folder with {{{ lot of }}} spaces^^!\\DB with very^^! ^)^)^) strange ((( name; created for core-6392.fdb' from rdb$database; #
# act.gbak(switches=['-rep', '-se', 'localhost:service_mgr', '-verbint', '99999', '-y', str(res_log), str(tmp_fbk), str(tmp_fdb) ])
# runcmd=''' with open(res_log, 'r') as f:
# @echo off for line in f:
# setlocal enabledelayedexpansion enableextensions if error_pattern.search(line):
# set ISC_USER=%(user_name)s print('Restore FAILED:', line)
# set ISC_PASSWORD=%(user_password)s break
# set FB_HOME=%(fb_home)s\\\\ if successful_restore_pattern.search(line):
# print(expected_restore_out)
# set tmpsql=%%~dpn0.sql break
# act.expected_stdout = expected_restore_out
# del %(extlog)s 2>nul act.stdout = capsys.readouterr().out
# assert act.clean_stdout == act.clean_expected_stdout
# mkdir "%(tmpdir)s" 2>nul act.reset()
# if exist "%(tmpdir)s" (
# echo Directory created OK.
# ) else (
# echo Could NOT create directory "%(tmpdir)s". ABEND.
# goto :final
# )
#
# if exist "%(tmpdir)s\\%(dbname)s" del "%(tmpdir)s\\%(dbname)s"
#
# (
# echo set bail on;
# echo create database "%(tmpdir)s\\%(dbname)s";
# echo set list on;
# echo select %(chksql)s as "CHECK POINT. Result:" from mon$database;
# ) > !tmpsql!
#
# echo CHECK POINT. Trying to create database.
# !FB_HOME!isql.exe -q -i !tmpsql!
#
# del !tmpsql!
#
# echo CHECK POINT. Trying to BACKUP without "-se" switch.
# !FB_HOME!gbak.exe -b -verbi 999999 -st tdrw localhost:"%(tmpdir)s\\%(dbname)s" "%(tmpdir)s\\%(bkname)s"
# if exist "%(tmpdir)s\\%(bkname)s" (
# echo CHECK POINT. Trying to restore without "-se".
# !FB_HOME!gbak.exe -rep -verbi 999999 -st tdrw "%(tmpdir)s\\%(bkname)s" localhost:"%(tmpdir)s\\%(dbname)s"
# )
#
# echo.
# echo CHECK POINT. Trying to backup using gbak WITH "-se" switch.
# if exist "%(tmpdir)s\\%(bkname)s" del "%(tmpdir)s\\%(bkname)s"
# !FB_HOME!gbak.exe -b -verbi 999999 -st tdrw -se localhost:service_mgr "%(tmpdir)s\\%(dbname)s" "%(tmpdir)s\\%(bkname)s"
# if exist "%(tmpdir)s\\%(bkname)s" (
# echo CHECK POINT. Trying to restore using gbak WITH "-se" switch.
# !FB_HOME!gbak.exe -rep -verbi 999999 -st tdrw -se localhost:service_mgr "%(tmpdir)s\\%(bkname)s" "%(tmpdir)s\\%(dbname)s"
# )
#
# echo.
# echo CHECK POINT. Trying to backup using fbsvcmgr.
# if exist "%(tmpdir)s\\%(bkname)s" del "%(tmpdir)s\\%(bkname)s"
#
# !FB_HOME!fbsvcmgr.exe localhost:service_mgr action_backup dbname "%(tmpdir)s\\%(dbname)s" bkp_file "%(tmpdir)s\\%(bkname)s" verbint 999999 bkp_stat tdrw
# if exist "%(tmpdir)s\\%(bkname)s" (
# echo CHECK POINT. Trying to restore using fbsvcmgr.
# !FB_HOME!fbsvcmgr.exe localhost:service_mgr action_restore res_replace bkp_file "%(tmpdir)s\\%(bkname)s" dbname "%(tmpdir)s\\%(dbname)s" verbint 999999 res_stat tdrw
# )
#
# :final
# if exist "%(tmpdir)s\\%(dbname)s" del "%(tmpdir)s\\%(dbname)s"
# if exist "%(tmpdir)s\\%(bkname)s" del "%(tmpdir)s\\%(bkname)s"
# rmdir "%(tmpdir)s"
# echo Bye-bye from %%~f0
# ''' % dict(globals(), **locals())
#
# f_extbat=open( extbat, 'w' )
# f_extbat.write(runcmd)
# flush_and_close(f_extbat)
#
# f_extlog=open( extlog, 'w' )
# subprocess.call( [ extbat ], stdout = f_extlog, stderr = subprocess.STDOUT )
# flush_and_close(f_extlog)
#
# allowed_patterns = [ re.compile(p, re.IGNORECASE) for p in
# (
# 'check\\s+point'
# ,'closing\\s+file(,)?\\s+committing(,)?\\s+.*finishing'
# ,'finishing(,)?\\s+closing(,)?\\s+.*going\\s+home'
# )
# ]
#
# with open(f_extlog.name, 'r') as f:
# for line in f:
# if 'gbak: ERROR' in line:
# print('UNEXPECTED ERROR occured: ' + line)
# else:
# for p in allowed_patterns:
# if p.search(line):
# print( (line if 'CHECK POINT' in line else p.search(line).group() ) )
#
# # CLEANUP
# #########
# time.sleep(1)
# #cleanup( [extbat, extlog] )
#
#---