From 6024165101677c844dc3bbb337e290df2e66eaf1 Mon Sep 17 00:00:00 2001 From: Martin Basti Date: Jun 20 2017 09:29:41 +0000 Subject: 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 --- diff --git a/ipapython/config.py b/ipapython/config.py index 9db2dcd..6349892 100644 --- a/ipapython/config.py +++ b/ipapython/config.py @@ -68,10 +68,9 @@ class IPAFormatter(IndentedHelpFormatter): def check_ip_option(option, opt, value): from ipapython.ipautil import CheckedIPAddress - ip_local = option.ip_local is True ip_netmask = option.ip_netmask is True try: - return CheckedIPAddress(value, parse_netmask=ip_netmask, match_local=ip_local) + return CheckedIPAddress(value, parse_netmask=ip_netmask) except Exception as 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 security-sensitive such as passwords. """ - ATTRS = Option.ATTRS + ["sensitive", "ip_local", "ip_netmask"] + ATTRS = Option.ATTRS + ["sensitive", "ip_netmask"] TYPES = Option.TYPES + ("ip", "dn") TYPE_CHECKER = copy(Option.TYPE_CHECKER) TYPE_CHECKER["ip"] = check_ip_option diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py index 2c020e3..5a6bf5a 100644 --- a/ipapython/ipautil.py +++ b/ipapython/ipautil.py @@ -135,7 +135,7 @@ class CheckedIPAddress(UnsafeIPAddress): 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): try: super(CheckedIPAddress, self).__init__(addr) @@ -166,14 +166,6 @@ class CheckedIPAddress(UnsafeIPAddress): if not allow_multicast and self.is_multicast(): 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.version == 4: self._net = netaddr.IPNetwork( diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py index 5f4bf15..5f7a346 100644 --- a/ipaserver/install/installutils.py +++ b/ipaserver/install/installutils.py @@ -590,7 +590,7 @@ def get_server_ip_address(host_name, unattended, setup_dns, ip_addresses): if len(hostaddr): for ha in hostaddr: try: - ips.append(ipautil.CheckedIPAddress(ha, match_local=False)) + ips.append(ipautil.CheckedIPAddress(ha)) except ValueError as e: root_logger.warning("Invalid IP address %s for %s: %s", ha, host_name, unicode(e)) diff --git a/ipaserver/plugins/dns.py b/ipaserver/plugins/dns.py index b075f0b..38747c0 100644 --- a/ipaserver/plugins/dns.py +++ b/ipaserver/plugins/dns.py @@ -567,7 +567,7 @@ def add_records_for_host_validation(option_name, host, domain, ip_addresses, che for ip_address in ip_addresses: try: ip = CheckedIPAddress( - ip_address, match_local=False, allow_multicast=True) + ip_address, allow_multicast=True) except Exception as 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: ip = CheckedIPAddress( - ip_address, match_local=False, allow_multicast=True) + ip_address, allow_multicast=True) if add_forward: add_forward_record(domain, host, unicode(ip)) diff --git a/ipaserver/plugins/host.py b/ipaserver/plugins/host.py index 1e1f9d8..364e5be 100644 --- a/ipaserver/plugins/host.py +++ b/ipaserver/plugins/host.py @@ -245,7 +245,7 @@ def validate_ipaddr(ugettext, ipaddr): Verify that we have either an IPv4 or IPv6 address. """ try: - CheckedIPAddress(ipaddr, match_local=False) + CheckedIPAddress(ipaddr) except Exception as e: return unicode(e) return None diff --git a/ipatests/test_ipapython/test_ipautil.py b/ipatests/test_ipapython/test_ipautil.py index 409cf2d..75011d5 100644 --- a/ipatests/test_ipapython/test_ipautil.py +++ b/ipatests/test_ipapython/test_ipautil.py @@ -64,9 +64,9 @@ pytestmark = pytest.mark.tier0 def test_ip_address(addr, words, prefixlen): if words is None: pytest.raises( - ValueError, ipautil.CheckedIPAddress, addr, match_local=False) + ValueError, ipautil.CheckedIPAddress, addr) else: - ip = ipautil.CheckedIPAddress(addr, match_local=False) + ip = ipautil.CheckedIPAddress(addr) assert ip.words == words assert ip.prefixlen == prefixlen