Abstract procedures for IP address warnings

Originaly there should be only two occurencees of this warning, one for
server, one for client. But obviously is not possible with current
installers to achive this goal, so I have to extract code to not mess
with 5 times copy and paste.

https://fedorahosted.org/freeipa/ticket/5814

Reviewed-By: David Kupka <dkupka@redhat.com>
This commit is contained in:
Martin Basti 2016-09-12 14:38:12 +02:00 committed by David Kupka
parent 271a4f0982
commit 1c96ff7a6c
4 changed files with 46 additions and 70 deletions

View File

@ -55,7 +55,9 @@ try:
from ipalib import api, errors from ipalib import api, errors
from ipalib import x509, certstore from ipalib import x509, certstore
from ipalib.util import ( from ipalib.util import (
normalize_hostname, validate_domain_name, verify_host_resolvable) normalize_hostname, validate_domain_name, verify_host_resolvable,
network_ip_address_warning, broadcast_ip_address_warning
)
from ipalib.constants import CACERT from ipalib.constants import CACERT
from ipapython.dn import DN from ipapython.dn import DN
from ipapython.ssh import SSHPublicKey from ipapython.ssh import SSHPublicKey
@ -1651,19 +1653,8 @@ def update_dns(server, hostname, options):
root_logger.info("Failed to determine this machine's ip address(es).") root_logger.info("Failed to determine this machine's ip address(es).")
return return
for ip in update_ips: network_ip_address_warning(update_ips)
if ip.is_network_addr(): broadcast_ip_address_warning(update_ips)
root_logger.warning("IP address %s might be network address", ip)
# fixme: once when loggers will be fixed, we can remove this print
print(
"WARNING: IP address {} might be network address".format(ip),
file=sys.stderr)
if ip.is_broadcast_addr():
root_logger.warning("IP address %s might be broadcast address", ip)
# fixme: once when loggers will be fixed, we can remove this print
print(
"WARNING: IP address {} might be broadcast address".format(ip),
file=sys.stderr)
update_txt = "debug\n" update_txt = "debug\n"
update_txt += ipautil.template_str(DELETE_TEMPLATE_A, update_txt += ipautil.template_str(DELETE_TEMPLATE_A,

View File

@ -21,7 +21,10 @@
Various utility functions. Various utility functions.
""" """
from __future__ import absolute_import from __future__ import (
absolute_import,
print_function,
)
import os import os
import socket import socket
@ -29,6 +32,7 @@ import re
import decimal import decimal
import dns import dns
import encodings import encodings
import sys
from weakref import WeakKeyDictionary from weakref import WeakKeyDictionary
import netaddr import netaddr
@ -45,6 +49,7 @@ from ipapython.ssh import SSHPublicKey
from ipapython.dn import DN, RDN from ipapython.dn import DN, RDN
from ipapython.dnsutil import DNSName from ipapython.dnsutil import DNSName
from ipapython.dnsutil import resolve_ip_addresses from ipapython.dnsutil import resolve_ip_addresses
from ipapython.ipa_log_manager import root_logger
if six.PY3: if six.PY3:
unicode = str unicode = str
@ -994,3 +999,23 @@ def check_principal_realm_in_trust_namespace(api_instance, *keys):
name='krbprincipalname', name='krbprincipalname',
error=_('realm or UPN suffix overlaps with trusted domain ' error=_('realm or UPN suffix overlaps with trusted domain '
'namespace')) 'namespace'))
def network_ip_address_warning(addr_list):
for ip in addr_list:
if ip.is_network_addr():
root_logger.warning("IP address %s might be network address", ip)
# fixme: once when loggers will be fixed, we can remove this
# print
print("WARNING: IP address {} might be network address".format(ip),
file=sys.stderr)
def broadcast_ip_address_warning(addr_list):
for ip in addr_list:
if ip.is_broadcast_addr():
root_logger.warning("IP address %s might be broadcast address", ip)
# fixme: once when loggers will be fixed, we can remove this
# print
print("WARNING: IP address {} might be broadcast address".format(
ip), file=sys.stderr)

View File

