Ejemplo n.º 1
0
def validate_and_normalize_mac(address):
    """Validate a MAC address and return normalized form.

    Checks whether the supplied MAC address is formally correct and
    normalize it to all lower case.

    :param address: MAC address to be validated and normalized.
    :returns: Normalized and validated MAC address.
    :raises: InvalidMAC If the MAC address is not valid.

    """
    if not netutils.is_valid_mac(address):
        raise exception.InvalidMAC(mac=address)
    return address.lower()
Ejemplo n.º 2
0
 def test_InvalidMAC(self):
     self.assertRaises(exception.InvalidMAC,
                       lambda: self.raise_(exception.InvalidMAC()))