hyperglass
hyperglass copied to clipboard
Error in bgp_router query on Huawei
In Huawei it is necessary to have a space after the slash "1.1.1.0 24", by the logs, this treatment is not happening.
[DEBUG] 20220128 01:01:14 | hyperglass.execution.drivers._construct:27 | __init__ → Constructing bgp_route query for '1.1.1.0/24'
[DEBUG] 20220128 01:01:14 | hyperglass.execution.drivers._construct:111 | queries → Constructed query: ['display bgp routing-table 1.1.1.0/24']
[DEBUG] 20220128 01:01:14 | hyperglass.execution.drivers.ssh_netmiko:57 | collect → Connecting directly to São Paulo, SP, Brasil
[DEBUG] 20220128 01:01:18 | hyperglass.execution.drivers.ssh_netmiko:103 | collect → Raw response for command "display bgp routing-table 1.1.1.0/24":
^
Error: Wrong parameter found at '^' position.
[DEBUG] 20220128 01:01:18 | hyperglass.execution.drivers._common:34 | parsed_response → Pre-parsed responses:
(" ^\nError: Wrong parameter found at '^' position.",)
[DEBUG] 20220128 01:01:18 | hyperglass.execution.drivers._common:80 | parsed_response → Post-parsed responses:
^
Error: Wrong parameter found at '^' position.
Up to version 1.0.0, this treatment is performed, according to the logs below.
[DEBUG] 20220128 00:44:52 | hyperglass.execution.drivers._construct:36 | __init__ → Constructing bgp_route query for '1.1.1.0/24'
[DEBUG] 20220128 00:44:52 | hyperglass.execution.drivers._construct:160 | queries → Constructed query: ['display bgp routing-table 1.1.1.0 24']
[DEBUG] 20220128 00:44:52 | hyperglass.execution.drivers.ssh_netmiko:57 | collect → Connecting directly to São Paulo, SP, Brasil
Best Regards
I have this same issue. Ping commands and traceroute work fine, but the command issued for the routing table is incorrect as already mentioned.
As per the example, display bgp routing-table 1.1.1.0/24 needs to be display bgp routing-table 1.1.1.0 24
What is the best way to address this?
I suspect this is being caused by the addition of the Formatter class in execution/drivers/_construct.py - this is a new addition in 1.0.4 that wasn't present in 1.0.0
Specifically - you can see that the formatting override for huawei and huawei_vrpv8 are ignored because the Formatter class references the original query target, rather than the corrected query target.
Line 39-40 in execution/drivers/_construct.py - where the query target is corrected.
if self.device.nos in TARGET_FORMAT_SPACE:
self.target = re.sub(r"\/", r" ", str(self.query_data.query_target))
Line 67-68 in execution/drivers/_construct.py - where the corrected query target is ignored and the original data is referenced and replaces the corrected query target with the uncorrected version.
with Formatter(self.device.nos, self.query_data.query_type) as formatter:
self.target = formatter(self.query_data.query_target)
This particular if statement will probably need to be moved into the Formatter class to fix this properly.
Further to the above - I don't have environment to test this in (so I don't want to create a pull request), but adding the following code to _construct.py may work - or at-least this is a starting point.
Delete or comment out the following lines Line 39-40:
if self.device.nos in TARGET_FORMAT_SPACE:
self.target = re.sub(r"\/", r" ", str(self.query_data.query_target))
Add the following to def _get_formatter(self) in the Formatter class:
if self.nos in TARGET_FORMAT_SPACE:
if self.query_type == "bgp_route":
return self._huawei_bgp_route
Add the following to the Formatter class
def _huawei_bgp_route(self, target: str) -> str:
""" Remove slashes from target for required platforms."""
self.target = re.sub(r"\/", r" ", str(self.query_data.query_target))
log.debug("Modified target '{}' to '{}'", self.query_data.query_target, self.target)
return self.target
If someone running Huawei gear is confident enough to try this in their installation and see if it resolves the issue, that would be good :) .
Pre-made file below: _construct.py.txt
Hi @jakeb91, did not work, the error below is the result when starting the Hyperglass service.
Traceback (most recent call last):
File "/usr/local/bin/hyperglass", line 11, in
Regards
For me it worked just editing the code below:
with Formatter(self.device.nos, self.query_data.query_type) as formatter:
self.target = re.sub(r"\/", r" ", str(self.query_data.query_target))
For me it worked just editing the code below:
with Formatter(self.device.nos, self.query_data.query_type) as formatter:self.target = re.sub(r"\/", r" ", str(self.query_data.query_target))
What version are you on? 1.0.4?
I will alter it in /hyperglass/execution/drivers/__construct.py
The error below is returned. Has anything been tweaked or just what was mentioned?
Traceback (most recent call last):
File "/usr/local/bin/hyperglass", line 11, in
Edit on /hyperglass/execution/drivers/_construct.py and not /hyperglass/execution/drivers/__construct.py
only just make these changes
with Formatter(self.device.nos, self.query_data.query_type) as formatter: self.target = re.sub(r"/", r" ", str(self.query_data.query_target))
Distro: Linux Debian 11 64Bits NetInstall HyperGlass: Version 1.0.4
#That way I was successful
Delete or comment out the following lines Line 39-40:
if self.device.nos in TARGET_FORMAT_SPACE:
self.target = re.sub(r"\/", r" ", str(self.query_data.query_target))
Add the following to def _get_formatter(self) in the Formatter class:
if self.nos in TARGET_FORMAT_SPACE:
if self.query_type == "bgp_route":
return self._huawei_bgp_route
Add the following to the Formatter class
def _huawei_bgp_route(self, target: str) -> str:
""" Remove slashes from target for required platforms."""
self.target = re.sub(r"\/", r" ", str(target))
log.debug("Modified target '{}' to '{}'", target, self.target)
return self.target
Above solutions did not work for me in real environment, the solution I found was:
with Formatter(self.device.nos, self.query_data.query_type) as formatter:
log.debug("==*HW*== '{}' to '{}'", self.device.nos, self.query_data.query_type)
if self.device.nos in TARGET_FORMAT_SPACE:
if self.query_data.query_type == "bgp_route":
self.target = re.sub(r"/", r" ", str(self.query_data.query_target))
else:
self.target = formatter(self.query_data.query_target)
else:
self.target = formatter(self.query_data.query_target)
Above solutions did not work for me in real environment, the solution I found was:
with Formatter(self.device.nos, self.query_data.query_type) as formatter: log.debug("==*HW*== '{}' to '{}'", self.device.nos, self.query_data.query_type) if self.device.nos in TARGET_FORMAT_SPACE: if self.query_data.query_type == "bgp_route": self.target = re.sub(r"/", r" ", str(self.query_data.query_target)) else: self.target = formatter(self.query_data.query_target) else: self.target = formatter(self.query_data.query_target)
The related pull request has the working / fixed code - I don't have access to Huawei gear anymore though so I was unable to test it.
I have the same issue here using huawei_vrpv8, the code just needs handle to remove the / from network prefix when the device is Huawei.