Skip to content

Reduce the number of ifconfig calls made in add_topo#19119

Merged
StormLiangMS merged 7 commits intosonic-net:masterfrom
ccroy-arista:fix-excess-ifconfigs
Jul 17, 2025
Merged

Reduce the number of ifconfig calls made in add_topo#19119
StormLiangMS merged 7 commits intosonic-net:masterfrom
ccroy-arista:fix-excess-ifconfigs

Conversation

@ccroy-arista
Copy link
Copy Markdown
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
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@wsycqyz
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@saiarcot895 I've updated the changes to use the os.listdir approach now.

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

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@StormLiangMS
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

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
Copy Markdown
Collaborator

r12f commented Jul 3, 2025

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

@ccroy-arista
Copy link
Copy Markdown
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
Copy Markdown
Collaborator

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
Copy Markdown
Contributor Author

Thanks Riff, will do :)

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

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@StormLiangMS
Copy link
Copy Markdown
Collaborator

hi @saiarcot895 would you help to review again for the update?

Copy link
Copy Markdown
Collaborator

@StormLiangMS StormLiangMS left a comment

Choose a reason for hiding this comment

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

LGTM

@StormLiangMS StormLiangMS merged commit 96bfe4d into sonic-net:master Jul 17, 2025
18 checks passed
@StormLiangMS
Copy link
Copy Markdown
Collaborator

hi @ccroy-arista could you check on the conflict to 202412?

@ccroy-arista
Copy link
Copy Markdown
Contributor Author

Manual cherry-pick to 202412 to resolve conflict: Azure/sonic-mgmt.msft#557

mssonicbld pushed a commit to mssonicbld/sonic-mgmt that referenced this pull request Jul 18, 2025
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.
@mssonicbld
Copy link
Copy Markdown
Collaborator

Cherry-pick PR to 202505: #19693

mssonicbld pushed a commit that referenced this pull request Jul 18, 2025
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.
StormLiangMS added a commit to Azure/sonic-mgmt.msft that referenced this pull request Jul 31, 2025
### Description of PR
This is a manual cherry-pick of
sonic-net/sonic-mgmt#19119 to 202412.

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 <number of VMs in
the topology> 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
- [x] Testbed and Framework(new/improvement)
- [ ] New Test case
    - [ ] Skipped for non-supported platforms
- [ ] Test case improvement

### Back port request
- [ ] 202205
- [ ] 202305
- [ ] 202311
- [ ] 202405
- [ ] 202411
- [x] 202412

### 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 <number of VMs in the topology> 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.
@ccroy-arista ccroy-arista deleted the fix-excess-ifconfigs branch July 31, 2025 05:42
opcoder0 pushed a commit to opcoder0/sonic-mgmt that referenced this pull request Dec 8, 2025
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.

Signed-off-by: opcoder0 <110003254+opcoder0@users.noreply.github.com>
gshemesh2 pushed a commit to gshemesh2/sonic-mgmt that referenced this pull request Dec 21, 2025
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.

Signed-off-by: Guy Shemesh <gshemesh@nvidia.com>
venu-nexthop pushed a commit to venu-nexthop/sonic-mgmt that referenced this pull request Jan 13, 2026
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.
gshemesh2 pushed a commit to gshemesh2/sonic-mgmt that referenced this pull request Jan 26, 2026
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.

Signed-off-by: Guy Shemesh <gshemesh@nvidia.com>
ytzur1 pushed a commit to ytzur1/sonic-mgmt that referenced this pull request Feb 2, 2026
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.

Signed-off-by: Yael Tzur <ytzur@nvidia.com>
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.

7 participants