CheckedIPAddress: remove match_local param

This parameter is unused in code. We are no longer testing if IP address
matches an interface in constructor.

https://pagure.io/freeipa/issue/4317

Reviewed-By: David Kupka <dkupka@redhat.com>
This commit is contained in:
Martin Basti 2017-06-14 14:54:43 +02:00 committed by David Kupka
parent 0b69e44f16
commit 6024165101
6 changed files with 9 additions and 18 deletions

View File

@ -68,10 +68,9 @@ class IPAFormatter(IndentedHelpFormatter):
def check_ip_option(option, opt, value): def check_ip_option(option, opt, value):
from ipapython.ipautil import CheckedIPAddress from ipapython.ipautil import CheckedIPAddress
ip_local = option.ip_local is True
ip_netmask = option.ip_netmask is True ip_netmask = option.ip_netmask is True
try: try:
return CheckedIPAddress(value, parse_netmask=ip_netmask, match_local=ip_local) return CheckedIPAddress(value, parse_netmask=ip_netmask)
except Exception as e: except Exception as e:
raise OptionValueError("option %s: invalid IP address %s: %s" % (opt, value, e)) raise OptionValueError("option %s: invalid IP address %s: %s" % (opt, value, e))
@ -86,7 +85,7 @@ class IPAOption(Option):
optparse.Option subclass with support of options labeled as optparse.Option subclass with support of options labeled as
security-sensitive such as passwords. security-sensitive such as passwords.
""" """
ATTRS = Option.ATTRS + ["sensitive", "ip_local", "ip_netmask"] ATTRS = Option.ATTRS + ["sensitive", "ip_netmask"]
TYPES = Option.TYPES + ("ip", "dn") TYPES = Option.TYPES + ("ip", "dn")
TYPE_CHECKER = copy(Option.TYPE_CHECKER) TYPE_CHECKER = copy(Option.TYPE_CHECKER)
TYPE_CHECKER["ip"] = check_ip_option TYPE_CHECKER["ip"] = check_ip_option

View File

@ -135,7 +135,7 @@ class CheckedIPAddress(UnsafeIPAddress):
Reserved or link-local addresses are never accepted. Reserved or link-local addresses are never accepted.
""" """
def __init__(self, addr, match_local=False, parse_netmask=True, def __init__(self, addr, parse_netmask=True,
allow_loopback=False, allow_multicast=False): allow_loopback=False, allow_multicast=False):
try: try:
super(CheckedIPAddress, self).__init__(addr) super(CheckedIPAddress, self).__init__(addr)
@ -166,14 +166,6 @@ class CheckedIPAddress(UnsafeIPAddress):
if not allow_multicast and self.is_multicast(): if not allow_multicast and self.is_multicast():
raise ValueError("cannot use multicast IP address {}".format(addr)) raise ValueError("cannot use multicast IP address {}".format(addr))
if match_local:
intf_details = self.get_matching_interface()
if not intf_details:
raise ValueError('no network interface matches the IP address '
'and netmask {}'.format(addr))
else:
self.set_ip_net(intf_details.ifnet)
if self._net is None: if self._net is None:
if self.version == 4: if self.version == 4:
self._net = netaddr.IPNetwork( self._net = netaddr.IPNetwork(

View File

@ -590,7 +590,7 @@ def get_server_ip_address(host_name, unattended, setup_dns, ip_addresses):
if len(hostaddr): if len(hostaddr):
for ha in hostaddr: for ha in hostaddr:
try: try:
ips.append(ipautil.CheckedIPAddress(ha, match_local=False)) ips.append(ipautil.CheckedIPAddress(ha))
except ValueError as e: except ValueError as e:
root_logger.warning("Invalid IP address %s for %s: %s", ha, host_name, unicode(e)) root_logger.warning("Invalid IP address %s for %s: %s", ha, host_name, unicode(e))

View File

@ -567,7 +567,7 @@ def add_records_for_host_validation(option_name, host, domain, ip_addresses, che
for ip_address in ip_addresses: for ip_address in ip_addresses:
try: try:
ip = CheckedIPAddress( ip = CheckedIPAddress(
ip_address, match_local=False, allow_multicast=True) ip_address, allow_multicast=True)
except Exception as e: except Exception as e:
raise errors.ValidationError(name=option_name, error=unicode(e)) raise errors.ValidationError(name=option_name, error=unicode(e))
@ -599,7 +599,7 @@ def add_records_for_host(host, domain, ip_addresses, add_forward=True, add_rever
for ip_address in ip_addresses: for ip_address in ip_addresses:
ip = CheckedIPAddress( ip = CheckedIPAddress(
ip_address, match_local=False, allow_multicast=True) ip_address, allow_multicast=True)
if add_forward: if add_forward:
add_forward_record(domain, host, unicode(ip)) add_forward_record(domain, host, unicode(ip))

View File

@ -245,7 +245,7 @@ def validate_ipaddr(ugettext, ipaddr):
Verify that we have either an IPv4 or IPv6 address. Verify that we have either an IPv4 or IPv6 address.
""" """
try: try:
CheckedIPAddress(ipaddr, match_local=False) CheckedIPAddress(ipaddr)
except Exception as e: except Exception as e:
return unicode(e) return unicode(e)
return None return None

View File

@ -64,9 +64,9 @@ pytestmark = pytest.mark.tier0
def test_ip_address(addr, words, prefixlen): def test_ip_address(addr, words, prefixlen):
if words is None: if words is None:
pytest.raises( pytest.raises(
ValueError, ipautil.CheckedIPAddress, addr, match_local=False) ValueError, ipautil.CheckedIPAddress, addr)
else: else:
ip = ipautil.CheckedIPAddress(addr, match_local=False) ip = ipautil.CheckedIPAddress(addr)
assert ip.words == words assert ip.words == words
assert ip.prefixlen == prefixlen assert ip.prefixlen == prefixlen