Extend ShowBgpAddressFamily Class - Enable running "show bgp {address_family} community {community}" on iosxr
GitHub Issue: Extend ShowBgpAddressFamily Class
Description
Currently, the ShowBgpAddressFamily class in this file parses commands show bgp and show bgp {address_family}. However, it needs to be extended to parse additional commands:
-
show bgp {address_family} community {community} -
show bgp {address_family} community {community} {exact_match}
The objective is to ensure that the output of these new commands is compatible with the existing logic for parsing show bgp.
Requirements
- Extend the
ShowBgpAddressFamilyclass to parse the additional commands mentioned above. - Ensure that the output format of the new commands aligns with the output format of
show bgpfor compatibility with existing parsing logic.
Additional Information
This enhancement aims to broaden the capabilities of the ShowBgpAddressFamily class to handle a wider range of BGP-related commands, facilitating more comprehensive parsing and analysis of BGP data.
Edited
Another miscellaneous bugs
- Your regex pattern did not work correctly for IPv6 addresses. The regex in the address ignored the format [a-f].
Additionally, your code does not handle IPv6 outputs from BGP correctly. Example:
s>i2001:718::2:99/128 195.113.156.4 0 100 0 i
s i 195.113.156.4 0 100 0 i
s>i2001:718::2:101/128
10.2.8.1 0 100 0 i
s i 10.2.8.1 0 100 0 i
s>i2001:718::2:116/128
195.113.156.9 1000 205 0 65086 i
s i 195.113.156.9 1000 205 0 65086 i
s i 2001:718:0:600:0:1a:1a:11
1000 110 0 65086 i
In this state, it completely ignores that the next hop and metrics are listed on the next line. My regex corrects this, however, there is a flaw in your code: you use a multiline regex but execute it on individual lines, which does not make sense. To make the code work correctly now, I need to modify the device output to this format:
s>i2001:718::2:99/128 195.113.156.4 0 100 0 i
s i 195.113.156.4 0 100 0 i
s>i2001:718::2:101/128 10.2.8.1 0 100 0 i
s i 10.2.8.1 0 100 0 i
s>i2001:718::2:116/128 195.113.156.9 1000 205 0 65086 i
s i 195.113.156.9 1000 205 0 65086 i
s i 2001:718:0:600:0:1a:1a:11 1000 110 0 65086 i
This is achieved with the following code:
raw_result = device.execute(command)
raw_result = raw_result.replace('\r\n', '\n')
lines = raw_result.split('\n')
result = [lines[0]]
for line in lines[1:]:
if line.startswith(' '):
result[-1] += line
else:
result.append(line)
formatted_text = '\n'.join(result)
# Run GENIE with preprocessed formatted text
device.parse(command, output=formatted_text)
This code concatenates lines that start with a space to the previous line.
With this output modification and my changes in the pull request, the "show bgp" command works for both IPv4 and IPv6 addresses. Currently, your implementation for IPv6 is not functional.
Hello @Kani999,
Thanks for taking care of the issue by yourself. I will check with the reviewers to get this PR reviewed soon.
Hello @Kani999,
Kindly fix the failing checks in your PR. If everything is correct at your end then re-trigger the checks with empty commit.
Hello @Kani999,
Reviewer has shared their reviews on your PR so kindly address those soon.
@SohanTirpude I'll take a look at it, but currently I think I will be able to do it during the second half of April.
During a fresh installation of genieparser and running tests locally, I failed on Install Dependencies:
ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.
unknown package:
Expected sha256 65d99392fb36a816ed1bc7ef19e7a23b9ef365[481](https://github.com/CiscoTestAutomation/genieparser/actions/runs/8049758739/job/21983808660?pr=822#step:4:482)1e02326f80002c258b889c3
Got 84c08c08404cdc00040fab5a1d79c42eece135685e19fb84ae8f3042078371eb
Error: Process completed with exit code 1.
And I have nothing to do with those changes. So I don't really know what is wrong with the build. Can you take a look at it?
Sure @Kani999.
Hello @Kani999,
We have released pyats 24.3 version, so kindly update your branch with latest, execute "make json" again and push your changes again.
Thank you.
@SohanTirpude could you help me with the broken CI?
It gives me and error at the:
- cheetah
- ShowInterfacesWired
- Golden -> cheetah -> ShowInterfacesWired
1700: 2024-04-04T10:10:41: Caught an exception while executing section ShowInterfacesWired:
1701: 2024-04-04T10:10:41: Traceback (most recent call last):
1702: 2024-04-04T10:10:41: File "/home/jankrupa/genieparser_fork/genieparser/src/genie/libs/parser/utils/unittests.py", line 498, in test
1703: 2024-04-04T10:10:41: self.test_golden(golden_steps, local_class,
1704: 2024-04-04T10:10:41: File "/home/jankrupa/genieparser_fork/genieparser/src/genie/libs/parser/utils/unittests.py", line 460, in wrapper
1705: 2024-04-04T10:10:41: func(self, *args, **kwargs)
1706: 2024-04-04T10:10:41: File "/home/jankrupa/genieparser_fork/genieparser/src/genie/libs/parser/utils/unittests.py", line 569, in test_golden
1707: 2024-04-04T10:10:41: golden_parsed_output = read_python_file(
1708: 2024-04-04T10:10:41: File "/home/jankrupa/genieparser_fork/genieparser/src/genie/libs/parser/utils/unittests.py", line 67, in read_python_file
1709: 2024-04-04T10:10:41: spec.loader.exec_module(module)
1710: 2024-04-04T10:10:41: File "<frozen importlib._bootstrap_external>", line 879, in exec_module
1711: 2024-04-04T10:10:41: File "<frozen importlib._bootstrap_external>", line 1016, in get_code
1712: 2024-04-04T10:10:41: File "<frozen importlib._bootstrap_external>", line 1073, in get_data
1713: 2024-04-04T10:10:41: FileNotFoundError: [Errno 2] No such file or directory: '/home/jankrupa/genieparser_fork/genieparser/tests/cheetah/ShowInterfacesWired/cli/equal/golden_output1_expected.py'
Summary of the problem:
- An exception occurred while executing a section of code related to showing wired interfaces.
- The traceback indicates that the error occurred in a file named unittests.py within the genieparser library.
- The error seems to be related to the inability to find a specific file named golden_output1_expected.py in the specified directory /home/jankrupa/genieparser_fork/genieparser/tests/cheetah/ShowInterfacesWired/cli/equal/.
- The issue seems to be with either the absence of the expected output file or a misconfiguration in the test setup.
I don't know if this is my problem. I did not changed anything in this part of code. Could you take a look at the problem of absence of the golden_output1_expected.py file?
Hello @Kani999,
Kindly pull the latest changes again, update your branch accordingly and try again. I hope you will not see this issue again.
Thank you.
Hi @SohanTirpude,
Everything seems to be working fine now.
I've would like to mention again that I've noticed a potential issue in the script implementation. The current regex, although it's multiline, executes on individual lines here, which might not be the intended behavior.
To ensure correct functionality, I had to modify the device output to the following format for IPv6:
# Before: execute CLI command and get output
for line in lines[1:]:
if line.startswith(' '):
result[-1] += line
else:
result.append(line)
formatted_text = '\n'.join(result)
# Run GENIE with preprocessed formatted text
device.parse(command, output=formatted_text)
This adjustment was necessary because the IPv6 output differs from IPv4, often splitting addresses into multiple lines.
Hello @Kani999,
As requested by reviewers, kindly add unit tests to your PR.
Thank you.
@SohanTirpude
Unit tests were added.
Hello @Kani999,
Thanks. Let me check with the reviewers then.
Thank you.
Hello @Kani999,
Kindly resolve the conflicts in your PR.
Thank you.
Hello @Kani999,
Kindly resolve the conflicts in your PR.
Thank you.
Could you please address the conflicts? I'm not able to identify any at the moment
Hello @Kani999,
The conflict is showing in this file: sdk_generator/outputs/github_parser.json. Kindly update your branch with latest dev branch and thre re-try again.
Thank you.
Hello, @SohanTirpude
I've solved the problem to updating genie to latest version. Can you look at the PR?
Thank you.
Hello @Kani999,
I have checked the PR but it seems you have not addressed the reviewer's comments. So, please address those and let me know once done.
Thank you.
The reviewer's comments suggested adding unit tests, which I have done. Perhaps they need to be "approved"? I am unsure what else needs to be added to the code.
If I am mistaken, could you please specify what else should be included?
Hello @Kani999,
Have you checked these comments: https://github.com/CiscoTestAutomation/genieparser/pull/822/files#r1514724904 and https://github.com/CiscoTestAutomation/genieparser/pull/822/files#r1514724716?
You have not addressed these comments yet so I don't think the reviewers will approve the PR.
@SohanTirpude I believe that the comments should be solved now.
Hello @Kani999, yeah it looks better now. Kindly give me some time to check with the reviewers on this PR.
Hello @Kani999,
It looks like your PR got merged. Thank you very much for your contribution. Hence, I am closing this issue. If you are facing any other issues, kindly open a new ticket.
Thank you.