@ -31,7 +31,11 @@ from ipaplatform.paths import paths
from ipaplatform.tasks import tasks from ipaplatform.tasks import tasks
from ipalib import api, constants, errors, x509 from ipalib import api, constants, errors, x509
from ipalib.constants import CACERT from ipalib.constants import CACERT
from ipalib.util import validate_domain_name from ipalib.util import (
validate_domain_name,
network_ip_address_warning,
broadcast_ip_address_warning,
)
import ipaclient.ntpconf import ipaclient.ntpconf
from ipaserver.install import ( from ipaserver.install import (
bindinstance, ca, cainstance, certs, dns, dsinstance, bindinstance, ca, cainstance, certs, dns, dsinstance,
@ -609,19 +613,8 @@ def install_check(installer):
not installer.interactive, False, not installer.interactive, False,
options.ip_addresses) options.ip_addresses)
for ip in ip_addresses: network_ip_address_warning(ip_addresses)
if ip.is_network_addr(): broadcast_ip_address_warning(ip_addresses)
root_logger.warning("IP address %s might be network address", ip)
# fixme: once when loggers will be fixed, we can remove this print
print(
"WARNING: IP address {} might be network address".format(ip),
file=sys.stderr)
if ip.is_broadcast_addr():
root_logger.warning("IP address %s might be broadcast address", ip)
# fixme: once when loggers will be fixed, we can remove this print
print(
"WARNING: IP address {} might be broadcast address".format(ip),
file=sys.stderr)
# installer needs to update hosts file when DNS subsystem will be # installer needs to update hosts file when DNS subsystem will be
# installed or custom addresses are used # installed or custom addresses are used

View File

@ -13,7 +13,6 @@ import dns.reversename as dnsreversename
import os import os
import shutil import shutil
import socket import socket
import sys
import tempfile import tempfile
import six import six
@ -28,6 +27,10 @@ from ipaplatform import services
from ipaplatform.tasks import tasks from ipaplatform.tasks import tasks
from ipaplatform.paths import paths from ipaplatform.paths import paths
from ipalib import api, certstore, constants, create_api, errors, rpc, x509 from ipalib import api, certstore, constants, create_api, errors, rpc, x509
from ipalib.util import (
network_ip_address_warning,
broadcast_ip_address_warning,
)
import ipaclient.ipachangeconf import ipaclient.ipachangeconf
import ipaclient.ntpconf import ipaclient.ntpconf
from ipaserver.install import ( from ipaserver.install import (
@ -736,27 +739,8 @@ def install_check(installer):
config.host_name, not installer.interactive, False, config.host_name, not installer.interactive, False,
options.ip_addresses) options.ip_addresses)
for ip in config.ips: network_ip_address_warning(config.ips)
if ip.is_network_addr(): broadcast_ip_address_warning(config.ips)
root_logger.warning(
"IP address %s might be network address", ip)
# fixme: once when loggers will be fixed, we can remove this
# print
print(
"WARNING: IP address {} might be network address".format(
ip),
file=sys.stderr
)
if ip.is_broadcast_addr():
root_logger.warning(
"IP address %s might be broadcast address", ip)
# fixme: once when loggers will be fixed, we can remove this
# print
print(
"WARNING: IP address {} might be broadcast address".format(
ip),
file=sys.stderr
)
except errors.ACIError: except errors.ACIError:
raise ScriptError("\nThe password provided is incorrect for LDAP server " raise ScriptError("\nThe password provided is incorrect for LDAP server "
@ -1329,25 +1313,8 @@ def promote_check(installer):
config.host_name, not installer.interactive, config.host_name, not installer.interactive,
False, options.ip_addresses) False, options.ip_addresses)
for ip in config.ips: network_ip_address_warning(config.ips)
if ip.is_network_addr(): broadcast_ip_address_warning(config.ips)
root_logger.warning(
"IP address %s might be network address", ip)
# fixme: once when loggers will be fixed, we can remove this
# print
print(
"WARNING: IP address {} might be network address".format(
ip), file=sys.stderr
)
if ip.is_broadcast_addr():
root_logger.warning(
"IP address %s might be broadcast address", ip)
# fixme: once when loggers will be fixed, we can remove this
# print
print(
"WARNING: IP address {} might be broadcast address".format(
ip), file=sys.stderr
)
except errors.ACIError: except errors.ACIError:
raise ScriptError("\nInsufficient privileges to promote the server.") raise ScriptError("\nInsufficient privileges to promote the server.")