diff options
author | Milan KubĂk <mkubik@redhat.com> | 2015-09-25 21:09:24 +0200 |
---|---|---|
committer | Martin Basti <mbasti@redhat.com> | 2015-10-02 14:01:50 +0200 |
commit | c22c60b87c101178e5e653cada53dfdb861d1ad0 (patch) | |
tree | 9d8154cc5082b97f965c5f385e9b5d47f4784cb2 /ipatests | |
parent | 14977b5d84796c02a2c2a41f78919810cce83732 (diff) | |
download | freeipa-c22c60b87c101178e5e653cada53dfdb861d1ad0.tar.gz freeipa-c22c60b87c101178e5e653cada53dfdb861d1ad0.tar.xz freeipa-c22c60b87c101178e5e653cada53dfdb861d1ad0.zip |
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>
Diffstat (limited to 'ipatests')
-rw-r--r-- | ipatests/test_integration/tasks.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/ipatests/test_integration/tasks.py b/ipatests/test_integration/tasks.py index 63e101838..1911b17cb 100644 --- a/ipatests/test_integration/tasks.py +++ b/ipatests/test_integration/tasks.py @@ -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]) |