mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
ipatests: configure Network Manager not to manage resolv.conf
For the duration of the test, makes resolv.conf unmanaged. If NetworkManager is not running, nothing is changed. https://fedorahosted.org/freeipa/ticket/5331 Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
committed by
Martin Basti
parent
14977b5d84
commit
c22c60b87c
@@ -354,6 +354,6 @@ class BasePathNamespace(object):
|
||||
DB2BAK = '/usr/sbin/db2bak'
|
||||
KDCPROXY_CONFIG = '/etc/ipa/kdcproxy/kdcproxy.conf'
|
||||
CERTMONGER = '/usr/sbin/certmonger'
|
||||
|
||||
NETWORK_MANAGER_CONFIG_DIR = '/etc/NetworkManager/conf.d'
|
||||
|
||||
path_namespace = BasePathNamespace
|
||||
|
||||
@@ -41,6 +41,8 @@ from ipalib.util import get_reverse_zone_default
|
||||
|
||||
log = log_mgr.get_logger(__name__)
|
||||
|
||||
IPATEST_NM_CONFIG = '20-ipatest-unmanaged-resolv.conf'
|
||||
|
||||
|
||||
def check_arguments_are(slice, instanceof):
|
||||
"""
|
||||
@@ -80,6 +82,7 @@ def prepare_host(host):
|
||||
def apply_common_fixes(host):
|
||||
fix_etc_hosts(host)
|
||||
fix_hostname(host)
|
||||
modify_nm_resolv_conf_settings(host)
|
||||
fix_resolv_conf(host)
|
||||
|
||||
|
||||
@@ -125,6 +128,38 @@ def fix_hostname(host):
|
||||
host.run_command('hostname > %s' % ipautil.shell_quote(backupname))
|
||||
|
||||
|
||||
def host_service_active(host, service):
|
||||
res = host.run_command(['systemctl', 'is-active', '--quiet', service],
|
||||
raiseonerr=False)
|
||||
|
||||
if res.returncode == 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def modify_nm_resolv_conf_settings(host):
|
||||
if not host_service_active(host, 'NetworkManager'):
|
||||
return
|
||||
|
||||
config = "[main]\ndns=none\n"
|
||||
path = os.path.join(paths.NETWORK_MANAGER_CONFIG_DIR, IPATEST_NM_CONFIG)
|
||||
|
||||
host.put_file_contents(path, config)
|
||||
host.run_command(['systemctl', 'restart', 'NetworkManager'],
|
||||
raiseonerr=False)
|
||||
|
||||
|
||||
def undo_nm_resolv_conf_settings(host):
|
||||
if not host_service_active(host, 'NetworkManager'):
|
||||
return
|
||||
|
||||
path = os.path.join(paths.NETWORK_MANAGER_CONFIG_DIR, IPATEST_NM_CONFIG)
|
||||
host.run_command(['rm', '-f', path], raiseonerr=False)
|
||||
host.run_command(['systemctl', 'restart', 'NetworkManager'],
|
||||
raiseonerr=False)
|
||||
|
||||
|
||||
def fix_resolv_conf(host):
|
||||
backup_file(host, paths.RESOLV_CONF)
|
||||
lines = host.get_file_contents(paths.RESOLV_CONF).splitlines()
|
||||
@@ -153,6 +188,7 @@ def fix_apache_semaphores(master):
|
||||
def unapply_fixes(host):
|
||||
restore_files(host)
|
||||
restore_hostname(host)
|
||||
undo_nm_resolv_conf_settings(host)
|
||||
|
||||
# Clean up the test directory
|
||||
host.run_command(['rm', '-rvf', host.config.test_dir])
|
||||
|
||||
Reference in New Issue
Block a user