-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Address cphc service_checker issue in sidecar container #25851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
FengPan-Frank
wants to merge
1
commit into
sonic-net:master
Choose a base branch
from
FengPan-Frank:fix_health_checker
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,021
−25
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -189,14 +189,20 @@ def fake_read_file_bytes_local(path: str): | |||||
| # Isolate POST_COPY_ACTIONS | ||||||
| monkeypatch.setattr(ss, "POST_COPY_ACTIONS", {}, raising=True) | ||||||
|
|
||||||
| # Mock _get_branch_name to return "202412" by default (avoids real file/nsenter I/O) | ||||||
| monkeypatch.setattr(ss, "_get_branch_name", lambda: "202412") | ||||||
| # Mock _get_branch_name to return "master" by default (avoids real file/nsenter I/O) | ||||||
| # Use "master" because it falls through to the default (non-branch-specific) path. | ||||||
| monkeypatch.setattr(ss, "_get_branch_name", lambda: "master") | ||||||
|
|
||||||
| # Provide a default container_checker in both filesystems so the auto-appended | ||||||
| # SyncItem from ensure_sync() is always satisfied and is a no-op. | ||||||
| container_fs["/usr/share/sonic/systemd_scripts/container_checker"] = b"default-checker" | ||||||
| host_fs["/bin/container_checker"] = b"default-checker" | ||||||
|
|
||||||
| # Provide a default service_checker.py in both filesystems so the auto-appended | ||||||
| # SyncItem from ensure_sync() is always satisfied and is a no-op. | ||||||
| container_fs["/usr/share/sonic/systemd_scripts/service_checker.py"] = b"default-service-checker" | ||||||
| host_fs["/usr/local/lib/python3.11/dist-packages/health_checker/service_checker.py"] = b"default-service-checker" | ||||||
|
|
||||||
| return ss, container_fs, host_fs, commands, config_db | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -466,6 +472,10 @@ def test_ensure_sync_uses_202411_checker(ss): | |||||
| container_fs["/usr/share/sonic/systemd_scripts/container_checker_202411"] = b"checker-202411" | ||||||
| host_fs["/bin/container_checker"] = b"old-checker" | ||||||
|
|
||||||
| # Also provide 202411 service_checker so it doesn't fail | ||||||
| container_fs["/usr/share/sonic/systemd_scripts/service_checker.py_202411"] = b"service-checker-202411" | ||||||
| host_fs[ss_mod.HOST_SERVICE_CHECKER] = b"service-checker-202411" | ||||||
|
|
||||||
| # Clear SYNC_ITEMS to focus only on the container_checker logic | ||||||
| ss_mod.SYNC_ITEMS[:] = [] | ||||||
|
|
||||||
|
|
@@ -507,3 +517,215 @@ def test_ensure_sync_202411_missing_checker_fails(ss): | |||||
|
|
||||||
| ok = ss_mod.ensure_sync() | ||||||
| assert ok is False | ||||||
|
|
||||||
|
|
||||||
| # ─────────── Tests for branch-conditional service_checker.py in ensure_sync ─────────── | ||||||
|
|
||||||
| def test_ensure_sync_uses_202411_service_checker(ss): | ||||||
| """When branch is 202411, ensure_sync uses the branch-specific service_checker.py.""" | ||||||
| ss_mod, container_fs, host_fs, commands, config_db = ss | ||||||
|
|
||||||
| ss_mod._get_branch_name = lambda: "202411" | ||||||
|
|
||||||
| # Provide the 202411-specific service_checker in the container and a different one on host | ||||||
| container_fs["/usr/share/sonic/systemd_scripts/service_checker.py_202411"] = b"service-checker-202411" | ||||||
| host_fs[ss_mod.HOST_SERVICE_CHECKER] = b"old-service-checker" | ||||||
|
|
||||||
| # Also provide container_checker so it doesn't fail | ||||||
| container_fs["/usr/share/sonic/systemd_scripts/container_checker_202411"] = b"checker-202411" | ||||||
| host_fs["/bin/container_checker"] = b"checker-202411" | ||||||
|
|
||||||
| ss_mod.SYNC_ITEMS[:] = [] | ||||||
|
|
||||||
| ok = ss_mod.ensure_sync() | ||||||
| assert ok is True | ||||||
| assert host_fs[ss_mod.HOST_SERVICE_CHECKER] == b"service-checker-202411" | ||||||
|
|
||||||
|
|
||||||
| def test_ensure_sync_uses_default_service_checker(ss): | ||||||
| """When branch is not 202411, ensure_sync uses the default service_checker.py.""" | ||||||
| ss_mod, container_fs, host_fs, commands, config_db = ss | ||||||
|
|
||||||
| # _get_branch_name already returns "202412" from fixture default | ||||||
|
||||||
| # _get_branch_name already returns "202412" from fixture default | |
| # _get_branch_name already returns "master" (a non-202411 branch) from the fixture by default |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we copy all the versions of container_checker and service_checker into the docker image?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only master change requires this copy, other version container_checker/service_checker are created in systemd_scripts repo directly.