mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
tests: Adapted installation methods to utilize methods from tasks
Master and replica installation methods were made to utilize corresponding methods from tasks.py for the sake of DRY Reviewed-By: David Kupka <dkupka@redhat.com>
This commit is contained in:
parent
725d8d0cac
commit
fad6ec8256
@ -32,6 +32,7 @@ from ipaplatform.paths import paths
|
|||||||
from ipapython.dn import DN
|
from ipapython.dn import DN
|
||||||
from ipatests.test_integration.base import IntegrationTest
|
from ipatests.test_integration.base import IntegrationTest
|
||||||
from ipatests.test_integration import tasks
|
from ipatests.test_integration import tasks
|
||||||
|
from ipalib.constants import DOMAIN_LEVEL_0
|
||||||
|
|
||||||
_DEFAULT = object()
|
_DEFAULT = object()
|
||||||
|
|
||||||
@ -120,16 +121,16 @@ class CALessBase(IntegrationTest):
|
|||||||
client_hostname = cls.clients[0].hostname
|
client_hostname = cls.clients[0].hostname
|
||||||
else:
|
else:
|
||||||
client_hostname = 'unused-client.test'
|
client_hostname = 'unused-client.test'
|
||||||
env = {
|
cls.env = {
|
||||||
'domain': cls.master.domain.name,
|
'domain': cls.master.domain.name,
|
||||||
'server1': cls.master.hostname,
|
'server1': cls.master.hostname,
|
||||||
'server2': replica_hostname,
|
'server2': replica_hostname,
|
||||||
'client': client_hostname,
|
'client': client_hostname,
|
||||||
'dbdir': 'nssdb',
|
'dbdir': 'nssdb',
|
||||||
'dbpassword': cls.cert_password,
|
|
||||||
'crl_path': cls.crl_path,
|
'crl_path': cls.crl_path,
|
||||||
|
'dirman_password': cls.master.config.dirman_password,
|
||||||
}
|
}
|
||||||
ipautil.run(['bash', '-ex', scriptfile], cwd=cls.cert_dir, env=env)
|
ipautil.run(['bash', '-ex', scriptfile], cwd=cls.cert_dir, env=cls.env)
|
||||||
|
|
||||||
for host in cls.get_all_hosts():
|
for host in cls.get_all_hosts():
|
||||||
tasks.apply_common_fixes(host)
|
tasks.apply_common_fixes(host)
|
||||||
@ -145,7 +146,8 @@ class CALessBase(IntegrationTest):
|
|||||||
def uninstall(cls, mh):
|
def uninstall(cls, mh):
|
||||||
# Remove the NSS database
|
# Remove the NSS database
|
||||||
shutil.rmtree(cls.cert_dir)
|
shutil.rmtree(cls.cert_dir)
|
||||||
|
for host in cls.get_all_hosts():
|
||||||
|
tasks.uninstall_master(host)
|
||||||
super(CALessBase, cls).uninstall(mh)
|
super(CALessBase, cls).uninstall(mh)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -165,7 +167,7 @@ class CALessBase(IntegrationTest):
|
|||||||
http_pin = cls.cert_password
|
http_pin = cls.cert_password
|
||||||
if dirsrv_pin is _DEFAULT:
|
if dirsrv_pin is _DEFAULT:
|
||||||
dirsrv_pin = cls.cert_password
|
dirsrv_pin = cls.cert_password
|
||||||
|
tasks.prepare_host(host)
|
||||||
files_to_copy = ['root.pem']
|
files_to_copy = ['root.pem']
|
||||||
if http_pkcs12_exists:
|
if http_pkcs12_exists:
|
||||||
files_to_copy.append(http_pkcs12)
|
files_to_copy.append(http_pkcs12)
|
||||||
@ -174,51 +176,36 @@ class CALessBase(IntegrationTest):
|
|||||||
for filename in set(files_to_copy):
|
for filename in set(files_to_copy):
|
||||||
cls.copy_cert(host, filename)
|
cls.copy_cert(host, filename)
|
||||||
|
|
||||||
host.collect_log(paths.IPASERVER_INSTALL_LOG)
|
# Remove existing ca certs from default database to avoid conflicts
|
||||||
host.collect_log(paths.IPACLIENT_INSTALL_LOG)
|
args = [paths.CERTUTIL, "-D", "-d", "/etc/httpd/alias", "-n"]
|
||||||
inst = host.domain.realm.replace('.', '-')
|
host.run_command(args + ["ca1"], raiseonerr=False)
|
||||||
host.collect_log(paths.SLAPD_INSTANCE_ERROR_LOG_TEMPLATE % inst)
|
host.run_command(args + ["ca1/server"], raiseonerr=False)
|
||||||
host.collect_log(paths.SLAPD_INSTANCE_ACCESS_LOG_TEMPLATE % inst)
|
|
||||||
|
|
||||||
args = [
|
extra_args = ['--http-cert-file', http_pkcs12,
|
||||||
'ipa-server-install',
|
'--dirsrv-cert-file', dirsrv_pkcs12,
|
||||||
'--http-cert-file', http_pkcs12,
|
'--ca-cert-file', root_ca_file,
|
||||||
'--dirsrv-cert-file', dirsrv_pkcs12,
|
'--ip-address', host.ip]
|
||||||
'--ca-cert-file', root_ca_file,
|
|
||||||
'--ip-address', host.ip,
|
|
||||||
'-r', host.domain.name,
|
|
||||||
'-p', host.config.dirman_password,
|
|
||||||
'-a', host.config.admin_password,
|
|
||||||
'--setup-dns',
|
|
||||||
'--forwarder', host.config.dns_forwarder,
|
|
||||||
]
|
|
||||||
|
|
||||||
if http_pin is not None:
|
if http_pin is not None:
|
||||||
args.extend(['--http-pin', http_pin])
|
extra_args.extend(['--http-pin', http_pin])
|
||||||
if dirsrv_pin is not None:
|
if dirsrv_pin is not None:
|
||||||
args.extend(['--dirsrv-pin', dirsrv_pin])
|
extra_args.extend(['--dirsrv-pin', dirsrv_pin])
|
||||||
if unattended:
|
return tasks.install_master(host, extra_args=extra_args,
|
||||||
args.extend(['-U'])
|
unattended=unattended,
|
||||||
|
stdin_text=stdin_text,
|
||||||
return host.run_command(args, raiseonerr=False, stdin_text=stdin_text)
|
raiseonerr=False)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def copy_cert(cls, host, filename):
|
def copy_cert(cls, host, filename):
|
||||||
host.transport.put_file(os.path.join(cls.cert_dir, filename),
|
host.transport.put_file(os.path.join(cls.cert_dir, filename),
|
||||||
os.path.join(host.config.test_dir, filename))
|
os.path.join(host.config.test_dir, filename))
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def uninstall_server(self, host=None):
|
|
||||||
if host is None:
|
|
||||||
host = self.master
|
|
||||||
host.run_command(['ipa-server-install', '--uninstall', '-U'])
|
|
||||||
|
|
||||||
def prepare_replica(self, _replica_number=0, replica=None, master=None,
|
def prepare_replica(self, _replica_number=0, replica=None, master=None,
|
||||||
http_pkcs12='replica.p12', dirsrv_pkcs12='replica.p12',
|
http_pkcs12='replica.p12', dirsrv_pkcs12='replica.p12',
|
||||||
http_pkcs12_exists=True, dirsrv_pkcs12_exists=True,
|
http_pkcs12_exists=True, dirsrv_pkcs12_exists=True,
|
||||||
http_pin=_DEFAULT, dirsrv_pin=_DEFAULT,
|
http_pin=_DEFAULT, dirsrv_pin=_DEFAULT,
|
||||||
root_ca_file='root.pem', unattended=True,
|
root_ca_file='root.pem', unattended=True,
|
||||||
stdin_text=None):
|
stdin_text=None, domain_level=None):
|
||||||
"""Prepare a CA-less replica
|
"""Prepare a CA-less replica
|
||||||
|
|
||||||
Puts the bundle file into test_dir on the replica if successful,
|
Puts the bundle file into test_dir on the replica if successful,
|
||||||
@ -234,78 +221,55 @@ class CALessBase(IntegrationTest):
|
|||||||
http_pin = self.cert_password
|
http_pin = self.cert_password
|
||||||
if dirsrv_pin is _DEFAULT:
|
if dirsrv_pin is _DEFAULT:
|
||||||
dirsrv_pin = self.cert_password
|
dirsrv_pin = self.cert_password
|
||||||
|
if domain_level is None:
|
||||||
|
domain_level = tasks.domainlevel(master)
|
||||||
files_to_copy = ['root.pem']
|
files_to_copy = ['root.pem']
|
||||||
if http_pkcs12_exists:
|
if http_pkcs12_exists:
|
||||||
files_to_copy.append(http_pkcs12)
|
files_to_copy.append(http_pkcs12)
|
||||||
if dirsrv_pkcs12_exists:
|
if dirsrv_pkcs12_exists:
|
||||||
files_to_copy.append(dirsrv_pkcs12)
|
files_to_copy.append(dirsrv_pkcs12)
|
||||||
for filename in set(files_to_copy):
|
if domain_level == DOMAIN_LEVEL_0:
|
||||||
master.transport.put_file(
|
destination_host = master
|
||||||
os.path.join(self.cert_dir, filename),
|
|
||||||
os.path.join(master.config.test_dir, filename))
|
|
||||||
|
|
||||||
replica.collect_log(paths.IPAREPLICA_INSTALL_LOG)
|
|
||||||
replica.collect_log(paths.IPACLIENT_INSTALL_LOG)
|
|
||||||
inst = replica.domain.realm.replace('.', '-')
|
|
||||||
replica.collect_log(paths.SLAPD_INSTANCE_ERROR_LOG_TEMPLATE % inst)
|
|
||||||
replica.collect_log(paths.SLAPD_INSTANCE_ACCESS_LOG_TEMPLATE % inst)
|
|
||||||
|
|
||||||
args = [
|
|
||||||
'ipa-replica-prepare',
|
|
||||||
'--ip-address', replica.ip,
|
|
||||||
'-p', replica.config.dirman_password,
|
|
||||||
]
|
|
||||||
|
|
||||||
if http_pkcs12:
|
|
||||||
args.extend(['--http-cert-file', http_pkcs12])
|
|
||||||
if dirsrv_pkcs12:
|
|
||||||
args.extend(['--dirsrv-cert-file', dirsrv_pkcs12])
|
|
||||||
if http_pin is not None:
|
|
||||||
args.extend(['--http-pin', http_pin])
|
|
||||||
if dirsrv_pin is not None:
|
|
||||||
args.extend(['--dirsrv-pin', dirsrv_pin])
|
|
||||||
|
|
||||||
args.extend([replica.hostname])
|
|
||||||
|
|
||||||
result = master.run_command(args, raiseonerr=False,
|
|
||||||
stdin_text=stdin_text)
|
|
||||||
|
|
||||||
if result.returncode == 0:
|
|
||||||
replica_bundle = master.get_file_contents(
|
|
||||||
paths.REPLICA_INFO_GPG_TEMPLATE % replica.hostname)
|
|
||||||
replica.put_file_contents(self.get_replica_filename(replica),
|
|
||||||
replica_bundle)
|
|
||||||
else:
|
else:
|
||||||
replica.run_command(['rm', self.get_replica_filename(replica)],
|
destination_host = replica
|
||||||
raiseonerr=False)
|
# Both master and replica lack ipatests folder by this time, so we need
|
||||||
|
# to re-create it
|
||||||
|
tasks.prepare_host(master)
|
||||||
|
tasks.prepare_host(replica)
|
||||||
|
for filename in set(files_to_copy):
|
||||||
|
try:
|
||||||
|
destination_host.transport.put_file(
|
||||||
|
os.path.join(self.cert_dir, filename),
|
||||||
|
os.path.join(destination_host.config.test_dir, filename))
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
extra_args = []
|
||||||
|
if http_pkcs12_exists:
|
||||||
|
extra_args.extend(['--http-cert-file', http_pkcs12])
|
||||||
|
if dirsrv_pkcs12_exists:
|
||||||
|
extra_args.extend(['--dirsrv-cert-file', dirsrv_pkcs12])
|
||||||
|
|
||||||
|
if http_pin is not None:
|
||||||
|
extra_args.extend(['--http-pin', http_pin])
|
||||||
|
if dirsrv_pin is not None:
|
||||||
|
extra_args.extend(['--dirsrv-pin', dirsrv_pin])
|
||||||
|
if domain_level == DOMAIN_LEVEL_0:
|
||||||
|
result = tasks.replica_prepare(master, replica,
|
||||||
|
extra_args=extra_args,
|
||||||
|
raiseonerr=False,
|
||||||
|
stdin_text=stdin_text)
|
||||||
|
else:
|
||||||
|
result = tasks.install_replica(master, replica, setup_ca=False,
|
||||||
|
extra_args=extra_args,
|
||||||
|
unattended=unattended,
|
||||||
|
stdin_text=stdin_text,
|
||||||
|
raiseonerr=False)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get_replica_filename(self, replica):
|
def get_replica_filename(self, replica):
|
||||||
return os.path.join(replica.config.test_dir,
|
return os.path.join(replica.config.test_dir,
|
||||||
'replica-info.gpg')
|
'replica-info.gpg')
|
||||||
|
|
||||||
def install_replica(self, _replica_number=0, replica=None,
|
|
||||||
unattended=True):
|
|
||||||
"""Install a CA-less replica
|
|
||||||
|
|
||||||
The bundle file is expected to be in the test_dir
|
|
||||||
|
|
||||||
Return value is the remote ipa-replica-install command
|
|
||||||
"""
|
|
||||||
if replica is None:
|
|
||||||
replica = self.replicas[_replica_number]
|
|
||||||
|
|
||||||
args = ['ipa-replica-install', '-U',
|
|
||||||
'-p', replica.config.dirman_password,
|
|
||||||
'-w', replica.config.admin_password,
|
|
||||||
'--ip-address', replica.ip,
|
|
||||||
self.get_replica_filename(replica)]
|
|
||||||
if unattended:
|
|
||||||
args.append('-U')
|
|
||||||
return replica.run_command(args)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def export_pkcs12(cls, nickname, filename='server.p12', password=None):
|
def export_pkcs12(cls, nickname, filename='server.p12', password=None):
|
||||||
"""Export a cert as PKCS#12 to the given file"""
|
"""Export a cert as PKCS#12 to the given file"""
|
||||||
|
Loading…
Reference in New Issue
Block a user