napalm-automation / napalm-base

Apache License 2.0
32 stars 48 forks source link

On Juniper EX switches doesn't work retrieving of mac addresses with net.mac #245

Closed udaltsov-dm closed 7 years ago

udaltsov-dm commented 7 years ago

The code is crashing with traceback: asw04-2:

comment:
    Cannot execute "get_mac_address_table" on 44.44.44.44 as admin. Reason: failed to detect EUI version: u'*'!
out:
    ----------
result:
    False
traceback:
    Traceback (most recent call last):
      File "/var/cache/salt/minion/extmods/proxy/napalm.py", line 294, in call
        out = getattr(NETWORK_DEVICE.get('DRIVER'), method)(**params)  # calls the method with the specified parameters
      File "/usr/lib/python2.7/site-packages/napalm_junos/junos.py", line 988, in get_mac_address_table
        mac_entry['mac'] = napalm_base.helpers.mac(mac)
      File "/usr/lib/python2.7/site-packages/napalm_base/helpers.py", line 219, in mac
        return py23_compat.text_type(EUI(raw, dialect=_MACFormat))
      File "/usr/lib/python2.7/site-packages/netaddr/eui/__init__.py", line 387, in __init__
        self.value = addr
      File "/usr/lib/python2.7/site-packages/netaddr/eui/__init__.py", line 437, in _set_value
        % value)
    AddrFormatError: failed to detect EUI version: u'*'

The reason of it is following: Juniper EX switches have a mac-address which is indicate flooding capabilities for listed vlan. The simple fix should be applied in helpers.py in function mac. If we faced with mac address we should change it to something valid, for example FF:FF:FF:FF:FF:FF.

if raw.endswith(':'): flat_raw = raw.replace(':', '') raw = '{flat_raw}{zeros_stuffed}'.format( flat_raw=flat_raw, zeros_stuffed='0'*(12-len(flat_raw)) )

if raw ==u'*':
        raw= 'FF:FF:FF:FF:FF:FF'

return py23_compat.text_type(EUI(raw, dialect=_MACFormat))

ktbyers commented 7 years ago

I think it is probably more logical to fix this issue in napalm-junos.

The mac function has a pretty delimited purpose i.e. standardizing the mac-address format (converting dot-format to standardized aa:bb...format).

This issue is more of a post processing issue on Juniper.

dbarrosop commented 7 years ago

What is the purpose of that *? Could you show an example? To me, getting the mac address table and getting a wildcard sounds weird. If it's UUF we should just filter that out and don't return it.

mirceaulinic commented 7 years ago

@udaltsov-dm if you have any examples, please paste here. I have mixed feelings if this should be here (i.e. we consider that '*' means 'FF:FF:FF:FF:FF:FF' on all platforms) or under napalm-junos if that's juniper specific thing (although I didn't see anything like that previously).

udaltsov-dm commented 7 years ago

@mirceaulinic juniper switches use to indicate flooding capabilities for some vlan. Here are the example from junos ex 3300: ex-switch> show ethernet-switching table | match All Anl Flood - All-members App Flood - All-members Bulk-DATA Flood - All-members DB Flood - All-members DMZ Flood - All-members Deploy * Flood - All-members

Here the example of XML output


<mac-table-entry junos:style="brief">
    <mac-vlan>Win</mac-vlan>
    <mac-address>*</mac-address>
    <mac-type>Flood</mac-type>
    <mac-age>-</mac-age>
    <mac-interfaces-list>
    <mac-interfaces>All-members</mac-interfaces>
    </mac-interfaces-list>
</mac-table-entry>

Probably it should be filtered in somewhere to mac addresses getting from the switch.

dbarrosop commented 7 years ago

Yes, I think we should filter that out. Doesn't make much sense IMHO.

udaltsov-dm commented 7 years ago

@dbarrosop should i create a separate ticket for napalm-junos? there only 2 strokes of code should be added in get_mac_address_table function of junos.py file.

mac = mac_entry.get('mac')
if mac == u'*':
    continue
dbarrosop commented 7 years ago

yes, you can send a PR if you prefer. You seem to know what needs to be done :)

mirceaulinic commented 7 years ago

@udaltsov-dm I am closing this, please submit the PR to napalm-junos at your will. Thanks!