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.
This commit is contained in:
Krzysztof Klimonda
2012-04-17 00:25:57 +02:00
parent 2a40a5f782
commit bbb86e36aa
6 changed files with 82 additions and 25 deletions

View File

@@ -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 + '.'

View File

@@ -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

View File

View File

@@ -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

View File

@@ -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")