Sandro Bonazzola has uploaded a new change for review.

Change subject: config: avoid to change existing configuration files
......................................................................

config: avoid to change existing configuration files

When reading configurarion files, just warn the user
that there is a deprecated key and warn the user
to fix it, avoiding to change existing configuration
files.
(cherry picked with modifications from
501e97de32a51f5d45db2582bc0bed691d4bf374)

Change-Id: I55c707424524826235f1faba52c0fafd72a27300
Signed-off-by: Sandro Bonazzola <sbona...@redhat.com>
---
M src/__main__.py
1 file changed, 19 insertions(+), 40 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-log-collector 
refs/changes/05/15405/1

diff --git a/src/__main__.py b/src/__main__.py
index 509eb9e..0ef7278 100755
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -270,51 +270,30 @@
                 if opt_value is not None:
                     self[option.dest] = opt_value
 
-    def _upgrade_configs(self, configs):
-        import ConfigParser
-        for configfile in configs:
-            cp = ConfigParser.ConfigParser()
-            cp.read(configfile)
-            try:
-                if cp.has_option('LogCollector', 'rhevm'):
-                    backupfile = "%s-%s" % (
-                        configfile,
-                        datetime.datetime.now().strftime('%Y%m%d%H%M%S')
-                    )
-                    logging.info(
-                        (
-                            'Upgrading {configfile} ; a backup of the old '
-                            'configuration will be saved in {backupfile}'
-                        ).format(
-                            configfile=configfile,
-                            backupfile=backupfile
-                        )
-                    )
-                    shutil.move(configfile, backupfile)
-                    cp.set(
-                        'LogCollector',
-                        'engine',
-                        cp.get('LogCollector', 'rhevm')
-                    )
-                    cp.remove_option('LogCollector', 'rhevm')
-                    with open(configfile, 'w') as f:
-                        cp.write(f)
-            except ConfigParser.NoSectionError:
-                pass
-            except IOError as e:
-                logging.error(
-                    'Failed to upgrade {filename}: {error}'.format(
-                        filename=configfile,
-                        error=e,
-                    )
-                )
-
     def from_file(self, filename):
         import ConfigParser
-        self._upgrade_configs([filename])
         cp = ConfigParser.ConfigParser()
         cp.read(filename)
 
+        #backward compatibility with existing setup
+        if cp.has_option('LogCollector', 'rhevm'):
+            if not cp.has_option('LogCollector', 'engine'):
+                cp.set(
+                    'LogCollector',
+                    'engine',
+                    cp.get('LogCollector', 'rhevm')
+                )
+                logging.warning(
+                    _(
+                        'A deprecated configuration key has been found. '
+                        'Please replace the deprecated key, \'rhevm\', '
+                        'with the new one \'engine\' in {configFiles}'
+                    ).format(
+                        configFiles=filename
+                    )
+                )
+            cp.remove_option('LogCollector', 'rhevm')
+
         # we want the items from the LogCollector section only
         try:
             opts = [


--
To view, visit http://gerrit.ovirt.org/15405
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I55c707424524826235f1faba52c0fafd72a27300
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-log-collector
Gerrit-Branch: ovirt-log-collector-3.2
Gerrit-Owner: Sandro Bonazzola <sbona...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to