On 10/01/2015 12:39 PM, Alexander Bokovoy wrote:
On Thu, 01 Oct 2015, Milan Kubík wrote:
On 10/01/2015 11:23 AM, Martin Basti wrote:



On 10/01/2015 10:18 AM, Milan Kubík wrote:
On 10/01/2015 10:06 AM, Milan Kubík wrote:
Fixes https://fedorahosted.org/freeipa/ticket/5331

Patch attached.


Patch for ipa-4-2 branch.

Milan


NACK

http://fpaste.org/273499/43691381/
I disagree. From [1]:

Fedora now by default relies on NetworkManager for network configuration. This is the case also for minimal installations and server installations.

The cloud image, which you are probably using does not have NetworkManager installed. I think we can rely on the default here and assume
NetworkManager is present.

If you and the list disagree, I will make the fix depend on NetworkManager's presence. Nitpick: there can be other services that manage (and rewrite) resolv.conf.
While other tools may do it, please make it so that your fix only
activated if NetworkManager is active.

We'll get to other services once we'll encounter them.

Ok. Now I only apply the config and restart NetworkManager when it is already running. I don't check if the service is enabled.

--
Milan Kubik

From c41e5941c7d24575495b8064f6412afcecab55ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Milan=20Kub=C3=ADk?= <mku...@redhat.com>
Date: Fri, 25 Sep 2015 21:09:24 +0200
Subject: [PATCH] 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
---
 ipaplatform/base/paths.py          |  2 +-
 ipatests/test_integration/tasks.py | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/ipaplatform/base/paths.py b/ipaplatform/base/paths.py
index 215caf90ea1ca4e5db8f43f8f09002ce5d5cd280..a272143d0053451c017c0df613951cc0e6d52c54 100644
--- a/ipaplatform/base/paths.py
+++ b/ipaplatform/base/paths.py
@@ -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
diff --git a/ipatests/test_integration/tasks.py b/ipatests/test_integration/tasks.py
index f579f286826f749a8c5f8433f2a8bf7348664ba9..db10a52e8a68b0104cf6f4c8b29b25a655fa742a 100644
--- a/ipatests/test_integration/tasks.py
+++ b/ipatests/test_integration/tasks.py
@@ -40,6 +40,8 @@ from ipatests.test_integration.host import Host
 
 log = log_mgr.get_logger(__name__)
 
+IPATEST_NM_CONFIG = '20-ipatest-unmanaged-resolv.conf'
+
 
 def prepare_host(host):
     if isinstance(host, Host):
@@ -56,6 +58,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)
 
 
@@ -101,6 +104,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()
@@ -128,6 +163,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])
-- 
2.6.0

From fb8ab435c71f08c6fcb9cc8f4a983a278824de44 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Milan=20Kub=C3=ADk?= <mku...@redhat.com>
Date: Fri, 25 Sep 2015 21:09:24 +0200
Subject: [PATCH] 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
---
 ipaplatform/base/paths.py          |  2 +-
 ipatests/test_integration/tasks.py | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/ipaplatform/base/paths.py b/ipaplatform/base/paths.py
index 215caf90ea1ca4e5db8f43f8f09002ce5d5cd280..a272143d0053451c017c0df613951cc0e6d52c54 100644
--- a/ipaplatform/base/paths.py
+++ b/ipaplatform/base/paths.py
@@ -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
diff --git a/ipatests/test_integration/tasks.py b/ipatests/test_integration/tasks.py
index 06049d4ae01332e0af4d8775b745342406fc868d..1b0d2b8679a2c588498ab01cd87d363eb4ab8e2f 100644
--- a/ipatests/test_integration/tasks.py
+++ b/ipatests/test_integration/tasks.py
@@ -40,6 +40,8 @@ from ipatests.test_integration.host import Host
 
 log = log_mgr.get_logger(__name__)
 
+IPATEST_NM_CONFIG = '20-ipatest-unmanaged-resolv.conf'
+
 
 def check_arguments_are(slice, instanceof):
     """
@@ -74,6 +76,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)
 
 
@@ -119,6 +122,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()
@@ -147,6 +182,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])
-- 
2.6.0

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to