def _get_mac_address_linux(): ''' Determine the MAC address of the system. ``eth0`` has preference if it exists, otherwise the first valid MAC address in the adapter list is returned. Linux version. :return: MAC address of the system or ``None`` if a valid MAC address is not found. :rtype: str or None ''' import salt.utils.network as network # pylint: disable=import-error,3rd-party-local-module-not-gated try: interfaces = network.interfaces() # 'eth0' has preference if it exists and has a valid MAC address. if 'eth0' in interfaces: hw_addr = interfaces['eth0'].get('hwaddr') if hw_addr and hw_addr != '00:00:00:00:00:00': return hw_addr.upper() # When 'eth0' doesn't exist, pick the first interface that has a valid # MAC address. for val in six.itervalues(interfaces): hw_addr = val.get('hwaddr') if hw_addr and hw_addr != '00:00:00:00:00:00': return hw_addr.upper() except Exception: # pylint: disable=broad-except pass return None
def test_interfaces(self): ''' Test for return a dictionary of information about all the interfaces on the minion ''' with patch.object(salt.utils.network, 'interfaces', return_value={}): self.assertDictEqual(network.interfaces(), {})