[action] [PR:4251] Add filesystem sync after plugin installation#4338
Merged
mssonicbld merged 1 commit intosonic-net:202511from Mar 9, 2026
Merged
[action] [PR:4251] Add filesystem sync after plugin installation#4338mssonicbld merged 1 commit intosonic-net:202511from
mssonicbld merged 1 commit intosonic-net:202511from
Conversation
<!--
Please make sure you've read and understood our contributing guidelines:
https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md
** Make sure all your commits include a signature generated with `git commit -s` **
If this is a bug fix, make sure your description includes "closes #xxxx",
"fixes #xxxx" or "resolves #xxxx" so that GitHub automatically closes the related
issue when the PR is merged.
If you are adding/modifying/removing any command or utility script, please also
make sure to add/modify/remove any unit tests from the tests
directory as appropriate.
If you are modifying or removing an existing 'show', 'config' or 'sonic-clear'
subcommand, or you are adding a new subcommand, please make sure you also
update the Command Line Reference Guide (doc/Command-Reference.md) to reflect
your changes.
Please provide the following information:
-->
#### Why I did it
In some scenarios, after install plugin then power cycle, file content might lost.
Before power cycle, file size is 205, also can found register function in python file, but after power cycle, this file size is 0, so assume this is caused by page cache didn't write back to disk on time, when power cycle happen.
Before power cycle:
```bash
2026 Feb 3 10:34:16.156531 sonic-testbed INFO [DIAGNOSTIC] Starting CLI plugins installation for package: cpu-report
2026 Feb 3 10:34:16.157013 sonic-testbed INFO [DIAGNOSTIC] Installing CLI plugin: package=cpu-report, command=show, src=/show.py, dst=/usr/local/lib/python3.13/dist-packages/show/plugins/cpu-report.py
2026 Feb 3 10:34:16.157177 sonic-testbed INFO [DIAGNOSTIC] Starting extract: image=sha256:1230c222517c88863253c94dba34a788b580604618373fff24ab737a7d519c3f, src=/show.py, dst=/usr/local/lib/python3.13/dist-packages/show/plugins/cpu-report.py
2026 Feb 3 10:34:16.267834 sonic-testbed INFO [DIAGNOSTIC] Tar buffer size: 2048 bytes, MD5: b0b48780efda61d230dc2e3592cc3ba6
2026 Feb 3 10:34:16.268709 sonic-testbed INFO [DIAGNOSTIC] Tar member: name=show.py, size=205, isfile=True
2026 Feb 3 10:34:16.269652 sonic-testbed INFO [DIAGNOSTIC] File extracted successfully: path=/usr/local/lib/python3.13/dist-packages/show/plugins/cpu-report.py, size=205, MD5=f2f3ca5258fd0685adf2cc44567934fb, elapsed=0.112s
2026 Feb 3 10:34:16.270313 sonic-testbed INFO [DIAGNOSTIC] Python syntax validation: PASS for /usr/local/lib/python3.13/dist-packages/show/plugins/cpu-report.py
2026 Feb 3 10:34:16.270820 sonic-testbed INFO [DIAGNOSTIC] Plugin file verification after extract: path=/usr/local/lib/python3.13/dist-packages/show/plugins/cpu-report.py, size=205, MD5=f2f3ca5258fd0685adf2cc44567934fb, mtime=1684332898.0, extract_time=0.113s
2026 Feb 3 10:34:16.271351 sonic-testbed INFO [DIAGNOSTIC] Python syntax check: PASS for /usr/local/lib/python3.13/dist-packages/show/plugins/cpu-report.py
2026 Feb 3 10:34:16.271638 sonic-testbed INFO [DIAGNOSTIC] Found "def register" in plugin file: /usr/local/lib/python3.13/dist-packages/show/plugins/cpu-report.py
2026 Feb 3 10:34:16.271918 sonic-testbed INFO [DIAGNOSTIC] Completed CLI plugins installation for package: cpu-report, elapsed=0.115s
```
After power cycle:
```bash
admin@sonic-testbed:~$ show version 2>&1
failed to import plugin show.plugins.cpu-report: module 'show.plugins.cpu-report' has no attribute 'register'
# file size is 0
admin@sonic-testbed:~$ ls -lih /usr/local/lib/python3.13/dist-packages/show/plugins/cpu-report.py
830572 -rw-r--r-- 1 root root 0 May 17 2023 /usr/local/lib/python3.13/dist-packages/show/plugins/cpu-report.py
# md5sum is different with previous
admin@sonic-testbed:~$ sudo md5sum /usr/local/lib/python3.13/dist-packages/show/plugins/cpu-report.py
d41d8cd98f00b204e9800998ecf8427e /usr/local/lib/python3.13/dist-packages/show/plugins/cpu-report.py
# file is empty
admin@sonic-testbed:~$ sudo stat /usr/local/lib/python3.13/dist-packages/show/plugins/cpu-report.py
File: /usr/local/lib/python3.13/dist-packages/show/plugins/cpu-report.py
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 0,27 Inode: 830572 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2026-02-03 10:34:16.266593882 +0200
Modify: 2023-05-17 17:14:58.000000000 +0300
Change: 2026-02-03 10:34:16.262593831 +0200
Birth: 2026-02-03 10:34:16.262593831 +0200
admin@sonic-testbed:~$ cat /usr/local/lib/python3.13/dist-packages/show/plugins/cpu-report.py
admin@sonic-testbed:~$
```
#### What I did
Fix intermittent plugin corruption after power cycle by adding `os.sync()` to flush filesystem buffers after all CLI plugins are installed. This prevents incomplete plugin files that cause `'module has no attribute 'register''` errors in show commands after system reboot.
#### How I did it
Added `os.sync()` system call in `PackageManager._install_cli_plugins()` method after all CLI plugin files are extracted and installed. This ensures that:
1. All plugin file data is flushed from the OS page cache to disk
2. File metadata and data are both persisted before the method returns
3. Plugin files remain intact even if an abrupt power loss occurs shortly after installation
#### How to verify it
1. Install cpu-report package: `sonic-package-manager install cpu-report==1.0.0 -y`
2. Enable feature: `config feature state cpu-report enabled`
3. Upgrade package: `sonic-package-manager install cpu-report==1.0.7 -y`
4. Upgrade again: `sonic-package-manager install cpu-report==1.0.8 -y`
5. Immediately perform power cycle
6. After reboot, run: `show version`
If there is problem, error is: failed to import plugin show.plugins.cpu-report: module 'show.plugins.cpu-report' has no attribute 'register'.
Signed-off-by: Sonic Build Admin <[email protected]>
Collaborator
Author
|
Original PR: #4251 |
Collaborator
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why I did it
In some scenarios, after install plugin then power cycle, file content might lost.
Before power cycle, file size is 205, also can found register function in python file, but after power cycle, this file size is 0, so assume this is caused by page cache didn't write back to disk on time, when power cycle happen.
Before power cycle:
After power cycle:
What I did
Fix intermittent plugin corruption after power cycle by adding
os.sync()to flush filesystem buffers after all CLI plugins are installed. This prevents incomplete plugin files that cause'module has no attribute 'register''errors in show commands after system reboot.How I did it
Added
os.sync()system call inPackageManager._install_cli_plugins()method after all CLI plugin files are extracted and installed. This ensures that:How to verify it
sonic-package-manager install cpu-report==1.0.0 -yconfig feature state cpu-report enabledsonic-package-manager install cpu-report==1.0.7 -ysonic-package-manager install cpu-report==1.0.8 -yshow versionIf there is problem, error is: failed to import plugin show.plugins.cpu-report: module 'show.plugins.cpu-report' has no attribute 'register'.
Signed-off-by: Sonic Build Admin [email protected]