Skip to content

Check if BGP has Loopback0 IP as its router ID#8576

Merged
kellyyeh merged 20 commits intosonic-net:masterfrom
kellyyeh:router-id
Jul 21, 2023
Merged

Check if BGP has Loopback0 IP as its router ID#8576
kellyyeh merged 20 commits intosonic-net:masterfrom
kellyyeh:router-id

Conversation

@kellyyeh
Copy link
Contributor

@kellyyeh kellyyeh commented Jun 13, 2023

Description of PR

Summary:
Fixes # (issue)

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • Test case(new/improvement)

Back port request

  • 201911
  • 202012
  • 202205

Approach

What is the motivation for this PR?

An issue was found that T0 did not announce Loopback to T1, this check is to bridge the test gap to ensure bgp router identifier matches Loopback0 IP.

How did you do it?

Added in sanity_check to match bgp router id and loopback0 ip

How did you verify/test it?

Ran a advanced_reboot manually and checked expected log: BGP router identifier:
https://elastictest.org/scheduler/testplan/649c780c75768730ce0de9f3

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

@mssonicbld
Copy link
Collaborator

The pre-commit check detected issues in the files touched by this pull request.
The pre-commit check is a mandatory check, please fix detected issues.

Detailed pre-commit check results:
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check python ast.........................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

tests/common/fixtures/advanced_reboot.py:225:13: E117 over-indented

check conditional mark sort..........................(no files to check)Skipped

To run the pre-commit checks locally, you can follow below steps:

  1. Ensure that default python is python3. In sonic-mgmt docker container, default python is python2. You can run
    the check by activating the python3 virtual environment in sonic-mgmt docker container or outside of sonic-mgmt
    docker container.
  2. Ensure that the pre-commit package is installed:
sudo pip install pre-commit
  1. Go to repository root folder
  2. Install the pre-commit hooks:
pre-commit install
  1. Use pre-commit to check staged file:
pre-commit
  1. Alternatively, you can check committed files using:
pre-commit run --from-ref <commit_id> --to-ref <commit_id>

@kellyyeh kellyyeh marked this pull request as ready for review June 27, 2023 16:22
@kellyyeh kellyyeh requested a review from vaibhavhd June 27, 2023 16:22
check_bgo_router_id_cmd = r"show ip bgp sum"
bgp_sum_result = self.duthost.shell(check_bgo_router_id_cmd, module_ignore_errors=True)
if bgp_sum_result["rc"] == 0:
match = re.search(r'BGP router identifier (\d+\.\d+\.\d+\.\d+)', bgp_sum_result["stdout"])
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 no way this data can be collected from DB or from a JSON output? The concern w/ CLI parsing is that if the format changes in future then the regex will fail and lead to false positives.

If there is no other way then this is acceptable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Found a way to get this in JSON! You could execute below vtysh command and get the json output. From it. routerId can be fetched.

