From 4d5151cceea8d9c1472d235994c2938687f3c869 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 9 Aug 2011 17:32:29 +0530 Subject: Enhanced error handling and written appropriate execution error into stderr. --- .../WebContent/scripts/Utils.py | 2 ++ .../WebContent/scripts/add_user_cifs_all.py | 1 + .../WebContent/scripts/create_volume_cifs_all.py | 1 + .../WebContent/scripts/delete_user_cifs_all.py | 1 + .../WebContent/scripts/delete_volume_cifs_all.py | 1 + .../WebContent/scripts/get_volume_user_cifs.py | 1 + .../WebContent/scripts/grun.py | 8 +++++--- .../WebContent/scripts/setup_cifs_config_all.py | 7 +++++-- .../WebContent/scripts/update_volume_cifs_all.py | 1 + 9 files changed, 18 insertions(+), 5 deletions(-) (limited to 'src/com.gluster.storage.management.gateway/WebContent/scripts') diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/Utils.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/Utils.py index 82f8b7b6..bcc6f177 100644 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/Utils.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/Utils.py @@ -1059,6 +1059,8 @@ def log(priority, message=None): def stripEmptyLines(content): + if not content: + return "" ret = "" for line in content.split("\n"): if line.strip() != "": diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py index f1e899ec..b9fcaf6d 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py @@ -87,6 +87,7 @@ def main(): if rv == 0: if not setUid(uid, userName): + sys.stderr.write("Failed to update user uid\n") sys.exit(11) sys.exit(rv) diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/create_volume_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/create_volume_cifs_all.py index 80b6da7c..b327580c 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/create_volume_cifs_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/create_volume_cifs_all.py @@ -51,6 +51,7 @@ def main(): rv = Utils.runCommand(["grun.py", serverFile, "create_volume_cifs.py", volumeName] + userList) if rv == 0: if not addVolumeCifsConf(volumeName, userList): + sys.stderr.write("Unable to update volume cifs configuration\n") sys.exit(11) sys.exit(rv) diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_user_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_user_cifs_all.py index d414fc2c..a6bf15dc 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_user_cifs_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_user_cifs_all.py @@ -51,6 +51,7 @@ def main(): rv = Utils.runCommand("grun.py %s delete_user_cifs.py %s" % (serverList, userName)) if rv == 0: if not removeUser(userName): + sys.stderr.write("Failed to remove user\n") sys.exit(10) sys.exit(rv) diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_volume_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_volume_cifs_all.py index b41e3d65..2e2b8db3 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_volume_cifs_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_volume_cifs_all.py @@ -49,6 +49,7 @@ def main(): rv = Utils.runCommand(["grun.py", serverFile, "delete_volume_cifs.py", volumeName]) if rv == 0: if not removeVolumeCifsConf(volumeName): + sys.stderr.write("Failed to remove volume cifs config file\n") sys.exit(11) sys.exit(rv) diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/get_volume_user_cifs.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/get_volume_user_cifs.py index 55821b60..33de3bf1 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/get_volume_user_cifs.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/get_volume_user_cifs.py @@ -40,6 +40,7 @@ def main(): sys.exit(0) except IOError, e: Utils.log("failed to read file %s: %s" % (cifsVolumeFile, str(e))) + sys.stderr.write("Failed to read cifs-volume-file %s: %s\n" % (cifsVolumeFile, str(e))) sys.exit(2) diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/grun.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/grun.py index e09ef5bc..cc00f466 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/grun.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/grun.py @@ -33,13 +33,15 @@ def main(): fp.close() except IOError, e: Utils.log("Failed to read server file %s: %s\n" % (serverFile, str(e))) + sys.stderr.write("Failed to read server file %s: %s\n" % (serverFile, str(e))) sys.exit(1) status = True for serverName in serverNameList: - rv = Utils.runCommand(sshCommandPrefix + [serverName.strip()] + command) - print "%s: %s" % (serverName, rv) - if rv != 0: + rv = Utils.runCommand(sshCommandPrefix + [serverName.strip()] + command, output=True) + if rv["Status"] != 0: + sys.stderr.write("%s: %s\nStdout:\n%s\nStderr:%s\n---\n" \ + % (serverName, rv["Status"], rv["Stdout"], rv["Stderr"])) status = False if status: diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/setup_cifs_config_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/setup_cifs_config_all.py index 8dd59c8c..657f05f7 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/setup_cifs_config_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/setup_cifs_config_all.py @@ -21,8 +21,11 @@ def main(): serverFile = sys.argv[1] - rv = Utils.runCommand(["grun.py", serverFile, "setup_cifs_config.py"]) - sys.exit(rv) + rv = Utils.runCommand(["grun.py", serverFile, "setup_cifs_config.py"], output=True) + if status["Status"] != 0: + sys.stderr.write("%s %s\n" % (Utils.stripEmptyLines(rv["Stderr"]), Utils.stripEmptyLines(rv["Stdout"]))) + sys.exit(-1) + sys.exit(0) if __name__ == "__main__": diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/update_volume_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/update_volume_cifs_all.py index a4d424b3..e2ea9ac2 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/update_volume_cifs_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/update_volume_cifs_all.py @@ -52,6 +52,7 @@ def main(): rv = Utils.runCommand(["grun.py", serverFile, "update_volume_cifs.py", volumeName] + userList) if rv == 0: if not updateVolumeCifsConf(volumeName, userList): + sys.stderr.write("Unable to update volume cifs configuration\n") sys.exit(11) sys.exit(rv) -- cgit From 99453fd4bd9975eeaa7616cbe2d4d47e01da3dde Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 9 Aug 2011 18:11:30 +0530 Subject: Revert "Enhanced error handling and written appropriate execution error into stderr." This reverts commit 36d1fa53d62f4c3f458b0fac58968b6fab6a271f. --- .../WebContent/scripts/Utils.py | 2 -- .../WebContent/scripts/add_user_cifs_all.py | 1 - .../WebContent/scripts/create_volume_cifs_all.py | 1 - .../WebContent/scripts/delete_user_cifs_all.py | 1 - .../WebContent/scripts/delete_volume_cifs_all.py | 1 - .../WebContent/scripts/get_volume_user_cifs.py | 1 - .../WebContent/scripts/grun.py | 8 +++----- .../WebContent/scripts/setup_cifs_config_all.py | 7 ++----- .../WebContent/scripts/update_volume_cifs_all.py | 1 - 9 files changed, 5 insertions(+), 18 deletions(-) (limited to 'src/com.gluster.storage.management.gateway/WebContent/scripts') diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/Utils.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/Utils.py index bcc6f177..82f8b7b6 100644 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/Utils.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/Utils.py @@ -1059,8 +1059,6 @@ def log(priority, message=None): def stripEmptyLines(content): - if not content: - return "" ret = "" for line in content.split("\n"): if line.strip() != "": diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py index b9fcaf6d..f1e899ec 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py @@ -87,7 +87,6 @@ def main(): if rv == 0: if not setUid(uid, userName): - sys.stderr.write("Failed to update user uid\n") sys.exit(11) sys.exit(rv) diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/create_volume_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/create_volume_cifs_all.py index b327580c..80b6da7c 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/create_volume_cifs_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/create_volume_cifs_all.py @@ -51,7 +51,6 @@ def main(): rv = Utils.runCommand(["grun.py", serverFile, "create_volume_cifs.py", volumeName] + userList) if rv == 0: if not addVolumeCifsConf(volumeName, userList): - sys.stderr.write("Unable to update volume cifs configuration\n") sys.exit(11) sys.exit(rv) diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_user_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_user_cifs_all.py index a6bf15dc..d414fc2c 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_user_cifs_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_user_cifs_all.py @@ -51,7 +51,6 @@ def main(): rv = Utils.runCommand("grun.py %s delete_user_cifs.py %s" % (serverList, userName)) if rv == 0: if not removeUser(userName): - sys.stderr.write("Failed to remove user\n") sys.exit(10) sys.exit(rv) diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_volume_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_volume_cifs_all.py index 2e2b8db3..b41e3d65 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_volume_cifs_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_volume_cifs_all.py @@ -49,7 +49,6 @@ def main(): rv = Utils.runCommand(["grun.py", serverFile, "delete_volume_cifs.py", volumeName]) if rv == 0: if not removeVolumeCifsConf(volumeName): - sys.stderr.write("Failed to remove volume cifs config file\n") sys.exit(11) sys.exit(rv) diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/get_volume_user_cifs.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/get_volume_user_cifs.py index 33de3bf1..55821b60 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/get_volume_user_cifs.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/get_volume_user_cifs.py @@ -40,7 +40,6 @@ def main(): sys.exit(0) except IOError, e: Utils.log("failed to read file %s: %s" % (cifsVolumeFile, str(e))) - sys.stderr.write("Failed to read cifs-volume-file %s: %s\n" % (cifsVolumeFile, str(e))) sys.exit(2) diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/grun.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/grun.py index cc00f466..e09ef5bc 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/grun.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/grun.py @@ -33,15 +33,13 @@ def main(): fp.close() except IOError, e: Utils.log("Failed to read server file %s: %s\n" % (serverFile, str(e))) - sys.stderr.write("Failed to read server file %s: %s\n" % (serverFile, str(e))) sys.exit(1) status = True for serverName in serverNameList: - rv = Utils.runCommand(sshCommandPrefix + [serverName.strip()] + command, output=True) - if rv["Status"] != 0: - sys.stderr.write("%s: %s\nStdout:\n%s\nStderr:%s\n---\n" \ - % (serverName, rv["Status"], rv["Stdout"], rv["Stderr"])) + rv = Utils.runCommand(sshCommandPrefix + [serverName.strip()] + command) + print "%s: %s" % (serverName, rv) + if rv != 0: status = False if status: diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/setup_cifs_config_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/setup_cifs_config_all.py index 657f05f7..8dd59c8c 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/setup_cifs_config_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/setup_cifs_config_all.py @@ -21,11 +21,8 @@ def main(): serverFile = sys.argv[1] - rv = Utils.runCommand(["grun.py", serverFile, "setup_cifs_config.py"], output=True) - if status["Status"] != 0: - sys.stderr.write("%s %s\n" % (Utils.stripEmptyLines(rv["Stderr"]), Utils.stripEmptyLines(rv["Stdout"]))) - sys.exit(-1) - sys.exit(0) + rv = Utils.runCommand(["grun.py", serverFile, "setup_cifs_config.py"]) + sys.exit(rv) if __name__ == "__main__": diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/update_volume_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/update_volume_cifs_all.py index e2ea9ac2..a4d424b3 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/update_volume_cifs_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/update_volume_cifs_all.py @@ -52,7 +52,6 @@ def main(): rv = Utils.runCommand(["grun.py", serverFile, "update_volume_cifs.py", volumeName] + userList) if rv == 0: if not updateVolumeCifsConf(volumeName, userList): - sys.stderr.write("Unable to update volume cifs configuration\n") sys.exit(11) sys.exit(rv) -- cgit From 1a2fd8fa98e300ec6c95febaf537b88ce32babd1 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 9 Aug 2011 19:03:53 +0530 Subject: Enhanced cifs functions to write errors into stderr. --- .../WebContent/scripts/add_user_cifs_all.py | 1 + .../WebContent/scripts/create_volume_cifs_all.py | 1 + .../WebContent/scripts/delete_user_cifs_all.py | 3 ++- .../WebContent/scripts/delete_volume_cifs_all.py | 1 + .../WebContent/scripts/get_volume_user_cifs.py | 1 + .../WebContent/scripts/grun.py | 10 +++++++--- .../WebContent/scripts/update_volume_cifs_all.py | 1 + 7 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src/com.gluster.storage.management.gateway/WebContent/scripts') diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py index f1e899ec..8e25ea5a 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py @@ -87,6 +87,7 @@ def main(): if rv == 0: if not setUid(uid, userName): + sys.stderr.write("Failed to add the user\n") sys.exit(11) sys.exit(rv) diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/create_volume_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/create_volume_cifs_all.py index 80b6da7c..61eaaa97 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/create_volume_cifs_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/create_volume_cifs_all.py @@ -51,6 +51,7 @@ def main(): rv = Utils.runCommand(["grun.py", serverFile, "create_volume_cifs.py", volumeName] + userList) if rv == 0: if not addVolumeCifsConf(volumeName, userList): + sys.stderr.write("Failed to add volume and user-list in cifs volume configuration\n") sys.exit(11) sys.exit(rv) diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_user_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_user_cifs_all.py index d414fc2c..a07eeae4 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_user_cifs_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_user_cifs_all.py @@ -51,7 +51,8 @@ def main(): rv = Utils.runCommand("grun.py %s delete_user_cifs.py %s" % (serverList, userName)) if rv == 0: if not removeUser(userName): - sys.exit(10) + Utils.log(("Failed to remove the user:%s on gateway server\n" % userName) + sys.exit(0) sys.exit(rv) diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_volume_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_volume_cifs_all.py index b41e3d65..26c654da 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_volume_cifs_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/delete_volume_cifs_all.py @@ -49,6 +49,7 @@ def main(): rv = Utils.runCommand(["grun.py", serverFile, "delete_volume_cifs.py", volumeName]) if rv == 0: if not removeVolumeCifsConf(volumeName): + sys.stderr.write("Failed to remove volume and user-list in cifs volume configuration\n") sys.exit(11) sys.exit(rv) diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/get_volume_user_cifs.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/get_volume_user_cifs.py index 55821b60..33de3bf1 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/get_volume_user_cifs.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/get_volume_user_cifs.py @@ -40,6 +40,7 @@ def main(): sys.exit(0) except IOError, e: Utils.log("failed to read file %s: %s" % (cifsVolumeFile, str(e))) + sys.stderr.write("Failed to read cifs-volume-file %s: %s\n" % (cifsVolumeFile, str(e))) sys.exit(2) diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/grun.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/grun.py index e09ef5bc..47477ce8 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/grun.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/grun.py @@ -33,13 +33,17 @@ def main(): fp.close() except IOError, e: Utils.log("Failed to read server file %s: %s\n" % (serverFile, str(e))) + sys.stderr.write("Failed to read server file %s: %s\n" % (serverFile, str(e))) sys.exit(1) status = True for serverName in serverNameList: - rv = Utils.runCommand(sshCommandPrefix + [serverName.strip()] + command) - print "%s: %s" % (serverName, rv) - if rv != 0: + rv = Utils.runCommand(sshCommandPrefix + [serverName.strip()] + command, output=True) + if rv["Status"] != 0: + sys.stderr.write("%s: %s\n" % (serverName, rv["Status"])) + sys.stderr.write("Stdout:\n%s\n" % rv["Stdout"])) + sys.stderr.write("Stderr:\n%s\n" % rv["Stderr"])) + sys.stderr.write("---\n") status = False if status: diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/update_volume_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/update_volume_cifs_all.py index a4d424b3..184e30b6 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/update_volume_cifs_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/update_volume_cifs_all.py @@ -52,6 +52,7 @@ def main(): rv = Utils.runCommand(["grun.py", serverFile, "update_volume_cifs.py", volumeName] + userList) if rv == 0: if not updateVolumeCifsConf(volumeName, userList): + sys.stderr.write("Failed to update volume and user-list in cifs volume configuration\n") sys.exit(11) sys.exit(rv) -- cgit