-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add pyeapi.Node shim to handle CLI translation Create a new Node class that checks EOS versions for forward and backward compatible command translation for FN-0039, along with unit tests for version detection and translation * Use json version instead of text Co-authored-by: Alexey Kolobynin <[email protected]> Co-authored-by: Mircea Ulinic <[email protected]>
- Loading branch information
1 parent
0770843
commit 803f764
Showing
9 changed files
with
580 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""pyeapi wrapper to fix cli syntax change""" | ||
import pyeapi | ||
from napalm.eos.utils.cli_syntax import cli_convert | ||
|
||
|
||
class Node(pyeapi.client.Node): | ||
""" | ||
pyeapi node wrapper to fix cli syntax change | ||
""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
if "cli_version" in kwargs: | ||
self.cli_version = kwargs["cli_version"] | ||
del kwargs["cli_version"] | ||
else: | ||
self.cli_version = 1 | ||
|
||
super(Node, self).__init__(*args, **kwargs) | ||
|
||
def update_cli_version(self, version): | ||
""" | ||
Update CLI version number for this device | ||
:param version: int: version number | ||
:return: None | ||
""" | ||
self.cli_version = version | ||
|
||
def run_commands(self, commands, **kwargs): | ||
""" | ||
Run commands wrapper | ||
:param commands: list of commands | ||
:param kwargs: other args | ||
:return: list of outputs | ||
""" | ||
if isinstance(commands, str): | ||
new_commands = [cli_convert(commands, self.cli_version)] | ||
else: | ||
new_commands = [cli_convert(cmd, self.cli_version) for cmd in commands] | ||
|
||
return super(Node, self).run_commands(new_commands, **kwargs) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"""Some functions to work with EOS version numbers""" | ||
import re | ||
|
||
|
||
class EOSVersion: | ||
""" | ||
Class to represent EOS version | ||
""" | ||
|
||
def __init__(self, version): | ||
""" | ||
Create object | ||
:param version: str: version string | ||
""" | ||
self.version = version | ||
self.numbers = [] | ||
self.type = "" | ||
|
||
self._parse(version) | ||
|
||
def _parse(self, version): | ||
""" | ||
Parse version string | ||
:param version: str: version | ||
:return: None | ||
""" | ||
m = re.match(r"^(?P<numbers>\d[\d.]+\d)", version) | ||
|
||
if m: | ||
self.numbers = m.group("numbers").split(".") | ||
|
||
def __lt__(self, other): | ||
if not len(self.numbers): | ||
return True | ||
|
||
for x, y in zip(self.numbers, other.numbers): | ||
if x < y: | ||
return True | ||
elif x > y: | ||
return False | ||
|
||
return False | ||
|
||
def __gt__(self, other): | ||
if not len(self.numbers): | ||
return False | ||
|
||
for x, y in zip(self.numbers, other.numbers): | ||
if x > y: | ||
return True | ||
elif x < y: | ||
return False | ||
|
||
return False | ||
|
||
def __eq__(self, other): | ||
if len(self.numbers) != len(other.numbers): | ||
return False | ||
|
||
for x, y in zip(self.numbers, other.numbers): | ||
if x != y: | ||
return False | ||
|
||
return True | ||
|
||
def __le__(self, other): | ||
return self < other or self == other | ||
|
||
def __ge__(self, other): | ||
return self > other or self == other |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"memTotal": 3954980, | ||
"uptime": 200478.31, | ||
"modelName": "DCS-7150S-64-CL-R", | ||
"internalVersion": "4.21.8M-2GB-13902577.4218M", | ||
"mfgName": "Arista", | ||
"serialNumber": "JPE00000000", | ||
"systemMacAddress": "00:1c:73:00:00:00", | ||
"bootupTimestamp": 1588135848.0, | ||
"memFree": 2558364, | ||
"version": "4.21.8M-2GB", | ||
"architecture": "i386", | ||
"isIntlVersion": false, | ||
"internalBuildId": "5af75062-ded5-4c99-8f44-daa88aa4414d", | ||
"hardwareRevision": "01.03" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
Tests for EOS cli_syntax | ||
""" | ||
from napalm.eos.utils.cli_syntax import cli_convert | ||
|
||
|
||
def test_cli_no_change_v2(): | ||
""" | ||
Test no change for basic commands in version 2 | ||
:return: | ||
""" | ||
commands = ["show version", "show interfaces"] | ||
|
||
for c in commands: | ||
assert c == cli_convert(c, 2) | ||
assert c == cli_convert(c, 1) | ||
|
||
|
||
def test_cli_no_change_non_exist_version(): | ||
""" | ||
Test no change for basic commands and non-existing versions | ||
:return: | ||
""" | ||
commands = ["show version", "show interfaces"] | ||
|
||
for c in commands: | ||
assert c == cli_convert(c, 100000) | ||
|
||
|
||
def test_cli_change_exact(): | ||
""" | ||
Test cli change for exact commands | ||
""" | ||
commands = ["show ipv6 bgp neighbors", "show lldp traffic"] | ||
expect = ["show ipv6 bgp peers", "show lldp counters"] | ||
|
||
for c, e in zip(commands, expect): | ||
assert e == cli_convert(c, 2) | ||
assert c == cli_convert(e, 1) | ||
|
||
|
||
def test_cli_change_long_commands(): | ||
""" | ||
Test cli change for long commands | ||
""" | ||
commands = ["show ipv6 bgp neighbors vrf all", "show lldp traffic | include test"] | ||
expect = ["show ipv6 bgp peers vrf all", "show lldp counters | include test"] | ||
|
||
for c, e in zip(commands, expect): | ||
assert e == cli_convert(c, 2) | ||
assert c == cli_convert(e, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Tests for versions utils""" | ||
from napalm.eos.utils.versions import EOSVersion | ||
|
||
|
||
def test_version_create(): | ||
""" | ||
Test we can create version object | ||
""" | ||
versions = ["4.21.7.1M", "4.20.24F-2GB", "blablabla"] | ||
|
||
for v in versions: | ||
assert v == EOSVersion(v).version | ||
|
||
|
||
def test_version_comparisons(): | ||
""" | ||
Test version comparison | ||
""" | ||
old_version = "4.21.7.1M" | ||
new_verion = "4.23.0F" | ||
|
||
assert EOSVersion(old_version) < EOSVersion(new_verion) | ||
assert EOSVersion(new_verion) > EOSVersion(old_version) | ||
assert EOSVersion(old_version) <= EOSVersion(new_verion) | ||
assert EOSVersion(new_verion) >= EOSVersion(old_version) | ||
assert not EOSVersion(old_version) < EOSVersion(old_version) | ||
assert EOSVersion(old_version) == EOSVersion(old_version) | ||
assert EOSVersion(old_version) <= EOSVersion(old_version) |