Skip to content
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

[config] Add support for multi-ASIC devices #877

Merged
merged 8 commits into from
May 2, 2020

Conversation

judyjoseph
Copy link
Contributor

@judyjoseph judyjoseph commented Apr 10, 2020

- What I did
Changes to the following config commands and scripts for Multi-ASIC devices.

config load : supports config load across all namespaces
config save : supports config save across all namespaces
config reload : supports reload of all services across namespaces.

- 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)

@judyjoseph judyjoseph requested review from jleveque and yxieca and removed request for jleveque April 10, 2020 20:56
@jleveque jleveque changed the title [multi-asic-cfg] config commands changes [config] Add support for multi-ASIC devices Apr 10, 2020
config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated
def reload(filename, yes, load_sysinfo):
"""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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we would need to check. Most of the time we just load from the default conifg_db.json file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@judyjoseph judyjoseph requested a review from lguohan April 12, 2020 02:45
@judyjoseph judyjoseph requested a review from jleveque April 19, 2020 23:22
@@ -291,14 +293,22 @@ def main():
required = False,
help = 'the unix socket that the desired database listens on',
default = None )
parser.add_argument('-n',
dest='namespace',
metavar='namespace details',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namespace details [](start = 33, length = 17)

asic namespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

metavar='namespace details',
type = str,
required = False,
help = 'The namespace whose DB instance we need to connect',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namespace [](start = 36, length = 9)

asic namespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep a space after comma

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also suggest for multi-npu case, the filename should be a a list files separated by comma as a single string.

Copy link
Contributor Author

@judyjoseph judyjoseph Apr 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the change to the argument "filename" from user to accepts as a single string with filenames separated by comma.

config/main.py Outdated
@@ -542,32 +586,132 @@ def config():
config.add_command(nat.nat)

@config.command()
@click.option('-n', '--namespace', help='Namespace name')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asic namespace

Copy link
Contributor Author

@judyjoseph judyjoseph Apr 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use this is more clear. "Asic namespace is not enabled on this platform!"

Copy link
Contributor Author

@judyjoseph judyjoseph Apr 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand the logic here. what is filename[0]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check my comments on the save comments. i think they apply to this command as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take care of.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DB services running in each ASIC namespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why quote is needed for namespace variable, but not others?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for global db, you do not need to supply -n option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@judyjoseph judyjoseph removed the request for review from yxieca April 24, 2020 18:48
@judyjoseph
Copy link
Contributor Author

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.

@qiluo-msft
Copy link
Contributor

@lguohan Why LGTM checker is not enabled in this PR? Could you help setup?

@lguohan
Copy link
Contributor

lguohan commented Apr 27, 2020

image

it says enabled.

@judyjoseph
Copy link
Contributor Author

retest this please

config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated Show resolved Hide resolved
@judyjoseph judyjoseph requested review from lguohan and jleveque May 1, 2020 15:09
config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated Show resolved Hide resolved
config/main.py Outdated Show resolved Hide resolved
@jleveque
Copy link
Contributor

jleveque commented May 1, 2020

Looks good to me. Will wait for @lguohan to review again.

@rlhui
Copy link
Contributor

rlhui commented May 2, 2020

retest vs please

@rlhui
Copy link
Contributor

rlhui commented May 2, 2020

retest vsimage please

@judyjoseph judyjoseph merged commit cb68e7d into sonic-net:master May 2, 2020
@judyjoseph judyjoseph deleted the config_cmds branch May 2, 2020 20:51
rlhui pushed a commit that referenced this pull request May 4, 2020
* [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
abdosi pushed a commit to abdosi/sonic-utilities that referenced this pull request Aug 4, 2020
* [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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants