Last active
March 14, 2017 15:25
-
-
Save bewing/67a11eff654e406c4dedf800681521c5 to your computer and use it in GitHub Desktop.
napalm-eos testing woes
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
def get_static_rp_config(self): | |
"""get_static_rp_config implementation for EOS.""" | |
vrf = py23_compat.text_type("default") | |
rp_config = {vrf: []} | |
pim_rp_config = self.device.run_commands(['show running-config | section ip pim rp-add'], | |
encoding='text')[0].get('output', None) | |
for line in pim_rp_config.splitlines(): | |
vrf_match = self._RE_PIM_VRF.search(line) | |
if vrf_match: | |
vrf = py23_compat.text_type(vrf_match.group('vrf')) | |
rp_config[vrf] = [] | |
rp_match = self._RE_PIM_RP.search(line) | |
if rp_match: | |
temp = rp_match.groupdict(None) | |
if (temp['acl'] is None and temp['mcast_subnet'] is None): | |
temp['mcast_subnet'] = '224.0.0.0/4' | |
if (temp['bsr_override'] is not None): | |
temp['bsr_override'] = True | |
if (temp['hashmask'] is not None): | |
temp['hashmask'] = int(temp['hashmask']) | |
if (temp['priority'] is not None): | |
temp['priority'] = int(temp['priority']) | |
rp_config[vrf].append(temp) | |
if len(rp_config["default"]) == 0: | |
return {} | |
return rp_config |
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
@wrap_test_cases | |
def test_get_static_rp_config(self, test_case): | |
"""Test get_static_rp_config method.""" | |
get_static_rp_config = self.device.get_static_rp_config() | |
assert isinstance(get_static_rp_config, dict) | |
if len(get_static_rp_config) > 0: | |
for vrf, rp_list in get_static_rp_config.items(): | |
assert isinstance(vrf, text_type) | |
for rp in rp_list: | |
assert isinstance(rp['acl'], text_type) if rp['acl'] is not None else True | |
assert isinstance(rp['bsr_override'], | |
True) if rp['bsr_override'] is not None else True | |
assert isinstance(rp['hashmask'], | |
int) if rp['hashmask'] is not None else True | |
assert isinstance(rp['mcast_subnet'], | |
text_type) if rp['mcast_subnet'] is not None else True | |
assert isinstance(rp['priority'], | |
int) if rp['priority'] is not None else True | |
assert isinstance(rp['rp_addr'], | |
text_type) if rp['rp_addr'] is not None else True | |
return get_static_rp_config |
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
================================================================================================================================== FAILURES =================================================================================================================================== | |
________________________________________________________________________________________________________________ TestGetter.test_get_static_rp_config[normal] _________________________________________________________________________________________________________________ | |
cls = <test_getters.TestGetter object at 0x1bedc10>, test_case = 'normal' | |
@functools.wraps(func) | |
def mock_wrapper(cls, test_case): | |
for patched_attr in cls.device.patched_attrs: | |
attr = getattr(cls.device, patched_attr) | |
attr.current_test = func.__name__ | |
attr.current_test_case = test_case | |
try: | |
# This is an ugly, ugly, ugly hack because some python objects don't load | |
# as expected. For example, dicts where integers are strings | |
> result = json.loads(json.dumps(func(cls, test_case))) | |
../napalm-base/napalm_base/test/getters.py:73: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <test_getters.TestGetter object at 0x1bedc10>, test_case = 'normal' | |
@wrap_test_cases | |
def test_get_static_rp_config(self, test_case): | |
"""Test get_static_rp_config method.""" | |
get_static_rp_config = self.device.get_static_rp_config() | |
assert isinstance(get_static_rp_config, dict) | |
if len(get_static_rp_config) > 0: | |
for vrf, rp_list in get_static_rp_config.items(): | |
assert isinstance(vrf, text_type) | |
for rp in rp_list: | |
assert isinstance(rp['acl'], text_type) if rp['acl'] is not None else True | |
assert isinstance(rp['bsr_override'], | |
True) if rp['bsr_override'] is not None else True | |
assert isinstance(rp['hashmask'], | |
int) if rp['hashmask'] is not None else True | |
assert isinstance(rp['mcast_subnet'], | |
text_type) if rp['mcast_subnet'] is not None else True | |
assert isinstance(rp['priority'], | |
int) if rp['priority'] is not None else True | |
assert isinstance(rp['rp_addr'], | |
> text_type) if rp['rp_addr'] is not None else True | |
E AssertionError | |
../napalm-base/napalm_base/test/getters.py:537: AssertionError |
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
from napalm_eos import EOSDriver | |
import pprint | |
device = EOSDriver("10.192.61.90", "admin", "admin") | |
device.open() | |
pprint.pprint(device.get_static_rp_config()) |
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
{u'default': [{u'acl': None, | |
u'bsr_override': None, | |
u'hashmask': None, | |
u'mcast_subnet': u'224.0.0.0/4', | |
u'priority': None, | |
u'rp_addr': u'192.0.2.1'} | |
]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment