Skip to content

Reduce the number of ifconfig calls made in add_topo #19119

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
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ccroy-arista
Copy link
Contributor

Description of PR

Within VMTopology.init, ifconfig -a is called for every VM. For topologies with several hundred VMs, each call to ifconfig -a can take an appreciable amount of time (from seconds to minutes, depending on exact number of VMs and processing power of the testbed server). Multiplying this across hundreds of VMs results in add_topo taking a significant amount of time to complete.

This change decreases the add_topo setup time by reducing the number of ifconfig -a calls within VMTopology.init from to 1.

This change reduces setup time for non-multi-DUT configurations only; it does not impact the setup time for multi-DUT configurations.

Summary:
Fixes # (issue)

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • New Test case
    • Skipped for non-supported platforms
  • Test case improvement

Back port request

  • 202205
  • 202305
  • 202311
  • 202405
  • 202411
  • 202412
  • 202503
  • 202505

Approach

What is the motivation for this PR?

To reduce the setup time for add_topo, particularly for topologies with a larger number of VMs.

How did you do it?

Reduced the number of ifconfig -a calls within VMTopology.init(...) from to 1.

How did you verify/test it?

Ran add_topo on a t1-isolated topology and confirmed that the setup time was reduced.

Any platform specific information?

This change reduces setup time for non-multi-DUT configurations only; it does not impact the setup time for multi-DUT configurations.

`ifconfig -a` is called for every VM in
a topology within
ansible/roles/vm_set/library/vm_topology.py.
For topologies with a couple hundred VMs,
this can take anywhere from seconds to minutes
for each call to `ifconfig -a`. Multiplying
this across the number of VMs results in
these calls taking up the majority of time
for add_topo to complete.
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@wsycqyz
Copy link
Contributor

wsycqyz commented Jun 23, 2025

The pre-commit check failed with:

flake8...................................................................Failed

  • hook id: flake8
  • exit code: 1

ansible/roles/vm_set/library/vm_topology.py:304:31: E201 whitespace after '['
ansible/roles/vm_set/library/vm_topology.py:304:70: E202 whitespace before ']'

@ccroy-arista can you help fix the issue?

# dualtor, hence why the former approach is preserved above for that case.
else:
# Get the intf information in a tabulated format. Discard the header row.
intf_rows = VMTopology.cmd('ifconfig -a -s').split('\n')[1:]
Copy link
Contributor

@saiarcot895 saiarcot895 Jun 23, 2025

Choose a reason for hiding this comment

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

Can ip -j addr (JSON output of ip addr) be used? That way, manual string parsing isn't needed, and it also replaces one use of ifconfig with ip.

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 to use ip -j addr.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@saiarcot895 I'm looking into using a sysfs approach with os.listdir, which should be an even more portable and general solution; I will provide an update once I have tested this approach, and if it works well then I'll update the PR as well.

Fix formatting errors encountered during pre-commit check.
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@StormLiangMS
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ccroy-arista ccroy-arista marked this pull request as draft July 3, 2025 16:48
@r12f
Copy link
Contributor

r12f commented Jul 3, 2025

hi @ccroy-arista , anything happened to this PR?

@ccroy-arista
Copy link
Contributor Author

Hi @r12f, I am updating this PR to a more portable and robust solution per: #19119 (comment)

I will mark the PR active again once the change is updated.

@r12f
Copy link
Contributor

r12f commented Jul 3, 2025

Ah, I see. Got it and no worries. Feel free to leave the PR in open state. It is just a regular "review-and-address-comment" cycles :D

@ccroy-arista
Copy link
Contributor Author

Thanks Riff, will do :)

@ccroy-arista ccroy-arista marked this pull request as ready for review July 3, 2025 17:50
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