@@ -146,24 +146,25 @@ def test_obtain_file_lock_no_previous_file(tmpdir):
146146 result = '{"wo_status": "ENDED", '
147147 result += '"wo_comment": "Lock obtained on the file {}",' .format (f_name )
148148 result += ' "wo_newparams": '
149- result += '{"SERVICEINSTANCEID": "12345", "process": "abc"}'
149+ result += '{"SERVICEINSTANCEID": "12345", "process": "abc", "PROCESSINSTANCEID": "2345" }'
150150 result += '}'
151151
152152 with patch ('msa_sdk.util.constants.UBI_JENTREPRISE_DIRECTORY' , f_dir ):
153153 with patch ('msa_sdk.util.constants.PROCESS_LOGS_DIRECTORY' , f_dir_log ):
154154 assert obtain_file_lock (
155155 f_name , 'w+' ,
156- {"SERVICEINSTANCEID" : "12345" , "process" : "abc" },
156+ {"SERVICEINSTANCEID" : "12345" , "process" : "abc" , "PROCESSINSTANCEID" : "2345" },
157157 0.5 , 2 ) == result
158158
159159 log_file = '{}/process-12345.log' .format (f_dir_log )
160160
161161 log_time = datetime .datetime .now ().strftime ("%Y-%m-%d %H:%M:%S" )
162162
163- log_msg = '\n === {} ===\n {}' .format (
164- log_time ,
163+ log_msg = '\n === {} ===|{}| \n {}\n === {} ===|{}| ' .format (
164+ log_time , 2345 ,
165165 ('{\n "SERVICEINSTANCEID": "12345",'
166- '\n "process": "abc"\n }' )
166+ '\n "process": "abc",'
167+ '\n "PROCESSINSTANCEID": "2345"\n }' ), log_time , 2345
167168 )
168169
169170 assert open (log_file ).read () == log_msg
@@ -187,24 +188,25 @@ def test_obtain_file_lock_when_unlocked(tmpdir):
187188 result = '{"wo_status": "ENDED", '
188189 result += '"wo_comment": "Lock obtained on the file {}",' .format (f_name )
189190 result += ' "wo_newparams": '
190- result += '{"SERVICEINSTANCEID": "12345", "process": "abc"}'
191+ result += '{"SERVICEINSTANCEID": "12345", "process": "abc", "PROCESSINSTANCEID": "2345" }'
191192 result += '}'
192193
193194 with patch ('msa_sdk.util.constants.UBI_JENTREPRISE_DIRECTORY' , f_dir ):
194195 with patch ('msa_sdk.util.constants.PROCESS_LOGS_DIRECTORY' , f_dir_log ):
195196 assert obtain_file_lock (
196197 f_name , 'w+' ,
197- {"SERVICEINSTANCEID" : "12345" , "process" : "abc" },
198+ {"SERVICEINSTANCEID" : "12345" , "process" : "abc" , "PROCESSINSTANCEID" : "2345" },
198199 1 , 2 ) == result
199200
200201 log_file = '{}/process-12345.log' .format (f_dir_log )
201202
202203 log_time = datetime .datetime .now ().strftime ("%Y-%m-%d %H:%M:%S" )
203204
204- log_msg = '\n === {} ===\n {}' .format (
205- log_time ,
205+ log_msg = '\n === {} ===|{}| \n {}\n === {} ===|{}| ' .format (
206+ log_time , 2345 ,
206207 ('{\n "SERVICEINSTANCEID": "12345",'
207- '\n "process": "abc"\n }' )
208+ '\n "process": "abc",'
209+ '\n "PROCESSINSTANCEID": "2345"\n }' ), log_time , 2345
208210 )
209211
210212 assert open (log_file ).read () == log_msg
@@ -229,7 +231,7 @@ def test_obtain_file_lock_when_locked(tmpdir):
229231 result += '"wo_comment": '
230232 result += '"Lock could not be obtained on the file {}",' .format (f_name )
231233 result += ' "wo_newparams": '
232- result += '{"SERVICEINSTANCEID": "12346", "process": "abc"}'
234+ result += '{"SERVICEINSTANCEID": "12346", "process": "abc", "PROCESSINSTANCEID": "2345" }'
233235 result += '}'
234236
235237 with patch ('msa_sdk.util.constants.UBI_JENTREPRISE_DIRECTORY' , f_dir ):
@@ -239,16 +241,17 @@ def test_obtain_file_lock_when_locked(tmpdir):
239241 f_dir_log ):
240242 assert obtain_file_lock (
241243 f_name , 'w+' , {"SERVICEINSTANCEID" : "12346" ,
242- "process" : "abc" }, 0.5 , 2 ) == result
244+ "process" : "abc" , "PROCESSINSTANCEID" : "2345" }, 0.5 , 2 ) == result
243245
244246 log_file = '{}/process-12346.log' .format (f_dir_log )
245247
246248 log_time = datetime .datetime .now ().strftime ("%Y-%m-%d %H:%M:%S" )
247249
248- log_msg = '\n === {} ===\n {}' .format (
249- log_time ,
250+ log_msg = '\n === {} ===|{}| \n {}\n === {} ===|{}| ' .format (
251+ log_time , 2345 ,
250252 ('{\n "SERVICEINSTANCEID": "12346",'
251- '\n "process": "abc"\n }' )
253+ '\n "process": "abc",'
254+ '\n "PROCESSINSTANCEID": "2345"\n }' ), log_time , 2345
252255 )
253256
254257 assert open (log_file ).read () == log_msg
@@ -274,23 +277,25 @@ def test_obtain_file_lock_content(tmpdir):
274277 result += '"wo_comment": '
275278 result += '"Lock could not be obtained on the file {}",' .format (f_name )
276279 result += ' "wo_newparams": '
277- result += '{"SERVICEINSTANCEID": "12345", "process": "abc"}'
280+ result += '{"SERVICEINSTANCEID": "12345", "process": "abc", "PROCESSINSTANCEID": "2345" }'
278281 result += '}'
279282
280283 with patch ('msa_sdk.util.constants.UBI_JENTREPRISE_DIRECTORY' , f_dir ):
281284 with patch ('msa_sdk.util.constants.PROCESS_LOGS_DIRECTORY' , f_dir_log ):
282285 assert obtain_file_lock (
283- f_name , 'w+' , {"SERVICEINSTANCEID" : "12345" , "process" : "abc" },
286+ f_name , 'w+' , {"SERVICEINSTANCEID" : "12345" , "process" : "abc" , "PROCESSINSTANCEID" : "2345" },
284287 0.5 , 2 ) == result
285288
286289 log_file = '{}/process-12345.log' .format (f_dir_log )
287290
288291 log_time = datetime .datetime .now ().strftime ("%Y-%m-%d %H:%M:%S" )
289292
290- log_msg = '\n === {} ===\n {}' .format (
291- log_time ,
293+ log_msg = '\n === {} ===|{}| \n {}\n === {} ===|{}| ' .format (
294+ log_time , 2345 ,
292295 ('{\n "SERVICEINSTANCEID": "12345",'
293- '\n "process": "abc"\n }' )
296+ '\n "process": "abc",'
297+ '\n "PROCESSINSTANCEID": "2345"\n }' ), log_time , 2345
298+
294299 )
295300
296301 assert open (log_file ).read () == log_msg
@@ -302,23 +307,24 @@ def test_obtain_file_lock_content(tmpdir):
302307 result = '{"wo_status": "ENDED", '
303308 result += '"wo_comment": "Lock obtained on the file {}",' .format (f_name )
304309 result += ' "wo_newparams": '
305- result += '{"SERVICEINSTANCEID": "12346", "process": "abc"}'
310+ result += '{"SERVICEINSTANCEID": "12346", "process": "abc", "PROCESSINSTANCEID": "2345" }'
306311 result += '}'
307312
308313 with patch ('msa_sdk.util.constants.UBI_JENTREPRISE_DIRECTORY' , f_dir ):
309314 with patch ('msa_sdk.util.constants.PROCESS_LOGS_DIRECTORY' , f_dir_log ):
310315 assert obtain_file_lock (
311- f_name , 'w+' , {"SERVICEINSTANCEID" : "12346" , "process" : "abc" },
316+ f_name , 'w+' , {"SERVICEINSTANCEID" : "12346" , "process" : "abc" , "PROCESSINSTANCEID" : "2345" },
312317 0.5 , 2 ) == result
313318
314319 log_file = '{}/process-12346.log' .format (f_dir_log )
315320
316321 log_time = datetime .datetime .now ().strftime ("%Y-%m-%d %H:%M:%S" )
317322
318- log_msg = '\n === {} ===\n {}' .format (
319- log_time ,
323+ log_msg = '\n === {} ===|{}| \n {}\n === {} ===|{}| ' .format (
324+ log_time , 2345 ,
320325 ('{\n "SERVICEINSTANCEID": "12346",'
321- '\n "process": "abc"\n }' )
326+ '\n "process": "abc",'
327+ '\n "PROCESSINSTANCEID": "2345"\n }' ), log_time , 2345
322328 )
323329
324330 assert open (log_file ).read () == log_msg
@@ -344,23 +350,24 @@ def test_release_file_lock(tmpdir):
344350 result += '"wo_comment": '
345351 result += '"Lock released on the file {}",' .format (f_name )
346352 result += ' "wo_newparams": '
347- result += '{"SERVICEINSTANCEID": "12345", "process": "abc"}'
353+ result += '{"SERVICEINSTANCEID": "12345", "process": "abc", "PROCESSINSTANCEID": "2345" }'
348354 result += '}'
349355
350356 with patch ('msa_sdk.util.constants.UBI_JENTREPRISE_DIRECTORY' , f_dir ):
351357 with patch ('msa_sdk.util.constants.PROCESS_LOGS_DIRECTORY' , f_dir_log ):
352358 assert release_file_lock (
353- f_name , {"SERVICEINSTANCEID" : "12345" , "process" : "abc" },
359+ f_name , {"SERVICEINSTANCEID" : "12345" , "process" : "abc" , "PROCESSINSTANCEID" : "2345" },
354360 0.5 , 2 ) == result
355361
356362 log_file = '{}/process-12345.log' .format (f_dir_log )
357363
358364 log_time = datetime .datetime .now ().strftime ("%Y-%m-%d %H:%M:%S" )
359365
360- log_msg = '\n === {} ===\n {}' .format (
361- log_time ,
366+ log_msg = '\n === {} ===|{}| \n {}\n === {} ===|{}| ' .format (
367+ log_time , 2345 ,
362368 ('{\n "SERVICEINSTANCEID": "12345",'
363- '\n "process": "abc"\n }' )
369+ '\n "process": "abc",'
370+ '\n "PROCESSINSTANCEID": "2345"\n }' ), log_time , 2345
364371 )
365372
366373 assert open (log_file ).read () == log_msg
@@ -389,25 +396,26 @@ def test_release_file_lock_failed(tmpdir):
389396 result += '"wo_comment": '
390397 result += '"Lock could not be released on the file {}",' .format (f_name )
391398 result += ' "wo_newparams": '
392- result += '{"SERVICEINSTANCEID": "12345", "process": "abc"}'
399+ result += '{"SERVICEINSTANCEID": "12345", "process": "abc", "PROCESSINSTANCEID": "2345" }'
393400 result += '}'
394401
395402 with patch ('msa_sdk.util.constants.UBI_JENTREPRISE_DIRECTORY' , f_dir ):
396403 with patch ('msa_sdk.util.constants.PROCESS_LOGS_DIRECTORY' , f_dir_log ):
397404 with patch ('msa_sdk.util.fcntl.flock' ) as mock_flock :
398405 mock_flock .side_effect = io .BlockingIOError
399406 assert release_file_lock (
400- f_name , {"SERVICEINSTANCEID" : "12345" , "process" : "abc" },
407+ f_name , {"SERVICEINSTANCEID" : "12345" , "process" : "abc" , "PROCESSINSTANCEID" : "2345" },
401408 0.5 , 2 ) == result
402409
403410 log_file = '{}/process-12345.log' .format (f_dir_log )
404411
405412 log_time = datetime .datetime .now ().strftime ("%Y-%m-%d %H:%M:%S" )
406413
407- log_msg = '\n === {} ===\n {}' .format (
408- log_time ,
414+ log_msg = '\n === {} ===|{}| \n {}\n === {} ===|{}| ' .format (
415+ log_time , 2345 ,
409416 ('{\n "SERVICEINSTANCEID": "12345",'
410- '\n "process": "abc"\n }' )
417+ '\n "process": "abc",'
418+ '\n "PROCESSINSTANCEID": "2345"\n }' ), log_time , 2345
411419 )
412420
413421 assert open (log_file ).read () == log_msg
@@ -435,6 +443,44 @@ def test_log_to_process_file_success(tmpdir):
435443 with open (f'{ temp_dir } /process-1234.log' , 'r' ) as log_file :
436444 assert re .match (check_pattern , log_file .read ())
437445
446+ def test_log_to_service_file_success (tmpdir ):
447+ """
448+ Test if log to process file is success
449+ """
450+
451+ temp_dir = tmpdir .mkdir ('log_to_process_file_success' )
452+
453+ with patch ('msa_sdk.constants.PROCESS_LOGS_DIRECTORY' , temp_dir ):
454+
455+ params = {"SERVICEINSTANCEID" : 1234 , "Other" : "Value" , "PROCESSINSTANCEID" : 2345 }
456+
457+ log_message = 'Lorem ipsum dolor sit amet'
458+
459+ assert log_to_process_file (params ['SERVICEINSTANCEID' ], log_message , params ['PROCESSINSTANCEID' ])
460+
461+ check_pattern = f'^.+?:|2345|:DEBUG:{ log_message } $'
462+ with open (f'{ temp_dir } /process-1234.log' , 'r' ) as log_file :
463+ assert re .match (check_pattern , log_file .read ())
464+
465+ def test_log_line_break_to_service_file_success (tmpdir ):
466+ """
467+ Test if log to process file is success
468+ """
469+
470+ temp_dir = tmpdir .mkdir ('log_to_process_file_success' )
471+
472+ with patch ('msa_sdk.constants.PROCESS_LOGS_DIRECTORY' , temp_dir ):
473+
474+ params = {"SERVICEINSTANCEID" : 1234 , "Other" : "Value" , "PROCESSINSTANCEID" : 2345 }
475+
476+ log_message = 'Lorem ipsum dolor sit amet\n test'
477+
478+ assert log_to_process_file (params ['SERVICEINSTANCEID' ], log_message , params ['PROCESSINSTANCEID' ])
479+
480+ check_pattern = f'^.+?:|2345|:DEBUG:{ log_message } $\n ^.+?:|2345|'
481+ with open (f'{ temp_dir } /process-1234.log' , 'r' ) as log_file :
482+ assert re .match (check_pattern , log_file .read ())
483+
438484
439485def test_log_to_process_file_fail ():
440486 """
0 commit comments