6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-23 05:53:06 +01:00
firebird-qa/tests/bugs/gh_1665_test.py

260 lines
9.7 KiB
Python
Raw Normal View History

#coding:utf-8
2022-01-27 20:08:36 +01:00
"""
ID: issue-1665
ISSUE: 1665
TITLE: TempDirectories parameter in firebird.conf ignored by global temporary tables
DESCRIPTION:
Source discussions:
1) https://github.com/FirebirdSQL/firebird/pull/311
("Introduce new setting TempTableDirectory as discussed in fb-devel, see also CORE-1241")
2) https://github.com/FirebirdSQL/firebird/issues/1665
("TempDirectories parameter in firebird.conf ignored by global temporary tables [CORE1241]")
Old: CORE-1241; discussion resumed 14.12.2020.
Commits (17.05.2021 15:46):
1) https://github.com/FirebirdSQL/firebird/commit/f2805020a6f34d253c93b8edac6068c1b35f9b89
"New setting TempTableDirectory.
Used to set directory where engine should put data of temporary tables and temporary blobs."
2) https://github.com/FirebirdSQL/firebird/commit/fd0fa8a3a58fbfe7fdc0641b4e48258643d72127
"Let include file name into error message when creation of temp file failed."
This test checks only second commit of above mentioned (i.e. message about invalid/incaccessible TempTableDirectory).
We make backup of current firebird.conf for changing it by adding line with 'TempTableDirectory' parameter
which has INVALID form for both Windows and Linux: '|DEFINITELY|INACCESSIBLE|' (no such folder can exist).
Then we establish connection to the test DB and run SQL which creates GTT and adds several rows in it.
NO exception must be raised in this case: GTT must be fulfilled w/o problems and FB must create temporary
file (fb_table_*) in some existing folder (defined by FIREBIRD_TMP variable; if it is undefined then such
file will be created in C:\\TEMP or /tmp - depending on OS).
But firebird.log must contain message about problem with creating file (fb_table_*) in the directory which
could not be accessed. We check old and new content of firebird.log with expecting to see message that
did appear about this problem.
::: NB :::
Affect of changed parameter TempTableDirectory can be seen only if DB is attached using *LOCAL* protocol.
Checked on 5.0.0.40
JIRA: CORE-1241
FBTEST: bugs.gh_1665
2022-01-27 20:08:36 +01:00
"""
import pytest
2022-01-27 20:08:36 +01:00
from firebird.qa import *
2022-01-27 20:08:36 +01:00
db = db_factory()
2022-01-27 20:08:36 +01:00
act = python_act('db', substitutions=[('[ \t]+', ' '), ('.*fb_table_.*', 'fb_table_')])
2022-01-27 20:08:36 +01:00
expected_stdout = """
+ Error creating file in TempTableDirectory "|DEFINITELY|INACCESSIBLE|"
+ I/O error during "CreateFile (create)" operation for file "|DEFINITELY|INACCESSIBLE|\\fb_table_"
+ Error while trying to create file
"""
2022-01-27 20:08:36 +01:00
@pytest.mark.skip('FIXME: Not IMPLEMENTED')
@pytest.mark.version('>=5.0')
def test_1(act: Action):
pytest.fail("Not IMPLEMENTED")
# test_script_1
#---
2022-01-25 22:55:48 +01:00
#
# import sys
# import os
# import shutil
# import time
# import datetime
# from datetime import timedelta
# import subprocess
# import difflib
# import re
# import codecs
# from fdb import services
2022-01-25 22:55:48 +01:00
#
# os.environ["ISC_USER"] = user_name
# os.environ["ISC_PASSWORD"] = user_password
2022-01-25 22:55:48 +01:00
#
# db_name=db_conn.database_name
# db_conn.close()
# #--------------------------------------------
2022-01-25 22:55:48 +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
# # 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
#
# 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
#
# #--------------------------------------------
2022-01-25 22:55:48 +01:00
#
# def cleanup( f_names_list ):
# global os
# for f in f_names_list:
# if type(f) == file:
# del_name = f.name
# elif type(f) == str:
# del_name = f
# else:
# print('Unrecognized type of element:', f, ' - can not be treated as file.')
# del_name = None
2022-01-25 22:55:48 +01:00
#
# if del_name and os.path.isfile( del_name ):
# os.remove( del_name )
2022-01-25 22:55:48 +01:00
#
# #--------------------------------------------
2022-01-25 22:55:48 +01:00
#
# def svc_get_fb_log( f_fb_log ):
2022-01-25 22:55:48 +01:00
#
# global subprocess
# subprocess.call( [ context['fbsvcmgr_path'],
# "localhost:service_mgr",
# "user", user_name,
# "password", user_password,
# "action_get_fb_log"
# ],
# stdout=f_fb_log, stderr=subprocess.STDOUT
# )
# return
2022-01-25 22:55:48 +01:00
#
# #--------------------------------------------
2022-01-25 22:55:48 +01:00
#
# def try_to_use_tempdir( db_name ):
2022-01-25 22:55:48 +01:00
#
# global flush_and_close
# global subprocess
# global cleanup
# sql_chk= '''
# set list on;
# select rdb$config_name, rdb$config_value from rdb$config g where upper(g.rdb$config_name) = upper('TempTableDirectory');
# recreate global temporary table gtt_test(s varchar(100) unique) on commit preserve rows;
# commit;
# set count on;
# insert into gtt_test(s) select lpad('',100,uuid_to_char(gen_uuid())) from rdb$types rows 100;
# commit;
# '''
2022-01-25 22:55:48 +01:00
#
# f_connect_sql = open( os.path.join(context['temp_directory'],'tmp_1665_check.sql'), 'w')
# f_connect_sql.write( sql_chk )
# flush_and_close( f_connect_sql )
2022-01-25 22:55:48 +01:00
#
# f_connect_log=open( os.path.join(context['temp_directory'],'tmp_1665_check.log'), 'w')
2022-01-25 22:55:48 +01:00
#
# ###############
# ### ACHTUNG ###
# ###############
# # LOCAL protocol must be used here!
# # Attempt to connect using remote protocol will fail: engine returns previous value of DefaultTimeZone.
# # One need to wait at least 130 seconds after changing firebird.conf for new value be returned at this case!
# # The reason of that is 10+60+60 seconds which are needed to fully unload shmem-related structures from memory.
# # Explanation from Vlad: letter 24.01.2021 18:00, subj: "System audit in FB. Is there some kind of timeout of 130 seconds ?"
# # (it was discussion about attempts make test for CORE-5993)
# # See also: http://tracker.firebirdsql.org/browse/CORE-6476
2022-01-25 22:55:48 +01:00
#
# subprocess.call( [ context['isql_path'], db_name, "-i", f_connect_sql.name ], stdout=f_connect_log, stderr=subprocess.STDOUT )
# flush_and_close( f_connect_log )
# cleanup( (f_connect_sql, f_connect_log) )
2022-01-25 22:55:48 +01:00
#
# #---------------------------------------------
2022-01-25 22:55:48 +01:00
#
# svc = services.connect(host='localhost', user=user_name, password=user_password)
# fb_home = svc.get_home_directory()
# svc.close()
2022-01-25 22:55:48 +01:00
#
# dts = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
2022-01-25 22:55:48 +01:00
#
# fbconf_cur = os.path.join(fb_home, 'firebird.conf')
# fbconf_bak = os.path.join(context['temp_directory'], 'firebird_'+dts+'.bak')
2022-01-25 22:55:48 +01:00
#
# shutil.copy2( fbconf_cur, fbconf_bak )
2022-01-25 22:55:48 +01:00
#
# f_fbconf=open( fbconf_cur, 'r')
# fbconf_content=f_fbconf.readlines()
# flush_and_close( f_fbconf )
2022-01-25 22:55:48 +01:00
#
# for i,s in enumerate( fbconf_content ):
# line = s.lower().lstrip()
# if line.startswith( 'TempTableDirectory'.lower() ):
# fbconf_content[i] = '# [temply commented] ' + s
2022-01-25 22:55:48 +01:00
#
# text2app='''
# ### TEMPORARY CHANGED BY FBTEST FRAMEWORK ###
# TempTableDirectory = |DEFINITELY|INACCESSIBLE|
# ##############################################
# '''
2022-01-25 22:55:48 +01:00
#
# f_fbconf=open( fbconf_cur, 'w')
# f_fbconf.writelines( fbconf_content + [ '\\n' + x for x in text2app.split('\\n') ] )
# flush_and_close( f_fbconf )
# #..........................................
2022-01-25 22:55:48 +01:00
#
# # Get FB log before trying to use invalid TempTableDirectory
# ###################
# f_fblog_before=open( os.path.join(context['temp_directory'],'tmp_1665_fblog_before.txt'), 'w')
# svc_get_fb_log( f_fblog_before )
# flush_and_close( f_fblog_before )
2022-01-25 22:55:48 +01:00
#
# try_to_use_tempdir( db_name )
2022-01-25 22:55:48 +01:00
#
# # Get FB log after trying to use invalid TempTableDirectory
# ##################
# f_fblog_after=open( os.path.join(context['temp_directory'],'tmp_1665_fblog_after.txt'), 'w')
# svc_get_fb_log( f_fblog_after )
# flush_and_close( f_fblog_after)
2022-01-25 22:55:48 +01:00
#
#
# old_fb_log=open(f_fblog_before.name, 'r')
# new_fb_log=open(f_fblog_after.name, 'r')
2022-01-25 22:55:48 +01:00
#
# fb_log_diff = ''.join(difflib.unified_diff(
2022-01-25 22:55:48 +01:00
# old_fb_log.readlines(),
# new_fb_log.readlines()
# ))
# old_fb_log.close()
# new_fb_log.close()
2022-01-25 22:55:48 +01:00
#
# f_diff=open( os.path.join(context['temp_directory'],'tmp_1665_fblog_diff.txt'), 'w')
# f_diff.write(fb_log_diff)
# flush_and_close( f_diff )
2022-01-25 22:55:48 +01:00
#
# ##################################################
2022-01-25 22:55:48 +01:00
#
# # RESTORE previous content of firebird.conf. This must be done BEFORE drop mapping!
# shutil.move( fbconf_bak, fbconf_cur )
2022-01-25 22:55:48 +01:00
#
# # Compare content of previous and current firebird.log: we have to found in current log
# # messages like these:
# # Database: ...
# # Error creating file in TempTableDirectory "|DEFINITELY|INACCESSIBLE"
# # I/O error during "CreateFile (create)" operation for file "|DEFINITELY|INACCESSIBLE|..."
# # Error while trying to create file
# # NB: we use codecs.open() in order to skip localized message.
2022-01-25 22:55:48 +01:00
#
# allowed_patterns = (
# re.compile('Error creating file in TempTableDirectory "|DEFINITELY|INACCESSIBLE|"', re.IGNORECASE)
# ,re.compile('I/O error during "CreateFile (create)" operation for file "|DEFINITELY|INACCESSIBLE|(\\/)fb_table_.*"', re.IGNORECASE)
# ,re.compile('Error while trying to create file')
# )
2022-01-25 22:55:48 +01:00
#
# with codecs.open( f_diff.name, 'r', encoding = 'utf-8', errors = 'ignore' ) as f:
# for line in f:
# if line.startswith('+'):
# ls = line.strip()
# match2some = [ p.search(ls) for p in allowed_patterns ]
# if max(match2some) != None:
# print(ls)
2022-01-25 22:55:48 +01:00
#
# # cleanup:
# ##########
# time.sleep(1)
# cleanup( (old_fb_log, new_fb_log, f_diff) )
2022-01-25 22:55:48 +01:00
#
#---