Skip to content
This repository has been archived by the owner on Mar 7, 2018. It is now read-only.

Make use of mac() and ip() helpers. #46

Merged
merged 14 commits into from
Oct 24, 2016
Merged

Make use of mac() and ip() helpers. #46

merged 14 commits into from
Oct 24, 2016

Conversation

inetuid
Copy link
Contributor

@inetuid inetuid commented Sep 17, 2016

Implements #31

Copy link
Member

@mirceaulinic mirceaulinic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good @inetuid! Thanks!

Copy link
Member

@mirceaulinic mirceaulinic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed that you missed some details, please update @inetuid

@@ -1277,7 +1277,7 @@ def _parse_per_peer_bgp_detail(peer_output):
unicode, item['last_event']))
item['remote_address'] = (
napalm_base.helpers.convert(
unicode, item['remote_address']))
napalm_base.helpers.ip, item['remote_address']))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be napalm_base.helpers.ip(item['remote_address']))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convert() looks to call the first argument (napalm_base.helpers.ip) with the second argument (item['remote_address']):

def convert(to, who, default=u''):
    if who is None:
        return default
    try:
        return to(who)
    except:
        return default

So I don't think it's appropriate to pass napalm_base.helpers.ip(item['remote_address'])).

You could argue that the whole convert part is unnecessary, but I went for minimal changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, missed that napalm_base.helpers.ip is passed as argument for convert.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And yeah. you can get rid of the convert - not needed anymore

@@ -1292,10 +1292,10 @@ def _parse_per_peer_bgp_detail(peer_output):
unicode, item['routing_table']))
item['router_id'] = (
napalm_base.helpers.convert(
unicode, item['router_id']))
napalm_base.helpers.ip, item['router_id']))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be napalm_base.helpers.ip(item['router_id']))

item['local_address'] = (
napalm_base.helpers.convert(
unicode, item['local_address']))
napalm_base.helpers.ip, item['local_address']))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be napalm_base.helpers.ip(item['local_address']))

@@ -789,8 +789,8 @@ def get_arp_table(self):
arp_table.append(
{
'interface' : interface,
'mac' : mac_format,
'ip' : ip,
'mac' : napalm_base.helpers.mac(mac_format),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can also use mac_raw instead of mac_format and remove the unnecessary lines.

@@ -957,7 +957,7 @@ def get_mac_address_table(self):
moves = mac_entry.get('moves', 0)
mac_table.append(
{
'mac' : mac_format,
'mac' : napalm_base.helpers.mac(mac_format),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, can use mac_raw

@mirceaulinic mirceaulinic added this to the 0.4.0 milestone Oct 2, 2016
@inetuid
Copy link
Contributor Author

inetuid commented Oct 4, 2016

Not sure if/what I need to do with this?

@mirceaulinic
Copy link
Member

@inetuid Can you please rebase?

@dbarrosop
Copy link
Member

If someone rebases this I will merge it and release a new version : )

@inetuid
Copy link
Contributor Author

inetuid commented Oct 6, 2016

Assuming a rebase is fixing the merge (not updating the commit log) I made a change but it's now failing the unit tests. The tests pass if I run them locally on my development box but fail under Travis. Looks like the case difference in the mac() method is causing the problem.

@mirceaulinic mirceaulinic modified the milestones: 0.4.1, 0.4.0 Oct 6, 2016
@mirceaulinic
Copy link
Member

mirceaulinic commented Oct 6, 2016

@inetuid You did good. The new testing framework compares the expected data with the information returned by the getters - and seems to be case sensitive (e.g.: {"expected": "08:00:27:10:c4:8f", "result": "08:00:27:10:C4:8F"}). For the moment you can update the contents of the tests, converting all MAC addresses to upper in expected_result.json for the following tests:

For traceroute, as the unresponsive hops are marked with * (which obviously is not a valid IP address), you should do:

hop_addr = hop_details[4+probe_index*5]
ip_address = napalm_base.helpers.convert(napalm_base.helpers.ip, hop_addr, hop_addr)

Which returns the raw value (*) in case unable to convert to ip format.

@@ -1190,7 +1188,7 @@ def traceroute(self, destination, source='', ttl=0, timeout=0):
traceroute_result['success'][hop_index] = {'probes': {}}
for probe_index in range(probes):
host_name = hop_details[3+probe_index*5]
ip_address = hop_details[4+probe_index*5]
ip_address = napalm_base.helpers.ip(hop_details[4+probe_index*5])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with this @inetuid

hop_addr = hop_details[4+probe_index*5]
ip_address = napalm_base.helpers.convert(napalm_base.helpers.ip, hop_addr, hop_addr)

@inetuid
Copy link
Contributor Author

inetuid commented Oct 21, 2016

Changes made.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.08%) to 79.639% when pulling 417ca00 on inetuid:develop into 1f0b976 on napalm-automation:develop.

@mirceaulinic mirceaulinic merged commit 6f3d099 into napalm-automation:develop Oct 24, 2016
@mirceaulinic mirceaulinic modified the milestones: 0.4.0, 0.4.1 Oct 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants