forked from sonic-net/sonic-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
[multi-asic][warm_restart] add Multi-ASIC support for warm_restart commands #99
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3812,92 +3812,156 @@ def warm_restart(ctx, redis_unix_socket_path): | |
| # Note: redis_unix_socket_path is a path string, and the ground truth is now from database_config.json. | ||
| # We only use it as a bool indicator on either unix_socket_path or tcp port | ||
| use_unix_socket_path = bool(redis_unix_socket_path) | ||
| config_db = ConfigDBConnector(use_unix_socket_path=use_unix_socket_path) | ||
| config_db.connect(wait_for_init=False) | ||
|
|
||
| # warm restart enable/disable config is put in stateDB, not persistent across cold reboot, not saved to config_DB.json file | ||
| state_db = SonicV2Connector(use_unix_socket_path=use_unix_socket_path) | ||
| state_db.connect(state_db.STATE_DB, False) | ||
| TABLE_NAME_SEPARATOR = '|' | ||
| prefix = 'WARM_RESTART_ENABLE_TABLE' + TABLE_NAME_SEPARATOR | ||
| ctx.obj = {'db': config_db, 'state_db': state_db, 'prefix': prefix} | ||
| ctx.obj = {'prefix': prefix} | ||
|
|
||
| asic_namespaces = multi_asic.get_namespace_list() | ||
| all_namespaces = asic_namespaces | ||
| if multi_asic.is_multi_asic(): | ||
| all_namespaces = [multi_asic_util.constants.DEFAULT_NAMESPACE] + asic_namespaces | ||
| ctx.obj["all_namespaces"] = all_namespaces | ||
| ctx.obj["asic_namespaces"] = asic_namespaces | ||
| ctx.obj["state_db"] = {} | ||
| ctx.obj["config_db"] = {} | ||
| for namespace in all_namespaces: | ||
| config_db = ConfigDBConnector(namespace=namespace, use_unix_socket_path=use_unix_socket_path); | ||
| config_db.connect(wait_for_init=False) | ||
| state_db = SonicV2Connector(namespace=namespace, use_unix_socket_path=use_unix_socket_path); | ||
| state_db.connect(state_db.STATE_DB, False) | ||
| ctx.obj["state_db"][namespace] = state_db | ||
| ctx.obj["config_db"][namespace] = config_db | ||
|
|
||
|
|
||
| @warm_restart.command('enable') | ||
| @click.option('--namespace', '-n', 'namespace', default=None, help='Namespace name') | ||
| @click.argument('module', metavar='<module>', default='system', required=False) | ||
| @click.pass_context | ||
| def warm_restart_enable(ctx, module): | ||
| state_db = ctx.obj['state_db'] | ||
| config_db = ctx.obj['db'] | ||
| def warm_restart_enable(ctx, namespace, module): | ||
| if namespace is not None: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor:
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need check None, which means user did not provide. '' - is global ns |
||
| if namespace not in ctx.obj["all_namespaces"]: | ||
| raise click.UsageError("Invalid namespace: {}".format(namespace)) | ||
| namespaces = [namespace] if namespace else ctx.obj["all_namespaces"] | ||
|
|
||
| config_db = ctx.obj["config_db"][multi_asic_util.constants.DEFAULT_NAMESPACE] | ||
| feature_table = config_db.get_table('FEATURE') | ||
| if module != 'system' and module not in feature_table: | ||
| sys.exit('Feature {} is unknown'.format(module)) | ||
| prefix = ctx.obj['prefix'] | ||
| _hash = '{}{}'.format(prefix, module) | ||
| state_db.set(state_db.STATE_DB, _hash, 'enable', 'true') | ||
| state_db.close(state_db.STATE_DB) | ||
|
|
||
| for namespace in namespaces: | ||
| state_db = ctx.obj["state_db"][namespace] | ||
| state_db.set(state_db.STATE_DB, _hash, 'enable', 'true') | ||
| state_db.close(state_db.STATE_DB) | ||
|
|
||
|
|
||
| @warm_restart.command('disable') | ||
| @click.option('--namespace', '-n', 'namespace', default=None, help='Namespace name') | ||
| @click.argument('module', metavar='<module>', default='system', required=False) | ||
| @click.pass_context | ||
| def warm_restart_disable(ctx, module): | ||
| state_db = ctx.obj['state_db'] | ||
| config_db = ctx.obj['db'] | ||
| def warm_restart_disable(ctx, namespace, module): | ||
| if namespace is not None: | ||
| if namespace not in ctx.obj["all_namespaces"]: | ||
| raise click.UsageError("Invalid namespace: {}".format(namespace)) | ||
| namespaces = [namespace] if namespace else ctx.obj["all_namespaces"] | ||
|
|
||
| config_db = ctx.obj["config_db"][multi_asic_util.constants.DEFAULT_NAMESPACE] | ||
| feature_table = config_db.get_table('FEATURE') | ||
| if module != 'system' and module not in feature_table: | ||
| sys.exit('Feature {} is unknown'.format(module)) | ||
| prefix = ctx.obj['prefix'] | ||
| _hash = '{}{}'.format(prefix, module) | ||
| state_db.set(state_db.STATE_DB, _hash, 'enable', 'false') | ||
| state_db.close(state_db.STATE_DB) | ||
|
|
||
| for namespace in namespaces: | ||
| state_db = ctx.obj["state_db"][namespace] | ||
| state_db.set(state_db.STATE_DB, _hash, 'enable', 'false') | ||
| state_db.close(state_db.STATE_DB) | ||
|
|
||
|
|
||
| @warm_restart.command('neighsyncd_timer') | ||
| @click.option('--namespace', '-n', 'namespace', default=None, help='Namespace name') | ||
| @click.argument('seconds', metavar='<seconds>', required=True, type=int) | ||
| @click.pass_context | ||
| def warm_restart_neighsyncd_timer(ctx, seconds): | ||
| db = ValidatedConfigDBConnector(ctx.obj['db']) | ||
| def warm_restart_neighsyncd_timer(ctx, namespace, seconds): | ||
| if namespace is not None: | ||
| if namespace not in ctx.obj["asic_namespaces"]: | ||
| raise click.UsageError("Invalid namespace: {}".format(namespace)) | ||
| namespaces = [namespace] if namespace else ctx.obj["asic_namespaces"] | ||
|
|
||
| if ADHOC_VALIDATION: | ||
| if seconds not in range(1, 9999): | ||
| ctx.fail("neighsyncd warm restart timer must be in range 1-9999") | ||
| try: | ||
| db.mod_entry('WARM_RESTART', 'swss', {'neighsyncd_timer': seconds}) | ||
| except ValueError as e: | ||
| ctx.fail("Invalid ConfigDB. Error: {}".format(e)) | ||
|
|
||
| for namespace in namespaces: | ||
| db = ValidatedConfigDBConnector(ctx.obj["config_db"][namespace]) | ||
| try: | ||
| db.mod_entry('WARM_RESTART', 'swss', {'neighsyncd_timer': seconds}) | ||
| except ValueError as e: | ||
| ctx.fail("Invalid ConfigDB. Error: {}".format(e)) | ||
|
|
||
|
|
||
| @warm_restart.command('bgp_timer') | ||
| @click.option('--namespace', '-n', 'namespace', default=None, help='Namespace name') | ||
| @click.argument('seconds', metavar='<seconds>', required=True, type=int) | ||
| @click.pass_context | ||
| def warm_restart_bgp_timer(ctx, seconds): | ||
| db = ValidatedConfigDBConnector(ctx.obj['db']) | ||
| def warm_restart_bgp_timer(ctx, namespace, seconds): | ||
| if namespace is not None: | ||
| if namespace not in ctx.obj["asic_namespaces"]: | ||
| raise click.UsageError("Invalid namespace: {}".format(namespace)) | ||
| namespaces = [namespace] if namespace else ctx.obj["asic_namespaces"] | ||
|
|
||
| if ADHOC_VALIDATION: | ||
| if seconds not in range(1, 3600): | ||
| ctx.fail("bgp warm restart timer must be in range 1-3600") | ||
| try: | ||
| db.mod_entry('WARM_RESTART', 'bgp', {'bgp_timer': seconds}) | ||
| except ValueError as e: | ||
| ctx.fail("Invalid ConfigDB. Error: {}".format(e)) | ||
|
|
||
| for namespace in namespaces: | ||
| db = ValidatedConfigDBConnector(ctx.obj["config_db"][namespace]) | ||
| try: | ||
| db.mod_entry('WARM_RESTART', 'bgp', {'bgp_timer': seconds}) | ||
| except ValueError as e: | ||
| ctx.fail("Invalid ConfigDB. Error: {}".format(e)) | ||
|
|
||
|
|
||
| @warm_restart.command('teamsyncd_timer') | ||
| @click.option('--namespace', '-n', 'namespace', default=None, help='Namespace name') | ||
| @click.argument('seconds', metavar='<seconds>', required=True, type=int) | ||
| @click.pass_context | ||
| def warm_restart_teamsyncd_timer(ctx, seconds): | ||
| db = ValidatedConfigDBConnector(ctx.obj['db']) | ||
| def warm_restart_teamsyncd_timer(ctx, namespace, seconds): | ||
| if namespace is not None: | ||
| if namespace not in ctx.obj["asic_namespaces"]: | ||
| raise click.UsageError("Invalid namespace: {}".format(namespace)) | ||
| namespaces = [namespace] if namespace else ctx.obj["asic_namespaces"] | ||
|
|
||
| if ADHOC_VALIDATION: | ||
| if seconds not in range(1, 3600): | ||
| ctx.fail("teamsyncd warm restart timer must be in range 1-3600") | ||
| try: | ||
| db.mod_entry('WARM_RESTART', 'teamd', {'teamsyncd_timer': seconds}) | ||
| except ValueError as e: | ||
| ctx.fail("Invalid ConfigDB. Error: {}".format(e)) | ||
| ctx.fail("bgp warm restart timer must be in range 1-3600") | ||
|
|
||
| for namespace in namespaces: | ||
| db = ValidatedConfigDBConnector(ctx.obj["config_db"][namespace]) | ||
| try: | ||
| db.mod_entry('WARM_RESTART', 'teamd', {'teamsyncd_timer': seconds}) | ||
| except ValueError as e: | ||
| ctx.fail("Invalid ConfigDB. Error: {}".format(e)) | ||
|
|
||
|
|
||
| @warm_restart.command('bgp_eoiu') | ||
| @click.option('--namespace', '-n', 'namespace', default=None, help='Namespace name') | ||
| @click.argument('enable', metavar='<enable>', default='true', required=False, type=click.Choice(["true", "false"])) | ||
| @click.pass_context | ||
| def warm_restart_bgp_eoiu(ctx, enable): | ||
| db = ValidatedConfigDBConnector(ctx.obj['db']) | ||
| try: | ||
| db.mod_entry('WARM_RESTART', 'bgp', {'bgp_eoiu': enable}) | ||
| except ValueError as e: | ||
| ctx.fail("Invalid ConfigDB. Error: {}".format(e)) | ||
| def warm_restart_bgp_eoiu(ctx, namespace, enable): | ||
| if namespace is not None: | ||
| if namespace not in ctx.obj["asic_namespaces"]: | ||
| raise click.UsageError("Invalid namespace: {}".format(namespace)) | ||
| namespaces = [namespace] if namespace else ctx.obj["asic_namespaces"] | ||
|
|
||
| for namespace in namespaces: | ||
| db = ValidatedConfigDBConnector(ctx.obj["config_db"][namespace]) | ||
| try: | ||
| db.mod_entry('WARM_RESTART', 'bgp', {'bgp_eoiu': enable}) | ||
| except ValueError as e: | ||
| ctx.fail("Invalid ConfigDB. Error: {}".format(e)) | ||
|
|
||
|
|
||
| def vrf_add_management_vrf(config_db): | ||
| """Enable management vrf in config DB""" | ||
|
|
||
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
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.
If you use this decorator instead, you won't namespace validation inside funtion:
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.
This will reduce the number of changes in this file
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.
@oleksandrivantsiv I see the benefit of doing this, but not sure how to mock
multi_asicfunctions later in a test case. Since this decorator runs on module import time, it likelly needs reloading module after mock setup. I tried this but seems this does not play well withClickRunnerI will check what I can do.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.
@oleksandrivantsiv I find it less suitable for this command. The choice enumerates asic namesapces while my commands use global and asic namespaces. Also makes mocking harder
The only benefit of choice is CLI feedback, but this is not a user facing CLI