Yedidyah Bar David has uploaded a new change for review.

Change subject: packaging: setup: On upgrade use existing NFS export ACL
......................................................................

packaging: setup: On upgrade use existing NFS export ACL

Bug-Url: https://bugzilla.redhat.com/1058018
Change-Id: Ia2672e1caed04d2b6b0c894eaa106949b2df83c3
Signed-off-by: Yedidyah Bar David <d...@redhat.com>
---
M packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/system/exportfs.py
1 file changed, 51 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/36/23736/1

diff --git 
a/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/system/exportfs.py 
b/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/system/exportfs.py
index b129e1b..56d594a 100644
--- a/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/system/exportfs.py
+++ b/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/system/exportfs.py
@@ -46,7 +46,8 @@
             ^
             (?P<path>\S+)
             \s+
-            .*
+            (?P<acl>[^\#]*[^\#\s])
+            (?P<comment>\s*\#.*)?
             $
         """,
     )
@@ -54,6 +55,7 @@
     def _read_and_find_path(self, conf, path):
         index = None
         content = None
+        acl = None
         if os.path.exists(conf):
             with open(conf, 'r') as f:
                 content = f.read().splitlines()
@@ -61,8 +63,9 @@
                 matcher = self._RE_EXPORTS_LINE.match(line)
                 if matcher and matcher.group('path') == path:
                     index = i
+                    acl = matcher.group('acl')
                     break
-        return content, index
+        return content, index, acl
 
     def __init__(self, context):
         super(Plugin, self).__init__(context=context)
@@ -104,6 +107,46 @@
         self._enabled = self.environment[
             osetupcons.ConfigEnv.ISO_DOMAIN_NFS_MOUNT_POINT
         ] is not None
+        path = self.environment[
+            osetupcons.ConfigEnv.ISO_DOMAIN_NFS_MOUNT_POINT
+        ]
+        self._exports_content, self._exports_index, self._exports_acl = (
+            self._read_and_find_path(
+                osetupcons.FileLocations.NFS_EXPORT_FILE,
+                path
+            )
+        )
+        exports_d_content, exports_d_index, exports_d_acl = (
+            self._read_and_find_path(
+                osetupcons.FileLocations.OVIRT_NFS_EXPORT_FILE,
+                path
+            )
+        )
+
+        acl = self.environment[osetupcons.ConfigEnv.ISO_DOMAIN_NFS_ACL]
+        if acl is None:
+            if exports_d_acl is not None and self._exports_acl is None:
+                acl = exports_d_acl
+            elif self._exports_acl is not None and exports_d_acl is None:
+                acl = self._exports_acl
+            elif exports_d_acl is None and self._exports_acl is None:
+                # Unlikely. It means that we did not get acl from user
+                # and also can't find it in any exports file
+                self.logger.error(
+                    _('NFS export ACL not set and not found in exports')
+                )
+            else:
+                # Set in both files! Error too.
+                self.logger.error(
+                    _(
+                        '{path} exported in both {exp} and {exp_d}'
+                    ).format(
+                        path=path,
+                        exp=osetupcons.FileLocations.NFS_EXPORT_FILE,
+                        exp_d=osetupcons.FileLocations.OVIRT_NFS_EXPORT_FILE,
+                    )
+                )
+        self.environment[osetupcons.ConfigEnv.ISO_DOMAIN_NFS_ACL] = acl
 
     @plugin.event(
         stage=plugin.Stages.STAGE_MISC,
@@ -140,14 +183,8 @@
                 osetupcons.ConfigEnv.ISO_DOMAIN_NFS_ACL
             ],
         )
-        exports_content, exports_index = (
-            self._read_and_find_path(
-                osetupcons.FileLocations.NFS_EXPORT_FILE,
-                path
-            )
-        )
         if self._conf == osetupcons.FileLocations.OVIRT_NFS_EXPORT_FILE:
-            if exports_index is not None:
+            if self._exports_index is not None:
                 # This probably means that in a previous setup we added
                 # the path to /etc/exports instead of creating our
                 # own file in /etc/exports.d as we do now. Delete the
@@ -155,11 +192,11 @@
                 # The transaction below does not pass modifiedList
                 # nor do we call addChanges - we do not revert this
                 # fix on cleanup.
-                del exports_content[exports_index]
+                del self._exports_content[self._exports_index]
                 self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append(
                     filetransaction.FileTransaction(
                         name=osetupcons.FileLocations.NFS_EXPORT_FILE,
-                        content=exports_content,
+                        content=self._exports_content,
                     )
                 )
             content = [
@@ -169,10 +206,10 @@
             ]
         else:
             changes = {'added': new_line}
-            if exports_index is not None:
-                old_line = exports_content.pop(exports_index)
+            if self._exports_index is not None:
+                old_line = self._exports_content.pop(self._exports_index)
                 changes['removed'] = old_line
-            content = exports_content
+            content = self._exports_content
             content.append(new_line)
             exports_uninstall_group.addChanges(
                 group='exportfs',


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia2672e1caed04d2b6b0c894eaa106949b2df83c3
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Yedidyah Bar David <d...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to