Skip to content

Add rotation capable logging tool for customized ansible modules#4302

Merged
wangxin merged 2 commits intosonic-net:masterfrom
wangxin:ansible-module-logging
Sep 22, 2021
Merged

Add rotation capable logging tool for customized ansible modules#4302
wangxin merged 2 commits intosonic-net:masterfrom
wangxin:ansible-module-logging

Conversation

@wangxin
Copy link
Collaborator

@wangxin wangxin commented Sep 17, 2021

Description of PR

Summary:
Fixes # (issue)

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • Test case(new/improvement)

Back port request

  • 201911

Approach

What is the motivation for this PR?

Currently ansible/module_utils/debug_utils provided some functions for logging
in customized ansible modules. There are two issues with current tool:

  1. There is no log rotation. Currently the conn_graph_facts module is using this
    tool. Each call of the conn_graph_facts module would generate a log file to /tmp
    folder of the sonic-mgmt container. Massive number log files would be generated
    after couple rounds of nightly tests.
  2. It is tedious to use the tool.

How did you do it?

This PR improved the existing logging tool in two ways:

  1. Add log rotation support. It will keep the most recent 10 files at most.
  2. Much more easier to use. Just import it and call it. Then we can use
    logging.debug, logging.info, etc., to log in customized ansible modules.

How did you verify/test it?

Test run a script using the conn_graph_facts module over 10 times. Check the generated logs.

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

Currently ansible/module_utils/debug_utils provided some functions for logging
in customized ansible modules. There are two issues with current tool:
1. There is no log rotation. Currently the conn_graph_facts module is using this
tool. Each call of the conn_graph_facts module would generate a log file to /tmp
folder of the sonic-mgmt container. Massive number log files would be generated
after couple rounds of nightly tests.
2. It is tedious to use the tool.

This PR improved the existing logging tool in two ways:
1. Add log rotation support. It will keep the most recent 10 files at most.
2. Much more easier to use. Just import it and call it. Then we can use
logging.debug, logging.info, etc., to log in customized modules.

Signed-off-by: Xin Wang <[email protected]>
@wangxin wangxin requested a review from a team as a code owner September 17, 2021 09:14
@lgtm-com
Copy link

lgtm-com bot commented Sep 17, 2021

This pull request introduces 1 alert when merging 1b6fe59 into e916cb8 - view on LGTM.com

new alerts:

  • 1 for Unused import

Copy link
Collaborator

@lolyu lolyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wangxin wangxin merged commit 5e5af69 into sonic-net:master Sep 22, 2021
yutongzhang-microsoft added a commit that referenced this pull request Oct 13, 2021
Description of PR
Some homebrew ansible modules may generate log files to /tmp folder on the host that it was executed. These modules manage the log files by their own and do not support log rotation. A new log rotation capable module utility was added in #4302

Update below ansible modules to use the new tool for logging:
ansible/roles/vm_set/library/sonic_kickstart.py
ansible/roles/vm_set/library/ceos_network.py
ansible/roles/vm_set/library/kickstart.py
ansible/roles/vm_set/library/vm_topology.py

What is the motivation for this PR?
Use the new log rotation capable module utility which was added in #4302 to support log rotation.

How did you do it?
I import the new log rotation capable module utility at the front of each file and use it to support log rotation. Meanwhile, I delete the previous functions which were related to the log.

How did you verify/test it?
I use ./testbed-cli.sh add-topo, deploy-mg and remove-topo to test it.

Signed-off-by: Yutong Zhang <[email protected]>
@wangxin wangxin deleted the ansible-module-logging branch December 13, 2021 09:26
kazinator-arista pushed a commit to kazinator-arista/sonic-mgmt that referenced this pull request Mar 4, 2026
…atically (#25595)

#### Why I did it
src/sonic-utilities
```
* ddc241ec - (HEAD -> 202511, origin/202511) [storm-control] Fixed show storm-control interface command display (sonic-net#4302) (32 hours ago) [mssonicbld]
* fbd3f90b - [fast-reboot][cosmetic] Fixed debug/error prints with the correct reboot type (sonic-net#4286) (5 days ago) [Yair Raviv]
* efdffa2a - Added counterpoll CLI support (sonic-net#4291) (6 days ago) [mssonicbld]
* 567ad5b3 - [Smartswitch] Prevent early exit of reboot status (sonic-net#4287) (6 days ago) [mssonicbld]
```
#### How I did it
#### How to verify it
#### Description for the changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants