Yedidyah Bar David has uploaded a new change for review. Change subject: packaging: setup: Overwrite iso nfs export only if new ......................................................................
packaging: setup: Overwrite iso nfs export only if new Only overwrite the nfs export line for the iso domain if the domain did not exist before this run. Only move the export line from /etc/exports to /etc/exports.d for an existing domain. Bug-Url: https://bugzilla.redhat.com/1058018 Change-Id: Ia12c50b30c5df9f0da446ddbbf54c7ca73b7dd3d Signed-off-by: Yedidyah Bar David <d...@redhat.com> --- M packaging/setup/plugins/ovirt-engine-setup/ovirt-engine/system/exportfs.py 1 file changed, 65 insertions(+), 33 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/75/23975/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..e3cd565 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 @@ -104,20 +104,71 @@ self._enabled = self.environment[ osetupcons.ConfigEnv.ISO_DOMAIN_NFS_MOUNT_POINT ] is not None + self._exports_content, self._exports_index = ( + self._read_and_find_path( + osetupcons.FileLocations.NFS_EXPORT_FILE, + self.environment[ + osetupcons.ConfigEnv.ISO_DOMAIN_NFS_MOUNT_POINT + ], + ) + ) @plugin.event( stage=plugin.Stages.STAGE_MISC, - condition=lambda self: self._enabled, + condition=lambda self: ( + self._enabled and + self.environment[osetupcons.ConfigEnv.ISO_DOMAIN_EXISTS] and + self._conf == osetupcons.FileLocations.OVIRT_NFS_EXPORT_FILE and + self._exports_index is not None + ), + after=( + osetupcons.Stages.CONFIG_ISO_DOMAIN_AVAILABLE, + ), + ) + def _misc_move_line_to_exports_d(self): + """ + Move export line from /etc/exports to /etc/exports.d + """ + # 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. Mode the + # line from /etc/exports to /etc/exports.d . + # The transactions below do not pass modifiedList + # nor do we call addChanges - we do not revert this + # fix on cleanup. + old_line = self._exports_content.pop(self._exports_index) + self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( + filetransaction.FileTransaction( + name=osetupcons.FileLocations.NFS_EXPORT_FILE, + content=self._exports_content, + ) + ) + new_content = [ + '# The following line was moved to this file from /etc/exports', + '# by engine-setup. Future invocations of engine-setup might', + '# overwrite this file.', + new_line, + ] + self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( + filetransaction.FileTransaction( + name=self._conf, + content=new_content, + ) + ) + + @plugin.event( + stage=plugin.Stages.STAGE_MISC, + condition=lambda self: ( + self._enabled and + not self.environment[osetupcons.ConfigEnv.ISO_DOMAIN_EXISTS] + ), after=( osetupcons.Stages.CONFIG_ISO_DOMAIN_AVAILABLE, ), ) def _misc(self): """ - Assume that if /etc/exports.d exists we have exports.d support. - Always create single exports.d entry for our engine, no matter - what we had before. - In /etc/exports make sure we have our own path. + Export iso domain """ uninstall_files = [] exports_uninstall_group = self.environment[ @@ -131,48 +182,29 @@ group='exportfs', fileList=uninstall_files, ) - path = self.environment[ - osetupcons.ConfigEnv.ISO_DOMAIN_NFS_MOUNT_POINT - ] new_line = '{path}\t{acl}'.format( - path=path, + path=self.environment[ + osetupcons.ConfigEnv.ISO_DOMAIN_NFS_MOUNT_POINT + ], acl=self.environment[ 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: - # 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 - # line from /etc/exports. - # 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] - self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( - filetransaction.FileTransaction( - name=osetupcons.FileLocations.NFS_EXPORT_FILE, - content=exports_content, - ) - ) + # If it's our own exports.d file, overwrite it unconditionally + # with a suitable comment content = [ '# This file is automatically generated by engine-setup.', '# Please do not edit manually.', new_line, ] else: + # It's the general /etc/exports, we have to be more careful. 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/23975 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia12c50b30c5df9f0da446ddbbf54c7ca73b7dd3d 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