Skip to content

[202411] fix show bgp cli on multiple asic device#3980

Merged
kperumalbfn merged 2 commits intosonic-net:202411from
lipxu:20250717_202411_bgpshow
Jul 17, 2025
Merged

[202411] fix show bgp cli on multiple asic device#3980
kperumalbfn merged 2 commits intosonic-net:202411from
lipxu:20250717_202411_bgpshow

Conversation

@lipxu
Copy link
Copy Markdown
Contributor

@lipxu lipxu commented Jul 17, 2025

What I did

The PR #3960 check the docker container's name.
Check the docker's name whether is exactly same with "bgp"
However, on multiple asic devices, there are several bgp containers, and named bgp0, bgp1 ....

How I did it

Modified the cmd to handle the multiple asic with several bgp containers.

How to verify it

Verified on multiple devices:

admin@strtk5-8800-lc1-1:~$ docker ps -a | grep bgp
8ff934f85dfb   docker-fpm-frr:latest             "/usr/bin/docker_ini…"   40 hours ago   Up 19 hours             bgp1
5702ae6e60c2   docker-fpm-frr:latest             "/usr/bin/docker_ini…"   40 hours ago   Up 19 hours             bgp0
e059d9688b25   docker-fpm-frr:latest             "/usr/bin/docker_ini…"   40 hours ago   Up 19 hours             bgp2
admin@strtk5-8800-lc1-1:~$ 
admin@strtk5-8800-lc1-1:~$ python
Python 3.11.2 (main, Nov 30 2024, 21:22:50) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> COMMAND_TIMEOUT = 300
>>> command = "sudo docker ps --format '{{.Image}}\t{{.Names}}' | awk '$2 ~ /^bgp([0-9]+)?$/' | cut -d'-' -f3 | cut -d':' -f1 | head -n 1"
>>> stdout = subprocess.check_output(command, shell=True, text=True, timeout=COMMAND_TIMEOUT)
>>> result = stdout.rstrip('\n')
>>> print(resutl)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'resutl' is not defined. Did you mean: 'result'?
>>> print(result)
frr
>>> 
admin@strtk5-8800-lc1-1:~$ 
admin@strtk5-8800-lc1-1:~$ python
Python 3.11.2 (main, Nov 30 2024, 21:22:50) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sonic_py_common.general import getstatusoutput_noshell_pipe
>>> cmd0 = ["sudo", "docker", "ps", "--format", "{{.Image}}\t{{.Names}}"]
>>> cmd1 = ["awk", '$2 ~ /^bgp([0-9]+)?$/']
>>> cmd2 = ["cut", "-d-", "-f3"]
>>> cmd3 = ["cut", "-d:", "-f1"]
>>> cmd4 = ["head", "-n", "1"]
>>> _, result = getstatusoutput_noshell_pipe(cmd0, cmd1, cmd2, cmd3, cmd4)
>>> print(result)
frr
>>> 

None multiple asic device

admin@bjw-can-2700-4:~$ docker ps -a | grep bgp
68cb4c153e7d   docker-fpm-frr:latest             "/usr/bin/docker_ini…"   18 hours ago   Up 2 hours              bgp
admin@bjw-can-2700-4:~$ 
admin@bjw-can-2700-4:~$ python
Python 3.11.2 (main, Nov 30 2024, 21:22:50) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> COMMAND_TIMEOUT = 300
>>> command = "sudo docker ps --format '{{.Image}}\t{{.Names}}' | awk '$2 ~ /^bgp([0-9]+)?$/' | cut -d'-' -f3 | cut -d':' -f1 | head -n 1"
>>> stdout = subprocess.check_output(command, shell=True, text=True, timeout=COMMAND_TIMEOUT)
>>> result = stdout.rstrip('\n')
>>> print(result)
frr
>>> 
>>> from sonic_py_common.general import getstatusoutput_noshell_pipe
>>> cmd0 = ["sudo", "docker", "ps", "--format", "{{.Image}}\t{{.Names}}"]
>>> cmd1 = ["awk", '$2 ~ /^bgp([0-9]+)?$/']
>>> cmd2 = ["cut", "-d-", "-f3"]
>>> cmd3 = ["cut", "-d:", "-f1"]
>>> cmd4 = ["head", "-n", "1"]
>>> _, result = getstatusoutput_noshell_pipe(cmd0, cmd1, cmd2, cmd3, cmd4)
>>> print(result)
frr
>>> 

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)

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@lipxu lipxu requested review from BYGX-wcr and qiluo-msft July 17, 2025 09:25
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown
Contributor

