Sandro Bonazzola has uploaded a new change for review. Change subject: packaging: allow interactive NFS exports cleanup during engine-cleanup ......................................................................
packaging: allow interactive NFS exports cleanup during engine-cleanup When running engine-cleanup the user will be asked for removing any configuration made by engine-setup in /etc/exports and for removing the directories that were previously exported. Change-Id: I0548ab358d0cbed32ceff3ceacefc57f1c068df4 Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=904149 Signed-off-by: Sandro Bonazzola <sbona...@redhat.com> --- M packaging/fedora/setup/engine-cleanup.py M packaging/fedora/setup/nfsutils.py 2 files changed, 53 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/48/11548/1 diff --git a/packaging/fedora/setup/engine-cleanup.py b/packaging/fedora/setup/engine-cleanup.py index 1b9e156..f38474e 100755 --- a/packaging/fedora/setup/engine-cleanup.py +++ b/packaging/fedora/setup/engine-cleanup.py @@ -13,6 +13,7 @@ import common_utils as utils import types import basedefs +import nfsutils # Consts BASE_NAME = "ovirt-engine" @@ -65,6 +66,11 @@ In addition, all existing DB connections will be closed." % (PROD_NAME) MSG_PROCEED_QUESTION = "Would you like to proceed" +MSG_INFO_CLEANING_NFS="Cleaning NFS Exports\n" +MSG_CLEAN_NFS_EXPORTS_QUESTION="Would you like to remove %s configuration from \ +%s" % (basedefs.APP_NAME, basedefs.FILE_ETC_EXPORTS) +MSG_CLEAN_NFS_EXPORTED_DIRS_QUESTION="Would you like to remove the following \ +directories:\n%s\n" #global err msg list err_messages = [] @@ -141,6 +147,29 @@ else: logging.debug("User chose to exit") return False + + +def cleanNFSExports(): + answer = askYesNo(MSG_CLEAN_NFS_EXPORTS_QUESTION) + if not answer: + logging.debug("User chose to not clean NFS exports") + return False + logging.debug("User chose to clean NFS exports") + removed = nfsutils.cleanNfsExports(" %s installer" % basedefs.APP_NAME) + if len(removed) == 0: + return True + path_list = "" + for p in removed: + path_list += "- %s\n" % p + answer = askYesNo(MSG_CLEAN_NFS_EXPORTED_DIRS_QUESTION % path_list) + if not answer: + logging.debug("User chose to not clean NFS exported directories") + return False + logging.debug("User chose to clean NFS exported directories") + for p in removed: + logging.debug("Removing directory %s" % p) + shutil.rmtree(p) + return True def initLogging(): @@ -414,6 +443,9 @@ # Stop notifierd service runFunc(stopNotifier, MSG_INFO_STOP_NOTIFIERD) + # Clean NFS exports + runFunc(cleanNFSExports, MSG_INFO_CLEANING_NFS) + if len(err_messages) == 0: print MSG_INFO_CLEANUP_OK else: diff --git a/packaging/fedora/setup/nfsutils.py b/packaging/fedora/setup/nfsutils.py index e904f2e..110ea6d 100644 --- a/packaging/fedora/setup/nfsutils.py +++ b/packaging/fedora/setup/nfsutils.py @@ -32,6 +32,27 @@ finally: exportFile.close() + +def cleanNfsExports(comment, exportFilePath=basedefs.FILE_ETC_EXPORTS): + """ + Remove all the lines added by engine-setup marked by comment from + exportFilePath. + """ + removed_exports = [] + with open(exportFilePath, "r+") as exportFile: + lines = exportFile.readlines() + exportFile.seek(0, os.SEEK_SET) + for line in lines: + if line.find(comment) != -1: + logging.debug("removing %s from %s" % (line, exportFilePath)) + path = line[:line.find("\t")] + removed_exports.append(path) + continue + exportFile.write(line) + exportFile.truncate() + return removed_exports + + def setSELinuxContextForDir(path, contextName): logging.debug("setting selinux context for %s" % path) if path.endswith("/"): -- To view, visit http://gerrit.ovirt.org/11548 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0548ab358d0cbed32ceff3ceacefc57f1c068df4 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Sandro Bonazzola <sbona...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches