[config] Add support for multi-ASIC devices#877
Conversation
…ates for handing namespace.
config/main.py
Outdated
| """Clear current configuration and import a previous saved config DB dump file.""" | ||
| if not yes: | ||
| click.confirm('Clear current config and reload config from the file %s?' % filename, abort=True) | ||
| click.confirm('Clear current config and reload config ?', abort=True) |
There was a problem hiding this comment.
So, for multi-ASIC platforms, there is no way to specify a file to load from because there are multiple files involved, is this correct? If so, maybe we should consider fixing the file for single-ASIC platforms as well, so that the behavior is consistent for both.
There was a problem hiding this comment.
Yes there are multiple files that need to be specified, might be difficult for user also to give as input. Are you referring to removing the filename option itself from the command ? if we remove won't it affect backward compatibility with some scripts using this command may be ?
There was a problem hiding this comment.
Yes, we would need to check. Most of the time we just load from the default conifg_db.json file.
There was a problem hiding this comment.
I am finding couple of testcases which uses filename option to specify the config_db.json file, there could be other use cases as well.
Hence I have updated the implementation so that the user can input specific config_db.json files even for namespace. This will make sure the behavior is consistent for all platforms. Please take a look.
… per namespace also.
scripts/db_migrator.py
Outdated
| default = None ) | ||
| parser.add_argument('-n', | ||
| dest='namespace', | ||
| metavar='namespace details', |
There was a problem hiding this comment.
namespace details [](start = 33, length = 17)
asic namespace
scripts/db_migrator.py
Outdated
| metavar='namespace details', | ||
| type = str, | ||
| required = False, | ||
| help = 'The namespace whose DB instance we need to connect', |
There was a problem hiding this comment.
namespace [](start = 36, length = 9)
asic namespace
config/main.py
Outdated
| @click.argument('filename', default='/etc/sonic/config_db.json', type=click.Path()) | ||
| def save(filename): | ||
| expose_value=False, prompt='Existing files will be overwritten, continue?') | ||
| @click.argument('filename',nargs=-1) |
There was a problem hiding this comment.
I also suggest for multi-npu case, the filename should be a a list files separated by comma as a single string.
There was a problem hiding this comment.
Made the change to the argument "filename" from user to accepts as a single string with filenames separated by comma.
config/main.py
Outdated
| config.add_command(nat.nat) | ||
|
|
||
| @config.command() | ||
| @click.option('-n', '--namespace', help='Namespace name') |
There was a problem hiding this comment.
This option of getting namespace from user is removed.
config/main.py
Outdated
| run_command(command, display_cmd=True) | ||
| if namespace: | ||
| if not is_multi_asic(): | ||
| click.echo("Namespace is not significant in a Single ASIC platform") |
There was a problem hiding this comment.
use this is more clear. "Asic namespace is not enabled on this platform!"
There was a problem hiding this comment.
This option of getting namespace from user is removed.
config/main.py
Outdated
| click.echo("Namespace is not significant in a Single ASIC platform") | ||
| return None | ||
| if not validate_namespace(namespace): | ||
| click.echo("Invalid Namespace entered {}".format(namespace)) |
There was a problem hiding this comment.
Invalid Asic namespace {}.
config/main.py
Outdated
| inst = namespace[len(NAMESPACE_PREFIX)] | ||
| cfg_file = "/etc/sonic/config_db{}.json".format(inst) | ||
| else: | ||
| cfg_file = filename[0] |
There was a problem hiding this comment.
I do not understand the logic here. what is filename[0]?
There was a problem hiding this comment.
Ok filename is returned as a tuple, as this is of type nargs=-1. But yes this is wrong in this case as here the tuple has only one element and I can just use cfg_file = filename.
Will fix it and update this and other similar places.
config/main.py
Outdated
| """Export current config DB to a file on disk.""" | ||
| command = "{} -d --print-data > {}".format(SONIC_CFGGEN_PATH, filename) | ||
| run_command(command, display_cmd=True) | ||
| if namespace: |
There was a problem hiding this comment.
is there a use case to save config db for each individual namespace? if not, then we do not need to provide this option. I feel like everytime we want to save config db, we should save all config dbs.
There was a problem hiding this comment.
Ok, I will remove the namespace option. So the only option available to the user is "filename" which he could give as input.
config/main.py
Outdated
| num_asic = _get_num_asic() | ||
| for inst in range(num_asic): | ||
| namespace = "{}{}".format(NAMESPACE_PREFIX, inst) | ||
| # Get the file from user input, else take the default file /etc/sonic/config_db{NS_id}.json |
There was a problem hiding this comment.
if user provide input, we should make sure user provide all 7 filenames. we should not sometimes take user input, sometime use the default values.
There was a problem hiding this comment.
Ok, now I have removed the namespace option to the commands - the user can either not provide any filenames , if he provides he needs to provide all namespacecount+1 of them
config/main.py
Outdated
| @click.argument('filename', default='/etc/sonic/config_db.json', type=click.Path(exists=True)) | ||
| def load(filename, yes): | ||
| @click.argument('filename',nargs=-1) | ||
| def load(filename, yes, namespace): |
There was a problem hiding this comment.
check my comments on the save comments. i think they apply to this command as well.
config/main.py
Outdated
| else: | ||
| command = "{} -j {} --write-to-db".format(SONIC_CFGGEN_PATH, filename) | ||
| """ In Single AISC platforms we have single DB service. In multi-ASIC platforms we have a global DB | ||
| service running in the host + DB services running in the namespace created per ASIC. |
There was a problem hiding this comment.
DB services running in each ASIC namespace
config/main.py
Outdated
| client.set(config_db.INIT_INDICATOR, 1) | ||
| # Get the config file, based on user input | ||
| if len(filename) > inst+1: | ||
| cfg_file = filename[inst+1] |
There was a problem hiding this comment.
check the user input first.
config/main.py
Outdated
| # the default config_db<namespaceID>.json format is used. | ||
|
|
||
| if os.path.isfile(INIT_CFG_FILE): | ||
| command = "{} -j {} -j {} -n \"{}\" --write-to-db".format(SONIC_CFGGEN_PATH, INIT_CFG_FILE, cfg_file, namespace) |
There was a problem hiding this comment.
why quote is needed for namespace variable, but not others?
There was a problem hiding this comment.
This code change was done earlier as per the initial approach for SonicV2Connector/ConfigDBConnector class .. where we had the default namespace as ''. Now that we have changed that to default None, I have updated the code likewise.
config/main.py
Outdated
| for inst in range(-1, num_asic-1): | ||
| # Get the namespace name, for linux host it is '' empty namespace string. | ||
| if inst is -1: | ||
| namespace = '' |
There was a problem hiding this comment.
for global db, you do not need to supply -n option.
There was a problem hiding this comment.
This again was done earlier as per the initial approach for SonicV2Connector/ConfigDBConnector class. Now I have added explicit check for namespace is None and added the -n flag.
…Connector class design
|
There are some testfailures here as the code change needs latest sonic-py-swsssdk , which is still not submodule updated in sonic-buildimage. Please ignore them while reviewing. |
|
@lguohan Why LGTM checker is not enabled in this PR? Could you help setup? |
|
retest this please |
|
Looks good to me. Will wait for @lguohan to review again. |
|
retest vs please |
|
retest vsimage please |
* [Phase 1] Multi ASIC config command changes, db_mgrator.py script updates for handing namespace. * Fixes and comment updates * Comments addressed + added support for user to input the config files per namespace also. * Updates per comments + based on the updated SonicV2Connector/ConfigDBConnector class design * Review comments update. * Help string updated for config save/reload/load
* [Phase 1] Multi ASIC config command changes, db_mgrator.py script updates for handing namespace. * Fixes and comment updates * Comments addressed + added support for user to input the config files per namespace also. * Updates per comments + based on the updated SonicV2Connector/ConfigDBConnector class design * Review comments update. * Help string updated for config save/reload/load

- What I did
Changes to the following config commands and scripts for Multi-ASIC devices.
- How I did it
The following are the changes introduced in this PR
The changes done here are based on the namespace support added in sonic-net/sonic-py-swsssdk#63
(a) Added API's to
> is_multi_asic()
> get_all_namespaces()
> validate_namespace(namespace)
(b) config load/save/reload commands : the action is taken on the linux host + if we are in multi-asic platform repeat the action in the namespaces. The filename argument is optional as before. If not given these are the default files used ( below eg: for a multi-ASIC device with 3 ASIC's )
/etc/sonic/config_db.json --> for global linux host database
/etc/sonic/config_db0.json --> for "asic0" namespace
/etc/sonic/config_db1.json --> for "asic1" namespace
/etc/sonic/config_db2.json --> for "asic2" namespace
If the filename argument needs to be provided it needs to be given as a string of config file names separated by comma
(c) Updates to the db_migrator.py script.
- How to verify it
Verified on multi-ASIC platform
- Previous command output (if the output of a command-line utility has changed)
- New command output (if the output of a command-line utility has changed)