$ vtysh -c "show ip bgp summary json" 
{
"ipv4Unicast":{
  "routerId":"10.1.0.32",


loopback0 = str(self.mgFacts['minigraph_lo_interfaces'][0]['addr'])

return bgp_router_id == loopback0
Copy link
Contributor

Choose a reason for hiding this comment

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

bgp_router_id is defined only when the match is successful. The check here can fail w/ bgp_router_id not defined if the match is not successful and fail ungracefully.

@vaibhavhd
Copy link
Contributor

@StormLiangMS just FYI: this is a test gap that is being addressed. Today no test matches the router-id to be same as Loopback0's IP. With this change the verification will be done as part of sanity tests.

@mssonicbld
Copy link
Collaborator

The pre-commit check detected issues in the files touched by this pull request.
The pre-commit check is a mandatory check, please fix detected issues.

Detailed pre-commit check results:
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check python ast.........................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

tests/common/fixtures/advanced_reboot.py:574:121: E501 line too long (125 > 120 characters)

check conditional mark sort..........................(no files to check)Skipped

To run the pre-commit checks locally, you can follow below steps:

  1. Ensure that default python is python3. In sonic-mgmt docker container, default python is python2. You can run
    the check by activating the python3 virtual environment in sonic-mgmt docker container or outside of sonic-mgmt
    docker container.
  2. Ensure that the pre-commit package is installed:
sudo pip install pre-commit
  1. Go to repository root folder
  2. Install the pre-commit hooks:
pre-commit install
  1. Use pre-commit to check staged file:
pre-commit
  1. Alternatively, you can check committed files using:
pre-commit run --from-ref <commit_id> --to-ref <commit_id>

@mssonicbld
Copy link
Collaborator

The pre-commit check detected issues in the files touched by this pull request.
The pre-commit check is a mandatory check, please fix detected issues.

Detailed pre-commit check results:
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check python ast.........................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

tests/common/fixtures/advanced_reboot.py:575:121: E501 line too long (125 > 120 characters)

check conditional mark sort..........................(no files to check)Skipped

To run the pre-commit checks locally, you can follow below steps:

  1. Ensure that default python is python3. In sonic-mgmt docker container, default python is python2. You can run
    the check by activating the python3 virtual environment in sonic-mgmt docker container or outside of sonic-mgmt
    docker container.
  2. Ensure that the pre-commit package is installed:
sudo pip install pre-commit
  1. Go to repository root folder
  2. Install the pre-commit hooks:
pre-commit install
  1. Use pre-commit to check staged file:
pre-commit
  1. Alternatively, you can check committed files using:
pre-commit run --from-ref <commit_id> --to-ref <commit_id>

@mssonicbld
Copy link
Collaborator

The pre-commit check detected issues in the files touched by this pull request.
The pre-commit check is a mandatory check, please fix detected issues.

Detailed pre-commit check results:
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check python ast.........................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

tests/common/fixtures/advanced_reboot.py:240:95: E502 the backslash is redundant between brackets
tests/common/fixtures/advanced_reboot.py:241:34: E127 continuation line over-indented for visual indent

check conditional mark sort..........................(no files to check)Skipped

To run the pre-commit checks locally, you can follow below steps:

  1. Ensure that default python is python3. In sonic-mgmt docker container, default python is python2. You can run
    the check by activating the python3 virtual environment in sonic-mgmt docker container or outside of sonic-mgmt
    docker container.
  2. Ensure that the pre-commit package is installed:
sudo pip install pre-commit
  1. Go to repository root folder
  2. Install the pre-commit hooks:
pre-commit install
  1. Use pre-commit to check staged file:
pre-commit
  1. Alternatively, you can check committed files using:
pre-commit run --from-ref <commit_id> --to-ref <commit_id>

@mssonicbld
Copy link
Collaborator

The pre-commit check detected issues in the files touched by this pull request.
The pre-commit check is a mandatory check, please fix detected issues.

Detailed pre-commit check results:
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check python ast.........................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

tests/common/fixtures/advanced_reboot.py:240:95: E502 the backslash is redundant between brackets

check conditional mark sort..........................(no files to check)Skipped

To run the pre-commit checks locally, you can follow below steps:

  1. Ensure that default python is python3. In sonic-mgmt docker container, default python is python2. You can run
    the check by activating the python3 virtual environment in sonic-mgmt docker container or outside of sonic-mgmt
    docker container.
  2. Ensure that the pre-commit package is installed:
sudo pip install pre-commit
  1. Go to repository root folder
  2. Install the pre-commit hooks:
pre-commit install
  1. Use pre-commit to check staged file:
pre-commit
  1. Alternatively, you can check committed files using:
pre-commit run --from-ref <commit_id> --to-ref <commit_id>

@mssonicbld
Copy link
Collaborator

The pre-commit check detected issues in the files touched by this pull request.
The pre-commit check is a mandatory check, please fix detected issues.

Detailed pre-commit check results:
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check python ast.........................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

tests/common/fixtures/advanced_reboot.py:239:29: E128 continuation line under-indented for visual indent

check conditional mark sort..........................(no files to check)Skipped

To run the pre-commit checks locally, you can follow below steps:

  1. Ensure that default python is python3. In sonic-mgmt docker container, default python is python2. You can run
    the check by activating the python3 virtual environment in sonic-mgmt docker container or outside of sonic-mgmt
    docker container.
  2. Ensure that the pre-commit package is installed:
sudo pip install pre-commit
  1. Go to repository root folder
  2. Install the pre-commit hooks:
pre-commit install
  1. Use pre-commit to check staged file:
pre-commit
  1. Alternatively, you can check committed files using:
pre-commit run --from-ref <commit_id> --to-ref <commit_id>

"""
check_bgp_router_id_cmd = r'vtysh -c "show ip bgp summary json"'
bgp_summary = self.duthost.shell(check_bgp_router_id_cmd, module_ignore_errors=True)
bgp_summary_json = json.loads(bgp_summary['stdout'])
Copy link
Contributor

Choose a reason for hiding this comment

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

Possible exception here if stdout is not in json format for some reason.

return not check_result['failed']

def _check_bgp_router_id(tbinfo):
duthost = kwargs['node']
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like there is duplication of whole logic here. So can we put this into commons and import at both the places?

@mssonicbld
Copy link
Collaborator

The pre-commit check detected issues in the files touched by this pull request.
The pre-commit check is a mandatory check, please fix detected issues.

Detailed pre-commit check results:
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check python ast.........................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

tests/common/fixtures/advanced_reboot.py:558:121: E501 line too long (125 > 120 characters)
tests/common/fixtures/advanced_reboot.py:559:29: E128 continuation line under-indented for visual indent

check conditional mark sort..........................(no files to check)Skipped

To run the pre-commit checks locally, you can follow below steps:

  1. Ensure that default python is python3. In sonic-mgmt docker container, default python is python2. You can run
    the check by activating the python3 virtual environment in sonic-mgmt docker container or outside of sonic-mgmt
    docker container.
  2. Ensure that the pre-commit package is installed:
sudo pip install pre-commit
  1. Go to repository root folder
  2. Install the pre-commit hooks:
pre-commit install
  1. Use pre-commit to check staged file:
pre-commit
  1. Alternatively, you can check committed files using:
pre-commit run --from-ref <commit_id> --to-ref <commit_id>

@mssonicbld
Copy link
Collaborator

The pre-commit check detected issues in the files touched by this pull request.
The pre-commit check is a mandatory check, please fix detected issues.

Detailed pre-commit check results:
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check python ast.........................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

tests/common/fixtures/advanced_reboot.py:559:25: E128 continuation line under-indented for visual indent

check conditional mark sort..........................(no files to check)Skipped

To run the pre-commit checks locally, you can follow below steps:

  1. Ensure that default python is python3. In sonic-mgmt docker container, default python is python2. You can run
    the check by activating the python3 virtual environment in sonic-mgmt docker container or outside of sonic-mgmt
    docker container.
  2. Ensure that the pre-commit package is installed:
sudo pip install pre-commit
  1. Go to repository root folder
  2. Install the pre-commit hooks:
pre-commit install
  1. Use pre-commit to check staged file:
pre-commit
  1. Alternatively, you can check committed files using:
pre-commit run --from-ref <commit_id> --to-ref <commit_id>

@kellyyeh kellyyeh requested a review from vaibhavhd July 18, 2023 07:53
@arlakshm
Copy link
Contributor

Hi @kellyyeh @vaibhavhd, this check will not work for chassis linecard which have single asic. Please check.

@kellyyeh
Copy link
Contributor Author

Hi @kellyyeh @vaibhavhd, this check will not work for chassis linecard which have single asic. Please check.

Created PR #9090

@mssonicbld
Copy link
Collaborator

Cherry-pick PR to 202205: #9134

@mssonicbld
Copy link
Collaborator

@kellyyeh PR conflicts with 202012 branch

kellyyeh added a commit to kellyyeh/sonic-mgmt that referenced this pull request Jul 31, 2023
wangxin pushed a commit that referenced this pull request Aug 1, 2023
This is a cherry-pick PR for #8576 and #9090
* Check if BGP has Loopback0 IP as its router ID (#8576)
* Skip check_bgp_router_id on T2 devices (#9090)

What is the motivation for this PR?
An issue was found that T0 did not announce Loopback to T1, this check is to bridge the test gap to ensure bgp router identifier matches Loopback0 IP.

How did you do it?
Added in sanity_check to match bgp router id and loopback0 ip

How did you verify/test it?
Ran a advanced_reboot manually and checked expected log: BGP router identifier:
https://elastictest.org/scheduler/testplan/649c780c75768730ce0de9f3
AharonMalkin pushed a commit to AharonMalkin/sonic-mgmt that referenced this pull request Jan 25, 2024
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.

5 participants