URL: https://github.com/freeipa/freeipa/pull/2093
Author: netoarmando
 Title: #2093: ipa-client-install: Update how comments are added by 
ipachangeconf
Action: opened

PR body:
"""
Due to how 'openldap-client' parses its configuration files this patch changes 
how comments are added, moving them to the line above instead of appending to 
the same line.

Issue: https://pagure.io/freeipa/issue/5202
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/2093/head:pr2093
git checkout pr2093
From f170656d03a4d248dadc91e00c98a700feb75ede Mon Sep 17 00:00:00 2001
From: Armando Neto <abiag...@redhat.com>
Date: Tue, 3 Jul 2018 11:00:57 -0300
Subject: [PATCH] ipa-client-install: Update how comments are added by
 ipachangeconf

Due to how 'openldap-client' parses its configuration files this patch
changes how comments are added, moving them to the line above instead
of appending to the same line.

Issue: https://pagure.io/freeipa/issue/5202

Signed-off-by: Armando Neto <abiag...@redhat.com>

Signed-off-by: Armando Neto <abiag...@redhat.com>
---
 ipaclient/install/ipachangeconf.py       |  8 ++++++-
 ipatests/test_install/test_changeconf.py | 36 ++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 ipatests/test_install/test_changeconf.py

diff --git a/ipaclient/install/ipachangeconf.py b/ipaclient/install/ipachangeconf.py
index 7626619817..a156c4afd2 100644
--- a/ipaclient/install/ipachangeconf.py
+++ b/ipaclient/install/ipachangeconf.py
@@ -349,11 +349,17 @@ def mergeOld(self, oldopts, newopts):
                     opts.append(no)
                     continue
                 if no['action'] == 'addifnotset':
+                    opts.append({
+                        'name': 'comment',
+                        'type': 'comment',
+                        'value': self._dump_line(
+                            no['name'], u' modified by IPA'
+                        ),
+                    })
                     opts.append({'name': 'comment', 'type': 'comment',
                                 'value': self._dump_line(no['name'],
                                                          self.dassign,
                                                          no['value'],
-                                                         u' # modified by IPA'
                                                          )})
                     opts.append(o)
                     continue
diff --git a/ipatests/test_install/test_changeconf.py b/ipatests/test_install/test_changeconf.py
new file mode 100644
index 0000000000..36582ff145
--- /dev/null
+++ b/ipatests/test_install/test_changeconf.py
@@ -0,0 +1,36 @@
+# Copyright (C) 2018  FreeIPA Contributors see COPYING for license
+
+from __future__ import absolute_import
+
+import pytest
+from ipaclient.install.ipachangeconf import IPAChangeConf
+
+
+@pytest.fixture(scope='session')
+def config_file(tmpdir_factory):
+    file = tmpdir_factory.mktemp('data').join('config_file.conf')
+    file.write('VAR_NAME user-defined-value\n')
+    return file
+
+
+def test_addifnotset_action(config_file):
+    """Test if addifnotset action adds a comment about the modified conf."""
+    ipa_conf = IPAChangeConf('IPA Installer Test')
+    ipa_conf.setOptionAssignment(' ')
+
+    opts = [
+        {
+            'action': 'addifnotset',
+            'name': 'VAR_NAME',
+            'type': 'option',
+            'value': 'ipa-modified-value',
+        }
+    ]
+
+    ipa_conf.changeConf(str(config_file), opts)
+
+    assert config_file.readlines() == [
+        '#VAR_NAME modified by IPA\n',
+        '#VAR_NAME ipa-modified-value\n',
+        'VAR_NAME user-defined-value\n',
+    ]
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/freeipa-devel@lists.fedorahosted.org/message/FBZ2JN2UIZYYIWNMYPZOMGYSBXEMIDAW/

Reply via email to