-
Notifications
You must be signed in to change notification settings - Fork 195
Module graceful shutdown support #667
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
rameshraghupathy
wants to merge
41
commits into
sonic-net:master
Choose a base branch
from
rameshraghupathy:graceful-shutdown
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.
Open
Changes from 28 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
ecd68c9
Refactored for graceful shutdown
rameshraghupathy b022801
Refactored for graceful shutdown
rameshraghupathy ef2f282
Refactored for graceful shutdown, fixing UT
rameshraghupathy 98c2146
Refactored for graceful shutdown, fixing UT
rameshraghupathy b959da9
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy 5b2c0f6
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy b02d32e
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy fde2fd4
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy 3aee661
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy 983992d
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy ad81510
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy e74e00e
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy 72f7eba
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy b920d0f
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy 6d3bb42
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy 468f2ee
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy 7a28e87
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy 36d0df1
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy 32a4ee6
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy 8f7e3ae
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy 9f406f5
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy b0dafa2
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy e56983a
Refactored for graceful shutdown, fixing UT - Final round of tweaks
rameshraghupathy 9f81fac
Addressed review comments after the refactoring
rameshraghupathy 33c503e
Addressed review comments after the refactoring
rameshraghupathy 08faf9d
Fixing ut
rameshraghupathy b612f80
Fixing ut
rameshraghupathy 1987132
Fixing ut
rameshraghupathy 3169b9d
Addressed review comments related to refactoring
rameshraghupathy 500f3d3
Fixing test failures
rameshraghupathy 8762717
Improving coverage
rameshraghupathy ddf58cc
Improving coverage
rameshraghupathy 9223003
Merge branch 'sonic-net:master' into graceful-shutdown
rameshraghupathy 8cd0c59
Improving coverage
rameshraghupathy 75e0d47
Improving coverage
rameshraghupathy b424cb7
Improving coverage
rameshraghupathy 663c496
Fixing test failures
rameshraghupathy 8332565
Merge branch 'sonic-net:master' into graceful-shutdown
rameshraghupathy 6148a5e
Aliging with the module_base.py changes such as common API, timezone,…
rameshraghupathy b44cd97
Merge branch 'graceful-shutdown' of https://github.com/rameshraghupat…
rameshraghupathy e1b2dc5
Fixing test failures
rameshraghupathy 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 |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # tests/conftest.py | ||
| import os | ||
| import sys | ||
| from imp import load_source | ||
|
|
||
| # 1) Ensure the daemon script is importable and loaded exactly once | ||
| _REPO_ROOT = os.path.dirname(os.path.dirname(__file__)) | ||
| _SCRIPTS_DIR = os.path.join(_REPO_ROOT, "scripts") | ||
| _base = os.path.join(_SCRIPTS_DIR, "chassisd") | ||
| _chassisd_path = _base if os.path.exists(_base) else _base + ".py" | ||
|
|
||
| # Keep environment light for unit tests (many tests set this too; setting early helps) | ||
| os.environ.setdefault("CHASSISD_UNIT_TESTING", "1") | ||
|
|
||
| if "chassisd" not in sys.modules: | ||
| load_source("chassisd", _chassisd_path) | ||
|
|
||
| # 2) Provide a very small, memory-light stub for SonicV2Connector used by chassisd | ||
| # (Prevents lots of real redis connectors from being created across tests.) | ||
| class _FakeRedis: | ||
| __slots__ = ("_h",) # keep memory footprint tiny | ||
| def __init__(self): self._h = {} | ||
| def hgetall(self, key): return dict(self._h.get(key, {})) | ||
| def hset(self, key, *args, **kwargs): | ||
| if "mapping" in kwargs: | ||
| self._h.setdefault(key, {}).update(kwargs["mapping"]) | ||
| return 1 | ||
| if len(args) == 2: | ||
| field, value = args | ||
| self._h.setdefault(key, {})[field] = value | ||
| return 1 | ||
| return 0 | ||
|
|
||
| class _DummyV2: | ||
| # match what production code uses | ||
| STATE_DB = 6 | ||
| CHASSIS_STATE_DB = 15 # harmless constant if referenced | ||
| def __init__(self, *a, **k): self._client = _FakeRedis() | ||
| def connect(self, _dbid): return None | ||
| def close(self): return None | ||
| def get_redis_client(self, _dbid): return self._client | ||
|
|
||
| # 3) Patch both the module-under-test’s swsscommon and the global swsscommon, if present | ||
| chassisd = sys.modules["chassisd"] | ||
|
|
||
| try: | ||
| import swsscommon as _sc | ||
| except Exception: | ||
| _sc = None | ||
|
|
||
| # Patch the symbol used by chassisd | ||
| if hasattr(chassisd, "swsscommon"): | ||
| chassisd.swsscommon.SonicV2Connector = _DummyV2 | ||
| # ensure constants exist if code references them | ||
| if not hasattr(chassisd.swsscommon.SonicV2Connector, "STATE_DB"): | ||
| chassisd.swsscommon.SonicV2Connector.STATE_DB = 6 | ||
|
|
||
| # Also patch the top-level swsscommon for tests that import it directly | ||
| if _sc is not None: | ||
| _sc.SonicV2Connector = _DummyV2 | ||
| if not hasattr(_sc.SonicV2Connector, "STATE_DB"): | ||
| _sc.SonicV2Connector.STATE_DB = 6 |
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.
@rameshraghupathy when do we clear the transition flags set by chassisd admin state changes?