Skip to content

Commit

Permalink
Version 0.2.14
Browse files Browse the repository at this point in the history
Fix interface_split, add tests
  • Loading branch information
mihudec committed Sep 8, 2020
1 parent dc04a07 commit ebe3046
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ jobs:
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Show Folder Structure
run: ls -la ./tests
- name: Test CommonUtils
run: |
python -m unittest discover -s ./tests -p "test_CommonUtils.py"
- name: Test CiscoRange
run: |
python -m unittest discover -s ./tests -p "test_CiscoRange.py"
- name: Test BaseConfigParser
run: |
python -m unittest discover -s ./tests -p "test_BaseConfigParser.py"
- name: Test CiscoIosParser
run: |
python -m unittest discover -s ./tests -p "test_CiscoIosParser.py"
- name: Test BaseInterfaceLine
run: |
python -m unittest discover -s ./tests -p "test_BaseInterfaceLine.py"
Expand Down
7 changes: 6 additions & 1 deletion ccutils/ccparser/CiscoIosParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,13 @@ def vrfs(self):
address_families = []
afi_lines = candidate.re_search_children(regex=self._address_family_regex)
for line in afi_lines:
# print(line)
print(line)
entry = line.re_search(regex=self._address_family_regex, group="ALL")
rt_candidates = line.re_search_children(regex=self._vrf_afi_rt_regex, group="ALL")
print(rt_candidates)
if len(rt_candidates):
entry["import"] = [x["rt"] for x in rt_candidates if x["action"] == "import"]
entry["export"] = [x["rt"] for x in rt_candidates if x["action"] == "export"]
entry = remove_empty_values(entry)
address_families.append(entry)
if len(address_families):
Expand Down
3 changes: 2 additions & 1 deletion ccutils/utils/common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def split_interface_name(interface: str):
list: List containing name and number of interface, such as ``["GigabitEthernet", "0/10"]``
"""
pattern = re.compile(pattern=r"(?P<name>^[A-z\-]+(?=\d))(?P<number>[\d+\/]+)")
#pattern = re.compile(pattern=r"(?P<name>^[A-z\-]+(?=\d))(?P<number>[\d+\/]+)")
pattern = re.compile(pattern=r"(?P<name>[A-z]{2,}(?:[A-z\-])*)(?P<number>\d+(?:\/\d+)*(?:\:\d+)?(?:\.\d+)?)")
try:
match = re.match(pattern=pattern, string=interface)
except TypeError as e:
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
add_module_names = False

# The short X.Y version
version = '0.2.13'
version = '0.2.14'
# The full version, including alpha/beta/rc tags
release = '0.2.13-beta'
release = '0.2.14-beta'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='ccutils',
version='0.2.13',
version='0.2.14',
packages=find_packages(exclude=["test", "examples"]),
url='https://github.org/mihudec/ccutils',
license='',
Expand Down
1 change: 1 addition & 0 deletions tests/resources/cisco_ios_vrf_definition.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
vrf definition VRF-A
rd 65421:1327
description
!
address-family ipv4
route-target export 65000:1327
Expand Down
43 changes: 42 additions & 1 deletion tests/results/cisco_ios_vrf_definition.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
{
"vrfs": {}
"VRF-A": {
"rd": "65421:1327",
"description": null,
"address_families": [
{
"afi": "ipv4",
"import": [
"65000:327"
],
"export": [
"65000:1327"
]
}
]
},
"VRF-B": {
"rd": "65421:11",
"description": null,
"address_families": [
{
"afi": "ipv4",
"import": [
"65000:10"
],
"export": [
"65000:11"
]
}
]
},
"Mgmt-intf": {
"rd": null,
"description": null,
"address_families": [
{
"afi": "ipv4"
},
{
"afi": "ipv6"
}
]
}
}
36 changes: 36 additions & 0 deletions tests/test_CommonUtils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import unittest
from ccutils.utils.common_utils import split_interface_name, convert_interface_name
import json


class TestCommonUtils(unittest.TestCase):

def test_split_interface_name(self):
testmap = {
"FastEthernet0/20": ["FastEthernet", "0/20"],
"Vlan1": ["Vlan", "1"],
"Port-channel1": ["Port-channel", "1"],
"GigabitEthernet1/0/1.20": ["GigabitEthernet", "1/0/1.20"],
}
for interface, parts in testmap.items():
with self.subTest(msg="{}".format(interface)):
want = parts
have = split_interface_name(interface=interface)
self.assertEqual(want, have)

def test_convert_interface_name(self):
testmap = {
"FastEthernet0/20": "Fa0/20",
"Vlan1": "Vl1",
"Port-channel1": "Po1",
"GigabitEthernet1/0/1.20": "Gi1/0/1.20",
"Port-channel10.20": "Po10.20",
}
for interface, parts in testmap.items():
with self.subTest(msg="{}".format(interface)):
want = parts
have = convert_interface_name(interface=interface, out="short")
self.assertEqual(want, have)

if __name__ == '__main__':
unittest.main()

0 comments on commit ebe3046

Please sign in to comment.