Skip to content

Commit

Permalink
[multi-asic][chassis] fix the port index in port_index_map for masic (#…
Browse files Browse the repository at this point in the history
…3897)

What is the motivation for this PR?
The change done in PR #3643 to use the get_port_map, does not work for multi-ASIC platforms. The existing logic in config_facts gives the same index for ports on different ASICs.

The PR is a fix for this problem. get_port_map will use the port index present in the config_db.

How did you do it?
Change in config_facts to get the port index from config_db if its available. If the index is not present use the exisiting lofic to generate the index

How did you verify/test it?
run the test platform_tests/rest_reload_config.py to verify

Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
  • Loading branch information
arlakshm committed Jul 28, 2021
1 parent 13d46b7 commit 60af1ac
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions ansible/library/config_facts.py
Expand Up @@ -71,8 +71,16 @@ def create_maps(config):
port_name_list = config["PORT"].keys()
port_name_list_sorted = natsorted(port_name_list)

for idx, val in enumerate(port_name_list_sorted):
port_index_map[val] = idx
#get the port_index from config_db if available
port_index_map = {
name: int(v['index'])
for name, v in config['PORT'].iteritems()
if 'index' in v
}
if not port_index_map:
#if not available generate an index
for idx, val in enumerate(port_name_list_sorted):
port_index_map[val] = idx

port_name_to_alias_map = { name : v['alias'] if 'alias' in v else '' for name, v in config["PORT"].iteritems()}

Expand Down Expand Up @@ -136,7 +144,7 @@ def main():
cfg_file_path = PERSISTENT_CONFIG_PATH.format("")
with open(cfg_file_path, "r") as f:
config = json.load(f)
elif m_args["source"] == "running":
elif m_args["source"] == "running":
config = get_running_config(module, namespace)
results = get_facts(config)
module.exit_json(ansible_facts=results)
Expand Down

0 comments on commit 60af1ac

Please sign in to comment.