diff options
author | Tim <timothyasir@gluster.com> | 2011-08-10 13:16:43 +0530 |
---|---|---|
committer | Tim <timothyasir@gluster.com> | 2011-08-10 13:29:54 +0530 |
commit | 1811ec9c6177feebff19e5e02a1b26a942d3dcf8 (patch) | |
tree | 36115248e07bfa1fa8f1ab409801c392c34d89b1 | |
parent | 578247d221b3aea335c4b883a6655cca5ec831b2 (diff) |
Bug 3374 - [CIFS] updating volume with a non-existent user succeeds.
Added checks to find non-existing user/s
Moved CIFS_VOLUME_FILE, CIFS_USER_FILE, DEFAULT_UID to Globals.py
Added getCifsUserUid function into Utils.py
Fixed typo in grun.py
11 files changed, 96 insertions, 52 deletions
diff --git a/src/com.gluster.storage.management.gateway.scripts/src/Globals.py b/src/com.gluster.storage.management.gateway.scripts/src/Globals.py index d5cb1ae0..cfab83b6 100644 --- a/src/com.gluster.storage.management.gateway.scripts/src/Globals.py +++ b/src/com.gluster.storage.management.gateway.scripts/src/Globals.py @@ -22,7 +22,7 @@ GLUSTER_PROBE_VERSION = "1.0.0" DEFAULT_BUFSIZE = 1024 SERVER_PORT = 24731 DEFAULT_BACKLOG = 5 -DEFAULT_TIMEOUT = 5 +DEFAULT_TIMEOUT = 3 DEFAULT_ID_LENGTH = 16 GLUSTER_PLATFORM_VERSION = "3.2" @@ -129,3 +129,7 @@ VERSION_DICTONARY = {} AWS_WEB_SERVICE_URL = "http://169.254.169.254/latest" REAL_SAMBA_CONF_FILE = "/etc/samba/real.smb.conf" + +DEFAULT_UID = 1024000 +CIFS_USER_FILE = "/opt/glustermg/etc/users.cifs" +CIFS_VOLUME_FILE = "/opt/glustermg/etc/volumes.cifs" diff --git a/src/com.gluster.storage.management.gateway.scripts/src/Utils.py b/src/com.gluster.storage.management.gateway.scripts/src/Utils.py index 82f8b7b6..be5df757 100644 --- a/src/com.gluster.storage.management.gateway.scripts/src/Utils.py +++ b/src/com.gluster.storage.management.gateway.scripts/src/Utils.py @@ -1084,3 +1084,18 @@ def getGlusterVersion(): if not rv["Stdout"]: return None return rv["Stdout"].strip().split()[1] + +def getCifsUserUid(userName): + try: + fp = open(Globals.CIFS_USER_FILE) + content = fp.read() + fp.close() + except IOError, e: + Utils.log("failed to read file %s: %s" % (Globals.CIFS_USER_FILE, str(e))) + return False + + for line in content.strip().split(): + tokens = line.split(":") + if tokens[1] == userName: + return int(tokens[0]) + return None diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/Globals.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/Globals.py index 89d3d098..cfab83b6 100644 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/Globals.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/Globals.py @@ -129,3 +129,7 @@ VERSION_DICTONARY = {} AWS_WEB_SERVICE_URL = "http://169.254.169.254/latest" REAL_SAMBA_CONF_FILE = "/etc/samba/real.smb.conf" + +DEFAULT_UID = 1024000 +CIFS_USER_FILE = "/opt/glustermg/etc/users.cifs" +CIFS_VOLUME_FILE = "/opt/glustermg/etc/volumes.cifs" 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..be5df757 100644 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/Utils.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/Utils.py @@ -1084,3 +1084,18 @@ def getGlusterVersion(): if not rv["Stdout"]: return None return rv["Stdout"].strip().split()[1] + +def getCifsUserUid(userName): + try: + fp = open(Globals.CIFS_USER_FILE) + content = fp.read() + fp.close() + except IOError, e: + Utils.log("failed to read file %s: %s" % (Globals.CIFS_USER_FILE, str(e))) + return False + + for line in content.strip().split(): + tokens = line.split(":") + if tokens[1] == userName: + return int(tokens[0]) + return None 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 40ad5228..525bb596 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 @@ -11,20 +11,17 @@ if not p1 in sys.path: sys.path.append(p1) if not p2 in sys.path: sys.path.append(p2) +import Globals import Utils -defaultUid = 1024000 -cifsUserFile = "/opt/glustermg/etc/users.cifs" - - def getUid(userName): try: - fp = open(cifsUserFile) + fp = open(Globals.CIFS_USER_FILE) content = fp.read() fp.close() except IOError, e: - Utils.log("failed to read file %s: %s" % (cifsUserFile, str(e))) + Utils.log("failed to read file %s: %s" % (Globals.CIFS_USER_FILE, str(e))) return False for line in content.strip().split(): @@ -35,30 +32,30 @@ def getUid(userName): def getLastUid(): - if not os.path.exists(cifsUserFile): - return defaultUid + if not os.path.exists(Globals.CIFS_USER_FILE): + return Globals.DEFAULTUID try: - fp = open(cifsUserFile) + fp = open(Globals.CIFS_USER_FILE) content = fp.read() fp.close() except IOError, e: - Utils.log("failed to read file %s: %s" % (cifsUserFile, str(e))) + Utils.log("failed to read file %s: %s" % (Globals.CIFS_USER_FILE, str(e))) return False lines = content.strip().split() if not lines: - return defaultUid + return Globals.DEFAULTUID return int(lines[-1].split(":")[0]) def setUid(uid, userName): try: - fp = open(cifsUserFile, "a") + fp = open(Globals.CIFS_USER_FILE, "a") fp.write("%s:%s\n" % (uid, userName)) fp.close() return True except IOError, e: - Utils.log("failed to write file %s: %s" % (cifsUserFile, str(e))) + Utils.log("failed to write file %s: %s" % (Globals.CIFS_USER_FILE, str(e))) return False 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 70b84e6b..59e74bed 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 @@ -11,30 +11,28 @@ if not p1 in sys.path: sys.path.append(p1) if not p2 in sys.path: sys.path.append(p2) +import Globals import Utils -cifsVolumeFile = "/opt/glustermg/etc/volumes.cifs" - - def addVolumeCifsConf(volumeName, userList): try: - fp = open(cifsVolumeFile) + fp = open(Globals.CIFS_VOLUME_FILE) content = fp.read() fp.close() except IOError, e: - Utils.log("failed to read file %s: %s" % (cifsVolumeFile, str(e))) + Utils.log("failed to read file %s: %s" % (Globals.CIFS_VOLUME_FILE, str(e))) content = "" try: - fp = open(cifsVolumeFile, "w") + fp = open(Globals.CIFS_VOLUME_FILE, "w") for line in content.split(): if line.split(":")[0] != volumeName: fp.write("%s\n" % line) fp.write("%s:%s\n" % (volumeName, ":".join(userList))) fp.close() except IOError, e: - Utils.log("failed to write file %s: %s" % (cifsVolumeFile, str(e))) + Utils.log("failed to write file %s: %s" % (Globals.CIFS_VOLUME_FILE, str(e))) return False return True @@ -48,6 +46,15 @@ def main(): volumeName = sys.argv[2] userList = sys.argv[3:] + missingUserList = [] + for userName in userList: + if not Utils.getCifsUserUid(userName): + missingUserList.append(userName) + + if missingUserList: + sys.stderr.write("User %s does not exists\n" % missingUserList) + sys.exit(1) + rv = Utils.runCommand(["grun.py", serverFile, "create_volume_cifs.py", volumeName] + userList) if rv == 0: if not addVolumeCifsConf(volumeName, userList): 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 a07eeae4..3c68891c 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 @@ -11,23 +11,21 @@ if not p1 in sys.path: sys.path.append(p1) if not p2 in sys.path: sys.path.append(p2) +import Globals import Utils -cifsUserFile = "/opt/glustermg/etc/users.cifs" - - def removeUser(userName): try: - fp = open(cifsUserFile) + fp = open(Globals.CIFS_USER_FILE) content = fp.read() fp.close() except IOError, e: - Utils.log("failed to read file %s: %s" % (cifsUserFile, str(e))) + Utils.log("failed to read file %s: %s" % (Globals.CIFS_USER_FILE, str(e))) return False try: - fp = open(cifsUserFile, "w") + fp = open(Globals.CIFS_USER_FILE, "w") lines = content.strip().split() for line in lines: if line.split(":")[1] == userName: @@ -35,7 +33,7 @@ def removeUser(userName): fp.write("%s\n" % line) fp.close() except IOError, e: - Utils.log("failed to write file %s: %s" % (cifsUserFile, str(e))) + Utils.log("failed to write file %s: %s" % (Globals.CIFS_USER_FILE, str(e))) return False return True @@ -51,7 +49,7 @@ def main(): rv = Utils.runCommand("grun.py %s delete_user_cifs.py %s" % (serverList, userName)) if rv == 0: if not removeUser(userName): - Utils.log(("Failed to remove the user:%s on gateway server\n" % userName) + 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 d51e647d..3456b92d 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 @@ -11,29 +11,27 @@ if not p1 in sys.path: sys.path.append(p1) if not p2 in sys.path: sys.path.append(p2) +import Globals import Utils -cifsVolumeFile = "/opt/glustermg/etc/volumes.cifs" - - def removeVolumeCifsConf(volumeName): try: - fp = open(cifsVolumeFile) + fp = open(Globals.CIFS_VOLUME_FILE) content = fp.read() fp.close() except IOError, e: - Utils.log("failed to read file %s: %s" % (cifsVolumeFile, str(e))) + Utils.log("failed to read file %s: %s" % (Globals.CIFS_VOLUME_FILE, str(e))) content = "" try: - fp = open(cifsVolumeFile, "w") + fp = open(Globals.CIFS_VOLUME_FILE, "w") for line in content.split(): if line.split(":")[0] != volumeName: fp.write("%s\n" % line) fp.close() except IOError, e: - Utils.log("failed to write file %s: %s" % (cifsVolumeFile, str(e))) + Utils.log("failed to write file %s: %s" % (Globals.CIFS_VOLUME_FILE, str(e))) return False return True 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..c385633e 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 @@ -11,12 +11,10 @@ if not p1 in sys.path: sys.path.append(p1) if not p2 in sys.path: sys.path.append(p2) +import Globals import Utils -cifsVolumeFile = "/opt/glustermg/etc/volumes.cifs" - - def main(): if len(sys.argv) < 2: sys.stderr.write("usage: %s VOLUME_NAME\n" % os.path.basename(sys.argv[0])) @@ -24,11 +22,11 @@ def main(): volumeName = sys.argv[1] - if not os.path.exists(cifsVolumeFile): + if not os.path.exists(Globals.CIFS_VOLUME_FILE): sys.exit(0) try: - fp = open(cifsVolumeFile) + fp = open(Globals.CIFS_VOLUME_FILE) content = fp.read() fp.close() for line in content.split(): @@ -39,8 +37,8 @@ def main(): # given volume is not configured for cifs export 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))) + Utils.log("failed to read file %s: %s" % (Globals.CIFS_VOLUME_FILE, str(e))) + sys.stderr.write("Failed to read cifs-volume-file %s: %s\n" % (Globals.CIFS_VOLUME_FILE, 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 47477ce8..f2e2d944 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/grun.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/grun.py @@ -41,8 +41,8 @@ def main(): 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("Stdout:\n%s\n" % rv["Stdout"]) + sys.stderr.write("Stderr:\n%s\n" % rv["Stderr"]) sys.stderr.write("---\n") status = False 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 6a0be968..c5c9d1ef 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 @@ -11,23 +11,21 @@ if not p1 in sys.path: sys.path.append(p1) if not p2 in sys.path: sys.path.append(p2) +import Globals import Utils -cifsVolumeFile = "/opt/glustermg/etc/volumes.cifs" - - def updateVolumeCifsConf(volumeName, userList): try: - fp = open(cifsVolumeFile) + fp = open(Globals.CIFS_VOLUME_FILE) content = fp.read() fp.close() except IOError, e: - Utils.log("failed to read file %s: %s" % (cifsVolumeFile, str(e))) + Utils.log("failed to read file %s: %s" % (Globals.CIFS_VOLUME_FILE, str(e))) return False try: - fp = open(cifsVolumeFile, "w") + fp = open(Globals.CIFS_VOLUME_FILE, "w") for line in content.split(): if line.split(":")[0] == volumeName: fp.write("%s:%s\n" % (volumeName, ":".join(userList))) @@ -35,7 +33,7 @@ def updateVolumeCifsConf(volumeName, userList): fp.write("%s\n" % line) fp.close() except IOError, e: - Utils.log("failed to write file %s: %s" % (cifsVolumeFile, str(e))) + Utils.log("failed to write file %s: %s" % (Globals.CIFS_VOLUME_FILE, str(e))) return False return True @@ -49,6 +47,16 @@ def main(): volumeName = sys.argv[2] userList = sys.argv[3:] + missingUserList = [] + for userName in userList: + if not Utils.getCifsUserUid(userName): + missingUserList.append(userName) + + if missingUserList: + sys.stderr.write("User %s does not exists\n" % missingUserList) + sys.exit(1) + + rv = Utils.runCommand(["grun.py", serverFile, "update_volume_cifs.py", volumeName] + userList) if rv == 0: if not updateVolumeCifsConf(volumeName, userList): |