add new clear_logfile method:#4095
Conversation
|
@hholoubk please make sure the CI static check is passed. |
| else: | ||
| cmdRes = remote_old.run_remote_cmd(cmd, cmd_parms, runner_on_target) | ||
|
|
||
| if isinstance(str_in_log, str): |
There was a problem hiding this comment.
I do think we need to add this support. This function is an utility and docstring already has clear description that str_in_log variable is a boolean. So the user needs to give correct type for this parameter by themselves.
There was a problem hiding this comment.
(did you mean ...that we DON"T need this support ... .. according rest of the comment it looks like this )
issue is .. that if it is named "str_in_log" .. than it is misleading name and the we should update the docstring ...
this way the utility will be more robust ... (as I spent one hour debugging why it doesn't work with "False" ...
and if the content of str_in_log is passed from parameter .. it was interpretted as string ...
what do you think?
I can do some performance testing how this will impact the test runs
There was a problem hiding this comment.
sorry, I missed "not".
As you can see
def check_logfile(
search_str,
log_file,
str_in_log=True, ===> this indicates the boolean, I think.
And there is also indicator in below codes:
if str_in_log == bool(int(cmdRes.exit_status)):
But anyway, an easy way to make better readability is we add type for parameter in docstring.
So could you help update the docstring?
For example:
:param str_in_log: bool, True if the file should include the given string,
otherwise, False
| return backup_file | ||
|
|
||
|
|
||
| def clear_logfile(log_file_name, |
There was a problem hiding this comment.
I suggest we make the function simple that it only does one thing to clear a specified log file. We do not need to embed the backup operation. Leave the backup operation to the end users if they need.
There was a problem hiding this comment.
Yes ... make sense ... the function is now in utils_logfile.py ... and doesn't contain backup of file (I've fully removed the function, as it is not necessary for this case ... and ti will need agreement with team to properly design it as part of the utils_logfile.py
| :param backup_old_log: if True, the actual content of log_file will be backuped; default False | ||
|
|
||
| Returns: | ||
| str or None: The name of the backup file if created, otherwise None. |
There was a problem hiding this comment.
We just return True for clearing the log file successfully or False for failing to make it empty.
| return obj_conf | ||
|
|
||
|
|
||
| def backup_logfile(log_file, backup_file_name, backup_dir="/tmp"): |
There was a problem hiding this comment.
removed whole function - not needed for the test
| Returns: | ||
| str: The name of created backup file | ||
| """ | ||
|
|
There was a problem hiding this comment.
We'd better provide an opportunity for the end users to define the final backup_file_name without changes (like + timestamp). So I would suggest below
if not backup_file_name:
timestamp = time.strftime('%Y%m%d_%H%M%S')
backup_file_name = f"{backup_file_name}_{timestamp}.log"
There was a problem hiding this comment.
removed whole function - not needed for the test
|
|
||
| timestamp = time.strftime('%Y%m%d_%H%M%S') | ||
| backup_file_name = f"{backup_file_name}_{timestamp}.log" | ||
| backup_file = os.path.join(backup_dir, backup_file_name) |
There was a problem hiding this comment.
For backup_dir, its default is /tmp. Then the end user needs to remove the backup file by themselves.
I would suggest we use data_dir.get_tmp_dir() if the end user does not provide any value because the avocado-vt will help clear the files in data_dir.get_tmp_dir() at the end of the test for us.
So is it better if we use below:
if not backup_dir:
backup_file = os.path.join(data_dir.get_tmp_dir(), backup_file_name)
There was a problem hiding this comment.
removed whole function - not needed for the test
| return obj_conf | ||
|
|
||
|
|
||
| def backup_logfile(log_file, backup_file_name, backup_dir="/tmp"): |
There was a problem hiding this comment.
We do suggest not add any new function to libvirt.py any more because it is too long and not categorized.
Could you please move it to utils_logfile.py?
There was a problem hiding this comment.
.. moved (just the clear_log_file ... not the backup, as it is not necessary ... and it would need properly design more things to reflect file structure
7c565c9 to
998f80a
Compare
|
@dzhengfy statick check should be ok |
75fb96f to
71c0a88
Compare
Yingshun
left a comment
There was a problem hiding this comment.
Please fix the Static checks failures, thx!
|
|
||
| def clear_log_file(log_file_name, log_dir=None): | ||
| """ | ||
| Clears the (e.g. VM) log file before a test run. closes the |
There was a problem hiding this comment.
let's complete the sentence, thx!
|
Still got errors in checks, plz fix them, thanks! |
4a20953 to
5cf3ca3
Compare
The previous errors were caused by some check limit ... it looks good now |
|
@hholoubk Please also fix the problem in Static checks. |
fea4d4f to
95760e2
Compare
|
I hope I have finaly realized .. what should be in commit message. |
- this will clear defined log_file - so the test will consider only the messages added in the test run. - previous log can be backuped to the tmp dir if requrired (the restore not yet prepared) add new backup_logfile method: used in clear_logfile, but it can be used just as is + minor refactor to process not only bollean str_in_log variable (as it comes from test in my case as str) Signed-off-by: hholoubk <hholoubk@redhat.com>
95760e2 to
df0ba53
Compare

add new backup_logfile method: used in clear_logfile, but it can be used just as is