From bbb86e36aaefeaf12af33efbc71255a95d2c0312 Mon Sep 17 00:00:00 2001 From: Krzysztof Klimonda Date: Tue, 17 Apr 2012 00:25:57 +0200 Subject: [PATCH] move check_inst out of bindinstance.py create a new platform utils module which imports a proper implementation from platform.PLATFORM.instances.utils. Move the current check_inst to the fedora16 package and create debian implementation which uses dpkg-query to check for bind9 and bind-dyndb-ldap packages. --- .../platform/base/instances/bind.py | 25 ----------- ipapython/platform/debian/instances/utils.py | 45 +++++++++++++++++++ ipapython/platform/fedora16/__init__.py | 0 .../platform/fedora16/instances/__init__.py | 0 .../platform/fedora16/instances/utils.py | 28 ++++++++++++ ipapython/platform/utils.py | 9 ++++ 6 files changed, 82 insertions(+), 25 deletions(-) rename ipaserver/install/bindinstance.py => ipapython/platform/base/instances/bind.py (95%) create mode 100644 ipapython/platform/debian/instances/utils.py create mode 100644 ipapython/platform/fedora16/__init__.py create mode 100644 ipapython/platform/fedora16/instances/__init__.py create mode 100644 ipapython/platform/fedora16/instances/utils.py create mode 100644 ipapython/platform/utils.py diff --git a/ipaserver/install/bindinstance.py b/ipapython/platform/base/instances/bind.py similarity index 95% rename from ipaserver/install/bindinstance.py rename to ipapython/platform/base/instances/bind.py index ddf549770..a1308adbd 100644 --- a/ipaserver/install/bindinstance.py +++ b/ipapython/platform/base/instances/bind.py @@ -36,31 +36,6 @@ from ipalib.constants import DNS_ZONE_REFRESH import ipalib from ipalib import api, util, errors -def check_inst(unattended): - has_bind = True - # So far this file is always present in both RHEL5 and Fedora if all the necessary - # bind packages are installed (RHEL5 requires also the pkg: caching-nameserver) - if not os.path.exists('/etc/named.rfc1912.zones'): - print "BIND was not found on this system" - print "Please install the 'bind' package and start the installation again" - has_bind = False - - # Also check for the LDAP BIND plug-in - if not os.path.exists('/usr/lib/bind/ldap.so') and \ - not os.path.exists('/usr/lib64/bind/ldap.so'): - print "The BIND LDAP plug-in was not found on this system" - print "Please install the 'bind-dyndb-ldap' package and start the installation again" - has_bind = False - - if not has_bind: - return False - - if not unattended and os.path.exists('/etc/named.conf'): - msg = "Existing BIND configuration detected, overwrite?" - return ipautil.user_input(msg, False) - - return True - def normalize_zone(zone): if zone[-1] != '.': return zone + '.' diff --git a/ipapython/platform/debian/instances/utils.py b/ipapython/platform/debian/instances/utils.py new file mode 100644 index 000000000..4055e6fbb --- /dev/null +++ b/ipapython/platform/debian/instances/utils.py @@ -0,0 +1,45 @@ +import os +import subprocess + +import ipautil + +from hashutil import md5 + +def bind_check_installation(unattended): + # files in /etc/ are not being deleted on package removal, so we can't + # rely on them to check if BIND is installed. Also, because Debian has + # switched to the multiarch filesystem layout there is no easy way + # to look for the ldap.so BIND plugin. But we can query dpkg database + # to see if both packages are installed, it actually feels like a cleaner + # solution. + dpkg_query = ['/usr/bin/dpkg-query', '-W', '-f', '${Package}'] + try: + ipautil.run(dpkg_query + ['bind'], raiseonerr=True): + except ipautil.CalledProcessError: + print "BIND was not found on this system" + print "Please install the 'bind9' package and start the installation again" + has_bind = False + + try: + ipautil.run(dpkg_query + ['bind-dyndb-ldap'], raiseonerr=True) + except ipautil.CalledProcessError: + print "The BIND LDAP plug-in was not found on this system" + print "Please install the 'bind-dyndb-ldap' package and start the installation again" + has_bind = False + + if not has_bind: + return False + + dpkg_query = ['/usr/bin/dpkg-query', '-W', '-f', '${Conffiles}'] + stdout, stderr, ret = ipautil.run(dpkg_query) + # convert dpkg-query output into a mapping fname->md5sum + conf_files = dict([p.strip().split(' ') for p in stdout.split('\n')]) + + # IPA installation modified named.local so lets check it for local changes + fname = '/etc/bind/named.local' + hash = md5.new(open(fname, 'rb').read()).digest() + if conf_files[fname] != hash: + msg = "Existing BIND configuration detected, overwrite?" + return ipautil.user_input(msg, False) + + return True diff --git a/ipapython/platform/fedora16/__init__.py b/ipapython/platform/fedora16/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/ipapython/platform/fedora16/instances/__init__.py b/ipapython/platform/fedora16/instances/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/ipapython/platform/fedora16/instances/utils.py b/ipapython/platform/fedora16/instances/utils.py new file mode 100644 index 000000000..b2b77b650 --- /dev/null +++ b/ipapython/platform/fedora16/instances/utils.py @@ -0,0 +1,28 @@ +import os + +import ipautil + +def bind_check_installation(unattended): + has_bind = True + # So far this file is always present in both RHEL5 and Fedora if all the necessary + # bind packages are installed (RHEL5 requires also the pkg: caching-nameserver) + if not os.path.exists('/etc/named.rfc1912.zones'): + print "BIND was not found on this system" + print "Please install the 'bind' package and start the installation again" + has_bind = False + + # Also check for the LDAP BIND plug-in + if not os.path.exists('/usr/lib/bind/ldap.so') and \ + not os.path.exists('/usr/lib64/bind/ldap.so'): + print "The BIND LDAP plug-in was not found on this system" + print "Please install the 'bind-dyndb-ldap' package and start the installation again" + has_bind = False + + if not has_bind: + return False + + if not unattended and os.path.exists('/etc/named.conf'): + msg = "Existing BIND configuration detected, overwrite?" + return ipautil.user_input(msg, False) + + return True diff --git a/ipapython/platform/utils.py b/ipapython/platform/utils.py new file mode 100644 index 000000000..9ce76dab5 --- /dev/null +++ b/ipapython/platform/utils.py @@ -0,0 +1,9 @@ +"""small utils used by other instances that require platform-dependent +implementations""" + +from .SUPPORTED_PLATFORM.utils import * + +def bind_check_installation(unattended): + """checks if the bind server has been properly installed.""" + raise NotImplementedError("this function has to be implemented" + "in the platform module")