@BYGX-wcr BYGX-wcr left a comment

Choose a reason for hiding this comment

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

LGTM

@kperumalbfn
Copy link
Copy Markdown
Contributor

@lipxu Could you create a PR in master and this will be required in 202505 as well.

@kperumalbfn kperumalbfn merged commit ac66b67 into sonic-net:202411 Jul 17, 2025
7 checks passed
@lipxu
Copy link
Copy Markdown
Contributor Author

lipxu commented Jul 18, 2025

@lipxu Could you create a PR in master and this will be required in 202505 as well.

Thanks for reminder, it's for master #3981, thanks

mssonicbld added a commit to mssonicbld/sonic-utilities.msft that referenced this pull request Jul 23, 2025
<!--
    Please make sure you've read and understood our contributing guidelines:
    https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

    ** Make sure all your commits include a signature generated with `git commit -s` **

    If this is a bug fix, make sure your description includes "closes #xxxx",
    "fixes #xxxx" or "resolves #xxxx" so that GitHub automatically closes the related
    issue when the PR is merged.

    If you are adding/modifying/removing any command or utility script, please also
    make sure to add/modify/remove any unit tests from the tests
    directory as appropriate.

    If you are modifying or removing an existing 'show', 'config' or 'sonic-clear'
    subcommand, or you are adding a new subcommand, please make sure you also
    update the Command Line Reference Guide (doc/Command-Reference.md) to reflect
    your changes.

    Please provide the following information:
-->

#### What I did
The PR sonic-net/sonic-utilities#3960 check the docker container's name.
Check the docker's name whether is exactly same with "bgp"
However, on multiple asic devices, there are several bgp containers, and named bgp0, bgp1 ....

#### How I did it
Modified the cmd to handle the multiple asic with several bgp containers.

#### How to verify it
run the cmd manually on both multiple and single asic device
sonic-net/sonic-utilities#3980

#### 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)
mssonicbld added a commit to Azure/sonic-utilities.msft that referenced this pull request Jul 23, 2025
<!--
 Please make sure you've read and understood our contributing guidelines:
 https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

 failure_prs.log skip_prs.log Make sure all your commits include a signature generated with `git commit -s` **

 If this is a bug fix, make sure your description includes "closes #xxxx",
 "fixes #xxxx" or "resolves #xxxx" so that GitHub automatically closes the related
 issue when the PR is merged.

 If you are adding/modifying/removing any command or utility script, please also
 make sure to add/modify/remove any unit tests from the tests
 directory as appropriate.

 If you are modifying or removing an existing 'show', 'config' or 'sonic-clear'
 subcommand, or you are adding a new subcommand, please make sure you also
 update the Command Line Reference Guide (doc/Command-Reference.md) to reflect
 your changes.

 Please provide the following information:
-->

#### What I did
The PR sonic-net/sonic-utilities#3960 check the docker container's name.
Check the docker's name whether is exactly same with "bgp"
However, on multiple asic devices, there are several bgp containers, and named bgp0, bgp1 ....

#### How I did it
Modified the cmd to handle the multiple asic with several bgp containers.

#### How to verify it
run the cmd manually on both multiple and single asic device
sonic-net/sonic-utilities#3980

#### 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)
stepanblyschak pushed a commit to stepanblyschak/sonic-utilities that referenced this pull request Aug 9, 2025
…net#215)

* Add GCU Support for SKU Mellanox-SN4280-C48/O8C40/O8V40 (sonic-net#3968)

Add GCU Support for SKU Mellanox-SN4280-C48/O8C40/O8V40

* [202411] fix show bgp cli on multiple asic device (sonic-net#3980)

[202411] fix show bgp cli on multiple asic device

---------

Co-authored-by: Sai Rama Mohan Reddy S <63886014+ram25794@users.noreply.github.com>
Co-authored-by: Liping Xu <108326363+lipxu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants