mirror of
https://github.com/FirebirdSQL/firebird-qa.git
synced 2025-01-22 21:43:06 +01:00
Added/Updated bugs\core_3658_test.py. ACHTUNG: EXPLICIT invocation of fbsvcmgr required, see notes. Checked on 3.0.8.33535 (SS/CS), 4.0.1.2692 (SS/CS), 5.0.0.730 (SS/CS)
This commit is contained in:
parent
c2f82e1a6e
commit
1c19a8c9f5
@ -5,182 +5,81 @@ ID: issue-4008
|
|||||||
ISSUE: 4008
|
ISSUE: 4008
|
||||||
TITLE: FBSVCMGR connects to server as OS user name rather than value of ISC_USER environment variable
|
TITLE: FBSVCMGR connects to server as OS user name rather than value of ISC_USER environment variable
|
||||||
DESCRIPTION:
|
DESCRIPTION:
|
||||||
NOTES:
|
|
||||||
[17.11.2021] pcisar
|
|
||||||
Implementation is complicated, and IMHO not worth of realization
|
|
||||||
JIRA: CORE-3658
|
JIRA: CORE-3658
|
||||||
FBTEST: bugs.core_3658
|
FBTEST: bugs.core_3658
|
||||||
|
NOTES:
|
||||||
|
[17.11.2021] pcisar
|
||||||
|
Implementation is complicated, and IMHO not worth of realization
|
||||||
|
[19.09.2022] pzotov
|
||||||
|
We have to EXPLICITLY invoke fbsvcmgr in this test rather than call it using 'with act.trace()'.
|
||||||
|
This is because act.trace() *always* will define user/password pair and substitute them into
|
||||||
|
returned TraceSession( ... ) instance, so we have no ability to call trace manager with IMPLICIT
|
||||||
|
credentials, i.e. via ISC_* env. variables.
|
||||||
|
|
||||||
|
Checked on 3.0.8.33535 (SS/CS), 4.0.1.2692 (SS/CS), 5.0.0.730 (SS/CS)
|
||||||
"""
|
"""
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import locale
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
import time
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from firebird.qa import *
|
from firebird.qa import *
|
||||||
|
|
||||||
db = db_factory()
|
db = db_factory()
|
||||||
|
|
||||||
act = python_act('db')
|
act = python_act('db')
|
||||||
|
|
||||||
expected_stdout = """
|
tmp_trace_cfg = temp_file('tmp_trace_3658.cfg')
|
||||||
Expected line found.
|
tmp_trace_log = temp_file('tmp_trace_3658.log')
|
||||||
Expected line found.
|
|
||||||
Expected line found.
|
svc_items = [
|
||||||
Expected line found.
|
'log_services = true',
|
||||||
"""
|
'log_errors = true',
|
||||||
|
]
|
||||||
|
|
||||||
@pytest.mark.skip("FIXME: Test fate to be determined")
|
|
||||||
@pytest.mark.version('>=3')
|
@pytest.mark.version('>=3')
|
||||||
def test_1(act: Action):
|
def test_1(act: Action, tmp_trace_cfg: Path, tmp_trace_log: Path, capsys):
|
||||||
pytest.skip("Not IMPLEMENTED")
|
#print( os.environ.get('ISC_USER', 'UNKNOWN_ISC_USR') )
|
||||||
|
#print( os.environ.get('ISC_PASSWORD', 'UNKNOWN_ISC_PSW') )
|
||||||
|
|
||||||
# test_script_1
|
trace_txt = """
|
||||||
#---
|
services
|
||||||
# import os
|
{
|
||||||
# import subprocess
|
enabled = true
|
||||||
# from subprocess import Popen
|
log_initfini = false
|
||||||
# import time
|
log_services = true
|
||||||
# import re
|
log_errors = true
|
||||||
#
|
}
|
||||||
# os.environ["ISC_USER"] = user_name
|
"""
|
||||||
# os.environ["ISC_PASSWORD"] = user_password
|
|
||||||
#
|
tmp_trace_cfg.write_text(trace_txt)
|
||||||
# # Obtain engine version:
|
|
||||||
# engine = str(db_conn.engine_version) # convert to text because 'float' object has no attribute 'startswith'
|
with act.envar('ISC_USER', act.db.user), act.envar('ISC_PASSWORD', act.db.password):
|
||||||
# db_file = db_conn.database_name
|
|
||||||
# db_conn.close()
|
with tmp_trace_log.open('w') as f_log:
|
||||||
#
|
# EXPLICIT call of FB utility 'fbsvcmgr':
|
||||||
# #---------------------------------------------
|
p = subprocess.Popen( [act.vars['fbsvcmgr'], 'localhost:service_mgr', 'action_trace_start', 'trc_cfg', tmp_trace_cfg], stdout = f_log, stderr = subprocess.STDOUT )
|
||||||
#
|
time.sleep(2)
|
||||||
# def flush_and_close(file_handle):
|
|
||||||
# # https://docs.python.org/2/library/os.html#os.fsync
|
# ::: DO NOT USE HERE :::
|
||||||
# # If you're starting with a Python file object f,
|
# with act.trace(svc_events = svc_items, ...):
|
||||||
# # first do f.flush(), and
|
# pass
|
||||||
# # then do os.fsync(f.fileno()), to ensure that all internal buffers associated with f are written to disk.
|
|
||||||
# global os
|
p.terminate()
|
||||||
#
|
|
||||||
# file_handle.flush()
|
# service_mgr, (Service 0000000000C8B140, SYSDBA, TCPv6:::1/60775, C:\python3x\python.exe:18960)
|
||||||
# if file_handle.mode not in ('r', 'rb'):
|
p = re.compile('service_mgr,\\s+\\(\\s*Service\\s+\\w{16}[,]?\\s+' + act.db.user+ '[,]?', re.IGNORECASE)
|
||||||
# # otherwise: "OSError: [Errno 9] Bad file descriptor"!
|
|
||||||
# os.fsync(file_handle.fileno())
|
expected_stdout = 'Found expected line: 1'
|
||||||
# file_handle.close()
|
with open(tmp_trace_log,'r') as f:
|
||||||
#
|
for line in f:
|
||||||
# #--------------------------------------------
|
if line.strip():
|
||||||
#
|
if p.search(line):
|
||||||
# def cleanup( f_names_list ):
|
print(expected_stdout)
|
||||||
# global os
|
break
|
||||||
# for i in range(len( f_names_list )):
|
|
||||||
# if os.path.isfile( f_names_list[i]):
|
act.expected_stdout = expected_stdout
|
||||||
# os.remove( f_names_list[i] )
|
act.stdout = capsys.readouterr().out
|
||||||
# if os.path.isfile( f_names_list[i]):
|
assert act.clean_stdout == act.clean_expected_stdout
|
||||||
# print('ERROR: can not remove file ' + f_names_list[i])
|
|
||||||
#
|
|
||||||
# #--------------------------------------------
|
|
||||||
#
|
|
||||||
# txt25 = '''# Trace config, format for 2.5. Generated auto, do not edit!
|
|
||||||
# <services>
|
|
||||||
# enabled true
|
|
||||||
# log_services true
|
|
||||||
# log_errors true
|
|
||||||
# </services>
|
|
||||||
# '''
|
|
||||||
#
|
|
||||||
# # NOTES ABOUT TRACE CONFIG FOR 3.0:
|
|
||||||
# # 1) Header contain clauses in different format vs FB 2.5: its header's data must be enclosed with '{' '}';
|
|
||||||
# # 2) Name and value must be separated by EQUALITY sign ('=') in FB-3 trace.conf, otherwise we get runtime error:
|
|
||||||
# # element "<. . .>" have no attribute value set
|
|
||||||
# txt30 = '''# Trace config, format for 2.5. Generated auto, do not edit!
|
|
||||||
# services
|
|
||||||
# {
|
|
||||||
# enabled = true
|
|
||||||
# log_services = true
|
|
||||||
# log_errors = true
|
|
||||||
# }
|
|
||||||
# '''
|
|
||||||
#
|
|
||||||
# f_trccfg=open( os.path.join(context['temp_directory'],'tmp_trace_3658.cfg'), 'w')
|
|
||||||
# if engine.startswith('2.5'):
|
|
||||||
# f_trccfg.write(txt25)
|
|
||||||
# else:
|
|
||||||
# f_trccfg.write(txt30)
|
|
||||||
# flush_and_close( f_trccfg )
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# # ##############################################################
|
|
||||||
# # S T A R T T R A C E i n S E P A R A T E P R O C E S S
|
|
||||||
# # ##############################################################
|
|
||||||
#
|
|
||||||
# f_trclog=open( os.path.join(context['temp_directory'],'tmp_trace_3658.log'), 'w')
|
|
||||||
# p = Popen([ context['fbsvcmgr_path'], "localhost:service_mgr" , "action_trace_start" , "trc_cfg" , f_trccfg.name], stdout=f_trclog, stderr=subprocess.STDOUT)
|
|
||||||
# time.sleep(2)
|
|
||||||
#
|
|
||||||
# # ####################################################
|
|
||||||
# # G E T A C T I V E T R A C E S E S S I O N I D
|
|
||||||
# # ####################################################
|
|
||||||
# # Save active trace session info into file for further parsing it and obtain session_id back (for stop):
|
|
||||||
#
|
|
||||||
# f_trclst=open( os.path.join(context['temp_directory'],'tmp_trace_3658.lst'), 'w')
|
|
||||||
# subprocess.call([context['fbsvcmgr_path'], "localhost:service_mgr", "action_trace_list"], stdout=f_trclst, stderr=subprocess.STDOUT)
|
|
||||||
# flush_and_close( f_trclst )
|
|
||||||
#
|
|
||||||
# # !!! DO NOT REMOVE THIS LINE !!!
|
|
||||||
# time.sleep(1)
|
|
||||||
#
|
|
||||||
# trcssn=0
|
|
||||||
# with open( f_trclst.name,'r') as f:
|
|
||||||
# for line in f:
|
|
||||||
# i=1
|
|
||||||
# if 'Session ID' in line:
|
|
||||||
# for word in line.split():
|
|
||||||
# if i==3:
|
|
||||||
# trcssn=word
|
|
||||||
# i=i+1
|
|
||||||
# break
|
|
||||||
#
|
|
||||||
# # Result: `trcssn` is ID of active trace session. Now we have to terminate it:
|
|
||||||
#
|
|
||||||
# # ####################################################
|
|
||||||
# # S E N D R E Q U E S T T R A C E T O S T O P
|
|
||||||
# # ####################################################
|
|
||||||
# fn_nul = open(os.devnull, 'w')
|
|
||||||
# subprocess.call([context['fbsvcmgr_path'], "localhost:service_mgr", "action_trace_stop","trc_id", trcssn], stdout=fn_nul)
|
|
||||||
# fn_nul.close()
|
|
||||||
#
|
|
||||||
# # 23.02.2021. DELAY FOR AT LEAST 1 SECOND REQUIRED HERE!
|
|
||||||
# # Otherwise trace log can remain empty.
|
|
||||||
# time.sleep(1)
|
|
||||||
#
|
|
||||||
# # Doc about Popen.terminate():
|
|
||||||
# # https://docs.python.org/2/library/subprocess.html
|
|
||||||
# # Stop the child. On Posix OSs the method sends SIGTERM to the child.
|
|
||||||
# # On Windows the Win32 API function TerminateProcess() is called to stop the child.
|
|
||||||
#
|
|
||||||
# # Doc about Win API TerminateProcess() function:
|
|
||||||
# # https://msdn.microsoft.com/en-us/library/windows/desktop/ms686714%28v=vs.85%29.aspx
|
|
||||||
# # The terminated process cannot exit until all pending I/O has been completed or canceled.
|
|
||||||
# # TerminateProcess is ____asynchronous____; it initiates termination and returns immediately.
|
|
||||||
# # ^^^^^^^^^^^^
|
|
||||||
# p.terminate()
|
|
||||||
# flush_and_close( f_trclog )
|
|
||||||
#
|
|
||||||
# # Output log of trace for comparing it with expected.
|
|
||||||
# # ::: NB ::: Content if trace log is converted to UPPER case in order to reduce change of mismatching with
|
|
||||||
# # updated trace output in some future versions:
|
|
||||||
#
|
|
||||||
# # Windows:
|
|
||||||
# # 2.5.x: service_mgr, (Service 00000000007C9B88, SYSDBA, TCPv4:127.0.0.1/59583, C:\\FBsCin
|
|
||||||
# bsvcmgr.exe:6888)
|
|
||||||
# # 3.0.x: service_mgr, (Service 000000000818B140, SYSDBA, TCPv6:::1/59557, C:\\FBSS
|
|
||||||
# bsvcmgr.exe:7044)
|
|
||||||
# # 4.0.x: service_mgr, (Service 0000000010B51DC0, SYSDBA, TCPv6:::1/59569, C:\\FB SS
|
|
||||||
# bsvcmgr.exe:5616)
|
|
||||||
# # Linux:
|
|
||||||
# # service_mgr, (Service 0x7f46c4027c40, SYSDBA, TCPv4:127.0.0.1/51226, /var/tmp/fb40tmp/bin/fbsvcmgr:20947)
|
|
||||||
#
|
|
||||||
# p=re.compile('service_mgr,[ ]+\\(\\s*Service[ ]+\\S+[,]?[ ]+sysdba[,]?', re.IGNORECASE)
|
|
||||||
# with open( f_trclog.name,'r') as f:
|
|
||||||
# for line in f:
|
|
||||||
# if p.search(line):
|
|
||||||
# print('Expected line found.')
|
|
||||||
#
|
|
||||||
# cleanup( [i.name for i in (f_trccfg, f_trclog, f_trclst) ] )
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#---
|
|
||||||
|
Loading…
Reference in New Issue
Block a user